Author: swd847
Date: 2010-07-18 06:39:12 -0400 (Sun, 18 Jul 2010)
New Revision: 13432
Added:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/AbstractUserTransaction.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/SynchronizationRegistry.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/Transaction.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionExtension.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionInterceptor.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/Work.java
Removed:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/AbstractUserTransaction.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/AfterTransactionCompletion.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/BeforeTransactionCompletion.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/JtaTxInterceptor.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/SynchronizationRegistry.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/Transaction.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionExtension.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionInterceptor.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionPropagation.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/Transactional.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/UserTransaction.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/Work.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/
Modified:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/CMTTransaction.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/EJB.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/EjbSynchronizations.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/EntityTransaction.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/LocalEjbSynchronizations.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/Naming.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/NoTransaction.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/SeSynchronizations.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/Synchronizations.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionQualifier.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/UTTransaction.java
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionInterceptorTest.java
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/UserTransactionTest.java
Log:
move classes
Copied:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction (from
rev 13428, modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction)
Deleted:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/AbstractUserTransaction.java
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/AbstractUserTransaction.java 2010-07-18
08:51:36 UTC (rev 13428)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/AbstractUserTransaction.java 2010-07-18
10:39:12 UTC (rev 13432)
@@ -1,107 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.seam.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/persistence/transaction/AbstractUserTransaction.java
(from rev 13431,
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/AbstractUserTransaction.java)
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/AbstractUserTransaction.java
(rev 0)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/AbstractUserTransaction.java 2010-07-18
10:39:12 UTC (rev 13432)
@@ -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.persistence.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;
+
+import org.jboss.seam.persistence.transaction.UserTransaction;
+
+/**
+ * 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;
+ }
+
+}
Deleted:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/AfterTransactionCompletion.java
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/AfterTransactionCompletion.java 2010-07-18
08:51:36 UTC (rev 13428)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/AfterTransactionCompletion.java 2010-07-18
10:39:12 UTC (rev 13432)
@@ -1,37 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.seam.transaction;
-
-public class AfterTransactionCompletion
-{
- private final boolean success;
-
- public AfterTransactionCompletion(boolean success)
- {
- this.success = success;
- }
-
- public boolean success()
- {
- return success;
- }
-}
Deleted:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/BeforeTransactionCompletion.java
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/BeforeTransactionCompletion.java 2010-07-18
08:51:36 UTC (rev 13428)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/BeforeTransactionCompletion.java 2010-07-18
10:39:12 UTC (rev 13432)
@@ -1,27 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.seam.transaction;
-
-public class BeforeTransactionCompletion
-{
-
-}
Modified:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/CMTTransaction.java
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/CMTTransaction.java 2010-07-18
08:51:36 UTC (rev 13428)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/CMTTransaction.java 2010-07-18
10:39:12 UTC (rev 13432)
@@ -19,7 +19,7 @@
* 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;
+package org.jboss.seam.persistence.transaction;
import javax.ejb.EJBContext;
import javax.transaction.HeuristicMixedException;
Modified:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/EJB.java
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/EJB.java 2010-07-18
08:51:36 UTC (rev 13428)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/EJB.java 2010-07-18
10:39:12 UTC (rev 13432)
@@ -19,7 +19,7 @@
* 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;
+package org.jboss.seam.persistence.transaction;
import javax.ejb.EJBContext;
import javax.naming.NameNotFoundException;
Modified:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/EjbSynchronizations.java
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/EjbSynchronizations.java 2010-07-18
08:51:36 UTC (rev 13428)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/EjbSynchronizations.java 2010-07-18
10:39:12 UTC (rev 13432)
@@ -19,7 +19,7 @@
* 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;
+package org.jboss.seam.persistence.transaction;
import java.rmi.RemoteException;
import java.util.LinkedList;
Modified:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/EntityTransaction.java
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/EntityTransaction.java 2010-07-18
08:51:36 UTC (rev 13428)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/EntityTransaction.java 2010-07-18
10:39:12 UTC (rev 13432)
@@ -19,7 +19,7 @@
* 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;
+package org.jboss.seam.persistence.transaction;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
Deleted:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/JtaTxInterceptor.java
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/JtaTxInterceptor.java 2010-07-18
08:51:36 UTC (rev 13428)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/JtaTxInterceptor.java 2010-07-18
10:39:12 UTC (rev 13432)
@@ -1,146 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.seam.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
Modified:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/LocalEjbSynchronizations.java
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/LocalEjbSynchronizations.java 2010-07-18
08:51:36 UTC (rev 13428)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/LocalEjbSynchronizations.java 2010-07-18
10:39:12 UTC (rev 13432)
@@ -19,7 +19,7 @@
* 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;
+package org.jboss.seam.persistence.transaction;
import javax.ejb.Local;
Modified:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/Naming.java
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/Naming.java 2010-07-18
08:51:36 UTC (rev 13428)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/Naming.java 2010-07-18
10:39:12 UTC (rev 13432)
@@ -19,7 +19,7 @@
* 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;
+package org.jboss.seam.persistence.transaction;
import java.util.Hashtable;
Modified:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/NoTransaction.java
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/NoTransaction.java 2010-07-18
08:51:36 UTC (rev 13428)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/NoTransaction.java 2010-07-18
10:39:12 UTC (rev 13432)
@@ -19,7 +19,7 @@
* 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;
+package org.jboss.seam.persistence.transaction;
import javax.persistence.EntityManager;
import javax.transaction.HeuristicMixedException;
Modified:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/SeSynchronizations.java
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/SeSynchronizations.java 2010-07-18
08:51:36 UTC (rev 13428)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/SeSynchronizations.java 2010-07-18
10:39:12 UTC (rev 13432)
@@ -19,7 +19,7 @@
* 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;
+package org.jboss.seam.persistence.transaction;
import java.util.Stack;
Deleted:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/SynchronizationRegistry.java
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/SynchronizationRegistry.java 2010-07-18
08:51:36 UTC (rev 13428)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/SynchronizationRegistry.java 2010-07-18
10:39:12 UTC (rev 13432)
@@ -1,94 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.seam.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/persistence/transaction/SynchronizationRegistry.java
(from rev 13429,
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/SynchronizationRegistry.java)
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/SynchronizationRegistry.java
(rev 0)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/SynchronizationRegistry.java 2010-07-18
10:39:12 UTC (rev 13432)
@@ -0,0 +1,96 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.seam.persistence.transaction;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.enterprise.inject.spi.BeanManager;
+import javax.transaction.Status;
+import javax.transaction.Synchronization;
+
+import org.jboss.seam.persistence.transaction.event.AfterTransactionCompletion;
+import org.jboss.seam.persistence.transaction.event.BeforeTransactionCompletion;
+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);
+ }
+ }
+ }
+
+}
Modified:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/Synchronizations.java
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/Synchronizations.java 2010-07-18
08:51:36 UTC (rev 13428)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/Synchronizations.java 2010-07-18
10:39:12 UTC (rev 13432)
@@ -19,7 +19,7 @@
* 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;
+package org.jboss.seam.persistence.transaction;
import javax.transaction.Synchronization;
Deleted:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/Transaction.java
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/Transaction.java 2010-07-18
08:51:36 UTC (rev 13428)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/Transaction.java 2010-07-18
10:39:12 UTC (rev 13432)
@@ -1,109 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.seam.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/persistence/transaction/Transaction.java
(from rev 13431,
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/Transaction.java)
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/Transaction.java
(rev 0)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/Transaction.java 2010-07-18
10:39:12 UTC (rev 13432)
@@ -0,0 +1,110 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.seam.persistence.transaction;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.naming.InitialContext;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+
+import org.jboss.seam.persistence.transaction.UserTransaction;
+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;
+ }
+ }
+ }
+
+}
+
+
Deleted:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionExtension.java
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/TransactionExtension.java 2010-07-18
08:51:36 UTC (rev 13428)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionExtension.java 2010-07-18
10:39:12 UTC (rev 13432)
@@ -1,157 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.seam.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/persistence/transaction/TransactionExtension.java
(from rev 13431,
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/TransactionExtension.java)
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionExtension.java
(rev 0)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionExtension.java 2010-07-18
10:39:12 UTC (rev 13432)
@@ -0,0 +1,158 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.seam.persistence.transaction;
+
+import java.util.Collections;
+import java.util.Set;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.BeforeBeanDiscovery;
+import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.enterprise.inject.spi.InjectionTarget;
+
+import org.jboss.seam.persistence.transaction.UserTransaction;
+import org.jboss.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)
+ {
+
+ }
+
+ }
+}
Deleted:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionInterceptor.java
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/TransactionInterceptor.java 2010-07-18
08:51:36 UTC (rev 13428)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionInterceptor.java 2010-07-18
10:39:12 UTC (rev 13432)
@@ -1,141 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.seam.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);
- }
-
-}
Copied:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionInterceptor.java
(from rev 13431,
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/TransactionInterceptor.java)
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionInterceptor.java
(rev 0)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionInterceptor.java 2010-07-18
10:39:12 UTC (rev 13432)
@@ -0,0 +1,145 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.seam.persistence.transaction;
+
+import 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;
+
+import org.jboss.seam.persistence.transaction.TransactionPropagation;
+import org.jboss.seam.persistence.transaction.Transactional;
+import org.jboss.seam.persistence.transaction.UserTransaction;
+
+/**
+ * Implements transaction propagation rules for Seam JavaBean components.
+ *
+ * @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/persistence/transaction/TransactionPropagation.java
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/TransactionPropagation.java 2010-07-18
08:51:36 UTC (rev 13428)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionPropagation.java 2010-07-18
10:39:12 UTC (rev 13432)
@@ -1,61 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.seam.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
Modified:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionQualifier.java
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/TransactionQualifier.java 2010-07-18
08:51:36 UTC (rev 13428)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionQualifier.java 2010-07-18
10:39:12 UTC (rev 13432)
@@ -19,7 +19,7 @@
* 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;
+package org.jboss.seam.persistence.transaction;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
Deleted:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/Transactional.java
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/Transactional.java 2010-07-18
08:51:36 UTC (rev 13428)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/Transactional.java 2010-07-18
10:39:12 UTC (rev 13432)
@@ -1,49 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.seam.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
Modified:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/UTTransaction.java
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/UTTransaction.java 2010-07-18
08:51:36 UTC (rev 13428)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/UTTransaction.java 2010-07-18
10:39:12 UTC (rev 13432)
@@ -19,7 +19,7 @@
* 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;
+package org.jboss.seam.persistence.transaction;
import javax.transaction.HeuristicMixedException;
import javax.transaction.HeuristicRollbackException;
Deleted:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/UserTransaction.java
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/UserTransaction.java 2010-07-18
08:51:36 UTC (rev 13428)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/UserTransaction.java 2010-07-18
10:39:12 UTC (rev 13432)
@@ -1,57 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.seam.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;
-}
Deleted:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/Work.java
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/Work.java 2010-07-18
08:51:36 UTC (rev 13428)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/Work.java 2010-07-18
10:39:12 UTC (rev 13432)
@@ -1,118 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.seam.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);
- }
-}
Copied:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/Work.java
(from rev 13431,
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/transaction/Work.java)
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/Work.java
(rev 0)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/Work.java 2010-07-18
10:39:12 UTC (rev 13432)
@@ -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.persistence.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.persistence.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);
+ }
+}
Modified:
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionInterceptorTest.java
===================================================================
---
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionInterceptorTest.java 2010-07-18
09:59:43 UTC (rev 13431)
+++
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/TransactionInterceptorTest.java 2010-07-18
10:39:12 UTC (rev 13432)
@@ -15,9 +15,9 @@
import org.jboss.arquillian.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.seam.persistence.transaction.Transaction;
+import org.jboss.seam.persistence.transaction.TransactionInterceptor;
import org.jboss.seam.persistence.transaction.UserTransaction;
-import org.jboss.seam.transaction.Transaction;
-import org.jboss.seam.transaction.TransactionInterceptor;
import org.jboss.seam.transactions.test.util.ArtifactNames;
import org.jboss.seam.transactions.test.util.DontRollBackException;
import org.jboss.seam.transactions.test.util.EntityManagerProvider;
Modified:
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/UserTransactionTest.java
===================================================================
---
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/UserTransactionTest.java 2010-07-18
09:59:43 UTC (rev 13431)
+++
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/UserTransactionTest.java 2010-07-18
10:39:12 UTC (rev 13432)
@@ -16,8 +16,8 @@
import org.jboss.arquillian.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.seam.persistence.transaction.Transaction;
import org.jboss.seam.persistence.transaction.UserTransaction;
-import org.jboss.seam.transaction.Transaction;
import org.jboss.seam.transactions.test.util.ArtifactNames;
import org.jboss.seam.transactions.test.util.MavenArtifactResolver;
import org.jboss.shrinkwrap.api.Archive;