[seam-commits] Seam SVN: r13416 - modules/persistence/trunk/src/main/java/org/jboss/seam/transaction.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Fri Jul 16 19:46:41 EDT 2010
Author: swd847
Date: 2010-07-16 19:46:40 -0400 (Fri, 16 Jul 2010)
New Revision: 13416
Added:
modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/TransactionQualifier.java
Modified:
modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/Transaction.java
modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/TransactionExtension.java
Log:
make transactions use @ManagedProducer
Modified: modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/Transaction.java
===================================================================
--- modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/Transaction.java 2010-07-16 22:31:47 UTC (rev 13415)
+++ modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/Transaction.java 2010-07-16 23:46:40 UTC (rev 13416)
@@ -6,12 +6,15 @@
import javax.naming.NameNotFoundException;
import javax.naming.NamingException;
+import org.jboss.weld.extensions.managedproducer.ManagedProducer;
+
/**
* Supports injection of a Seam UserTransaction object that wraps the current
* JTA transaction or EJB container managed transaction.
*
* @author Mike Youngstrom
* @author Gavin King
+ * @author Stuart Douglas
*
*/
@ApplicationScoped
@@ -21,6 +24,8 @@
@Inject
Synchronizations synchronizations;
+ @ManagedProducer
+ @TransactionQualifier
public UserTransaction getTransaction() throws NamingException
{
try
Modified: modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/TransactionExtension.java
===================================================================
--- modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/TransactionExtension.java 2010-07-16 22:31:47 UTC (rev 13415)
+++ modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/TransactionExtension.java 2010-07-16 23:46:40 UTC (rev 13416)
@@ -14,7 +14,6 @@
import javax.enterprise.inject.spi.InjectionPoint;
import javax.enterprise.inject.spi.InjectionTarget;
import javax.enterprise.inject.spi.ProcessBean;
-import javax.naming.NamingException;
import org.jboss.weld.extensions.annotated.AnnotatedTypeBuilder;
import org.jboss.weld.extensions.bean.BeanBuilder;
@@ -75,17 +74,7 @@
BeanBuilder<UserTransaction> builder = new BeanBuilder<UserTransaction>(utbuilder.create(), manager);
builder.defineBeanFromAnnotatedType();
- Set<Bean<?>> beans = manager.getBeans(Transaction.class);
- if (beans.isEmpty())
- {
- log.error("No bean with type " + Transaction.class.getName() + " registered, SEAM TRANSACTIONS ARE DISABLED");
- }
- else if (beans.size() > 1)
- {
- log.error("More than 1 bean with type " + Transaction.class.getName() + " registered, SEAM TRANSACTIONS ARE DISABLED");
- }
- Bean<?> bean = beans.iterator().next();
- builder.setBeanLifecycle(new TransactionLifecycle(manager, (Bean) bean));
+ builder.setBeanLifecycle(new TransactionLifecycle(manager));
builder.setInjectionTarget(new NoOpInjectionTarget());
event.addBean(builder.create());
}
@@ -96,26 +85,22 @@
private final BeanManager manager;
- private final Bean<Transaction> transactionBean;
+ private Bean<?> transactionBean;
- public TransactionLifecycle(BeanManager manager, Bean<Transaction> transactionBean)
+ public TransactionLifecycle(BeanManager manager)
{
this.manager = manager;
- this.transactionBean = transactionBean;
-
}
public UserTransaction create(BeanImpl<UserTransaction> bean, CreationalContext<UserTransaction> ctx)
{
- Transaction t = (Transaction) manager.getReference(transactionBean, Transaction.class, ctx);
- try
+ if (transactionBean == null)
{
- return t.getTransaction();
+ // this does not need to be thread safe, it does not matter if this
+ // is initialised twice
+ setupBeanDefinition();
}
- catch (NamingException e)
- {
- throw new RuntimeException(e);
- }
+ return (UserTransaction) manager.getReference(transactionBean, UserTransaction.class, ctx);
}
public void destroy(BeanImpl<UserTransaction> bean, UserTransaction arg0, CreationalContext<UserTransaction> arg1)
@@ -123,6 +108,23 @@
arg1.release();
}
+ /**
+ * we need to init the bean definition lazily, as there
+ */
+ private void setupBeanDefinition()
+ {
+ Set<Bean<?>> beans = manager.getBeans(UserTransaction.class, new TransactionQualifier.TransactionQualifierLiteral());
+ if (beans.isEmpty())
+ {
+ log.error("No bean with type " + UserTransaction.class.getName() + " and qualifier " + TransactionQualifier.class.getName() + " registered, SEAM TRANSACTIONS ARE DISABLED");
+ }
+ else if (beans.size() > 1)
+ {
+ log.error("More than 1 bean with type " + UserTransaction.class.getName() + " and qualifier " + TransactionQualifier.class.getName() + " registered, SEAM TRANSACTIONS ARE DISABLED");
+ }
+ transactionBean = beans.iterator().next();
+ }
+
}
private static class NoOpInjectionTarget implements InjectionTarget<UserTransaction>
@@ -135,7 +137,7 @@
public Set<InjectionPoint> getInjectionPoints()
{
- return Collections.EMPTY_SET;
+ return Collections.emptySet();
}
public void dispose(UserTransaction instance)
Added: modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/TransactionQualifier.java
===================================================================
--- modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/TransactionQualifier.java (rev 0)
+++ modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/TransactionQualifier.java 2010-07-16 23:46:40 UTC (rev 13416)
@@ -0,0 +1,23 @@
+package org.jboss.seam.transaction;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+import javax.enterprise.util.AnnotationLiteral;
+import javax.inject.Qualifier;
+
+/**
+ * Internal qualifier that is used to stop some beans from being exposed to the
+ * user
+ *
+ * @author Stuart Douglas
+ *
+ */
+ at Retention(RetentionPolicy.RUNTIME)
+ at Qualifier
+ at interface TransactionQualifier
+{
+ public static class TransactionQualifierLiteral extends AnnotationLiteral<TransactionQualifier> implements TransactionQualifier
+ {
+ }
+}
More information about the seam-commits
mailing list