Author: swd847
Date: 2010-07-18 04:51:36 -0400 (Sun, 18 Jul 2010)
New Revision: 13428
Added:
modules/persistence/trunk/api/
modules/persistence/trunk/api/pom.xml
modules/persistence/trunk/api/src/
modules/persistence/trunk/api/src/main/
modules/persistence/trunk/api/src/main/java/
modules/persistence/trunk/api/src/main/resources/
modules/persistence/trunk/api/src/test/
modules/persistence/trunk/api/src/test/java/
modules/persistence/trunk/api/src/test/resources/
modules/persistence/trunk/impl/
modules/persistence/trunk/impl/pom.xml
modules/persistence/trunk/impl/src/
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/PersistenceContextExtension.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/AbstractUserTransaction.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/AfterTransactionCompletion.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/BeforeTransactionCompletion.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/CMTTransaction.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/EJB.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/EjbSynchronizations.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/EntityTransaction.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/JtaTxInterceptor.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/LocalEjbSynchronizations.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/Naming.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/NoTransaction.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/SeSynchronizations.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/SynchronizationRegistry.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/Synchronizations.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/Transaction.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/TransactionExtension.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/TransactionInterceptor.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/TransactionPropagation.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/TransactionQualifier.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/Transactional.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/UTTransaction.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/UserTransaction.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/Work.java
modules/persistence/trunk/impl/src/main/resources/META-INF/beans.xml
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/
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/TransactionObserver.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/DontRollBackException.java
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/util/EntityManagerProvider.java
modules/persistence/trunk/impl/src/test/resources-glassfish/
modules/persistence/trunk/impl/src/test/resources-jbossas/
modules/persistence/trunk/impl/src/test/resources/META-INF/
modules/persistence/trunk/impl/src/test/resources/arquillian.xml
Removed:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/PersistenceContextExtension.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/JtaTxInterceptor.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/TransactionPropagation.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/Transactional.java
modules/persistence/trunk/impl/src/main/resources/META-INF/beans.xml
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/SimpleTest.java
modules/persistence/trunk/src/
Modified:
modules/persistence/trunk/pom.xml
Log:
change module structure to follow guidelines
Property changes on: modules/persistence/trunk/api
___________________________________________________________________
Name: svn:ignore
+ target
.classpath
.project
.settings
Added: modules/persistence/trunk/api/pom.xml
===================================================================
--- modules/persistence/trunk/api/pom.xml (rev 0)
+++ modules/persistence/trunk/api/pom.xml 2010-07-18 08:51:36 UTC (rev 13428)
@@ -0,0 +1,27 @@
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <artifactId>seam-persistence-parent</artifactId>
+ <groupId>org.jboss.seam.persistence</groupId>
+ <version>3.0.0-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.jboss.seam</groupId>
+ <artifactId>seam-persistence-api</artifactId>
+ <packaging>jar</packaging>
+ <version>3.0.0-SNAPSHOT</version>
+ <name>Seam Persistence API</name>
+
+ <prerequisites>
+ <maven>3.0</maven>
+ </prerequisites>
+
+ <scm>
+
<
connection>scm:svn:http://anonsvn.jboss.org/repos/seam/modules/persist...
+
<
developerConnection>scm:svn:https://svn.jboss.org/repos/seam/modules/p...
+
<
url>http://fisheye.jboss.org/browse/Seam/modules/persistence/trunk/api...
+ </scm>
+
+</project>
+
Property changes on: modules/persistence/trunk/impl
___________________________________________________________________
Name: svn:ignore
+ .classpath
.settings
target
.project
transaction.log
Copied: modules/persistence/trunk/impl/pom.xml (from rev 13405,
modules/persistence/trunk/pom.xml)
===================================================================
--- modules/persistence/trunk/impl/pom.xml (rev 0)
+++ modules/persistence/trunk/impl/pom.xml 2010-07-18 08:51:36 UTC (rev 13428)
@@ -0,0 +1,242 @@
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <artifactId>seam-persistence-parent</artifactId>
+ <groupId>org.jboss.seam.persistence</groupId>
+ <version>3.0.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.jboss.seam</groupId>
+ <artifactId>seam-persistence</artifactId>
+ <packaging>jar</packaging>
+ <version>3.0.0-SNAPSHOT</version>
+ <name>Seam Persistence</name>
+
+ <properties>
+ <seam.version>3.0.0.b01</seam.version>
+ <arquillian.version>1.0.0-SNAPSHOT</arquillian.version>
+ <junit.version>4.8.1</junit.version>
+ <jboss.home>${env.JBOSS_HOME}</jboss.home>
+ <jboss.domain>default</jboss.domain>
+ <glassfish.version>3.0.1-b19</glassfish.version>
+ <jboss-as-client.version>6.0.0-SNAPSHOT</jboss-as-client.version>
+ <jboss-javaee6-spec.version>1.0.0.Beta4</jboss-javaee6-spec.version>
+ <jboss-server-manager.version>1.0.3.GA</jboss-server-manager.version>
+ </properties>
+
+ <prerequisites>
+ <maven>3.0</maven>
+ </prerequisites>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.seam</groupId>
+ <artifactId>seam</artifactId>
+ <version>${seam.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.arquillian</groupId>
+ <artifactId>arquillian-junit</artifactId>
+ <version>${arquillian.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ </dependency>
+
+ </dependencies>
+
+
+ </dependencyManagement>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.hibernate.javax.persistence</groupId>
+ <artifactId>hibernate-jpa-2.0-api</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.spec.javax.interceptor</groupId>
+ <artifactId>jboss-interceptors-api_1.1_spec</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.transaction</groupId>
+ <artifactId>jta</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.enterprise</groupId>
+ <artifactId>cdi-api</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.spec</groupId>
+ <artifactId>jboss-javaee-6.0</artifactId>
+ <version>${jboss-javaee6-spec.version}</version>
+ <type>pom</type>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.weld</groupId>
+ <artifactId>weld-extensions</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <type>jar</type>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.arquillian</groupId>
+ <artifactId>arquillian-junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+
+ <profiles>
+ <profile>
+ <id>default</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+
+ <profile>
+ <id>jbossas-remote-60</id>
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.arquillian.container</groupId>
+ <artifactId>arquillian-jbossas-remote-6</artifactId>
+ <version>${arquillian.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.spec</groupId>
+ <artifactId>jboss-javaee-6.0</artifactId>
+ <version>${jboss-javaee6-spec.version}</version>
+ <type>pom</type>
+ <scope>provided</scope>
+ </dependency>
+ <!-- need for org.jnp.interfaces.NamingContextFactory -->
+ <dependency>
+ <groupId>org.jboss.jbossas</groupId>
+ <artifactId>jboss-as-client</artifactId>
+ <version>${jboss-as-client.version}</version>
+ <type>pom</type>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <testResources>
+ <testResource>
+ <directory>src/test/resources</directory>
+ </testResource>
+ <testResource>
+ <directory>src/test/resources-jbossas</directory>
+ </testResource>
+ </testResources>
+ </build>
+ </profile>
+
+ <profile>
+ <id>glassfish-embedded-30</id>
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.arquillian.container</groupId>
+ <artifactId>arquillian-glassfish-embedded-30</artifactId>
+ <version>${arquillian.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.extras</groupId>
+ <artifactId>glassfish-embedded-all</artifactId>
+ <version>${glassfish.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <testResources>
+ <testResource>
+ <directory>src/test/resources</directory>
+ </testResource>
+ <testResource>
+ <directory>src/test/resources-glassfish</directory>
+ </testResource>
+ </testResources>
+ </build>
+ </profile>
+
+ <profile>
+ <id>glassfish-remote-30</id>
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.arquillian.container</groupId>
+ <artifactId>arquillian-glassfish-remote-30</artifactId>
+ <version>${arquillian.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.extras</groupId>
+ <artifactId>glassfish-embedded-all</artifactId>
+ <version>${glassfish.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <testResources>
+ <testResource>
+ <directory>src/test/resources</directory>
+ </testResource>
+ <testResource>
+ <directory>src/test/resources-glassfish</directory>
+ </testResource>
+ </testResources>
+ </build>
+ </profile>
+ </profiles>
+
+ <scm>
+
<
connection>scm:svn:http://anonsvn.jboss.org/repos/seam/modules/persist...
+
<
developerConnection>scm:svn:https://svn.jboss.org/repos/seam/modules/p...
+
<
url>http://fisheye.jboss.org/browse/Seam/modules/persistence/trunk<...
+ </scm>
+
+</project>
+
Copied: modules/persistence/trunk/impl/src (from rev 13402,
modules/persistence/trunk/src)
Deleted:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/PersistenceContextExtension.java
===================================================================
---
modules/persistence/trunk/src/main/java/org/jboss/seam/persistence/PersistenceContextExtension.java 2010-07-15
04:17:18 UTC (rev 13402)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/PersistenceContextExtension.java 2010-07-18
08:51:36 UTC (rev 13428)
@@ -1,256 +0,0 @@
-package org.jboss.seam.persistence;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.event.Observes;
-import javax.enterprise.inject.Alternative;
-import javax.enterprise.inject.Any;
-import javax.enterprise.inject.Default;
-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.ProcessProducer;
-import javax.enterprise.inject.spi.Producer;
-import javax.enterprise.util.AnnotationLiteral;
-import javax.inject.Qualifier;
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
-import javax.persistence.PersistenceContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Support for managed persistence contexts in a Java SE environment or Servlet
container.
- *
- * <p>Unlike with standard Java EE, the unitName attribute on {@link
PersistenceContext} must
- * be provided if the persistence unit is assigned a name in persistence.xml. This
- * class supports multiple persistence units, but it does not permit multiple
- * producers for the same persistence unit (naturally).</p>
- *
- * @author Gavin King
- * @author Dan Allen
- */
-public class PersistenceContextExtension implements Extension
-{
- private static final Logger log =
LoggerFactory.getLogger(PersistenceContextExtension.class);
-
- private Map<String, Bean<EntityManagerFactory>> emfBeans = new
HashMap<String, Bean<EntityManagerFactory>>();
-
- private Boolean bootstrapRequired;
-
- /**
- * For @PersistenceContext producer fields, make a bean for the EMF, then
- * wrap the producer CDI creates, to get the EM from the EMF bean we made
- * instead of trying to get it from the Java EE component environment.
- */
- void processProducer(@Observes ProcessProducer<?, EntityManager> pp, final
BeanManager bm)
- {
- if (Boolean.FALSE.equals(bootstrapRequired))
- {
- return;
- }
- else if (bootstrapRequired == null)
- {
- if (isPersistenceContainerManaged())
- {
- bootstrapRequired = false;
- return;
- }
- else
- {
- bootstrapRequired = true;
- log.info("Java SE persistence bootstrap required");
- }
- }
-
- if (pp.getAnnotatedMember().isAnnotationPresent(PersistenceContext.class))
- {
- AnnotatedField<?> field = (AnnotatedField<?>)
pp.getAnnotatedMember();
- final String unitName =
field.getAnnotation(PersistenceContext.class).unitName();
- if (!emfBeans.containsKey(unitName))
- {
- log.info("Found persistence context producer for persistence unit:
" + unitName);
- final Class<?> module = field.getJavaMember().getDeclaringClass();
- final Set<Annotation> qualifiers = new HashSet<Annotation>();
- for (Annotation ann : field.getAnnotations())
- {
- Class<? extends Annotation> annotationType = ann.annotationType();
- // if ( bm.isQualifier(annotationType)) {
- if (annotationType.isAnnotationPresent(Qualifier.class))
- { // work around bug in Weld
- qualifiers.add(ann);
- }
- }
- if (qualifiers.isEmpty())
- {
- qualifiers.add(new AnnotationLiteral<Default>()
- {
- /** default value. Added only to suppress compiler warnings. */
- private static final long serialVersionUID = 1L;
- });
- }
- qualifiers.add(new AnnotationLiteral<Any>()
- {
- /** default value. Added only to suppress compiler warnings. */
- private static final long serialVersionUID = 1L;
- });
- final boolean alternative = field.isAnnotationPresent(Alternative.class);
- final Set<Type> types = new HashSet<Type>()
- {
- /** default value. Added only to suppress compiler warnings. */
- private static final long serialVersionUID = 1L;
- {
- add(EntityManagerFactory.class);
- add(Object.class);
- }
- };
-
- // create and register a bean for the EMF
- emfBeans.put(unitName, new Bean<EntityManagerFactory>()
- {
- public Set<Type> getTypes()
- {
- return types;
- }
-
- public Class<? extends Annotation> getScope()
- {
- return ApplicationScoped.class;
- }
-
- public EntityManagerFactory
create(CreationalContext<EntityManagerFactory> ctx)
- {
- return Persistence.createEntityManagerFactory(unitName);
- }
-
- public void destroy(EntityManagerFactory emf,
CreationalContext<EntityManagerFactory> ctx)
- {
- emf.close();
- ctx.release();
- }
-
- public Class<?> getBeanClass()
- {
- return module;
- }
-
- public Set<InjectionPoint> getInjectionPoints()
- {
- return Collections.emptySet();
- }
-
- public String getName()
- {
- return null;
- }
-
- public Set<Annotation> getQualifiers()
- {
- return qualifiers;
- }
-
- public Set<Class<? extends Annotation>> getStereotypes()
- {
- return Collections.emptySet();
-
- }
-
- public boolean isAlternative()
- {
- return alternative;
- }
-
- public boolean isNullable()
- {
- return false;
- }
- });
-
- }
- else
- {
- throw new RuntimeException("There can only be one producer per
persistence unit");
- }
-
- Producer<EntityManager> producer = new Producer<EntityManager>()
- {
- public Set<InjectionPoint> getInjectionPoints()
- {
- return Collections.emptySet();
- }
-
- public EntityManager produce(CreationalContext<EntityManager> ctx)
- {
- return getFactory(ctx).createEntityManager();
- }
-
- private EntityManagerFactory
getFactory(CreationalContext<EntityManager> ctx)
- {
- return (EntityManagerFactory) bm.getReference(emfBeans.get(unitName),
EntityManagerFactory.class, ctx);
- }
-
- public void dispose(EntityManager em)
- {
- if (em.isOpen()) // work around what I suspect is a bug in Weld
- {
- em.close();
- }
- }
- };
- pp.setProducer(producer);
- }
- }
-
- /**
- * Register the EMF bean with the container.
- */
- void afterBeanDiscovery(@Observes AfterBeanDiscovery abd)
- {
- for (Bean<EntityManagerFactory> emfBean : emfBeans.values())
- {
- abd.addBean(emfBean);
- }
- }
-
- /**
- * Check whether persistence is container managed. For now, this simply
- * checks for the presence of the EJB API. If it's present, we assume
- * this is an EE environment and that persistence is container managed.
- */
- boolean isPersistenceContainerManaged() {
- boolean eeEnv = true;
- try
- {
- if (Thread.currentThread().getContextClassLoader() != null)
- {
-
Thread.currentThread().getContextClassLoader().loadClass("javax.ejb.Stateless");
- }
- else
- {
- Class.forName("javax.ejb.Stateless");
- }
- }
- catch (ClassNotFoundException e)
- {
- eeEnv = false;
- }
- catch (NoClassDefFoundError e)
- {
- eeEnv = false;
- }
-
- return eeEnv;
- }
-}
Copied:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/PersistenceContextExtension.java
(from rev 13427,
modules/persistence/trunk/src/main/java/org/jboss/seam/persistence/PersistenceContextExtension.java)
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/PersistenceContextExtension.java
(rev 0)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/PersistenceContextExtension.java 2010-07-18
08:51:36 UTC (rev 13428)
@@ -0,0 +1,278 @@
+/*
+ * 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;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.Alternative;
+import javax.enterprise.inject.Any;
+import javax.enterprise.inject.Default;
+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.ProcessProducer;
+import javax.enterprise.inject.spi.Producer;
+import javax.enterprise.util.AnnotationLiteral;
+import javax.inject.Qualifier;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+import javax.persistence.PersistenceContext;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Support for managed persistence contexts in a Java SE environment or Servlet
container.
+ *
+ * <p>Unlike with standard Java EE, the unitName attribute on {@link
PersistenceContext} must
+ * be provided if the persistence unit is assigned a name in persistence.xml. This
+ * class supports multiple persistence units, but it does not permit multiple
+ * producers for the same persistence unit (naturally).</p>
+ *
+ * @author Gavin King
+ * @author Dan Allen
+ */
+public class PersistenceContextExtension implements Extension
+{
+ private static final Logger log =
LoggerFactory.getLogger(PersistenceContextExtension.class);
+
+ private Map<String, Bean<EntityManagerFactory>> emfBeans = new
HashMap<String, Bean<EntityManagerFactory>>();
+
+ private Boolean bootstrapRequired;
+
+ /**
+ * For @PersistenceContext producer fields, make a bean for the EMF, then
+ * wrap the producer CDI creates, to get the EM from the EMF bean we made
+ * instead of trying to get it from the Java EE component environment.
+ */
+ void processProducer(@Observes ProcessProducer<?, EntityManager> pp, final
BeanManager bm)
+ {
+ if (Boolean.FALSE.equals(bootstrapRequired))
+ {
+ return;
+ }
+ else if (bootstrapRequired == null)
+ {
+ if (isPersistenceContainerManaged())
+ {
+ bootstrapRequired = false;
+ return;
+ }
+ else
+ {
+ bootstrapRequired = true;
+ log.info("Java SE persistence bootstrap required");
+ }
+ }
+
+ if (pp.getAnnotatedMember().isAnnotationPresent(PersistenceContext.class))
+ {
+ AnnotatedField<?> field = (AnnotatedField<?>)
pp.getAnnotatedMember();
+ final String unitName =
field.getAnnotation(PersistenceContext.class).unitName();
+ if (!emfBeans.containsKey(unitName))
+ {
+ log.info("Found persistence context producer for persistence unit:
" + unitName);
+ final Class<?> module = field.getJavaMember().getDeclaringClass();
+ final Set<Annotation> qualifiers = new HashSet<Annotation>();
+ for (Annotation ann : field.getAnnotations())
+ {
+ Class<? extends Annotation> annotationType = ann.annotationType();
+ // if ( bm.isQualifier(annotationType)) {
+ if (annotationType.isAnnotationPresent(Qualifier.class))
+ { // work around bug in Weld
+ qualifiers.add(ann);
+ }
+ }
+ if (qualifiers.isEmpty())
+ {
+ qualifiers.add(new AnnotationLiteral<Default>()
+ {
+ /** default value. Added only to suppress compiler warnings. */
+ private static final long serialVersionUID = 1L;
+ });
+ }
+ qualifiers.add(new AnnotationLiteral<Any>()
+ {
+ /** default value. Added only to suppress compiler warnings. */
+ private static final long serialVersionUID = 1L;
+ });
+ final boolean alternative = field.isAnnotationPresent(Alternative.class);
+ final Set<Type> types = new HashSet<Type>()
+ {
+ /** default value. Added only to suppress compiler warnings. */
+ private static final long serialVersionUID = 1L;
+ {
+ add(EntityManagerFactory.class);
+ add(Object.class);
+ }
+ };
+
+ // create and register a bean for the EMF
+ emfBeans.put(unitName, new Bean<EntityManagerFactory>()
+ {
+ public Set<Type> getTypes()
+ {
+ return types;
+ }
+
+ public Class<? extends Annotation> getScope()
+ {
+ return ApplicationScoped.class;
+ }
+
+ public EntityManagerFactory
create(CreationalContext<EntityManagerFactory> ctx)
+ {
+ return Persistence.createEntityManagerFactory(unitName);
+ }
+
+ public void destroy(EntityManagerFactory emf,
CreationalContext<EntityManagerFactory> ctx)
+ {
+ emf.close();
+ ctx.release();
+ }
+
+ public Class<?> getBeanClass()
+ {
+ return module;
+ }
+
+ public Set<InjectionPoint> getInjectionPoints()
+ {
+ return Collections.emptySet();
+ }
+
+ public String getName()
+ {
+ return null;
+ }
+
+ public Set<Annotation> getQualifiers()
+ {
+ return qualifiers;
+ }
+
+ public Set<Class<? extends Annotation>> getStereotypes()
+ {
+ return Collections.emptySet();
+
+ }
+
+ public boolean isAlternative()
+ {
+ return alternative;
+ }
+
+ public boolean isNullable()
+ {
+ return false;
+ }
+ });
+
+ }
+ else
+ {
+ throw new RuntimeException("There can only be one producer per
persistence unit");
+ }
+
+ Producer<EntityManager> producer = new Producer<EntityManager>()
+ {
+ public Set<InjectionPoint> getInjectionPoints()
+ {
+ return Collections.emptySet();
+ }
+
+ public EntityManager produce(CreationalContext<EntityManager> ctx)
+ {
+ return getFactory(ctx).createEntityManager();
+ }
+
+ private EntityManagerFactory
getFactory(CreationalContext<EntityManager> ctx)
+ {
+ return (EntityManagerFactory) bm.getReference(emfBeans.get(unitName),
EntityManagerFactory.class, ctx);
+ }
+
+ public void dispose(EntityManager em)
+ {
+ if (em.isOpen()) // work around what I suspect is a bug in Weld
+ {
+ em.close();
+ }
+ }
+ };
+ pp.setProducer(producer);
+ }
+ }
+
+ /**
+ * Register the EMF bean with the container.
+ */
+ void afterBeanDiscovery(@Observes AfterBeanDiscovery abd)
+ {
+ for (Bean<EntityManagerFactory> emfBean : emfBeans.values())
+ {
+ abd.addBean(emfBean);
+ }
+ }
+
+ /**
+ * Check whether persistence is container managed. For now, this simply
+ * checks for the presence of the EJB API. If it's present, we assume
+ * this is an EE environment and that persistence is container managed.
+ */
+ boolean isPersistenceContainerManaged() {
+ boolean eeEnv = true;
+ try
+ {
+ if (Thread.currentThread().getContextClassLoader() != null)
+ {
+
Thread.currentThread().getContextClassLoader().loadClass("javax.ejb.Stateless");
+ }
+ else
+ {
+ Class.forName("javax.ejb.Stateless");
+ }
+ }
+ catch (ClassNotFoundException e)
+ {
+ eeEnv = false;
+ }
+ catch (NoClassDefFoundError e)
+ {
+ eeEnv = false;
+ }
+
+ return eeEnv;
+ }
+}
Copied:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/AbstractUserTransaction.java
(from rev 13427,
modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/AbstractUserTransaction.java)
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/AbstractUserTransaction.java
(rev 0)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/AbstractUserTransaction.java 2010-07-18
08:51:36 UTC (rev 13428)
@@ -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.transaction;
+
+import static javax.transaction.Status.STATUS_ACTIVE;
+import static javax.transaction.Status.STATUS_COMMITTED;
+import static javax.transaction.Status.STATUS_MARKED_ROLLBACK;
+import static javax.transaction.Status.STATUS_NO_TRANSACTION;
+import static javax.transaction.Status.STATUS_ROLLEDBACK;
+
+import javax.persistence.EntityManager;
+import javax.transaction.Synchronization;
+import javax.transaction.SystemException;
+
+/**
+ * Base implementation of UserTransaction
+ *
+ * @author Gavin King
+ *
+ */
+public abstract class AbstractUserTransaction implements UserTransaction
+{
+
+ private final Synchronizations synchronizations;
+
+ public AbstractUserTransaction(Synchronizations synchronizations)
+ {
+ this.synchronizations = synchronizations;
+ }
+
+ public boolean isActive() throws SystemException
+ {
+ return getStatus() == STATUS_ACTIVE;
+ }
+
+ public boolean isActiveOrMarkedRollback() throws SystemException
+ {
+ int status = getStatus();
+ return status == STATUS_ACTIVE || status == STATUS_MARKED_ROLLBACK;
+ }
+
+ public boolean isRolledBackOrMarkedRollback() throws SystemException
+ {
+ int status = getStatus();
+ return status == STATUS_ROLLEDBACK || status == STATUS_MARKED_ROLLBACK;
+ }
+
+ public boolean isMarkedRollback() throws SystemException
+ {
+ return getStatus() == STATUS_MARKED_ROLLBACK;
+ }
+
+ public boolean isNoTransaction() throws SystemException
+ {
+ return getStatus() == STATUS_NO_TRANSACTION;
+ }
+
+ public boolean isRolledBack() throws SystemException
+ {
+ return getStatus() == STATUS_ROLLEDBACK;
+ }
+
+ public boolean isCommitted() throws SystemException
+ {
+ return getStatus() == STATUS_COMMITTED;
+ }
+
+ public boolean isConversationContextRequired()
+ {
+ return false;
+ }
+
+ public abstract void registerSynchronization(Synchronization sync);
+
+ public void enlist(EntityManager entityManager) throws SystemException
+ {
+ if (isActiveOrMarkedRollback())
+ {
+ entityManager.joinTransaction();
+ }
+ }
+
+ public Synchronizations getSynchronizations()
+ {
+ return synchronizations;
+ }
+
+}
Copied:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/AfterTransactionCompletion.java
(from rev 13427,
modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/AfterTransactionCompletion.java)
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/AfterTransactionCompletion.java
(rev 0)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/AfterTransactionCompletion.java 2010-07-18
08:51:36 UTC (rev 13428)
@@ -0,0 +1,37 @@
+/*
+ * 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.transaction;
+
+public class AfterTransactionCompletion
+{
+ private final boolean success;
+
+ public AfterTransactionCompletion(boolean success)
+ {
+ this.success = success;
+ }
+
+ public boolean success()
+ {
+ return success;
+ }
+}
Copied:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/BeforeTransactionCompletion.java
(from rev 13427,
modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/BeforeTransactionCompletion.java)
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/BeforeTransactionCompletion.java
(rev 0)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/BeforeTransactionCompletion.java 2010-07-18
08:51:36 UTC (rev 13428)
@@ -0,0 +1,27 @@
+/*
+ * 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.transaction;
+
+public class BeforeTransactionCompletion
+{
+
+}
Copied:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/CMTTransaction.java
(from rev 13427,
modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/CMTTransaction.java)
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/CMTTransaction.java
(rev 0)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/CMTTransaction.java 2010-07-18
08:51:36 UTC (rev 13428)
@@ -0,0 +1,149 @@
+/*
+ * 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.transaction;
+
+import javax.ejb.EJBContext;
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+import javax.transaction.Status;
+import javax.transaction.Synchronization;
+import javax.transaction.SystemException;
+import javax.transaction.UserTransaction;
+
+import org.jboss.weld.extensions.core.Veto;
+
+/**
+ * Wraps EJBContext transaction management in a UserTransaction interface. Note
+ * that container managed transactions cannot be controlled by the application,
+ * so begin(), commit() and rollback() are disallowed in a CMT.
+ *
+ * @author Mike Youngstrom
+ * @author Gavin King
+ * @author Stuart Douglas
+ *
+ */
+@Veto
+public class CMTTransaction extends AbstractUserTransaction
+{
+
+ private final EJBContext ejbContext;
+
+ public CMTTransaction(EJBContext ejbContext, Synchronizations sync)
+ {
+ super(sync);
+ this.ejbContext = ejbContext;
+ if (ejbContext == null)
+ {
+ throw new IllegalArgumentException("null EJBContext");
+ }
+ }
+
+ public void begin() throws NotSupportedException, SystemException
+ {
+ ejbContext.getUserTransaction().begin();
+ getSynchronizations().afterTransactionBegin();
+ }
+
+ public void commit() throws RollbackException, HeuristicMixedException,
HeuristicRollbackException, SecurityException, IllegalStateException, SystemException
+ {
+ UserTransaction userTransaction = ejbContext.getUserTransaction();
+ boolean success = false;
+ Synchronizations synchronizations = getSynchronizations();
+ synchronizations.beforeTransactionCommit();
+ try
+ {
+ userTransaction.commit();
+ success = true;
+ }
+ finally
+ {
+ synchronizations.afterTransactionCommit(success);
+ }
+ }
+
+ public void rollback() throws IllegalStateException, SecurityException,
SystemException
+ {
+ UserTransaction userTransaction = ejbContext.getUserTransaction();
+ try
+ {
+ userTransaction.rollback();
+ }
+ finally
+ {
+ getSynchronizations().afterTransactionRollback();
+ }
+ }
+
+ public int getStatus() throws SystemException
+ {
+ try
+ {
+ // TODO: not correct for SUPPORTS or NEVER!
+ if (!ejbContext.getRollbackOnly())
+ {
+ return Status.STATUS_ACTIVE;
+ }
+ else
+ {
+ return Status.STATUS_MARKED_ROLLBACK;
+ }
+ }
+ catch (IllegalStateException ise)
+ {
+ try
+ {
+ return ejbContext.getUserTransaction().getStatus();
+ }
+ catch (IllegalStateException is)
+ {
+ return Status.STATUS_NO_TRANSACTION;
+ }
+ }
+ }
+
+ public void setRollbackOnly() throws IllegalStateException, SystemException
+ {
+ ejbContext.setRollbackOnly();
+ }
+
+ public void setTransactionTimeout(int timeout) throws SystemException
+ {
+ ejbContext.getUserTransaction().setTransactionTimeout(timeout);
+ }
+
+ @Override
+ public void registerSynchronization(Synchronization sync)
+ {
+ Synchronizations synchronizations = getSynchronizations();
+ if (synchronizations.isAwareOfContainerTransactions())
+ {
+ synchronizations.registerSynchronization(sync);
+ }
+ else
+ {
+ throw new UnsupportedOperationException("cannot register synchronization
with container transaction, use <transaction:ejb-transaction/>");
+ }
+ }
+
+}
Copied: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/EJB.java
(from rev 13427,
modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/EJB.java)
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/EJB.java
(rev 0)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/EJB.java 2010-07-18
08:51:36 UTC (rev 13428)
@@ -0,0 +1,60 @@
+/*
+ * 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.transaction;
+
+import javax.ejb.EJBContext;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+
+/**
+ * utility class to look up the EJBContext
+ *
+ *
+ */
+public class EJB
+{
+ public static String ejbContextName = "java:comp.ejb3/EJBContext";
+ public static final String STANDARD_EJB_CONTEXT_NAME =
"java:comp/EJBContext";
+
+ public static EJBContext getEJBContext() throws NamingException
+ {
+ try
+ {
+ return (EJBContext) Naming.getInitialContext().lookup(ejbContextName);
+ }
+ catch (NameNotFoundException nnfe)
+ {
+ return (EJBContext)
Naming.getInitialContext().lookup(STANDARD_EJB_CONTEXT_NAME);
+ }
+ }
+
+ protected static String getEjbContextName()
+ {
+ return ejbContextName;
+ }
+
+ protected static void setEjbContextName(String ejbContextName)
+ {
+ EJB.ejbContextName = ejbContextName;
+ }
+
+}
Copied:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/EjbSynchronizations.java
(from rev 13427,
modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/EjbSynchronizations.java)
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/EjbSynchronizations.java
(rev 0)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/EjbSynchronizations.java 2010-07-18
08:51:36 UTC (rev 13428)
@@ -0,0 +1,135 @@
+/*
+ * 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.transaction;
+
+import java.rmi.RemoteException;
+import java.util.LinkedList;
+
+import javax.ejb.EJBException;
+import javax.ejb.Remove;
+import javax.ejb.SessionSynchronization;
+import javax.ejb.Stateful;
+import javax.ejb.TransactionAttribute;
+import javax.ejb.TransactionAttributeType;
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+import javax.transaction.Synchronization;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Receives JTA transaction completion notifications from the EJB container, and
+ * passes them on to the registered Synchronizations. This implementation is
+ * fully aware of container managed transactions and is able to register
+ * Synchronizations for the container transaction.
+ *
+ * @author Gavin King
+ *
+ */
+@Stateful
+@RequestScoped
+(a)TransactionAttribute(TransactionAttributeType.SUPPORTS)
+public class EjbSynchronizations implements LocalEjbSynchronizations,
SessionSynchronization
+{
+ private static final Logger log = LoggerFactory.getLogger(EjbSynchronizations.class);
+
+ @Inject
+ private BeanManager beanManager;
+
+ // maintain two lists to work around a bug in JBoss EJB3 where a new
+ // SessionSynchronization
+ // gets registered each time the bean is called
+ protected LinkedList<SynchronizationRegistry> synchronizations = new
LinkedList<SynchronizationRegistry>();
+ protected LinkedList<SynchronizationRegistry> committing = new
LinkedList<SynchronizationRegistry>();
+
+ public void afterBegin()
+ {
+ log.debug("afterBegin");
+ synchronizations.addLast(new SynchronizationRegistry(beanManager));
+ }
+
+ public void beforeCompletion() throws EJBException, RemoteException
+ {
+ log.debug("beforeCompletion");
+ SynchronizationRegistry sync = synchronizations.removeLast();
+ sync.beforeTransactionCompletion();
+ committing.addLast(sync);
+ }
+
+ public void afterCompletion(boolean success) throws EJBException, RemoteException
+ {
+ log.debug("afterCompletion");
+ if (committing.isEmpty())
+ {
+ if (success)
+ {
+ throw new IllegalStateException("beforeCompletion was never
called");
+ }
+ else
+ {
+ synchronizations.removeLast().afterTransactionCompletion(false);
+ }
+ }
+ else
+ {
+ committing.removeFirst().afterTransactionCompletion(success);
+ }
+ }
+
+ public boolean isAwareOfContainerTransactions()
+ {
+ return true;
+ }
+
+ public void afterTransactionBegin()
+ {
+ // noop, let JTA notify us
+ }
+
+ public void afterTransactionCommit(boolean success)
+ {
+ // noop, let JTA notify us
+ }
+
+ public void afterTransactionRollback()
+ {
+ // noop, let JTA notify us
+ }
+
+ public void beforeTransactionCommit()
+ {
+ // noop, let JTA notify us
+ }
+
+ public void registerSynchronization(Synchronization sync)
+ {
+ synchronizations.getLast().registerSynchronization(sync);
+ }
+
+ @Remove
+ public void destroy()
+ {
+ }
+
+}
Copied:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/EntityTransaction.java
(from rev 13427,
modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/EntityTransaction.java)
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/EntityTransaction.java
(rev 0)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/EntityTransaction.java 2010-07-18
08:51:36 UTC (rev 13428)
@@ -0,0 +1,181 @@
+/*
+ * 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.transaction;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.persistence.EntityManager;
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+import javax.transaction.Status;
+import javax.transaction.Synchronization;
+import javax.transaction.SystemException;
+
+import org.jboss.weld.extensions.core.Veto;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Support for the JPA EntityTransaction API.
+ *
+ * Adapts JPA transaction management to a Seam UserTransaction
+ * interface.For use in non-JTA-capable environments.
+ *
+ * @author Gavin King
+ *
+ */
+@RequestScoped
+@Veto
+public class EntityTransaction extends AbstractUserTransaction
+{
+ private static final Logger log = LoggerFactory.getLogger(EntityTransaction.class);
+
+ @Inject
+ private EntityManager entityManager;
+
+
+ @Inject
+ public EntityTransaction(Synchronizations sync)
+ {
+ super(sync);
+ }
+
+ private javax.persistence.EntityTransaction getDelegate()
+ {
+ return entityManager.getTransaction();
+ }
+
+ public void begin() throws NotSupportedException, SystemException
+ {
+ log.debug("beginning JPA resource-local transaction");
+ //TODO: translate exceptions that occur into the correct JTA exception
+ try
+ {
+ getDelegate().begin();
+ getSynchronizations().afterTransactionBegin();
+ }
+ catch (RuntimeException re)
+ {
+ throw re;
+ }
+ }
+
+ public void commit() throws RollbackException, HeuristicMixedException,
+ HeuristicRollbackException, SecurityException, IllegalStateException,
SystemException
+ {
+ log.debug("committing JPA resource-local transaction");
+ javax.persistence.EntityTransaction delegate = getDelegate();
+ boolean success = false;
+ try
+ {
+ if ( delegate.getRollbackOnly() )
+ {
+ delegate.rollback();
+ throw new RollbackException();
+ }
+ else
+ {
+ getSynchronizations().beforeTransactionCommit();
+ delegate.commit();
+ success = true;
+ }
+ }
+ finally
+ {
+ getSynchronizations().afterTransactionCommit(success);
+ }
+ }
+
+ public void rollback() throws IllegalStateException, SecurityException,
SystemException
+ {
+ log.debug("rolling back JPA resource-local transaction");
+ //TODO: translate exceptions that occur into the correct JTA exception
+ javax.persistence.EntityTransaction delegate = getDelegate();
+ try
+ {
+ delegate.rollback();
+ }
+ finally
+ {
+ getSynchronizations().afterTransactionRollback();
+ }
+ }
+
+ public void setRollbackOnly() throws IllegalStateException, SystemException
+ {
+ log.debug("marking JPA resource-local transaction for rollback");
+ getDelegate().setRollbackOnly();
+ }
+
+ public int getStatus() throws SystemException
+ {
+ if (getDelegate().getRollbackOnly())
+ {
+ return Status.STATUS_MARKED_ROLLBACK;
+ }
+ else if (getDelegate().isActive())
+ {
+ return Status.STATUS_ACTIVE;
+ }
+ else
+ {
+ return Status.STATUS_NO_TRANSACTION;
+ }
+ }
+
+ public void setTransactionTimeout(int timeout) throws SystemException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void registerSynchronization(Synchronization sync)
+ {
+ if ( log.isDebugEnabled() )
+ {
+ log.debug("registering synchronization: " + sync);
+ }
+ //try to register the synchronization directly with the
+ //persistence provider, but if this fails, just hold
+ //on to it myself
+ // if ( !PersistenceProvider.instance().registerSynchronization(sync,
+ // currentEntityManager) )
+ // {
+ // getSynchronizations().registerSynchronization(sync);
+ // }
+ }
+
+ @Override
+ public boolean isConversationContextRequired()
+ {
+ return true;
+ }
+
+ @Override
+ public void enlist(EntityManager entityManager)
+ {
+ //no-op
+ }
+
+}
Deleted:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/JtaTxInterceptor.java
===================================================================
---
modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/JtaTxInterceptor.java 2010-07-15
04:17:18 UTC (rev 13402)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/JtaTxInterceptor.java 2010-07-18
08:51:36 UTC (rev 13428)
@@ -1,123 +0,0 @@
-package org.jboss.seam.transaction;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
-import javax.inject.Inject;
-import javax.interceptor.AroundInvoke;
-import javax.interceptor.Interceptor;
-import javax.interceptor.InvocationContext;
-import javax.transaction.Status;
-import javax.transaction.UserTransaction;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * A rudimentary transaction interceptor implementation, intended as a proof
- * of concept.
- *
- * @author Matt Corey
- * @author Dan Allen
- */
-public @Transactional @Interceptor class JtaTxInterceptor {
-
- private static final Logger log = LoggerFactory.getLogger(JtaTxInterceptor.class);
-
- @Inject private UserTransaction utx;
-
- /**
- * Super quick impl. Needs to be done correctly.
- */
- @AroundInvoke
- public Object workInTransaction(InvocationContext ic) throws Exception {
- // TODO cache this information
- TransactionPropagation type = getTransactionPropagation(ic.getMethod());
-
- int status = utx.getStatus();
- boolean transactionActive = (status == Status.STATUS_ACTIVE || status ==
Status.STATUS_MARKED_ROLLBACK);
- boolean beginTransaction = isNewTransactionRequired(type, transactionActive);
-
- if (beginTransaction) {
- log.debug("Beginning transaction");
- utx.begin();
- }
-
- Object result = null;
- try {
- result = ic.proceed();
-
- if (beginTransaction) {
- if (utx.getStatus() == Status.STATUS_MARKED_ROLLBACK) {
- log.debug("Rolling back transaction marked for rollback");
- utx.rollback();
- }
- else {
- log.debug("Committing transaction");
- utx.commit();
- }
- }
-
- return result;
- } catch (Exception e) {
- if (beginTransaction && utx.getStatus() != Status.STATUS_NO_TRANSACTION)
{
- // FIXME don't rollback if this is an application exception which
indicates no rollback
- log.debug("Rolling back transaction as the result of an
exception");
- utx.rollback();
- }
-
- throw e;
- }
- }
-
- /**
- * Get the TransactionPropagation value
- * FIXME cache this information
- */
- private TransactionPropagation getTransactionPropagation(Method m) {
- // first look at the explicit method-level annotation
- if (m.isAnnotationPresent(Transactional.class)) {
- return m.getAnnotation(Transactional.class).value();
- }
- // now look at the method-level meta-annotations
- for (Annotation a: m.getAnnotations()) {
- if (a.annotationType().isAnnotationPresent(Transactional.class)) {
- return a.annotationType().getAnnotation(Transactional.class).value();
- }
- }
- // now try the explicit class-level annotation
- if (m.getDeclaringClass().isAnnotationPresent(Transactional.class)) {
- return m.getDeclaringClass().getAnnotation(Transactional.class).value();
- }
- // finally, try the class-level meta-annotations
- for (Annotation a: m.getDeclaringClass().getAnnotations()) {
- if (a.annotationType().isAnnotationPresent(Transactional.class)) {
- return a.annotationType().getAnnotation(Transactional.class).value();
- }
- }
- return null;
- }
-
- private boolean isNewTransactionRequired(TransactionPropagation type, boolean
transactionActive) {
- switch (type) {
- case REQUIRED:
- return !transactionActive;
- case SUPPORTS:
- return false;
- case MANDATORY:
- if (!transactionActive) {
- throw new IllegalStateException("No transaction active on call to
method that requires a transaction.");
- }
- else {
- return false;
- }
- case NEVER:
- if (transactionActive) {
- throw new IllegalStateException("Transaction active on call to method
that does not support transactions.");
- }
- else {
- return false;
- }
- default:
- throw new IllegalArgumentException("Unknown transaction type " +
type);
- }
- }
-}
\ No newline at end of file
Copied:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/JtaTxInterceptor.java
(from rev 13427,
modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/JtaTxInterceptor.java)
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/JtaTxInterceptor.java
(rev 0)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/JtaTxInterceptor.java 2010-07-18
08:51:36 UTC (rev 13428)
@@ -0,0 +1,146 @@
+/*
+ * 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.transaction;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+
+import javax.inject.Inject;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.Interceptor;
+import javax.interceptor.InvocationContext;
+import javax.transaction.Status;
+import javax.transaction.UserTransaction;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A rudimentary transaction interceptor implementation, intended as a proof
+ * of concept.
+ *
+ * @author Matt Corey
+ * @author Dan Allen
+ */
+public @Transactional @Interceptor class JtaTxInterceptor {
+
+ private static final Logger log = LoggerFactory.getLogger(JtaTxInterceptor.class);
+
+ @Inject private UserTransaction utx;
+
+ /**
+ * Super quick impl. Needs to be done correctly.
+ */
+ @AroundInvoke
+ public Object workInTransaction(InvocationContext ic) throws Exception {
+ // TODO cache this information
+ TransactionPropagation type = getTransactionPropagation(ic.getMethod());
+
+ int status = utx.getStatus();
+ boolean transactionActive = (status == Status.STATUS_ACTIVE || status ==
Status.STATUS_MARKED_ROLLBACK);
+ boolean beginTransaction = isNewTransactionRequired(type, transactionActive);
+
+ if (beginTransaction) {
+ log.debug("Beginning transaction");
+ utx.begin();
+ }
+
+ Object result = null;
+ try {
+ result = ic.proceed();
+
+ if (beginTransaction) {
+ if (utx.getStatus() == Status.STATUS_MARKED_ROLLBACK) {
+ log.debug("Rolling back transaction marked for rollback");
+ utx.rollback();
+ }
+ else {
+ log.debug("Committing transaction");
+ utx.commit();
+ }
+ }
+
+ return result;
+ } catch (Exception e) {
+ if (beginTransaction && utx.getStatus() != Status.STATUS_NO_TRANSACTION)
{
+ // FIXME don't rollback if this is an application exception which
indicates no rollback
+ log.debug("Rolling back transaction as the result of an
exception");
+ utx.rollback();
+ }
+
+ throw e;
+ }
+ }
+
+ /**
+ * Get the TransactionPropagation value
+ * FIXME cache this information
+ */
+ private TransactionPropagation getTransactionPropagation(Method m) {
+ // first look at the explicit method-level annotation
+ if (m.isAnnotationPresent(Transactional.class)) {
+ return m.getAnnotation(Transactional.class).value();
+ }
+ // now look at the method-level meta-annotations
+ for (Annotation a: m.getAnnotations()) {
+ if (a.annotationType().isAnnotationPresent(Transactional.class)) {
+ return a.annotationType().getAnnotation(Transactional.class).value();
+ }
+ }
+ // now try the explicit class-level annotation
+ if (m.getDeclaringClass().isAnnotationPresent(Transactional.class)) {
+ return m.getDeclaringClass().getAnnotation(Transactional.class).value();
+ }
+ // finally, try the class-level meta-annotations
+ for (Annotation a: m.getDeclaringClass().getAnnotations()) {
+ if (a.annotationType().isAnnotationPresent(Transactional.class)) {
+ return a.annotationType().getAnnotation(Transactional.class).value();
+ }
+ }
+ return null;
+ }
+
+ private boolean isNewTransactionRequired(TransactionPropagation type, boolean
transactionActive) {
+ switch (type) {
+ case REQUIRED:
+ return !transactionActive;
+ case SUPPORTS:
+ return false;
+ case MANDATORY:
+ if (!transactionActive) {
+ throw new IllegalStateException("No transaction active on call to
method that requires a transaction.");
+ }
+ else {
+ return false;
+ }
+ case NEVER:
+ if (transactionActive) {
+ throw new IllegalStateException("Transaction active on call to method
that does not support transactions.");
+ }
+ else {
+ return false;
+ }
+ default:
+ throw new IllegalArgumentException("Unknown transaction type " +
type);
+ }
+ }
+}
\ No newline at end of file
Copied:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/LocalEjbSynchronizations.java
(from rev 13427,
modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/LocalEjbSynchronizations.java)
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/LocalEjbSynchronizations.java
(rev 0)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/LocalEjbSynchronizations.java 2010-07-18
08:51:36 UTC (rev 13428)
@@ -0,0 +1,36 @@
+/*
+ * 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.transaction;
+
+import javax.ejb.Local;
+
+/**
+ * Local interface for EjbTransaction
+ *
+ * @author Gavin King
+ *
+ */
+@Local
+public interface LocalEjbSynchronizations extends Synchronizations
+{
+ public void destroy();
+}
Copied:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/Naming.java (from
rev 13427,
modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/Naming.java)
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/Naming.java
(rev 0)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/Naming.java 2010-07-18
08:51:36 UTC (rev 13428)
@@ -0,0 +1,104 @@
+/*
+ * 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.transaction;
+
+import java.util.Hashtable;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * this has been ported to seam and hacked to make it work
+ *
+ * we need to figure out what we are doing with JNDI in seam 3 and make this go
+ * away
+ *
+ * @author stuart
+ *
+ */
+public final class Naming
+{
+ private static final Logger log = LoggerFactory.getLogger(Naming.class);
+ private static Hashtable initialContextProperties;
+
+ private static InitialContext initialContext;
+
+ public static InitialContext getInitialContext(Hashtable<String, String> props)
throws NamingException
+ {
+ if (props == null)
+ {
+ // throw new
+ // IllegalStateException("JNDI properties not initialized, Seam was not
started correctly");
+ }
+ props = new Hashtable<String, String>();
+
+ if (log.isDebugEnabled())
+ {
+ log.debug("JNDI InitialContext properties:" + props);
+ }
+
+ try
+ {
+ return props.size() == 0 ? new InitialContext() : new InitialContext(props);
+ }
+ catch (NamingException e)
+ {
+ log.debug("Could not obtain initial context");
+ throw e;
+ }
+
+ }
+
+ public static InitialContext getInitialContext() throws NamingException
+ {
+ if (initialContext == null)
+ initInitialContext();
+
+ return initialContext;
+ }
+
+ private static synchronized void initInitialContext() throws NamingException
+ {
+ if (initialContext == null)
+ {
+ initialContext = getInitialContext(initialContextProperties);
+ }
+ }
+
+ private Naming()
+ {
+ }
+
+ public static void setInitialContextProperties(Hashtable initialContextProperties)
+ {
+ Naming.initialContextProperties = initialContextProperties;
+ initialContext = null;
+ }
+
+ public static Hashtable getInitialContextProperties()
+ {
+ return initialContextProperties;
+ }
+}
Copied:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/NoTransaction.java
(from rev 13427,
modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/NoTransaction.java)
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/NoTransaction.java
(rev 0)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/NoTransaction.java 2010-07-18
08:51:36 UTC (rev 13428)
@@ -0,0 +1,93 @@
+/*
+ * 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.transaction;
+
+import javax.persistence.EntityManager;
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+import javax.transaction.Status;
+import javax.transaction.Synchronization;
+import javax.transaction.SystemException;
+
+import org.jboss.weld.extensions.core.Veto;
+
+/**
+ * When no kind of transaction management exists.
+ *
+ * @author Mike Youngstrom
+ * @author Gavin King
+ *
+ */
+@Veto
+public class NoTransaction extends AbstractUserTransaction
+{
+
+ public NoTransaction()
+ {
+ super(null);
+ }
+
+ public void begin() throws NotSupportedException, SystemException
+ {
+ throw new UnsupportedOperationException("no transaction");
+ }
+
+ public void commit() throws RollbackException, HeuristicMixedException,
HeuristicRollbackException, SecurityException, IllegalStateException, SystemException
+ {
+ throw new UnsupportedOperationException("no transaction");
+ }
+
+ public int getStatus() throws SystemException
+ {
+ return Status.STATUS_NO_TRANSACTION;
+ }
+
+ public void rollback() throws IllegalStateException, SecurityException,
SystemException
+ {
+ throw new UnsupportedOperationException("no transaction");
+ }
+
+ public void setRollbackOnly() throws IllegalStateException, SystemException
+ {
+ throw new UnsupportedOperationException("no transaction");
+ }
+
+ public void setTransactionTimeout(int timeout) throws SystemException
+ {
+ throw new UnsupportedOperationException("no transaction");
+ }
+
+ @Override
+ public void registerSynchronization(Synchronization sync)
+ {
+ throw new UnsupportedOperationException("no transaction");
+ }
+
+ @Override
+ public void enlist(EntityManager entityManager) throws SystemException
+ {
+ // no-op
+ }
+
+}
Copied:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/SeSynchronizations.java
(from rev 13427,
modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/SeSynchronizations.java)
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/SeSynchronizations.java
(rev 0)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/SeSynchronizations.java 2010-07-18
08:51:36 UTC (rev 13428)
@@ -0,0 +1,97 @@
+/*
+ * 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.transaction;
+
+import java.util.Stack;
+
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.inject.Alternative;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+import javax.transaction.Synchronization;
+
+/**
+ * This implementation does not have access to the JTA TransactionManager, so it
+ * is not fully aware of container managed transaction lifecycle, and is not
+ * able to register Synchronizations with a container managed transaction.
+ *
+ * This is an alternative, and as such must be enabled in beans.xml.
+ *
+ * @author Gavin King
+ * @author Stuart Douglas
+ */
+@RequestScoped
+@Alternative
+public class SeSynchronizations implements Synchronizations
+{
+ protected Stack<SynchronizationRegistry> synchronizations = new
Stack<SynchronizationRegistry>();
+
+ @Inject
+ private BeanManager beanManager;
+
+ public void afterTransactionBegin()
+ {
+ synchronizations.push(new SynchronizationRegistry(beanManager));
+ }
+
+ public void afterTransactionCommit(boolean success)
+ {
+ if (!synchronizations.isEmpty())
+ {
+ synchronizations.pop().afterTransactionCompletion(success);
+ }
+ }
+
+ public void afterTransactionRollback()
+ {
+ if (!synchronizations.isEmpty())
+ {
+ synchronizations.pop().afterTransactionCompletion(false);
+ }
+ }
+
+ public void beforeTransactionCommit()
+ {
+ if (!synchronizations.isEmpty())
+ {
+ synchronizations.peek().beforeTransactionCompletion();
+ }
+ }
+
+ public void registerSynchronization(Synchronization sync)
+ {
+ if (synchronizations.isEmpty())
+ {
+ throw new IllegalStateException("Transaction begin not detected, try
installing transaction:ejb-transaction in components.xml");
+ }
+ else
+ {
+ synchronizations.peek().registerSynchronization(sync);
+ }
+ }
+
+ public boolean isAwareOfContainerTransactions()
+ {
+ return false;
+ }
+
+}
Copied:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/SynchronizationRegistry.java
(from rev 13427,
modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/SynchronizationRegistry.java)
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/SynchronizationRegistry.java
(rev 0)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/SynchronizationRegistry.java 2010-07-18
08:51:36 UTC (rev 13428)
@@ -0,0 +1,94 @@
+/*
+ * 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.transaction;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.enterprise.inject.spi.BeanManager;
+import javax.transaction.Status;
+import javax.transaction.Synchronization;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A list of Synchronizations to be invoked before and after transaction
+ * completion. This class is used when we can't register a synchronization
+ * directly with JTA.
+ *
+ * @author Gavin King
+ *
+ */
+class SynchronizationRegistry
+{
+
+ private final BeanManager beanManager;
+
+ public SynchronizationRegistry(BeanManager beanManager)
+ {
+ this.beanManager = beanManager;
+ }
+
+ private static final Logger log =
LoggerFactory.getLogger(SynchronizationRegistry.class);
+
+ private List<Synchronization> synchronizations = new
ArrayList<Synchronization>();
+
+ void registerSynchronization(Synchronization sync)
+ {
+ synchronizations.add(sync);
+ }
+
+ void afterTransactionCompletion(boolean success)
+ {
+ beanManager.fireEvent(new AfterTransactionCompletion(success));
+ for (Synchronization sync : synchronizations)
+ {
+ try
+ {
+ sync.afterCompletion(success ? Status.STATUS_COMMITTED :
Status.STATUS_ROLLEDBACK);
+ }
+ catch (Exception e)
+ {
+ log.error("Exception processing transaction Synchronization after
completion", e);
+ }
+ }
+ synchronizations.clear();
+ }
+
+ void beforeTransactionCompletion()
+ {
+ beanManager.fireEvent(new BeforeTransactionCompletion());
+ for (Synchronization sync : synchronizations)
+ {
+ try
+ {
+ sync.beforeCompletion();
+ }
+ catch (Exception e)
+ {
+ log.error("Exception processing transaction Synchronization before
completion", e);
+ }
+ }
+ }
+
+}
Copied:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/Synchronizations.java
(from rev 13427,
modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/Synchronizations.java)
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/Synchronizations.java
(rev 0)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/Synchronizations.java 2010-07-18
08:51:36 UTC (rev 13428)
@@ -0,0 +1,45 @@
+/*
+ * 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.transaction;
+
+import javax.transaction.Synchronization;
+
+/**
+ * Interface for registering transaction synchronizations
+ *
+ * @author Gavin King
+ *
+ */
+public interface Synchronizations
+{
+ public void afterTransactionBegin();
+
+ public void afterTransactionCommit(boolean success);
+
+ public void afterTransactionRollback();
+
+ public void beforeTransactionCommit();
+
+ public void registerSynchronization(Synchronization sync);
+
+ public boolean isAwareOfContainerTransactions();
+}
\ No newline at end of file
Copied:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/Transaction.java
(from rev 13427,
modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/Transaction.java)
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/Transaction.java
(rev 0)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/Transaction.java 2010-07-18
08:51:36 UTC (rev 13428)
@@ -0,0 +1,109 @@
+/*
+ * 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.transaction;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.naming.InitialContext;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+
+import org.jboss.weld.extensions.managedproducer.ManagedProducer;
+
+/**
+ * Supports injection of a Seam UserTransaction object that wraps the current
+ * JTA transaction or EJB container managed transaction.
+ *
+ * @author Mike Youngstrom
+ * @author Gavin King
+ * @author Stuart Douglas
+ *
+ */
+@ApplicationScoped
+public class Transaction
+{
+
+ @Inject
+ Synchronizations synchronizations;
+
+ @ManagedProducer
+ @TransactionQualifier
+ public UserTransaction getTransaction() throws NamingException
+ {
+ try
+ {
+ return createUTTransaction();
+ }
+ catch (NameNotFoundException nnfe)
+ {
+ try
+ {
+ return createCMTTransaction();
+ }
+ catch (NameNotFoundException nnfe2)
+ {
+ return createNoTransaction();
+ }
+ }
+ }
+
+ protected UserTransaction createNoTransaction()
+ {
+ return new NoTransaction();
+ }
+
+ protected UserTransaction createCMTTransaction() throws NamingException
+ {
+ return new CMTTransaction(EJB.getEJBContext(), synchronizations);
+ }
+
+ protected UserTransaction createUTTransaction() throws NamingException
+ {
+ return new UTTransaction(getUserTransaction(), synchronizations);
+ }
+
+ protected javax.transaction.UserTransaction getUserTransaction() throws
NamingException
+ {
+ InitialContext context = Naming.getInitialContext();
+ try
+ {
+ return (javax.transaction.UserTransaction)
context.lookup("java:comp/UserTransaction");
+ }
+ catch (NameNotFoundException nnfe)
+ {
+ try
+ {
+ // Embedded JBoss has no java:comp/UserTransaction
+ javax.transaction.UserTransaction ut = (javax.transaction.UserTransaction)
context.lookup("UserTransaction");
+ ut.getStatus(); // for glassfish, which can return an unusable UT
+ return ut;
+ }
+ catch (Exception e)
+ {
+ throw nnfe;
+ }
+ }
+ }
+
+}
+
+
Copied:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/TransactionExtension.java
(from rev 13427,
modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/TransactionExtension.java)
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/TransactionExtension.java
(rev 0)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/TransactionExtension.java 2010-07-18
08:51:36 UTC (rev 13428)
@@ -0,0 +1,157 @@
+/*
+ * 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.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.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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Extension than provides a {@link UserTransaction} if no other UserTransaction
+ * has been registered.
+ *
+ * This allows the user to register a transaction via seam XML and have it
+ * automatically replace the default UserTransaction implementation
+ *
+ * This is not done with alternatives, because that would require specifying the
+ * transaction manager on a per module basis, and some of the UserTransaction
+ * implementations need to be configured via seam xml anyway, so they would have
+ * to be configured twice
+ *
+ * @author Stuart Douglas
+ *
+ */
+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)
+ {
+ AnnotatedTypeBuilder<UserTransaction> utbuilder =
AnnotatedTypeBuilder.newInstance(UserTransaction.class);
+ BeanBuilder<UserTransaction> builder = new
BeanBuilder<UserTransaction>(utbuilder.create(), manager);
+ builder.defineBeanFromAnnotatedType();
+
+ builder.setBeanLifecycle(new TransactionLifecycle(manager));
+ builder.setInjectionTarget(new NoOpInjectionTarget());
+ DefaultBeanExtension.addDefaultBean(UserTransaction.class, builder.create());
+ }
+
+ private static class TransactionLifecycle implements
BeanLifecycle<UserTransaction>
+ {
+
+ private final BeanManager manager;
+
+ private Bean<?> transactionBean;
+
+ public TransactionLifecycle(BeanManager manager)
+ {
+ this.manager = manager;
+ }
+
+ public UserTransaction create(BeanImpl<UserTransaction> bean,
CreationalContext<UserTransaction> ctx)
+ {
+ if (transactionBean == null)
+ {
+ // this does not need to be thread safe, it does not matter if this
+ // is initialised twice
+ setupBeanDefinition();
+ }
+ return (UserTransaction) manager.getReference(transactionBean,
UserTransaction.class, ctx);
+ }
+
+ public void destroy(BeanImpl<UserTransaction> bean, UserTransaction arg0,
CreationalContext<UserTransaction> arg1)
+ {
+ arg1.release();
+ }
+
+ /**
+ * we need to init the bean definition lazily
+ */
+ private void setupBeanDefinition()
+ {
+ Set<Bean<?>> beans = manager.getBeans(UserTransaction.class, new
TransactionQualifier.TransactionQualifierLiteral());
+ if (beans.isEmpty())
+ {
+ log.error("No bean with type " + UserTransaction.class.getName() +
" and qualifier " + TransactionQualifier.class.getName() + " registered,
SEAM TRANSACTIONS ARE DISABLED");
+ }
+ else if (beans.size() > 1)
+ {
+ log.error("More than 1 bean with type " +
UserTransaction.class.getName() + " and qualifier " +
TransactionQualifier.class.getName() + " registered, SEAM TRANSACTIONS ARE
DISABLED");
+ }
+ transactionBean = beans.iterator().next();
+ }
+
+ }
+
+ private static class NoOpInjectionTarget implements
InjectionTarget<UserTransaction>
+ {
+
+ 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)
+ {
+
+ }
+
+ }
+}
Copied:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/TransactionInterceptor.java
(from rev 13427,
modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/TransactionInterceptor.java)
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/TransactionInterceptor.java
(rev 0)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/TransactionInterceptor.java 2010-07-18
08:51:36 UTC (rev 13428)
@@ -0,0 +1,141 @@
+/*
+ * 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.transaction;
+
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.inject.Inject;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.Interceptor;
+import javax.interceptor.InvocationContext;
+
+/**
+ * Implements transaction propagation rules for Seam JavaBean components.
+ *
+ * @author Gavin King
+ * @author Shane Bryzak
+ */
+@Transactional
+@Interceptor
+public class TransactionInterceptor
+{
+ private static final long serialVersionUID = -4364203056333738988L;
+
+ transient private Map<AnnotatedElement, TransactionMetadata> transactionMetadata
= new HashMap<AnnotatedElement, TransactionMetadata>();
+
+ @Inject
+ UserTransaction transaction;
+
+ private class TransactionMetadata
+ {
+ private boolean annotationPresent;
+ TransactionPropagation propType;
+
+ public TransactionMetadata(AnnotatedElement element)
+ {
+ annotationPresent = element.isAnnotationPresent(Transactional.class);
+
+ if (annotationPresent)
+ {
+ propType = element.getAnnotation(Transactional.class).value();
+ }
+ }
+
+ public boolean isAnnotationPresent()
+ {
+ return annotationPresent;
+ }
+
+ public boolean isNewTransactionRequired(boolean transactionActive)
+ {
+ return propType != null &&
propType.isNewTransactionRequired(transactionActive);
+ }
+ }
+
+ private TransactionMetadata lookupTransactionMetadata(AnnotatedElement element)
+ {
+ if (transactionMetadata == null)
+ {
+ transactionMetadata = new HashMap<AnnotatedElement,
TransactionMetadata>();
+ }
+
+ TransactionMetadata metadata = transactionMetadata.get(element);
+
+ if (metadata == null)
+ {
+ metadata = loadMetadata(element);
+ }
+
+ return metadata;
+ }
+
+ private synchronized TransactionMetadata loadMetadata(AnnotatedElement element)
+ {
+ if (!transactionMetadata.containsKey(element))
+ {
+ TransactionMetadata metadata = new TransactionMetadata(element);
+ transactionMetadata.put(element, metadata);
+ return metadata;
+ }
+
+ return transactionMetadata.get(element);
+ }
+
+ @AroundInvoke
+ public Object aroundInvoke(final InvocationContext invocation) throws Exception
+ {
+ return new Work()
+ {
+
+ @Override
+ protected Object work() throws Exception
+ {
+ return invocation.proceed();
+ }
+
+ @Override
+ protected boolean isNewTransactionRequired(boolean transactionActive)
+ {
+ return isNewTransactionRequired(invocation.getMethod(),
invocation.getTarget().getClass(), transactionActive);
+ }
+
+ private boolean isNewTransactionRequired(Method method, Class<?>
beanClass, boolean transactionActive)
+ {
+ TransactionMetadata metadata = lookupTransactionMetadata(method);
+ if (metadata.isAnnotationPresent())
+ {
+ return metadata.isNewTransactionRequired(transactionActive);
+ }
+ else
+ {
+ metadata = lookupTransactionMetadata(beanClass);
+ return metadata.isNewTransactionRequired(transactionActive);
+ }
+ }
+
+ }.workInTransaction(transaction);
+ }
+
+}
Deleted:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/TransactionPropagation.java
===================================================================
---
modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/TransactionPropagation.java 2010-07-15
04:17:18 UTC (rev 13402)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/TransactionPropagation.java 2010-07-18
08:51:36 UTC (rev 13428)
@@ -1,8 +0,0 @@
-package org.jboss.seam.transaction;
-
-/**
- * @author Dan Allen
- */
-public enum TransactionPropagation {
- REQUIRED, SUPPORTS, MANDATORY, NEVER;
-}
\ No newline at end of file
Copied:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/TransactionPropagation.java
(from rev 13427,
modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/TransactionPropagation.java)
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/TransactionPropagation.java
(rev 0)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/TransactionPropagation.java 2010-07-18
08:51:36 UTC (rev 13428)
@@ -0,0 +1,61 @@
+/*
+ * 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.transaction;
+
+/**
+ * @author Dan Allen
+ */
+public enum TransactionPropagation
+{
+ REQUIRED, SUPPORTS, MANDATORY, NEVER;
+
+ public boolean isNewTransactionRequired(boolean transactionActive)
+ {
+ switch (this)
+ {
+ case REQUIRED:
+ return !transactionActive;
+ case SUPPORTS:
+ return false;
+ case MANDATORY:
+ if (!transactionActive)
+ {
+ throw new IllegalStateException("No transaction active on call to
MANDATORY method");
+ }
+ else
+ {
+ return false;
+ }
+ case NEVER:
+ if (transactionActive)
+ {
+ throw new IllegalStateException("Transaction active on call to NEVER
method");
+ }
+ else
+ {
+ return false;
+ }
+ default:
+ throw new IllegalArgumentException();
+ }
+ }
+}
\ No newline at end of file
Copied:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/TransactionQualifier.java
(from rev 13427,
modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/TransactionQualifier.java)
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/TransactionQualifier.java
(rev 0)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/TransactionQualifier.java 2010-07-18
08:51:36 UTC (rev 13428)
@@ -0,0 +1,44 @@
+/*
+ * 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.transaction;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+import javax.enterprise.util.AnnotationLiteral;
+import javax.inject.Qualifier;
+
+/**
+ * Internal qualifier that is used to stop some beans from being exposed to the
+ * user
+ *
+ * @author Stuart Douglas
+ *
+ */
+(a)Retention(RetentionPolicy.RUNTIME)
+@Qualifier
+@interface TransactionQualifier
+{
+ public static class TransactionQualifierLiteral extends
AnnotationLiteral<TransactionQualifier> implements TransactionQualifier
+ {
+ }
+}
Deleted:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/Transactional.java
===================================================================
---
modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/Transactional.java 2010-07-15
04:17:18 UTC (rev 13402)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/Transactional.java 2010-07-18
08:51:36 UTC (rev 13428)
@@ -1,25 +0,0 @@
-package org.jboss.seam.transaction;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-import javax.enterprise.util.Nonbinding;
-import javax.interceptor.InterceptorBinding;
-
-/**
- * @author Dan Allen
- */
-@Inherited
-@InterceptorBinding
-(a)Retention(RetentionPolicy.RUNTIME)
-(a)Target({ElementType.METHOD, ElementType.TYPE})
-public @interface Transactional {
- /**
- * The transaction propagation type.
- *
- * @return REQUIRED by default
- */
- @Nonbinding TransactionPropagation value() default TransactionPropagation.REQUIRED;
-}
\ No newline at end of file
Copied:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/Transactional.java
(from rev 13427,
modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/Transactional.java)
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/Transactional.java
(rev 0)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/Transactional.java 2010-07-18
08:51:36 UTC (rev 13428)
@@ -0,0 +1,49 @@
+/*
+ * 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.transaction;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import javax.enterprise.util.Nonbinding;
+import javax.interceptor.InterceptorBinding;
+
+/**
+ * @author Dan Allen
+ */
+@Inherited
+@InterceptorBinding
+(a)Retention(RetentionPolicy.RUNTIME)
+@Target( { ElementType.METHOD, ElementType.TYPE })
+public @interface Transactional
+{
+ /**
+ * The transaction propagation type.
+ *
+ * @return REQUIRED by default
+ */
+ @Nonbinding
+ TransactionPropagation value() default TransactionPropagation.REQUIRED;
+}
\ No newline at end of file
Copied:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/UTTransaction.java
(from rev 13427,
modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/UTTransaction.java)
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/UTTransaction.java
(rev 0)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/UTTransaction.java 2010-07-18
08:51:36 UTC (rev 13428)
@@ -0,0 +1,117 @@
+/*
+ * 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.transaction;
+
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+import javax.transaction.Synchronization;
+import javax.transaction.SystemException;
+
+import org.jboss.weld.extensions.core.Veto;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Wraps JTA transaction management in a Seam UserTransaction interface.
+ *
+ * @author Mike Youngstrom
+ * @author Gavin King
+ *
+ */
+@Veto
+public class UTTransaction extends AbstractUserTransaction
+{
+ private static final Logger log = LoggerFactory.getLogger(UTTransaction.class);
+
+ private final javax.transaction.UserTransaction delegate;
+
+ UTTransaction(javax.transaction.UserTransaction delegate, Synchronizations sync)
+ {
+ super(sync);
+ this.delegate = delegate;
+ if (delegate == null)
+ {
+ throw new IllegalArgumentException("null UserTransaction");
+ }
+ }
+
+ public void begin() throws NotSupportedException, SystemException
+ {
+ log.debug("beginning JTA transaction");
+ delegate.begin();
+ getSynchronizations().afterTransactionBegin();
+ }
+
+ public void commit() throws RollbackException, HeuristicMixedException,
HeuristicRollbackException, SecurityException, IllegalStateException, SystemException
+ {
+ log.debug("committing JTA transaction");
+ boolean success = false;
+ Synchronizations synchronizations = getSynchronizations();
+ synchronizations.beforeTransactionCommit();
+ try
+ {
+ delegate.commit();
+ success = true;
+ }
+ finally
+ {
+ synchronizations.afterTransactionCommit(success);
+ }
+ }
+
+ public void rollback() throws IllegalStateException, SecurityException,
SystemException
+ {
+ log.debug("rolling back JTA transaction");
+ try
+ {
+ delegate.rollback();
+ }
+ finally
+ {
+ getSynchronizations().afterTransactionRollback();
+ }
+ }
+
+ public int getStatus() throws SystemException
+ {
+ return delegate.getStatus();
+ }
+
+ public void setRollbackOnly() throws IllegalStateException, SystemException
+ {
+ delegate.setRollbackOnly();
+ }
+
+ public void setTransactionTimeout(int timeout) throws SystemException
+ {
+ delegate.setTransactionTimeout(timeout);
+ }
+
+ @Override
+ public void registerSynchronization(Synchronization sync)
+ {
+ getSynchronizations().registerSynchronization(sync);
+ }
+
+}
Copied:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/UserTransaction.java
(from rev 13427,
modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/UserTransaction.java)
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/UserTransaction.java
(rev 0)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/UserTransaction.java 2010-07-18
08:51:36 UTC (rev 13428)
@@ -0,0 +1,57 @@
+/*
+ * 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.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;
+}
Copied: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/Work.java
(from rev 13427,
modules/persistence/trunk/src/main/java/org/jboss/seam/transaction/Work.java)
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/Work.java
(rev 0)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/Work.java 2010-07-18
08:51:36 UTC (rev 13428)
@@ -0,0 +1,118 @@
+/*
+ * 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.transaction;
+
+import javax.ejb.ApplicationException;
+import javax.transaction.Status;
+import javax.transaction.UserTransaction;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Performs work in a JTA transaction.
+ *
+ * @author Gavin King
+ */
+public abstract class Work<T>
+{
+ private static final Logger log = LoggerFactory.getLogger(Work.class);
+
+ protected abstract T work() throws Exception;
+
+ protected boolean isNewTransactionRequired(boolean transactionActive)
+ {
+ return !transactionActive;
+ }
+
+ public final T workInTransaction(org.jboss.seam.transaction.UserTransaction
transaction) throws Exception
+ {
+ boolean transactionActive = transaction.isActiveOrMarkedRollback() ||
transaction.isRolledBack();
+ // TODO: temp workaround, what should we really do in this case??
+ boolean newTransactionRequired = isNewTransactionRequired(transactionActive);
+ UserTransaction userTransaction = newTransactionRequired ? transaction : null;
+
+ try
+ {
+ if (newTransactionRequired)
+ {
+ log.debug("beginning transaction");
+ userTransaction.begin();
+ }
+
+ T result = work();
+ if (newTransactionRequired)
+ {
+ if (transaction.isMarkedRollback())
+ {
+ log.debug("rolling back transaction");
+ userTransaction.rollback();
+ }
+ else
+ {
+ log.debug("committing transaction");
+ userTransaction.commit();
+ }
+ }
+ return result;
+ }
+ catch (Exception e)
+ {
+ if (newTransactionRequired && userTransaction.getStatus() !=
Status.STATUS_NO_TRANSACTION )
+ {
+ if(isRollbackRequired(e, true))
+ {
+ log.debug("rolling back transaction");
+ userTransaction.rollback();
+ }
+ else
+ {
+ log.debug("committing transaction after
ApplicationException(rollback=false):" + e.getMessage());
+ userTransaction.commit();
+ }
+ }
+ else if (userTransaction.getStatus() != Status.STATUS_NO_TRANSACTION &&
isRollbackRequired(e, true))
+ {
+ userTransaction.setRollbackOnly();
+ }
+
+ throw e;
+ }
+
+ }
+
+ public static boolean isRollbackRequired(Exception e, boolean isJavaBean)
+ {
+ Class<? extends Exception> clazz = e.getClass();
+ return (isSystemException(e, isJavaBean, clazz)) ||
(clazz.isAnnotationPresent(ApplicationException.class) &&
clazz.getAnnotation(ApplicationException.class).rollback());
+ }
+
+ private static boolean isSystemException(Exception e, boolean isJavaBean, Class<?
extends Exception> clazz)
+ {
+ return isJavaBean && (e instanceof RuntimeException) &&
!clazz.isAnnotationPresent(ApplicationException.class);
+ // &&
+ // TODO: this is hackish, maybe just turn off RollackInterceptor for
+ // @Converter/@Validator components
+ // !JSF.VALIDATOR_EXCEPTION.isInstance(e) &&
+ // !JSF.CONVERTER_EXCEPTION.isInstance(e);
+ }
+}
Deleted: modules/persistence/trunk/impl/src/main/resources/META-INF/beans.xml
===================================================================
--- modules/persistence/trunk/src/main/resources/META-INF/beans.xml 2010-07-15 04:17:18
UTC (rev 13402)
+++ modules/persistence/trunk/impl/src/main/resources/META-INF/beans.xml 2010-07-18
08:51:36 UTC (rev 13428)
@@ -1,11 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- The contents of this file is permitted to be empty.
- The schema definition is provided for your convenience.
--->
-<beans
xmlns="http://java.sun.com/xml/ns/javaee"
-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="
-
http://java.sun.com/xml/ns/javaee
-
http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
-</beans>
Copied: modules/persistence/trunk/impl/src/main/resources/META-INF/beans.xml (from rev
13406, modules/persistence/trunk/src/main/resources/META-INF/beans.xml)
===================================================================
--- modules/persistence/trunk/impl/src/main/resources/META-INF/beans.xml
(rev 0)
+++ modules/persistence/trunk/impl/src/main/resources/META-INF/beans.xml 2010-07-18
08:51:36 UTC (rev 13428)
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ The contents of this file is permitted to be empty.
+ The schema definition is provided for your convenience.
+-->
+<beans
xmlns="http://java.sun.com/xml/ns/javaee"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+
http://java.sun.com/xml/ns/javaee
+
http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
+ <interceptors>
+ <class>org.jboss.seam.transaction.TransactionInterceptor</class>
+ </interceptors>
+</beans>
Deleted:
modules/persistence/trunk/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
===================================================================
---
modules/persistence/trunk/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension 2010-07-15
04:17:18 UTC (rev 13402)
+++
modules/persistence/trunk/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension 2010-07-18
08:51:36 UTC (rev 13428)
@@ -1 +0,0 @@
-org.jboss.seam.persistence.PersistenceContextExtension
Copied:
modules/persistence/trunk/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
(from rev 13415,
modules/persistence/trunk/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
(rev 0)
+++
modules/persistence/trunk/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension 2010-07-18
08:51:36 UTC (rev 13428)
@@ -0,0 +1,2 @@
+org.jboss.seam.persistence.PersistenceContextExtension
+org.jboss.seam.transaction.TransactionExtension
\ No newline at end of file
Copied: modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions (from rev
13405, modules/persistence/trunk/src/test/java/org/jboss/seam/transactions)
Deleted:
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/SimpleTest.java
===================================================================
---
modules/persistence/trunk/src/test/java/org/jboss/seam/transactions/test/SimpleTest.java 2010-07-15
12:52:34 UTC (rev 13405)
+++
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/SimpleTest.java 2010-07-18
08:51:36 UTC (rev 13428)
@@ -1,75 +0,0 @@
-package org.jboss.seam.transactions.test;
-
-import java.util.List;
-
-import javax.inject.Inject;
-import javax.persistence.EntityManager;
-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.transaction.Transaction;
-import org.jboss.seam.transaction.UserTransaction;
-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;
-
-(a)RunWith(Arquillian.class)
-public class SimpleTest
-{
- @Deployment
- public static Archive<?> createTestArchive()
- {
-
- WebArchive war = ShrinkWrap.create("test.war",
WebArchive.class).addLibraries(MavenArtifactResolver.resolve(ArtifactNames.WELD_EXTENSIONS)).addPackage(Transaction.class.getPackage()).addPackage(SimpleTest.class.getPackage()).addWebResource("META-INF/persistence.xml",
"classes/META-INF/persistence.xml").addWebResource(new ByteArrayAsset(new
byte[0]), "beans.xml");
-
- return war;
- }
-
- @Inject
- UserTransaction transaction;
-
- @PersistenceUnit
- EntityManagerFactory emf;
-
- @Test
- public void simpleTest() throws NotSupportedException, SystemException,
SecurityException, IllegalStateException, RollbackException, HeuristicMixedException,
HeuristicRollbackException
- {
- transaction.begin();
- EntityManager em = emf.createEntityManager();
- em.joinTransaction();
- Hotel h = new Hotel("test", "Fake St", "Wollongong",
"NSW", "2518", "Australia");
- em.persist(h);
- em.flush();
- transaction.commit();
-
- transaction.begin();
- em = emf.createEntityManager();
- em.joinTransaction();
- h = new Hotel("test2", "Fake St", "Wollongong",
"NSW", "2518", "Australia");
- em.persist(h);
- em.flush();
- transaction.rollback();
-
- transaction.begin();
- em = emf.createEntityManager();
- em.joinTransaction();
- List<Hotel> hotels = em.createQuery("select h from Hotel
h").getResultList();
- Assert.assertTrue(hotels.size() == 1);
- transaction.rollback();
-
- }
-}
Copied:
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionInterceptorTest.java
(from rev 13415,
modules/persistence/trunk/src/test/java/org/jboss/seam/transactions/test/TransactionInterceptorTest.java)
===================================================================
---
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionInterceptorTest.java
(rev 0)
+++
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionInterceptorTest.java 2010-07-18
08:51:36 UTC (rev 13428)
@@ -0,0 +1,108 @@
+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.transaction.Transaction;
+import org.jboss.seam.transaction.TransactionInterceptor;
+import org.jboss.seam.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.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;
+
+(a)RunWith(Arquillian.class)
+public class TransactionInterceptorTest
+{
+ @Deployment
+ public static Archive<?> createTestArchive()
+ {
+
+ WebArchive war = ShrinkWrap.create("test.war", WebArchive.class);
+ war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.WELD_EXTENSIONS));
+ 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");
+ 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;
+
+ @Inject
+ TransactionObserver observer;
+
+ @Test
+ public void testTransactionInterceptor() throws NotSupportedException,
SystemException, SecurityException, IllegalStateException, RollbackException,
HeuristicMixedException, HeuristicRollbackException
+ {
+ observer.setEnabled(true);
+ try
+ {
+ 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)
+ {
+ observer.setEnabled(false);
+ throw new RuntimeException(e);
+ }
+
+ }
+
+ 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/transactions/test/TransactionManagedBean.java
(from rev 13409,
modules/persistence/trunk/src/test/java/org/jboss/seam/transactions/test/TransactionManagedBean.java)
===================================================================
---
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionManagedBean.java
(rev 0)
+++
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionManagedBean.java 2010-07-18
08:51:36 UTC (rev 13428)
@@ -0,0 +1,44 @@
+package org.jboss.seam.transactions.test;
+
+import javax.inject.Inject;
+import javax.persistence.EntityManager;
+
+import org.jboss.seam.transaction.TransactionPropagation;
+import org.jboss.seam.transaction.Transactional;
+import org.jboss.seam.transactions.test.util.DontRollBackException;
+
+(a)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/transactions/test/TransactionObserver.java
(from rev 13409,
modules/persistence/trunk/src/test/java/org/jboss/seam/transactions/test/TransactionObserver.java)
===================================================================
---
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionObserver.java
(rev 0)
+++
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionObserver.java 2010-07-18
08:51:36 UTC (rev 13428)
@@ -0,0 +1,63 @@
+package org.jboss.seam.transactions.test;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.event.Observes;
+
+import org.jboss.seam.transaction.AfterTransactionCompletion;
+import org.jboss.seam.transaction.BeforeTransactionCompletion;
+
+@ApplicationScoped
+public class TransactionObserver
+{
+ private boolean expectSuccess, beforeTransaction, afterTransaction;
+ private boolean enabled = false;
+
+ public boolean isEnabled()
+ {
+ return enabled;
+ }
+
+ public void setEnabled(boolean enabled)
+ {
+ this.enabled = enabled;
+ }
+
+ public void reset(boolean expected)
+ {
+ beforeTransaction = false;
+ afterTransaction = false;
+ expectSuccess = expected;
+ }
+
+ public boolean isBeforeTransaction()
+ {
+ return beforeTransaction;
+ }
+
+ public boolean isAfterTransaction()
+ {
+ return afterTransaction;
+ }
+
+ public void observeBeforeTransactionCommit(@Observes BeforeTransactionCompletion
event)
+ {
+ beforeTransaction = true;
+ }
+
+ public void observeBeforeTransactionCommit(@Observes AfterTransactionCompletion
event)
+ {
+ afterTransaction = true;
+ if (expectSuccess != event.success())
+ {
+ throw new RuntimeException("Expected success to be " +
expectSuccess);
+ }
+ }
+
+ public void verify()
+ {
+ if (!((beforeTransaction || !expectSuccess) && afterTransaction))
+ {
+ throw new RuntimeException("Events not recieved before:" +
beforeTransaction + " after:" + afterTransaction);
+ }
+ }
+}
Copied:
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/UserTransactionTest.java
(from rev 13415,
modules/persistence/trunk/src/test/java/org/jboss/seam/transactions/test/UserTransactionTest.java)
===================================================================
---
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/UserTransactionTest.java
(rev 0)
+++
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/UserTransactionTest.java 2010-07-18
08:51:36 UTC (rev 13428)
@@ -0,0 +1,79 @@
+package org.jboss.seam.transactions.test;
+
+import java.util.List;
+
+import javax.inject.Inject;
+import javax.persistence.EntityManager;
+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.transaction.Transaction;
+import org.jboss.seam.transaction.UserTransaction;
+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;
+
+(a)RunWith(Arquillian.class)
+public class UserTransactionTest
+{
+ @Deployment
+ public static Archive<?> createTestArchive()
+ {
+
+ 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.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;
+
+ @Test
+ public void userTransactionTest() throws NotSupportedException, SystemException,
SecurityException, IllegalStateException, RollbackException, HeuristicMixedException,
HeuristicRollbackException
+ {
+ transaction.begin();
+ EntityManager em = emf.createEntityManager();
+ em.joinTransaction();
+ Hotel h = new Hotel("test", "Fake St", "Wollongong",
"NSW", "2518", "Australia");
+ em.persist(h);
+ em.flush();
+ transaction.commit();
+
+ transaction.begin();
+ em = emf.createEntityManager();
+ em.joinTransaction();
+ h = new Hotel("test2", "Fake St", "Wollongong",
"NSW", "2518", "Australia");
+ em.persist(h);
+ em.flush();
+ transaction.rollback();
+
+ transaction.begin();
+ em = emf.createEntityManager();
+ em.joinTransaction();
+ List<Hotel> hotels = em.createQuery("select h from Hotel
h").getResultList();
+ Assert.assertTrue(hotels.size() == 1);
+ transaction.rollback();
+ }
+
+}
Copied:
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/util/DontRollBackException.java
(from rev 13408,
modules/persistence/trunk/src/test/java/org/jboss/seam/transactions/test/util/DontRollBackException.java)
===================================================================
---
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/util/DontRollBackException.java
(rev 0)
+++
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/util/DontRollBackException.java 2010-07-18
08:51:36 UTC (rev 13428)
@@ -0,0 +1,9 @@
+package org.jboss.seam.transactions.test.util;
+
+import javax.ejb.ApplicationException;
+
+@ApplicationException(rollback = false)
+public class DontRollBackException extends Exception
+{
+
+}
Copied:
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/util/EntityManagerProvider.java
(from rev 13406,
modules/persistence/trunk/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
(rev 0)
+++
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/util/EntityManagerProvider.java 2010-07-18
08:51:36 UTC (rev 13428)
@@ -0,0 +1,12 @@
+package org.jboss.seam.transactions.test.util;
+
+import javax.enterprise.inject.Produces;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+public class EntityManagerProvider
+{
+ @PersistenceContext
+ @Produces
+ EntityManager entityManager;
+}
Copied: modules/persistence/trunk/impl/src/test/resources/META-INF (from rev 13405,
modules/persistence/trunk/src/test/resources/META-INF)
Copied: modules/persistence/trunk/impl/src/test/resources/arquillian.xml (from rev 13405,
modules/persistence/trunk/src/test/resources/arquillian.xml)
===================================================================
--- modules/persistence/trunk/impl/src/test/resources/arquillian.xml
(rev 0)
+++ modules/persistence/trunk/impl/src/test/resources/arquillian.xml 2010-07-18 08:51:36
UTC (rev 13428)
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<arquillian
xmlns="http://jboss.com/arquillian"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:gfembedded="urn:arq:org.jboss.arquillian.glassfish.embedded30"
+
xmlns:gfremote="urn:arq:org.jboss.arquillian.container.glassfish.remote30">
+
+ <engine>
+ <deploymentExportPath>/tmp/</deploymentExportPath>
+ </engine>
+
+ <gfremote:container>
+ <gfremote:remoteServerHttpPort>7070</gfremote:remoteServerHttpPort>
+ </gfremote:container>
+
+ <gfembedded:container>
+
<gfembedded:sunResourcesXml>src/test/resources-glassfish/sun-resources.xml</gfembedded:sunResourcesXml>
+ </gfembedded:container>
+
+</arquillian>
Copied: modules/persistence/trunk/impl/src/test/resources-glassfish (from rev 13405,
modules/persistence/trunk/src/test/resources-glassfish)
Copied: modules/persistence/trunk/impl/src/test/resources-jbossas (from rev 13405,
modules/persistence/trunk/src/test/resources-jbossas)
Modified: modules/persistence/trunk/pom.xml
===================================================================
--- modules/persistence/trunk/pom.xml 2010-07-18 07:59:16 UTC (rev 13427)
+++ modules/persistence/trunk/pom.xml 2010-07-18 08:51:36 UTC (rev 13428)
@@ -1,241 +1,101 @@
-<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
<parent>
- <artifactId>seam-parent</artifactId>
<groupId>org.jboss.seam</groupId>
- <version>2</version>
+ <artifactId>seam-parent</artifactId>
+ <version>1</version>
</parent>
- <modelVersion>4.0.0</modelVersion>
- <groupId>org.jboss.seam</groupId>
- <artifactId>seam-persistence</artifactId>
- <packaging>jar</packaging>
+ <artifactId>seam-persistence-parent</artifactId>
+ <groupId>org.jboss.seam.persistence</groupId>
<version>3.0.0-SNAPSHOT</version>
- <name>Seam Persistence</name>
- <properties>
- <seam.version>3.0.0.b01</seam.version>
- <arquillian.version>1.0.0-SNAPSHOT</arquillian.version>
- <junit.version>4.8.1</junit.version>
- <jboss.home>${env.JBOSS_HOME}</jboss.home>
- <jboss.domain>default</jboss.domain>
- <glassfish.version>3.0.1-b19</glassfish.version>
- <jboss-as-client.version>6.0.0-SNAPSHOT</jboss-as-client.version>
- <jboss-javaee6-spec.version>1.0.0.Beta4</jboss-javaee6-spec.version>
- <jboss-server-manager.version>1.0.3.GA</jboss-server-manager.version>
- </properties>
+ <packaging>pom</packaging>
+ <name>Seam Persistence Module Parent POM</name>
<prerequisites>
<maven>3.0</maven>
</prerequisites>
+ <description>
+ The Parent for Seam Persistence Modules
+ </description>
+
+ <url>http://www.seamframework.org</url>
+
+ <modules>
+ <module>api</module>
+ <module>impl</module>
+ </modules>
+
+ <properties>
+ <seam.version>3.0.0.b01</seam.version>
+ </properties>
+
<dependencyManagement>
<dependencies>
+
<dependency>
<groupId>org.jboss.seam</groupId>
<artifactId>seam</artifactId>
<version>${seam.version}</version>
- <type>pom</type>
<scope>import</scope>
+ <type>pom</type>
</dependency>
+ <!-- Need to use dependencyManagement to override org.jboss.seam:seam for
submodules -->
<dependency>
- <groupId>org.jboss.arquillian</groupId>
- <artifactId>arquillian-junit</artifactId>
- <version>${arquillian.version}</version>
- <scope>test</scope>
+ <groupId>org.jboss.seam.persistence</groupId>
+ <artifactId>seam-persistence-api</artifactId>
+ <version>${project.version}</version>
</dependency>
+
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>${junit.version}</version>
+ <groupId>org.jboss.seam.persistence</groupId>
+ <artifactId>seam-persistence</artifactId>
+ <version>${project.version}</version>
</dependency>
</dependencies>
-
-
</dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-core</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.hibernate.javax.persistence</groupId>
- <artifactId>hibernate-jpa-2.0-api</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.jboss.spec.javax.interceptor</groupId>
- <artifactId>jboss-interceptors-api_1.1_spec</artifactId>
- <scope>provided</scope>
- </dependency>
-
- <dependency>
- <groupId>javax.transaction</groupId>
- <artifactId>jta</artifactId>
- </dependency>
-
- <dependency>
- <groupId>javax.enterprise</groupId>
- <artifactId>cdi-api</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <scope>provided</scope>
- </dependency>
-
- <dependency>
- <groupId>org.jboss.spec</groupId>
- <artifactId>jboss-javaee-6.0</artifactId>
- <version>${jboss-javaee6-spec.version}</version>
- <type>pom</type>
- <scope>provided</scope>
- </dependency>
-
- <dependency>
- <groupId>org.jboss.weld</groupId>
- <artifactId>weld-extensions</artifactId>
- <version>1.0.0-SNAPSHOT</version>
- <type>jar</type>
- <scope>compile</scope>
- </dependency>
-
- <dependency>
- <groupId>org.jboss.arquillian</groupId>
- <artifactId>arquillian-junit</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
-
<profiles>
<profile>
- <id>default</id>
+ <id>distribution</id>
<activation>
- <activeByDefault>true</activeByDefault>
+ <property>
+ <name>release</name>
+ </property>
</activation>
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <skip>true</skip>
- </configuration>
- </plugin>
- </plugins>
- </build>
+ <modules>
+ <module>dist</module>
+ <module>docs/reference</module>
+ </modules>
</profile>
-
<profile>
- <id>jbossas-remote-60</id>
+ <id>arquillian-glassfish-embedded-30</id>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
- <artifactId>arquillian-jbossas-remote-6</artifactId>
- <version>${arquillian.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.jboss.spec</groupId>
- <artifactId>jboss-javaee-6.0</artifactId>
- <version>${jboss-javaee6-spec.version}</version>
- <type>pom</type>
- <scope>provided</scope>
- </dependency>
- <!-- need for org.jnp.interfaces.NamingContextFactory -->
- <dependency>
- <groupId>org.jboss.jbossas</groupId>
- <artifactId>jboss-as-client</artifactId>
- <version>${jboss-as-client.version}</version>
- <type>pom</type>
- <scope>test</scope>
- </dependency>
- </dependencies>
- <build>
- <testResources>
- <testResource>
- <directory>src/test/resources</directory>
- </testResource>
- <testResource>
- <directory>src/test/resources-jbossas</directory>
- </testResource>
- </testResources>
- </build>
- </profile>
-
- <profile>
- <id>glassfish-embedded-30</id>
- <dependencies>
- <dependency>
- <groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-glassfish-embedded-30</artifactId>
- <version>${arquillian.version}</version>
- <scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.glassfish.extras</groupId>
- <artifactId>glassfish-embedded-all</artifactId>
- <version>${glassfish.version}</version>
- <scope>provided</scope>
- </dependency>
</dependencies>
- <build>
- <testResources>
- <testResource>
- <directory>src/test/resources</directory>
- </testResource>
- <testResource>
- <directory>src/test/resources-glassfish</directory>
- </testResource>
- </testResources>
- </build>
</profile>
-
- <profile>
- <id>glassfish-remote-30</id>
- <dependencies>
- <dependency>
- <groupId>org.jboss.arquillian.container</groupId>
- <artifactId>arquillian-glassfish-remote-30</artifactId>
- <version>${arquillian.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.glassfish.extras</groupId>
- <artifactId>glassfish-embedded-all</artifactId>
- <version>${glassfish.version}</version>
- <scope>provided</scope>
- </dependency>
- </dependencies>
- <build>
- <testResources>
- <testResource>
- <directory>src/test/resources</directory>
- </testResource>
- <testResource>
- <directory>src/test/resources-glassfish</directory>
- </testResource>
- </testResources>
- </build>
- </profile>
</profiles>
+ <developers>
+ <developer>
+ <name>Stuart Douglas</name>
+ <email>stuart.w.douglas(a)gmail.com</email>
+ </developer>
+ </developers>
+
<scm>
-
<
connection>scm:svn:http://anonsvn.jboss.org/repos/seam/modules/persist...
-
<
developerConnection>scm:svn:https://svn.jboss.org/repos/seam/modules/p...
+
<
connection>scm:svn:http://anonsvn.jboss.org/repos/seam/modules/persist...
</connection>
+
<
developerConnection>scm:svn:https://svn.jboss.org/repos/seam/modules/p...
</developerConnection>
<
url>http://fisheye.jboss.org/browse/Seam/modules/persistence/trunk<...
</scm>
-
</project>