[seam-commits] Seam SVN: r13611 - modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Thu Aug 12 21:22:23 EDT 2010
Author: swd847
Date: 2010-08-12 21:22:22 -0400 (Thu, 12 Aug 2010)
New Revision: 13611
Added:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/DefaultSeamTransaction.java
Removed:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionBeanLifecycle.java
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionInvocationHandler.java
Modified:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionExtension.java
Log:
change transaction implementation to use @DefaultBean
Added: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/DefaultSeamTransaction.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/DefaultSeamTransaction.java (rev 0)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/DefaultSeamTransaction.java 2010-08-13 01:22:22 UTC (rev 13611)
@@ -0,0 +1,199 @@
+/*
+ * 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.inject.Inject;
+import javax.naming.InitialContext;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+import javax.persistence.EntityManager;
+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.seam.persistence.util.EJBContextUtils;
+import org.jboss.seam.persistence.util.NamingUtils;
+import org.jboss.weld.extensions.defaultbean.DefaultBean;
+
+/**
+ *
+ * Supports injection of a Seam UserTransaction object that wraps the current
+ * JTA transaction or EJB container managed transaction.
+ *
+ * @author Stuart Douglas
+ *
+ */
+ at DefaultBean(type = SeamTransaction.class)
+ at DefaultTransaction
+public class DefaultSeamTransaction implements SeamTransaction
+{
+ @Inject
+ private Synchronizations synchronizations;
+
+ public void enlist(EntityManager entityManager) throws SystemException
+ {
+ getSeamTransaction().enlist(entityManager);
+ }
+
+ public boolean isActive() throws SystemException
+ {
+ return getSeamTransaction().isActive();
+ }
+
+ public boolean isActiveOrMarkedRollback() throws SystemException
+ {
+ return getSeamTransaction().isActiveOrMarkedRollback();
+ }
+
+ public boolean isCommitted() throws SystemException
+ {
+ return getSeamTransaction().isCommitted();
+ }
+
+ public boolean isConversationContextRequired()
+ {
+ return getSeamTransaction().isConversationContextRequired();
+ }
+
+ public boolean isMarkedRollback() throws SystemException
+ {
+ return getSeamTransaction().isMarkedRollback();
+ }
+
+ public boolean isNoTransaction() throws SystemException
+ {
+ return getSeamTransaction().isNoTransaction();
+ }
+
+ public boolean isRolledBack() throws SystemException
+ {
+ return getSeamTransaction().isRolledBack();
+ }
+
+ public boolean isRolledBackOrMarkedRollback() throws SystemException
+ {
+ return getSeamTransaction().isRolledBackOrMarkedRollback();
+ }
+
+ public void registerSynchronization(Synchronization sync)
+ {
+ getSeamTransaction().registerSynchronization(sync);
+ }
+
+ public void begin() throws NotSupportedException, SystemException
+ {
+ getSeamTransaction().begin();
+ }
+
+ public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException
+ {
+ getSeamTransaction().commit();
+ }
+
+ public int getStatus() throws SystemException
+ {
+ return getSeamTransaction().getStatus();
+ }
+
+ public void rollback() throws IllegalStateException, SecurityException, SystemException
+ {
+ getSeamTransaction().rollback();
+ }
+
+ public void setRollbackOnly() throws IllegalStateException, SystemException
+ {
+ getSeamTransaction().setRollbackOnly();
+ }
+
+ public void setTransactionTimeout(int seconds) throws SystemException
+ {
+ getSeamTransaction().setTransactionTimeout(seconds);
+ }
+
+ protected SeamTransaction getSeamTransaction()
+ {
+ try
+ {
+ return createUTTransaction();
+ }
+ catch (NameNotFoundException nnfe)
+ {
+ try
+ {
+ return createCMTTransaction();
+ }
+ catch (NameNotFoundException nnfe2)
+ {
+ return createNoTransaction();
+ }
+ catch (NamingException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+ catch (NamingException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ protected SeamTransaction createNoTransaction()
+ {
+ return new NoTransaction();
+ }
+
+ protected SeamTransaction createCMTTransaction() throws NamingException
+ {
+ return new CMTTransaction(EJBContextUtils.getEJBContext(), synchronizations);
+ }
+
+ protected SeamTransaction createUTTransaction() throws NamingException
+ {
+ return new UTTransaction(getUserTransaction(), synchronizations);
+ }
+
+ protected javax.transaction.UserTransaction getUserTransaction() throws NamingException
+ {
+ InitialContext context = NamingUtils.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/TransactionBeanLifecycle.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionBeanLifecycle.java 2010-08-13 01:01:18 UTC (rev 13610)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionBeanLifecycle.java 2010-08-13 01:22:22 UTC (rev 13611)
@@ -1,66 +0,0 @@
-/**
- *
- */
-package org.jboss.seam.persistence.transaction;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Proxy;
-
-import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.inject.spi.Bean;
-import javax.enterprise.inject.spi.BeanManager;
-
-import org.jboss.weld.extensions.bean.BeanLifecycle;
-
-/**
- * BeanLifecycle for the default SeamTransaction bean
- *
- * @author Stuart Douglas
- *
- */
-class TransactionBeanLifecycle implements BeanLifecycle<SeamTransaction>
-{
- /**
- * proxy class for SeamTransaction
- */
- private static final Class proxy = Proxy.getProxyClass(SeamTransaction.class.getClassLoader(), SeamTransaction.class);
-
- private static final Constructor<SeamTransaction> proxyConstructor;
-
- static
- {
- try
- {
- proxyConstructor = proxy.getConstructor(InvocationHandler.class);
- }
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- }
-
- private final BeanManager manager;
-
- public TransactionBeanLifecycle(BeanManager manager)
- {
- this.manager = manager;
- }
-
- public SeamTransaction create(Bean<SeamTransaction> bean, CreationalContext<SeamTransaction> ctx)
- {
- try
- {
- return proxyConstructor.newInstance(new TransactionInvocationHandler(manager));
- }
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- }
-
- public void destroy(Bean<SeamTransaction> bean, SeamTransaction arg0, CreationalContext<SeamTransaction> arg1)
- {
- arg1.release();
- }
-}
\ No newline at end of file
Modified: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionExtension.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionExtension.java 2010-08-13 01:01:18 UTC (rev 13610)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionExtension.java 2010-08-13 01:22:22 UTC (rev 13611)
@@ -25,17 +25,12 @@
import javax.enterprise.inject.spi.Annotated;
import javax.enterprise.inject.spi.AnnotatedMethod;
import javax.enterprise.inject.spi.AnnotatedType;
-import javax.enterprise.inject.spi.BeanManager;
-import javax.enterprise.inject.spi.BeforeBeanDiscovery;
import javax.enterprise.inject.spi.Extension;
import javax.enterprise.inject.spi.ProcessAnnotatedType;
import javax.enterprise.util.AnnotationLiteral;
-import org.jboss.seam.persistence.transaction.literal.DefaultTransactionLiteral;
import org.jboss.seam.persistence.util.EjbApi;
import org.jboss.weld.extensions.annotated.AnnotatedTypeBuilder;
-import org.jboss.weld.extensions.bean.BeanBuilder;
-import org.jboss.weld.extensions.defaultbean.DefaultBeanExtension;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -59,17 +54,6 @@
private static final Logger log = LoggerFactory.getLogger(TransactionExtension.class);
- public void beforeBeanDiscovery(@Observes BeforeBeanDiscovery event, BeanManager manager, DefaultBeanExtension defaultBeanExtension)
- {
- AnnotatedTypeBuilder<SeamTransaction> utbuilder = new AnnotatedTypeBuilder().setJavaClass(SeamTransaction.class);
- BeanBuilder<SeamTransaction> builder = new BeanBuilder<SeamTransaction>(manager);
- builder.defineBeanFromAnnotatedType(utbuilder.create());
- builder.setBeanLifecycle(new TransactionBeanLifecycle(manager));
- builder.getQualifiers().clear();
- builder.getQualifiers().add(DefaultTransactionLiteral.INSTANCE);
- defaultBeanExtension.addDefaultBean(SeamTransaction.class, builder.create());
- }
-
/**
* Looks for @Transaction or @TransactionAttribute annotations and if they
* are found adds the transaction intercepter binding
Deleted: modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionInvocationHandler.java
===================================================================
--- modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionInvocationHandler.java 2010-08-13 01:01:18 UTC (rev 13610)
+++ modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionInvocationHandler.java 2010-08-13 01:22:22 UTC (rev 13611)
@@ -1,96 +0,0 @@
-package org.jboss.seam.persistence.transaction;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-
-import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.inject.spi.Bean;
-import javax.enterprise.inject.spi.BeanManager;
-import javax.naming.InitialContext;
-import javax.naming.NameNotFoundException;
-import javax.naming.NamingException;
-
-import org.jboss.seam.persistence.util.EJBContextUtils;
-import org.jboss.seam.persistence.util.NamingUtils;
-import org.jboss.weld.extensions.literal.DefaultLiteral;
-
-/**
- * Invocation handler for the default SeamTransaction proxy
- *
- * Supports injection of a Seam UserTransaction object that wraps the current
- * JTA transaction or EJB container managed transaction.
- *
- * @author Stuart Douglas
- *
- */
-public class TransactionInvocationHandler implements InvocationHandler
-{
-
- private final Synchronizations synchronizations;
-
- public TransactionInvocationHandler(BeanManager manager)
- {
- Bean<Synchronizations> bean = (Bean) manager.resolve(manager.getBeans(Synchronizations.class, DefaultLiteral.INSTANCE));
- CreationalContext<Synchronizations> ctx = manager.createCreationalContext(bean);
- synchronizations = (Synchronizations) manager.getReference(bean, Synchronizations.class, ctx);
- }
-
- public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
- {
- SeamTransaction instance;
- try
- {
- instance = createUTTransaction();
- }
- catch (NameNotFoundException nnfe)
- {
- try
- {
- instance = createCMTTransaction();
- }
- catch (NameNotFoundException nnfe2)
- {
- instance = createNoTransaction();
- }
- }
- return method.invoke(instance, args);
- }
-
- protected SeamTransaction createNoTransaction()
- {
- return new NoTransaction();
- }
-
- protected SeamTransaction createCMTTransaction() throws NamingException
- {
- return new CMTTransaction(EJBContextUtils.getEJBContext(), synchronizations);
- }
-
- protected SeamTransaction createUTTransaction() throws NamingException
- {
- return new UTTransaction(getUserTransaction(), synchronizations);
- }
-
- protected javax.transaction.UserTransaction getUserTransaction() throws NamingException
- {
- InitialContext context = NamingUtils.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;
- }
- }
- }
-}
More information about the seam-commits
mailing list