[seam-commits] Seam SVN: r13434 - in modules/persistence/trunk: api/src/main/resources and 6 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Sun Jul 18 08:21:58 EDT 2010
Author: swd847
Date: 2010-07-18 08:21:57 -0400 (Sun, 18 Jul 2010)
New Revision: 13434
Added:
modules/persistence/trunk/api/src/main/resources/META-INF/
modules/persistence/trunk/api/src/main/resources/META-INF/beans.xml
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionScopedObject.java
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionScopedTest.java
Modified:
modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/TransactionScoped.java
modules/persistence/trunk/impl/pom.xml
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/scope/TransactionScopeContext.java
modules/persistence/trunk/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionInterceptorTest.java
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/UserTransactionTest.java
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/util/ArtifactNames.java
Log:
update the TransactionScoped
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-18 10:53:55 UTC (rev 13433)
+++ modules/persistence/trunk/api/src/main/java/org/jboss/seam/persistence/transaction/TransactionScoped.java 2010-07-18 12:21:57 UTC (rev 13434)
@@ -41,9 +41,7 @@
@NormalScope(passivating = false)
public @interface TransactionScoped
{
- public static final TransactionScoped LITERAL = new TransactionScopedLiteral();
-
- static class TransactionScopedLiteral extends AnnotationLiteral<TransactionScoped> implements TransactionScoped
+ public static class TransactionScopedLiteral extends AnnotationLiteral<TransactionScoped> implements TransactionScoped
{
}
Added: modules/persistence/trunk/api/src/main/resources/META-INF/beans.xml
===================================================================
Modified: modules/persistence/trunk/impl/pom.xml
===================================================================
--- modules/persistence/trunk/impl/pom.xml 2010-07-18 10:53:55 UTC (rev 13433)
+++ modules/persistence/trunk/impl/pom.xml 2010-07-18 12:21:57 UTC (rev 13434)
@@ -31,6 +31,7 @@
<dependencies>
+
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
@@ -72,6 +73,18 @@
<artifactId>slf4j-api</artifactId>
<scope>provided</scope>
</dependency>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.weld</groupId>
+ <artifactId>weld-core</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.jboss.spec</groupId>
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-18 10:53:55 UTC (rev 13433)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/scope/TransactionScopeContext.java 2010-07-18 12:21:57 UTC (rev 13434)
@@ -48,7 +48,7 @@
public class TransactionScopeContext implements Context, Synchronization
{
- private final UserTransaction userTransaction;
+ private UserTransaction userTransaction;
private final BeanManager beanManager;
@@ -57,19 +57,31 @@
public TransactionScopeContext(BeanManager beanManager)
{
this.beanManager = beanManager;
- 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);
- userTransaction.registerSynchronization(this);
}
+ private void lazyInitialization()
+ {
+ if (userTransaction == null)
+ {
+ synchronized (this)
+ {
+ 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);
+ userTransaction.registerSynchronization(this);
+ }
+ }
+ }
+ }
+
private final ThreadLocal<Map<String, Object>> instanceStore = new ThreadLocal<Map<String, Object>>()
{
protected Map<String, Object> initialValue()
{
-
return new ConcurrentHashMap<String, Object>();
};
};
@@ -78,13 +90,13 @@
{
protected Map<String, CreationalContext<?>> initialValue()
{
-
return new ConcurrentHashMap<String, CreationalContext<?>>();
};
};
public <T> T get(Contextual<T> contextual)
{
+ lazyInitialization();
String id = identifierStore.getId(contextual);
Map<String, Object> map = instanceStore.get();
return (T) map.get(id);
@@ -92,12 +104,14 @@
public <T> T get(Contextual<T> contextual, CreationalContext<T> creationalContext)
{
+ lazyInitialization();
String id = identifierStore.getId(contextual);
Map<String, Object> map = instanceStore.get();
T instance = (T) map.get(id);
if (instance == null)
{
instance = contextual.create(creationalContext);
+ creationalContextStore.get().put(id, creationalContext);
map.put(id, instance);
}
return instance;
@@ -110,6 +124,7 @@
public boolean isActive()
{
+ lazyInitialization();
try
{
return userTransaction.isActive();
Modified: modules/persistence/trunk/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
===================================================================
--- modules/persistence/trunk/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension 2010-07-18 10:53:55 UTC (rev 13433)
+++ modules/persistence/trunk/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension 2010-07-18 12:21:57 UTC (rev 13434)
@@ -1,3 +1,3 @@
org.jboss.seam.persistence.PersistenceContextExtension
-org.jboss.seam.transaction.TransactionExtension
+org.jboss.seam.persistence.transaction.TransactionExtension
org.jboss.seam.persistence.transaction.scope.TransactionScopeExtension
\ No newline at end of file
Modified: modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionInterceptorTest.java
===================================================================
--- modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionInterceptorTest.java 2010-07-18 10:53:55 UTC (rev 13433)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionInterceptorTest.java 2010-07-18 12:21:57 UTC (rev 13434)
@@ -38,6 +38,7 @@
WebArchive war = ShrinkWrap.create("test.war", WebArchive.class);
war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.WELD_EXTENSIONS));
+ war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.SEAM_PERSISTENCE_API));
war.addPackage(Transaction.class.getPackage());
war.addClasses(TransactionInterceptorTest.class, TransactionManagedBean.class, Hotel.class, EntityManagerProvider.class, DontRollBackException.class, TransactionObserver.class);
war.addWebResource("META-INF/persistence.xml", "classes/META-INF/persistence.xml");
@@ -64,35 +65,38 @@
observer.setEnabled(true);
try
{
- observer.reset(true);
- bean.addHotel();
- assertHotels(1);
- observer.verify();
- observer.reset(false);
- try
- {
- bean.failToAddHotel();
+ observer.reset(true);
+ bean.addHotel();
+ assertHotels(1);
+ observer.verify();
+ observer.reset(false);
+ try
+ {
+ bean.failToAddHotel();
+ }
+ catch (Exception e)
+ {
+ }
+ assertHotels(1);
+ observer.verify();
+ observer.reset(true);
+ try
+ {
+ bean.addHotelWithApplicationException();
+ }
+ catch (DontRollBackException e)
+ {
+ }
+ assertHotels(2);
+ observer.verify();
}
catch (Exception e)
{
+ throw new RuntimeException(e);
}
- assertHotels(1);
- observer.verify();
- observer.reset(true);
- try
+ finally
{
- bean.addHotelWithApplicationException();
- }
- catch (DontRollBackException e)
- {
- }
- assertHotels(2);
- observer.verify();
- }
- catch (Exception e)
- {
observer.setEnabled(false);
- throw new RuntimeException(e);
}
}
Added: modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionScopedObject.java
===================================================================
--- modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionScopedObject.java (rev 0)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionScopedObject.java 2010-07-18 12:21:57 UTC (rev 13434)
@@ -0,0 +1,19 @@
+package org.jboss.seam.transactions.test;
+
+import org.jboss.seam.persistence.transaction.TransactionScoped;
+
+ at TransactionScoped
+public class TransactionScopedObject
+{
+ int value = 0;
+
+ public int getValue()
+ {
+ return value;
+ }
+
+ public void setValue(int value)
+ {
+ this.value = value;
+ }
+}
Added: modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionScopedTest.java
===================================================================
--- modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionScopedTest.java (rev 0)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionScopedTest.java 2010-07-18 12:21:57 UTC (rev 13434)
@@ -0,0 +1,75 @@
+package org.jboss.seam.transactions.test;
+
+import javax.inject.Inject;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.PersistenceUnit;
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+import javax.transaction.SystemException;
+
+import junit.framework.Assert;
+
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+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.MavenArtifactResolver;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.ByteArrayAsset;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+ at RunWith(Arquillian.class)
+public class TransactionScopedTest
+{
+ @Deployment
+ public static Archive<?> createTestArchive()
+ {
+
+ WebArchive war = ShrinkWrap.create("test.war", WebArchive.class);
+ war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.WELD_EXTENSIONS));
+ war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.SEAM_PERSISTENCE_API));
+ war.addPackage(Transaction.class.getPackage());
+ war.addPackage(TransactionScopeExtension.class.getPackage());
+ war.addClasses(TransactionScopedTest.class, Hotel.class, TransactionScopedObject.class);
+ war.addWebResource("META-INF/persistence.xml", "classes/META-INF/persistence.xml");
+ war.addWebResource(new ByteArrayAsset(new byte[0]), "beans.xml");
+ war.addWebResource("META-INF/services/javax.enterprise.inject.spi.Extension", "classes/META-INF/services/javax.enterprise.inject.spi.Extension");
+ return war;
+ }
+
+ @Inject
+ UserTransaction transaction;
+
+ @PersistenceUnit
+ EntityManagerFactory emf;
+
+ @Inject
+ TransactionScopedObject transactionScopedObject;
+
+ @Test
+ public void transactionScopeTest() throws NotSupportedException, SystemException, SecurityException, IllegalStateException, RollbackException, HeuristicMixedException, HeuristicRollbackException
+ {
+ transaction.begin();
+ transactionScopedObject.setValue(10);
+ Assert.assertTrue(transactionScopedObject.getValue() == 10);
+ transaction.commit();
+
+ transaction.begin();
+ Assert.assertTrue(transactionScopedObject.getValue() == 0);
+ transactionScopedObject.setValue(20);
+ Assert.assertTrue(transactionScopedObject.getValue() == 20);
+ transaction.rollback();
+
+ transaction.begin();
+ Assert.assertTrue(transactionScopedObject.getValue() == 0);
+ transaction.rollback();
+ }
+
+}
Modified: modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/UserTransactionTest.java
===================================================================
--- modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/UserTransactionTest.java 2010-07-18 10:53:55 UTC (rev 13433)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/UserTransactionTest.java 2010-07-18 12:21:57 UTC (rev 13434)
@@ -36,7 +36,9 @@
WebArchive war = ShrinkWrap.create("test.war", WebArchive.class);
war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.WELD_EXTENSIONS));
- war.addPackage(Transaction.class.getPackage()).addClasses(UserTransactionTest.class, Hotel.class);
+ war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.SEAM_PERSISTENCE_API));
+ war.addPackage(Transaction.class.getPackage());
+ war.addClasses(UserTransactionTest.class, Hotel.class);
war.addWebResource("META-INF/persistence.xml", "classes/META-INF/persistence.xml");
war.addWebResource(new ByteArrayAsset(new byte[0]), "beans.xml");
war.addWebResource("META-INF/services/javax.enterprise.inject.spi.Extension", "classes/META-INF/services/javax.enterprise.inject.spi.Extension");
Modified: modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/util/ArtifactNames.java
===================================================================
--- modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/util/ArtifactNames.java 2010-07-18 10:53:55 UTC (rev 13433)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/util/ArtifactNames.java 2010-07-18 12:21:57 UTC (rev 13434)
@@ -3,5 +3,6 @@
public class ArtifactNames
{
public static final String WELD_EXTENSIONS = "org.jboss.weld:weld-extensions:1.0.0-SNAPSHOT";
+ public static final String SEAM_PERSISTENCE_API = "org.jboss.seam.persistence:seam-persistence-api:3.0.0-SNAPSHOT";
}
More information about the seam-commits
mailing list