[seam-commits] Seam SVN: r13472 - in modules/persistence/trunk/impl/src: main/java/org/jboss/seam/persistence/util and 6 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Thu Jul 22 04:36:21 EDT 2010
Author: swd847
Date: 2010-07-22 04:36:20 -0400 (Thu, 22 Jul 2010)
New Revision: 13472
Added:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/util/
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/util/EjbApi.java
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/
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/TransactionManagedBean.java
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionScopedObject.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
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/util/ManagedPersistenceContextProvider.java
Removed:
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/TransactionManagedBean.java
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
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/UserTransactionTest.java
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/ManagedPersistenceContextExtension.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/transactions/test/util/EntityManagerProvider.java
Log:
change implementation of managed persistence context, update tests
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 08:12:29 UTC (rev 13471)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextBeanLifecycle.java 2010-07-22 08:36:20 UTC (rev 13472)
@@ -37,6 +37,13 @@
import org.jboss.weld.extensions.bean.BeanImpl;
import org.jboss.weld.extensions.bean.BeanLifecycle;
+/**
+ * Class that is responsible for creating and destroying the seam managed
+ * persistence context
+ *
+ * @author Stuart Douglas
+ *
+ */
public class ManagedPersistenceContextBeanLifecycle implements BeanLifecycle<EntityManager>
{
@@ -46,17 +53,6 @@
static final Class<?> proxyClass = Proxy.getProxyClass(EntityManager.class.getClassLoader(), EntityManager.class, Serializable.class);
- public ManagedPersistenceContextBeanLifecycle(Set<Annotation> qualifiers, BeanManager manager)
- {
- this.qualifiers = new Annotation[qualifiers.size()];
- int i = 0;
- for (Annotation a : qualifiers)
- {
- this.qualifiers[i++] = a;
- }
- this.manager = manager;
- }
-
static final Constructor<?> proxyConstructor;
static
@@ -71,6 +67,17 @@
}
}
+ public ManagedPersistenceContextBeanLifecycle(Set<Annotation> qualifiers, BeanManager manager)
+ {
+ this.qualifiers = new Annotation[qualifiers.size()];
+ int i = 0;
+ for (Annotation a : qualifiers)
+ {
+ this.qualifiers[i++] = a;
+ }
+ this.manager = manager;
+ }
+
public EntityManager create(BeanImpl<EntityManager> bean, CreationalContext<EntityManager> arg0)
{
try
Modified: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextExtension.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextExtension.java 2010-07-22 08:12:29 UTC (rev 13471)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/ManagedPersistenceContextExtension.java 2010-07-22 08:36:20 UTC (rev 13472)
@@ -22,22 +22,20 @@
package org.jboss.seam.persistence;
import java.lang.annotation.Annotation;
-import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import javax.enterprise.context.Dependent;
-import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.event.Observes;
+import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.AfterBeanDiscovery;
+import javax.enterprise.inject.spi.AnnotatedField;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.inject.spi.Extension;
-import javax.enterprise.inject.spi.InjectionPoint;
-import javax.enterprise.inject.spi.InjectionTarget;
-import javax.enterprise.inject.spi.ProcessProducer;
+import javax.enterprise.inject.spi.ProcessAnnotatedType;
import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
+import javax.persistence.PersistenceUnit;
import org.jboss.weld.extensions.annotated.AnnotatedTypeBuilder;
import org.jboss.weld.extensions.bean.BeanBuilder;
@@ -58,37 +56,64 @@
Set<Bean<?>> beans = new HashSet<Bean<?>>();
- public <T> void processProducer(@Observes ProcessProducer<T, EntityManagerFactory> event, BeanManager manager)
+ /**
+ * loops through the fields on an AnnotatedType looking for a @PersistnceUnit
+ * producer field that is annotated {@link SeamManaged}. Then found a
+ * corresponding smpc bean is created and registered. Any scope declaration
+ * on the producer are removed as this is not supported by the spec
+ *
+ */
+ public <T> void processAnnotatedType(@Observes ProcessAnnotatedType<T> event, BeanManager manager)
{
- if (!event.getAnnotatedMember().isAnnotationPresent(SeamManaged.class))
+ AnnotatedTypeBuilder<T> modifiedType = null;
+ for (AnnotatedField<? super T> f : event.getAnnotatedType().getFields())
{
- return;
- }
- Set<Annotation> qualifiers = new HashSet<Annotation>();
- Class scope = Dependent.class;
- for (Annotation a : event.getAnnotatedMember().getAnnotations())
- {
- if (manager.isQualifier(a.annotationType()))
+ // look for a seam managed persistence unit declaration
+ if (f.isAnnotationPresent(SeamManaged.class) && f.isAnnotationPresent(PersistenceUnit.class) && f.isAnnotationPresent(Produces.class))
{
- qualifiers.add(a);
+ if (modifiedType == null)
+ {
+ modifiedType = AnnotatedTypeBuilder.newInstance(event.getAnnotatedType()).mergeAnnotations(event.getAnnotatedType(), true);
+ }
+ Set<Annotation> qualifiers = new HashSet<Annotation>();
+ Class<? extends Annotation> scope = Dependent.class;
+ // get the qualifier and scope for the new bean
+ for (Annotation a : f.getAnnotations())
+ {
+ if (manager.isQualifier(a.annotationType()))
+ {
+ qualifiers.add(a);
+ }
+ else if (manager.isScope(a.annotationType()))
+ {
+ scope = a.annotationType();
+ }
+ }
+ if (qualifiers.isEmpty())
+ {
+ qualifiers.add(new DefaultLiteral());
+ }
+ // we need to remove the scope, they are not nessesarily supported
+ // on producer fields
+ if (scope != Dependent.class)
+ {
+ modifiedType.removeFromField(f.getJavaMember(), scope);
+ }
+ // create the new bean to be registerd later
+ AnnotatedTypeBuilder<EntityManager> typeBuilder = AnnotatedTypeBuilder.newInstance(EntityManager.class);
+ BeanBuilder<EntityManager> builder = new BeanBuilder<EntityManager>(typeBuilder.create(), manager);
+ builder.defineBeanFromAnnotatedType();
+ builder.setQualifiers(qualifiers);
+ builder.setScope(scope);
+ builder.setBeanLifecycle(new ManagedPersistenceContextBeanLifecycle(qualifiers, manager));
+ beans.add(builder.create());
}
- else if (manager.isScope(a.annotationType()))
- {
- scope = a.annotationType();
- }
+
}
- if (qualifiers.isEmpty())
+ if (modifiedType != null)
{
- qualifiers.add(new DefaultLiteral());
+ event.setAnnotatedType(modifiedType.create());
}
- AnnotatedTypeBuilder<EntityManager> typeBuilder = AnnotatedTypeBuilder.newInstance(EntityManager.class);
- BeanBuilder<EntityManager> builder = new BeanBuilder<EntityManager>(typeBuilder.create(), manager);
- builder.defineBeanFromAnnotatedType();
- builder.setQualifiers(qualifiers);
- builder.setScope(scope);
- builder.setInjectionTarget(new NoOpInjectionTarget());
- builder.setBeanLifecycle(new ManagedPersistenceContextBeanLifecycle(qualifiers, manager));
- beans.add(builder.create());
}
public void afterBeanDiscovery(@Observes AfterBeanDiscovery event)
@@ -99,38 +124,4 @@
}
}
- private static class NoOpInjectionTarget implements InjectionTarget<EntityManager>
- {
-
- public EntityManager produce(CreationalContext<EntityManager> ctx)
- {
- return null;
- }
-
- public Set<InjectionPoint> getInjectionPoints()
- {
- return Collections.emptySet();
- }
-
- public void dispose(EntityManager instance)
- {
-
- }
-
- public void preDestroy(EntityManager instance)
- {
-
- }
-
- public void postConstruct(EntityManager instance)
- {
-
- }
-
- public void inject(EntityManager instance, CreationalContext<EntityManager> ctx)
- {
-
- }
-
- }
}
Added: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/util/EjbApi.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/util/EjbApi.java (rev 0)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/util/EjbApi.java 2010-07-22 08:36:20 UTC (rev 13472)
@@ -0,0 +1,107 @@
+/*
+ * 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.util;
+
+import java.lang.annotation.Annotation;
+
+import org.jboss.weld.extensions.util.Reflections;
+
+/**
+ * Utility class that provides access to some annotations from the Java
+ * Enterprise Edition specs if they are present on the classpath
+ *
+ *
+ */
+public class EjbApi
+{
+
+ public @interface Dummy
+ {
+ }
+
+ public static final Class<Annotation> STATELESS;
+ public static final Class<Annotation> STATEFUL;
+ public static final Class<Annotation> MESSAGE_DRIVEN;
+ public static final Class<Annotation> PRE_PASSIVATE;
+ public static final Class<Annotation> POST_ACTIVATE;
+ public static final Class<Annotation> PRE_DESTROY;
+ public static final Class<Annotation> POST_CONSTRUCT;
+ public static final Class<Annotation> REMOTE;
+ public static final Class<Annotation> REMOVE;
+ public static final Class<Annotation> LOCAL;
+ public static final Class<Annotation> APPLICATION_EXCEPTION;
+ public static final Class<Annotation> PERSISTENCE_CONTEXT;
+ public static final Class<Annotation> PERSISTENCE_UNIT;
+ public static final Class<Annotation> INTERCEPTORS;
+ public static final Class<Annotation> AROUND_INVOKE;
+ public static final Class<Annotation> EJB_EXCEPTION;
+ public static final boolean INVOCATION_CONTEXT_AVAILABLE;
+
+ private static Class classForName(String name)
+ {
+ try
+ {
+ return Reflections.classForName(name);
+ }
+ catch (ClassNotFoundException cnfe)
+ {
+ return Dummy.class;
+ }
+ }
+
+ static
+ {
+ STATELESS = classForName("javax.ejb.Stateless");
+ STATEFUL = classForName("javax.ejb.Stateful");
+ MESSAGE_DRIVEN = classForName("javax.ejb.MessageDriven");
+ APPLICATION_EXCEPTION = classForName("javax.ejb.ApplicationException");
+ PERSISTENCE_CONTEXT = classForName("javax.persistence.PersistenceContext");
+ PERSISTENCE_UNIT = classForName("javax.persistence.PersistenceUnit");
+ REMOVE = classForName("javax.ejb.Remove");
+ REMOTE = classForName("javax.ejb.Remote");
+ LOCAL = classForName("javax.ejb.Local");
+ PRE_PASSIVATE = classForName("javax.ejb.PrePassivate");
+ POST_ACTIVATE = classForName("javax.ejb.PostActivate");
+ PRE_DESTROY = classForName("javax.annotation.PreDestroy");
+ POST_CONSTRUCT = classForName("javax.annotation.PostConstruct");
+ INTERCEPTORS = classForName("javax.interceptor.Interceptors");
+ AROUND_INVOKE = classForName("javax.interceptor.AroundInvoke");
+ EJB_EXCEPTION = classForName("javax.ejb.EJBException");
+ INVOCATION_CONTEXT_AVAILABLE = !classForName("javax.interceptor.InvocationContext").equals(Dummy.class);
+ }
+
+ public static String name(Annotation annotation)
+ {
+ return (String) Reflections.invokeAndWrap(Reflections.getMethod(annotation.annotationType(), "name"), annotation);
+ }
+
+ public static Class[] value(Annotation annotation)
+ {
+ return (Class[]) Reflections.invokeAndWrap(Reflections.getMethod(annotation.annotationType(), "value"), annotation);
+ }
+
+ public static boolean rollback(Annotation annotation)
+ {
+ return (Boolean) Reflections.invokeAndWrap(Reflections.getMethod(annotation.annotationType(), "rollback"), annotation);
+ }
+
+}
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 08:12:29 UTC (rev 13471)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/test/ManagedPersistenceContextTest.java 2010-07-22 08:36:20 UTC (rev 13472)
@@ -18,8 +18,8 @@
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.EntityManagerProvider;
import org.jboss.seam.transactions.test.util.Hotel;
+import org.jboss.seam.transactions.test.util.ManagedPersistenceContextProvider;
import org.jboss.seam.transactions.test.util.MavenArtifactResolver;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
@@ -39,7 +39,7 @@
war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.SEAM_PERSISTENCE_API));
war.addPackage(Transaction.class.getPackage());
war.addPackage(PersistenceContextExtension.class.getPackage());
- war.addClasses(ManagedPersistenceContextTest.class, Hotel.class, EntityManagerProvider.class);
+ war.addClasses(ManagedPersistenceContextTest.class, Hotel.class, ManagedPersistenceContextProvider.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");
Copied: modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionInterceptorTest.java (from rev 13468, modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionInterceptorTest.java)
===================================================================
--- modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionInterceptorTest.java (rev 0)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionInterceptorTest.java 2010-07-22 08:36:20 UTC (rev 13472)
@@ -0,0 +1,119 @@
+/*
+ * 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.transactions.test;
+
+import java.util.List;
+
+import javax.inject.Inject;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+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.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;
+import org.jboss.seam.transactions.test.util.Hotel;
+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;
+
+/**
+ * Tests the @Transactional interceptor
+ *
+ * @author stuart
+ *
+ */
+ at RunWith(Arquillian.class)
+public class TransactionInterceptorTest
+{
+ @Deployment
+ public static Archive<?> createTestArchive()
+ {
+
+ WebArchive war = ShrinkWrap.createDomain().getArchiveFactory().create(WebArchive.class, "test.war");
+ 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);
+ war.addWebResource("META-INF/persistence.xml", "classes/META-INF/persistence.xml");
+ war.addWebResource(new ByteArrayAsset(("<beans><interceptors><class>" + TransactionInterceptor.class.getName() + "</class></interceptors></beans>").getBytes()), "beans.xml");
+ war.addWebResource("META-INF/services/javax.enterprise.inject.spi.Extension", "classes/META-INF/services/javax.enterprise.inject.spi.Extension");
+ return war;
+ }
+
+ @Inject
+ TransactionManagedBean bean;
+
+ @Inject
+ UserTransaction transaction;
+
+ @PersistenceContext
+ EntityManager em;
+
+ @Test
+ public void testTransactionInterceptor() throws NotSupportedException, SystemException, SecurityException, IllegalStateException, RollbackException, HeuristicMixedException, HeuristicRollbackException
+ {
+
+ bean.addHotel();
+ assertHotels(1);
+ try
+ {
+ bean.failToAddHotel();
+ }
+ catch (Exception e)
+ {
+ }
+ assertHotels(1);
+ try
+ {
+ bean.addHotelWithApplicationException();
+ }
+ catch (DontRollBackException e)
+ {
+ }
+ assertHotels(2);
+ }
+
+ public void assertHotels(int count) throws NotSupportedException, SystemException
+ {
+ transaction.begin();
+ em.joinTransaction();
+ List<Hotel> hotels = em.createQuery("select h from Hotel h").getResultList();
+ Assert.assertTrue("Wrong number of hotels: " + hotels.size(), hotels.size() == count);
+ transaction.rollback();
+ }
+}
Copied: modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionManagedBean.java (from rev 13467, modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionManagedBean.java)
===================================================================
--- modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionManagedBean.java (rev 0)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionManagedBean.java 2010-07-22 08:36:20 UTC (rev 13472)
@@ -0,0 +1,65 @@
+/*
+ * 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.transactions.test;
+
+import javax.inject.Inject;
+import javax.persistence.EntityManager;
+
+import org.jboss.seam.persistence.transaction.TransactionPropagation;
+import org.jboss.seam.persistence.transaction.Transactional;
+import org.jboss.seam.transactions.test.util.DontRollBackException;
+import org.jboss.seam.transactions.test.util.Hotel;
+
+ at Transactional(TransactionPropagation.REQUIRED)
+public class TransactionManagedBean
+{
+
+ @Inject
+ EntityManager entityManager;
+
+ public void addHotel()
+ {
+ entityManager.joinTransaction();
+ Hotel h = new Hotel("test", "Fake St", "Wollongong", "NSW", "2518", "Australia");
+ entityManager.persist(h);
+ entityManager.flush();
+ }
+
+ public void failToAddHotel()
+ {
+ entityManager.joinTransaction();
+ Hotel h = new Hotel("test2", "Fake St", "Wollongong", "NSW", "2518", "Australia");
+ entityManager.persist(h);
+ entityManager.flush();
+ throw new RuntimeException("Roll back transaction");
+ }
+
+ public void addHotelWithApplicationException() throws DontRollBackException
+ {
+ entityManager.joinTransaction();
+ Hotel h = new Hotel("test3", "Fake St", "Wollongong", "NSW", "2518", "Australia");
+ entityManager.persist(h);
+ entityManager.flush();
+ throw new DontRollBackException();
+ }
+
+}
Copied: modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionScopedObject.java (from rev 13467, modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionScopedObject.java)
===================================================================
--- modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionScopedObject.java (rev 0)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionScopedObject.java 2010-07-22 08:36:20 UTC (rev 13472)
@@ -0,0 +1,19 @@
+package org.jboss.seam.persistence.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;
+ }
+}
Copied: modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionScopedTest.java (from rev 13467, modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionScopedTest.java)
===================================================================
--- modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionScopedTest.java (rev 0)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionScopedTest.java 2010-07-22 08:36:20 UTC (rev 13472)
@@ -0,0 +1,75 @@
+package org.jboss.seam.persistence.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.Hotel;
+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.createDomain().getArchiveFactory().create(WebArchive.class, "test.war");
+ 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();
+ }
+
+}
Copied: modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/UserTransactionTest.java (from rev 13467, modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/UserTransactionTest.java)
===================================================================
--- modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/UserTransactionTest.java (rev 0)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/UserTransactionTest.java 2010-07-22 08:36:20 UTC (rev 13472)
@@ -0,0 +1,81 @@
+package org.jboss.seam.persistence.transactions.test;
+
+import java.util.List;
+
+import javax.inject.Inject;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+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.transactions.test.util.ArtifactNames;
+import org.jboss.seam.transactions.test.util.Hotel;
+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 UserTransactionTest
+{
+ @Deployment
+ public static Archive<?> createTestArchive()
+ {
+ WebArchive war = ShrinkWrap.createDomain().getArchiveFactory().create(WebArchive.class, "test.war");
+ war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.WELD_EXTENSIONS));
+ 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");
+ return war;
+ }
+
+ @Inject
+ UserTransaction transaction;
+
+ @PersistenceContext
+ EntityManager em;
+
+ @Test
+ public void userTransactionTest() throws NotSupportedException, SystemException, SecurityException, IllegalStateException, RollbackException, HeuristicMixedException, HeuristicRollbackException
+ {
+ transaction.begin();
+ em.joinTransaction();
+ Hotel h = new Hotel("test", "Fake St", "Wollongong", "NSW", "2518", "Australia");
+ em.persist(h);
+ em.flush();
+ transaction.commit();
+ em.clear();
+
+ transaction.begin();
+ em.joinTransaction();
+ h = new Hotel("test2", "Fake St", "Wollongong", "NSW", "2518", "Australia");
+ em.persist(h);
+ em.flush();
+ transaction.rollback();
+ em.clear();
+
+ transaction.begin();
+ em.joinTransaction();
+ List<Hotel> hotels = em.createQuery("select h from Hotel h").getResultList();
+ Assert.assertTrue(hotels.size() == 1);
+ transaction.rollback();
+ em.clear();
+
+ }
+
+}
Deleted: 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-22 08:12:29 UTC (rev 13471)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionInterceptorTest.java 2010-07-22 08:36:20 UTC (rev 13472)
@@ -1,119 +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.transactions.test;
-
-import java.util.List;
-
-import javax.inject.Inject;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-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.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;
-import org.jboss.seam.transactions.test.util.Hotel;
-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;
-
-/**
- * Tests the @Transactional interceptor
- *
- * @author stuart
- *
- */
- at RunWith(Arquillian.class)
-public class TransactionInterceptorTest
-{
- @Deployment
- public static Archive<?> createTestArchive()
- {
-
- WebArchive war = ShrinkWrap.createDomain().getArchiveFactory().create(WebArchive.class, "test.war");
- 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);
- war.addWebResource("META-INF/persistence.xml", "classes/META-INF/persistence.xml");
- war.addWebResource(new ByteArrayAsset(("<beans><interceptors><class>" + TransactionInterceptor.class.getName() + "</class></interceptors></beans>").getBytes()), "beans.xml");
- war.addWebResource("META-INF/services/javax.enterprise.inject.spi.Extension", "classes/META-INF/services/javax.enterprise.inject.spi.Extension");
- return war;
- }
-
- @Inject
- TransactionManagedBean bean;
-
- @Inject
- UserTransaction transaction;
-
- @PersistenceContext
- EntityManager em;
-
- @Test
- public void testTransactionInterceptor() throws NotSupportedException, SystemException, SecurityException, IllegalStateException, RollbackException, HeuristicMixedException, HeuristicRollbackException
- {
-
- bean.addHotel();
- assertHotels(1);
- try
- {
- bean.failToAddHotel();
- }
- catch (Exception e)
- {
- }
- assertHotels(1);
- try
- {
- bean.addHotelWithApplicationException();
- }
- catch (DontRollBackException e)
- {
- }
- assertHotels(2);
- }
-
- public void assertHotels(int count) throws NotSupportedException, SystemException
- {
- transaction.begin();
- em.joinTransaction();
- List<Hotel> hotels = em.createQuery("select h from Hotel h").getResultList();
- Assert.assertTrue("Wrong number of hotels: " + hotels.size(), hotels.size() == count);
- transaction.rollback();
- }
-}
Deleted: modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionManagedBean.java
===================================================================
--- modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionManagedBean.java 2010-07-22 08:12:29 UTC (rev 13471)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionManagedBean.java 2010-07-22 08:36:20 UTC (rev 13472)
@@ -1,45 +0,0 @@
-package org.jboss.seam.transactions.test;
-
-import javax.inject.Inject;
-import javax.persistence.EntityManager;
-
-import org.jboss.seam.persistence.transaction.TransactionPropagation;
-import org.jboss.seam.persistence.transaction.Transactional;
-import org.jboss.seam.transactions.test.util.DontRollBackException;
-import org.jboss.seam.transactions.test.util.Hotel;
-
- at Transactional(TransactionPropagation.REQUIRED)
-public class TransactionManagedBean
-{
-
- @Inject
- EntityManager entityManager;
-
-
- public void addHotel()
- {
- entityManager.joinTransaction();
- Hotel h = new Hotel("test", "Fake St", "Wollongong", "NSW", "2518", "Australia");
- entityManager.persist(h);
- entityManager.flush();
- }
-
- public void failToAddHotel()
- {
- entityManager.joinTransaction();
- Hotel h = new Hotel("test2", "Fake St", "Wollongong", "NSW", "2518", "Australia");
- entityManager.persist(h);
- entityManager.flush();
- throw new RuntimeException("Roll back transaction");
- }
-
- public void addHotelWithApplicationException() throws DontRollBackException
- {
- entityManager.joinTransaction();
- Hotel h = new Hotel("test3", "Fake St", "Wollongong", "NSW", "2518", "Australia");
- entityManager.persist(h);
- entityManager.flush();
- throw new DontRollBackException();
- }
-
-}
Deleted: 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 2010-07-22 08:12:29 UTC (rev 13471)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionScopedObject.java 2010-07-22 08:36:20 UTC (rev 13472)
@@ -1,19 +0,0 @@
-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;
- }
-}
Deleted: 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 2010-07-22 08:12:29 UTC (rev 13471)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionScopedTest.java 2010-07-22 08:36:20 UTC (rev 13472)
@@ -1,75 +0,0 @@
-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.Hotel;
-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.createDomain().getArchiveFactory().create(WebArchive.class, "test.war");
- 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();
- }
-
-}
Deleted: 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-22 08:12:29 UTC (rev 13471)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/UserTransactionTest.java 2010-07-22 08:36:20 UTC (rev 13472)
@@ -1,81 +0,0 @@
-package org.jboss.seam.transactions.test;
-
-import java.util.List;
-
-import javax.inject.Inject;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-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.transactions.test.util.ArtifactNames;
-import org.jboss.seam.transactions.test.util.Hotel;
-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 UserTransactionTest
-{
- @Deployment
- public static Archive<?> createTestArchive()
- {
- WebArchive war = ShrinkWrap.createDomain().getArchiveFactory().create(WebArchive.class, "test.war");
- war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.WELD_EXTENSIONS));
- 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");
- return war;
- }
-
- @Inject
- UserTransaction transaction;
-
- @PersistenceContext
- EntityManager em;
-
- @Test
- public void userTransactionTest() throws NotSupportedException, SystemException, SecurityException, IllegalStateException, RollbackException, HeuristicMixedException, HeuristicRollbackException
- {
- transaction.begin();
- em.joinTransaction();
- Hotel h = new Hotel("test", "Fake St", "Wollongong", "NSW", "2518", "Australia");
- em.persist(h);
- em.flush();
- transaction.commit();
- em.clear();
-
- transaction.begin();
- em.joinTransaction();
- h = new Hotel("test2", "Fake St", "Wollongong", "NSW", "2518", "Australia");
- em.persist(h);
- em.flush();
- transaction.rollback();
- em.clear();
-
- transaction.begin();
- em.joinTransaction();
- List<Hotel> hotels = em.createQuery("select h from Hotel h").getResultList();
- Assert.assertTrue(hotels.size() == 1);
- transaction.rollback();
- em.clear();
-
- }
-
-}
Modified: modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/util/EntityManagerProvider.java
===================================================================
--- modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/util/EntityManagerProvider.java 2010-07-22 08:12:29 UTC (rev 13471)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/util/EntityManagerProvider.java 2010-07-22 08:36:20 UTC (rev 13472)
@@ -1,17 +1,33 @@
+/*
+ * 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.transactions.test.util;
-import javax.enterprise.context.RequestScoped;
import javax.enterprise.inject.Produces;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.PersistenceUnit;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
-import org.jboss.seam.persistence.SeamManaged;
-
public class EntityManagerProvider
{
- @PersistenceUnit
- @RequestScoped
+ @PersistenceContext
@Produces
- @SeamManaged
- EntityManagerFactory emf;
+ EntityManager em;
}
Added: modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/util/ManagedPersistenceContextProvider.java
===================================================================
--- modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/util/ManagedPersistenceContextProvider.java (rev 0)
+++ modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/util/ManagedPersistenceContextProvider.java 2010-07-22 08:36:20 UTC (rev 13472)
@@ -0,0 +1,38 @@
+/*
+ * 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.transactions.test.util;
+
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.inject.Produces;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.PersistenceUnit;
+
+import org.jboss.seam.persistence.SeamManaged;
+
+public class ManagedPersistenceContextProvider
+{
+ @PersistenceUnit
+ @RequestScoped
+ @Produces
+ @SeamManaged
+ EntityManagerFactory emf;
+}
More information about the seam-commits
mailing list