Author: swd847
Date: 2010-07-22 07:51:52 -0400 (Thu, 22 Jul 2010)
New Revision: 13477
Added:
modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/DefaultTransaction.java
modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/SeamTransaction.java
modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/literal/
modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/literal/DefaultTransactionLiteral.java
modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/literal/TransactionScopedLiteral.java
Removed:
modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/UserTransaction.java
Modified:
modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/TransactionScoped.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextBeanLifecycle.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextProxyHandler.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/AbstractUserTransaction.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/Transaction.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionExtension.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionInterceptor.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/Work.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/scope/TransactionScopeContext.java
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/test/ManagedPersistenceContextTest.java
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionInterceptorTest.java
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionScopedTest.java
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/UserTransactionTest.java
Log:
rename UserTransaction to SeamTransaction and add DefaultTransaction qualifier
Added:
modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/DefaultTransaction.java
===================================================================
---
modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/DefaultTransaction.java
(rev 0)
+++
modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/DefaultTransaction.java 2010-07-22
11:51:52 UTC (rev 13477)
@@ -0,0 +1,29 @@
+package org.jboss.seam.persistence.transaction;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import javax.inject.Qualifier;
+import javax.transaction.UserTransaction;
+
+/**
+ * Qualifier that is used to denote the SeamTransaction implementation that is
+ * used by the transaction interceptor and other seam transaction services.
+ *
+ * A qualifier is nessesary to prevent the seam provided {@link UserTransaction}
+ * wrapper {@link SeamTransaction} from conflicting with the container provided
+ * builtin UserTransaction
+ *
+ * @author Stuart Douglas
+ *
+ */
+@Qualifier
+@Documented
+(a)Retention(RetentionPolicy.RUNTIME)
+@Target( { ElementType.TYPE, ElementType.METHOD, ElementType.FIELD })
+public @interface DefaultTransaction
+{;
+}
Copied:
modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/SeamTransaction.java
(from rev 13467,
modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/UserTransaction.java)
===================================================================
---
modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/SeamTransaction.java
(rev 0)
+++
modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/SeamTransaction.java 2010-07-22
11:51:52 UTC (rev 13477)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.seam.persistence.transaction;
+
+import javax.persistence.EntityManager;
+import javax.transaction.Synchronization;
+import javax.transaction.SystemException;
+
+/**
+ * Extends the standard UserTransaction interface with a couple of helpful
+ * methods.
+ *
+ *
+ * @author Gavin King
+ *
+ */
+public interface SeamTransaction extends javax.transaction.UserTransaction
+{
+
+ public boolean isActive() throws SystemException;
+
+ public boolean isActiveOrMarkedRollback() throws SystemException;
+
+ public boolean isRolledBackOrMarkedRollback() throws SystemException;
+
+ public boolean isMarkedRollback() throws SystemException;
+
+ public boolean isNoTransaction() throws SystemException;
+
+ public boolean isRolledBack() throws SystemException;
+
+ public boolean isCommitted() throws SystemException;
+
+ public boolean isConversationContextRequired();
+
+ public abstract void registerSynchronization(Synchronization sync);
+
+ public void enlist(EntityManager entityManager) throws SystemException;
+}
Modified:
modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/TransactionScoped.java
===================================================================
---
modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/TransactionScoped.java 2010-07-22
10:54:46 UTC (rev 13476)
+++
modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/TransactionScoped.java 2010-07-22
11:51:52 UTC (rev 13477)
@@ -28,7 +28,6 @@
import java.lang.annotation.Target;
import javax.enterprise.context.NormalScope;
-import javax.enterprise.util.AnnotationLiteral;
/**
*
@@ -41,9 +40,5 @@
@NormalScope(passivating = false)
public @interface TransactionScoped
{
- public static class TransactionScopedLiteral extends
AnnotationLiteral<TransactionScoped> implements TransactionScoped
- {
- }
-
}
Deleted:
modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/UserTransaction.java
===================================================================
---
modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/UserTransaction.java 2010-07-22
10:54:46 UTC (rev 13476)
+++
modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/UserTransaction.java 2010-07-22
11:51:52 UTC (rev 13477)
@@ -1,58 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.seam.persistence.transaction;
-
-import javax.persistence.EntityManager;
-import javax.transaction.Synchronization;
-import javax.transaction.SystemException;
-
-/**
- * Extends the standard UserTransaction interface with a couple of helpful
- * methods.
- *
- *
- * @author Gavin King
- *
- */
-public interface UserTransaction extends javax.transaction.UserTransaction
-{
-
- public boolean isActive() throws SystemException;
-
- public boolean isActiveOrMarkedRollback() throws SystemException;
-
- public boolean isRolledBackOrMarkedRollback() throws SystemException;
-
- public boolean isMarkedRollback() throws SystemException;
-
- public boolean isNoTransaction() throws SystemException;
-
- public boolean isRolledBack() throws SystemException;
-
- public boolean isCommitted() throws SystemException;
-
- public boolean isConversationContextRequired();
-
- public abstract void registerSynchronization(Synchronization sync);
-
- public void enlist(EntityManager entityManager) throws SystemException;
-}
Added:
modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/literal/DefaultTransactionLiteral.java
===================================================================
---
modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/literal/DefaultTransactionLiteral.java
(rev 0)
+++
modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/literal/DefaultTransactionLiteral.java 2010-07-22
11:51:52 UTC (rev 13477)
@@ -0,0 +1,18 @@
+/**
+ *
+ */
+package org.jboss.seam.persistence.transaction.literal;
+
+import javax.enterprise.util.AnnotationLiteral;
+
+import org.jboss.seam.persistence.transaction.DefaultTransaction;
+
+public class DefaultTransactionLiteral extends
AnnotationLiteral<DefaultTransaction> implements DefaultTransaction
+{
+ private DefaultTransactionLiteral()
+ {
+ }
+
+ public static final DefaultTransactionLiteral INSTANCE = new
DefaultTransactionLiteral();
+
+}
\ No newline at end of file
Added:
modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/literal/TransactionScopedLiteral.java
===================================================================
---
modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/literal/TransactionScopedLiteral.java
(rev 0)
+++
modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/literal/TransactionScopedLiteral.java 2010-07-22
11:51:52 UTC (rev 13477)
@@ -0,0 +1,18 @@
+/**
+ *
+ */
+package org.jboss.seam.persistence.transaction.literal;
+
+import javax.enterprise.util.AnnotationLiteral;
+
+import org.jboss.seam.persistence.transaction.TransactionScoped;
+
+public class TransactionScopedLiteral extends AnnotationLiteral<TransactionScoped>
implements TransactionScoped
+{
+ private TransactionScopedLiteral()
+ {
+ }
+
+ TransactionScopedLiteral INSTANCE = new TransactionScopedLiteral();
+
+}
\ No newline at end of file
Modified:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextBeanLifecycle.java
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextBeanLifecycle.java 2010-07-22
10:54:46 UTC (rev 13476)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextBeanLifecycle.java 2010-07-22
11:51:52 UTC (rev 13477)
@@ -79,6 +79,9 @@
this.manager = manager;
}
+ /**
+ * creates the proxy
+ */
public EntityManager create(BeanImpl<EntityManager> bean,
CreationalContext<EntityManager> arg0)
{
try
@@ -101,13 +104,16 @@
arg1.release();
}
+ /**
+ * lazily resolve the relevant EMF
+ */
private EntityManagerFactory getEntityManagerFactory()
{
if (emf == null)
{
try
{
- emf = BeanResolver.getReference(EntityManagerFactory.class, qualifiers,
manager);
+ emf = BeanResolver.getReference(EntityManagerFactory.class, manager,
qualifiers);
}
catch (BeanResolutionException e)
{
Modified:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextProxyHandler.java
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextProxyHandler.java 2010-07-22
10:54:46 UTC (rev 13476)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextProxyHandler.java 2010-07-22
11:51:52 UTC (rev 13477)
@@ -30,8 +30,8 @@
import javax.transaction.Synchronization;
import javax.transaction.SystemException;
-import org.jboss.seam.persistence.transaction.UserTransaction;
-import org.jboss.weld.extensions.util.BeanResolutionException;
+import org.jboss.seam.persistence.transaction.SeamTransaction;
+import org.jboss.seam.persistence.transaction.literal.DefaultTransactionLiteral;
import org.jboss.weld.extensions.util.BeanResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -53,7 +53,7 @@
private transient BeanManager beanManager;
- private transient UserTransaction userTransaction;
+ private transient SeamTransaction userTransaction;
private transient boolean synchronizationRegistered;
@@ -76,7 +76,7 @@
private void joinTransaction() throws SystemException
{
- UserTransaction transaction = getUserTransaction();
+ SeamTransaction transaction = getUserTransaction();
if (transaction.isActive())
{
transaction.enlist(delegate);
@@ -95,13 +95,13 @@
}
}
- private UserTransaction getUserTransaction()
+ private SeamTransaction getUserTransaction()
{
if (userTransaction == null)
{
try
{
- userTransaction = BeanResolver.getDefaultReference(UserTransaction.class,
beanManager);
+ userTransaction = BeanResolver.getReference(SeamTransaction.class,
beanManager, DefaultTransactionLiteral.INSTANCE);
}
catch (Exception e)
{
Modified:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/AbstractUserTransaction.java
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/AbstractUserTransaction.java 2010-07-22
10:54:46 UTC (rev 13476)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/AbstractUserTransaction.java 2010-07-22
11:51:52 UTC (rev 13477)
@@ -31,7 +31,7 @@
import javax.transaction.Synchronization;
import javax.transaction.SystemException;
-import org.jboss.seam.persistence.transaction.UserTransaction;
+import org.jboss.seam.persistence.transaction.SeamTransaction;
/**
* Base implementation of UserTransaction
@@ -39,7 +39,7 @@
* @author Gavin King
*
*/
-public abstract class AbstractUserTransaction implements UserTransaction
+public abstract class AbstractUserTransaction implements SeamTransaction
{
private final Synchronizations synchronizations;
Modified:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/Transaction.java
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/Transaction.java 2010-07-22
10:54:46 UTC (rev 13476)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/Transaction.java 2010-07-22
11:51:52 UTC (rev 13477)
@@ -27,7 +27,7 @@
import javax.naming.NameNotFoundException;
import javax.naming.NamingException;
-import org.jboss.seam.persistence.transaction.UserTransaction;
+import org.jboss.seam.persistence.transaction.SeamTransaction;
import org.jboss.weld.extensions.managedproducer.ManagedProducer;
/**
@@ -48,7 +48,7 @@
@ManagedProducer
@TransactionQualifier
- public UserTransaction getTransaction() throws NamingException
+ public SeamTransaction getTransaction() throws NamingException
{
try
{
@@ -67,17 +67,17 @@
}
}
- protected UserTransaction createNoTransaction()
+ protected SeamTransaction createNoTransaction()
{
return new NoTransaction();
}
- protected UserTransaction createCMTTransaction() throws NamingException
+ protected SeamTransaction createCMTTransaction() throws NamingException
{
return new CMTTransaction(EJB.getEJBContext(), synchronizations);
}
- protected UserTransaction createUTTransaction() throws NamingException
+ protected SeamTransaction createUTTransaction() throws NamingException
{
return new UTTransaction(getUserTransaction(), synchronizations);
}
Modified:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionExtension.java
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionExtension.java 2010-07-22
10:54:46 UTC (rev 13476)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionExtension.java 2010-07-22
11:51:52 UTC (rev 13477)
@@ -21,29 +21,26 @@
*/
package org.jboss.seam.persistence.transaction;
-import java.util.Collections;
-import java.util.Set;
-
import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.event.Observes;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.inject.spi.BeforeBeanDiscovery;
import javax.enterprise.inject.spi.Extension;
-import javax.enterprise.inject.spi.InjectionPoint;
-import javax.enterprise.inject.spi.InjectionTarget;
-import org.jboss.seam.persistence.transaction.UserTransaction;
+import org.jboss.seam.persistence.transaction.literal.DefaultTransactionLiteral;
import org.jboss.weld.extensions.annotated.AnnotatedTypeBuilder;
import org.jboss.weld.extensions.bean.BeanBuilder;
import org.jboss.weld.extensions.bean.BeanImpl;
import org.jboss.weld.extensions.bean.BeanLifecycle;
import org.jboss.weld.extensions.defaultbean.DefaultBeanExtension;
+import org.jboss.weld.extensions.util.BeanResolutionException;
+import org.jboss.weld.extensions.util.BeanResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * Extension than provides a {@link UserTransaction} if no other UserTransaction
+ * Extension than provides a {@link SeamTransaction} if no other UserTransaction
* has been registered.
*
* This allows the user to register a transaction via seam XML and have it
@@ -59,22 +56,21 @@
*/
public class TransactionExtension implements Extension
{
- private boolean transactionRegistered = false;
private static final Logger log =
LoggerFactory.getLogger(TransactionExtension.class);
- public void beforeBeanDiscovery(@Observes BeforeBeanDiscovery event,BeanManager
manager)
+ public void beforeBeanDiscovery(@Observes BeforeBeanDiscovery event, BeanManager
manager)
{
- AnnotatedTypeBuilder<UserTransaction> utbuilder =
AnnotatedTypeBuilder.newInstance(UserTransaction.class);
- BeanBuilder<UserTransaction> builder = new
BeanBuilder<UserTransaction>(utbuilder.create(), manager);
+ AnnotatedTypeBuilder<SeamTransaction> utbuilder =
AnnotatedTypeBuilder.newInstance(SeamTransaction.class);
+ BeanBuilder<SeamTransaction> builder = new
BeanBuilder<SeamTransaction>(utbuilder.create(), manager);
builder.defineBeanFromAnnotatedType();
-
builder.setBeanLifecycle(new TransactionLifecycle(manager));
- builder.setInjectionTarget(new NoOpInjectionTarget());
- DefaultBeanExtension.addDefaultBean(UserTransaction.class, builder.create());
+ builder.getQualifiers().clear();
+ builder.getQualifiers().add(DefaultTransactionLiteral.INSTANCE);
+ DefaultBeanExtension.addDefaultBean(SeamTransaction.class, builder.create());
}
- private static class TransactionLifecycle implements
BeanLifecycle<UserTransaction>
+ private static class TransactionLifecycle implements
BeanLifecycle<SeamTransaction>
{
private final BeanManager manager;
@@ -86,7 +82,7 @@
this.manager = manager;
}
- public UserTransaction create(BeanImpl<UserTransaction> bean,
CreationalContext<UserTransaction> ctx)
+ public SeamTransaction create(BeanImpl<SeamTransaction> bean,
CreationalContext<SeamTransaction> ctx)
{
if (transactionBean == null)
{
@@ -94,10 +90,10 @@
// is initialised twice
setupBeanDefinition();
}
- return (UserTransaction) manager.getReference(transactionBean,
UserTransaction.class, ctx);
+ return (SeamTransaction) manager.getReference(transactionBean,
SeamTransaction.class, ctx);
}
- public void destroy(BeanImpl<UserTransaction> bean, UserTransaction arg0,
CreationalContext<UserTransaction> arg1)
+ public void destroy(BeanImpl<SeamTransaction> bean, SeamTransaction arg0,
CreationalContext<SeamTransaction> arg1)
{
arg1.release();
}
@@ -107,52 +103,16 @@
*/
private void setupBeanDefinition()
{
- Set<Bean<?>> beans = manager.getBeans(UserTransaction.class, new
TransactionQualifier.TransactionQualifierLiteral());
- if (beans.isEmpty())
+ try
{
- log.error("No bean with type " + UserTransaction.class.getName() +
" and qualifier " + TransactionQualifier.class.getName() + " registered,
SEAM TRANSACTIONS ARE DISABLED");
+ transactionBean = BeanResolver.resolveBean(SeamTransaction.class, manager,
new TransactionQualifier.TransactionQualifierLiteral());
}
- else if (beans.size() > 1)
+ catch (BeanResolutionException e)
{
- log.error("More than 1 bean with type " +
UserTransaction.class.getName() + " and qualifier " +
TransactionQualifier.class.getName() + " registered, SEAM TRANSACTIONS ARE
DISABLED");
+ throw new RuntimeException(e);
}
- transactionBean = beans.iterator().next();
}
}
- private static class NoOpInjectionTarget implements
InjectionTarget<UserTransaction>
- {
-
- public UserTransaction produce(CreationalContext<UserTransaction> ctx)
- {
- return null;
- }
-
- public Set<InjectionPoint> getInjectionPoints()
- {
- return Collections.emptySet();
- }
-
- public void dispose(UserTransaction instance)
- {
-
- }
-
- public void preDestroy(UserTransaction instance)
- {
-
- }
-
- public void postConstruct(UserTransaction instance)
- {
-
- }
-
- public void inject(UserTransaction instance,
CreationalContext<UserTransaction> ctx)
- {
-
- }
-
- }
}
Modified:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionInterceptor.java
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionInterceptor.java 2010-07-22
10:54:46 UTC (rev 13476)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionInterceptor.java 2010-07-22
11:51:52 UTC (rev 13477)
@@ -33,10 +33,6 @@
import javax.interceptor.Interceptor;
import javax.interceptor.InvocationContext;
-import org.jboss.seam.persistence.transaction.TransactionPropagation;
-import org.jboss.seam.persistence.transaction.Transactional;
-import org.jboss.seam.persistence.transaction.UserTransaction;
-
/**
* Implements transaction propagation rules for Seam JavaBean components.
*
@@ -51,7 +47,9 @@
transient private Map<AnnotatedElement, TransactionMetadata> transactionMetadata
= new HashMap<AnnotatedElement, TransactionMetadata>();
- @Inject Instance<UserTransaction> transaction;
+ @Inject
+ @DefaultTransaction
+ Instance<SeamTransaction> transaction;
private class TransactionMetadata
{
Modified:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/Work.java
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/Work.java 2010-07-22
10:54:46 UTC (rev 13476)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/Work.java 2010-07-22
11:51:52 UTC (rev 13477)
@@ -44,7 +44,7 @@
return !transactionActive;
}
- public final T
workInTransaction(org.jboss.seam.persistence.transaction.UserTransaction transaction)
throws Exception
+ public final T
workInTransaction(org.jboss.seam.persistence.transaction.SeamTransaction transaction)
throws Exception
{
boolean transactionActive = transaction.isActiveOrMarkedRollback() ||
transaction.isRolledBack();
// TODO: temp workaround, what should we really do in this case??
Modified:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/scope/TransactionScopeContext.java
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/scope/TransactionScopeContext.java 2010-07-22
10:54:46 UTC (rev 13476)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/scope/TransactionScopeContext.java 2010-07-22
11:51:52 UTC (rev 13477)
@@ -24,20 +24,20 @@
import java.lang.annotation.Annotation;
import java.util.HashMap;
import java.util.Map;
-import java.util.Set;
import java.util.Map.Entry;
import javax.enterprise.context.spi.Context;
import javax.enterprise.context.spi.Contextual;
import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
import javax.transaction.Synchronization;
import javax.transaction.SystemException;
+import org.jboss.seam.persistence.transaction.SeamTransaction;
import org.jboss.seam.persistence.transaction.TransactionScoped;
-import org.jboss.seam.persistence.transaction.UserTransaction;
-import org.jboss.weld.extensions.literal.DefaultLiteral;
+import org.jboss.seam.persistence.transaction.literal.DefaultTransactionLiteral;
+import org.jboss.weld.extensions.util.BeanResolutionException;
+import org.jboss.weld.extensions.util.BeanResolver;
/**
* Context for the {@link TransactionScoped} scope
@@ -48,7 +48,7 @@
public class TransactionScopeContext implements Context, Synchronization
{
- private UserTransaction userTransaction;
+ private SeamTransaction userTransaction;
private final BeanManager beanManager;
@@ -76,10 +76,14 @@
{
if (userTransaction == null)
{
- Set<Bean<?>> beans =
beanManager.getBeans(UserTransaction.class, new DefaultLiteral());
- Bean<UserTransaction> userTransactionBean =
(Bean<UserTransaction>) beans.iterator().next();
- CreationalContext<?> ctx =
beanManager.createCreationalContext(userTransactionBean);
- userTransaction = (UserTransaction)
beanManager.getReference(userTransactionBean, UserTransaction.class, ctx);
+ try
+ {
+ userTransaction = BeanResolver.getReference(SeamTransaction.class,
beanManager, DefaultTransactionLiteral.INSTANCE);
+ }
+ catch (BeanResolutionException e)
+ {
+ throw new RuntimeException(e);
+ }
}
}
}
Modified:
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/test/ManagedPersistenceContextTest.java
===================================================================
---
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/test/ManagedPersistenceContextTest.java 2010-07-22
10:54:46 UTC (rev 13476)
+++
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/test/ManagedPersistenceContextTest.java 2010-07-22
11:51:52 UTC (rev 13477)
@@ -15,8 +15,9 @@
import org.jboss.arquillian.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.seam.persistence.PersistenceContextExtension;
+import org.jboss.seam.persistence.transaction.DefaultTransaction;
+import org.jboss.seam.persistence.transaction.SeamTransaction;
import org.jboss.seam.persistence.transaction.Transaction;
-import org.jboss.seam.persistence.transaction.UserTransaction;
import org.jboss.seam.transactions.test.util.ArtifactNames;
import org.jboss.seam.transactions.test.util.Hotel;
import org.jboss.seam.transactions.test.util.ManagedPersistenceContextProvider;
@@ -47,7 +48,8 @@
}
@Inject
- UserTransaction transaction;
+ @DefaultTransaction
+ SeamTransaction transaction;
@Inject
EntityManager em;
Modified:
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionInterceptorTest.java
===================================================================
---
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionInterceptorTest.java 2010-07-22
10:54:46 UTC (rev 13476)
+++
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionInterceptorTest.java 2010-07-22
11:51:52 UTC (rev 13477)
@@ -36,9 +36,10 @@
import org.jboss.arquillian.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.seam.persistence.transaction.DefaultTransaction;
+import org.jboss.seam.persistence.transaction.SeamTransaction;
import org.jboss.seam.persistence.transaction.Transaction;
import org.jboss.seam.persistence.transaction.TransactionInterceptor;
-import org.jboss.seam.persistence.transaction.UserTransaction;
import org.jboss.seam.transactions.test.util.ArtifactNames;
import org.jboss.seam.transactions.test.util.DontRollBackException;
import org.jboss.seam.transactions.test.util.EntityManagerProvider;
@@ -79,7 +80,8 @@
TransactionManagedBean bean;
@Inject
- UserTransaction transaction;
+ @DefaultTransaction
+ SeamTransaction transaction;
@PersistenceContext
EntityManager em;
Modified:
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionScopedTest.java
===================================================================
---
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionScopedTest.java 2010-07-22
10:54:46 UTC (rev 13476)
+++
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionScopedTest.java 2010-07-22
11:51:52 UTC (rev 13477)
@@ -13,8 +13,9 @@
import org.jboss.arquillian.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.seam.persistence.transaction.DefaultTransaction;
+import org.jboss.seam.persistence.transaction.SeamTransaction;
import org.jboss.seam.persistence.transaction.Transaction;
-import org.jboss.seam.persistence.transaction.UserTransaction;
import org.jboss.seam.persistence.transaction.scope.TransactionScopeExtension;
import org.jboss.seam.transactions.test.util.ArtifactNames;
import org.jboss.seam.transactions.test.util.Hotel;
@@ -45,7 +46,8 @@
}
@Inject
- UserTransaction transaction;
+ @DefaultTransaction
+ SeamTransaction transaction;
@PersistenceUnit
EntityManagerFactory emf;
Modified:
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/UserTransactionTest.java
===================================================================
---
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/UserTransactionTest.java 2010-07-22
10:54:46 UTC (rev 13476)
+++
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/UserTransactionTest.java 2010-07-22
11:51:52 UTC (rev 13477)
@@ -15,8 +15,9 @@
import org.jboss.arquillian.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.seam.persistence.transaction.DefaultTransaction;
+import org.jboss.seam.persistence.transaction.SeamTransaction;
import org.jboss.seam.persistence.transaction.Transaction;
-import org.jboss.seam.persistence.transaction.UserTransaction;
import org.jboss.seam.transactions.test.util.ArtifactNames;
import org.jboss.seam.transactions.test.util.Hotel;
import org.jboss.seam.transactions.test.util.MavenArtifactResolver;
@@ -45,7 +46,8 @@
}
@Inject
- UserTransaction transaction;
+ @DefaultTransaction
+ SeamTransaction transaction;
@PersistenceContext
EntityManager em;