Author: swd847
Date: 2010-07-23 08:23:58 -0400 (Fri, 23 Jul 2010)
New Revision: 13489
Added:
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
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionalInterceptorBinding.java
Removed:
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/TransactionQualifier.java
Modified:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionExtension.java
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/test/ManagedPersistenceContextTest.java
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionInterceptorTest.java
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionScopedTest.java
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/UserTransactionTest.java
Log:
change implementaion of the default SeamTransaction bean
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/persistence/transaction/Transaction.java 2010-07-23
11:52:57 UTC (rev 13488)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/Transaction.java 2010-07-23
12:23:58 UTC (rev 13489)
@@ -1,110 +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.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.SeamTransaction;
-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 SeamTransaction getTransaction() throws NamingException
- {
- try
- {
- return createUTTransaction();
- }
- catch (NameNotFoundException nnfe)
- {
- try
- {
- return createCMTTransaction();
- }
- catch (NameNotFoundException nnfe2)
- {
- return createNoTransaction();
- }
- }
- }
-
- protected SeamTransaction createNoTransaction()
- {
- return new NoTransaction();
- }
-
- protected SeamTransaction createCMTTransaction() throws NamingException
- {
- return new CMTTransaction(EJB.getEJBContext(), synchronizations);
- }
-
- protected SeamTransaction 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;
- }
- }
- }
-
-}
-
-
Added:
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
(rev 0)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionBeanLifecycle.java 2010-07-23
12:23:58 UTC (rev 13489)
@@ -0,0 +1,66 @@
+/**
+ *
+ */
+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.BeanManager;
+
+import org.jboss.weld.extensions.bean.BeanImpl;
+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(BeanImpl<SeamTransaction> bean,
CreationalContext<SeamTransaction> ctx)
+ {
+ try
+ {
+ return proxyConstructor.newInstance(new TransactionInvocationHandler(manager));
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void destroy(BeanImpl<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-07-23
11:52:57 UTC (rev 13488)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionExtension.java 2010-07-23
12:23:58 UTC (rev 13489)
@@ -21,9 +21,7 @@
*/
package org.jboss.seam.persistence.transaction;
-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;
@@ -31,8 +29,6 @@
import org.jboss.seam.persistence.transaction.literal.DefaultTransactionLiteral;
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;
@@ -62,52 +58,10 @@
AnnotatedTypeBuilder<SeamTransaction> utbuilder =
AnnotatedTypeBuilder.newInstance(SeamTransaction.class);
BeanBuilder<SeamTransaction> builder = new
BeanBuilder<SeamTransaction>(utbuilder.create(), manager);
builder.defineBeanFromAnnotatedType();
- builder.setBeanLifecycle(new TransactionLifecycle(manager));
+ builder.setBeanLifecycle(new TransactionBeanLifecycle(manager));
builder.getQualifiers().clear();
builder.getQualifiers().add(DefaultTransactionLiteral.INSTANCE);
DefaultBeanExtension.addDefaultBean(SeamTransaction.class, builder.create());
}
- private static class TransactionLifecycle implements
BeanLifecycle<SeamTransaction>
- {
-
- private final BeanManager manager;
-
- private Bean<?> transactionBean;
-
- public TransactionLifecycle(BeanManager manager)
- {
- this.manager = manager;
- }
-
- public SeamTransaction create(BeanImpl<SeamTransaction> bean,
CreationalContext<SeamTransaction> ctx)
- {
- if (transactionBean == null)
- {
- // this does not need to be thread safe, it does not matter if this
- // is initialised twice
- setupBeanDefinition();
- }
- return (SeamTransaction) manager.getReference(transactionBean,
SeamTransaction.class, ctx);
- }
-
- public void destroy(BeanImpl<SeamTransaction> bean, SeamTransaction arg0,
CreationalContext<SeamTransaction> arg1)
- {
- arg1.release();
- }
-
- /**
- * we need to init the bean definition lazily
- */
- private void setupBeanDefinition()
- {
- transactionBean = (Bean) manager.resolve(manager.getBeans(SeamTransaction.class,
new TransactionQualifier.TransactionQualifierLiteral()));
- if (transactionBean == null)
- {
- throw new RuntimeException("Could not find SeamTransaction bean with
qualifier " + DefaultTransaction.class.getName());
- }
- }
-
- }
-
}
Added:
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
(rev 0)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionInvocationHandler.java 2010-07-23
12:23:58 UTC (rev 13489)
@@ -0,0 +1,94 @@
+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.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(EJB.getEJBContext(), synchronizations);
+ }
+
+ protected SeamTransaction 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/TransactionQualifier.java
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionQualifier.java 2010-07-23
11:52:57 UTC (rev 13488)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionQualifier.java 2010-07-23
12:23:58 UTC (rev 13489)
@@ -1,44 +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.persistence.transaction;
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-
-import javax.enterprise.util.AnnotationLiteral;
-import javax.inject.Qualifier;
-
-/**
- * Internal qualifier that is used to stop some beans from being exposed to the
- * user
- *
- * @author Stuart Douglas
- *
- */
-(a)Retention(RetentionPolicy.RUNTIME)
-@Qualifier
-@interface TransactionQualifier
-{
- public static class TransactionQualifierLiteral extends
AnnotationLiteral<TransactionQualifier> implements TransactionQualifier
- {
- }
-}
Added:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionalInterceptorBinding.java
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionalInterceptorBinding.java
(rev 0)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/transaction/TransactionalInterceptorBinding.java 2010-07-23
12:23:58 UTC (rev 13489)
@@ -0,0 +1,22 @@
+package org.jboss.seam.persistence.transaction;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import javax.interceptor.InterceptorBinding;
+
+/**
+ * Interceptor binding for {@link Transactional} beans
+ *
+ * @author Stuart Douglas
+ *
+ */
+(a)Retention(RetentionPolicy.RUNTIME)
+@InterceptorBinding
+@Target( { ElementType.TYPE, ElementType.METHOD })
+public @interface TransactionalInterceptorBinding
+{
+
+}
Modified:
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/test/ManagedPersistenceContextTest.java
===================================================================
---
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/test/ManagedPersistenceContextTest.java 2010-07-23
11:52:57 UTC (rev 13488)
+++
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/test/ManagedPersistenceContextTest.java 2010-07-23
12:23:58 UTC (rev 13489)
@@ -17,7 +17,7 @@
import org.jboss.seam.persistence.PersistenceContextExtension;
import org.jboss.seam.persistence.transaction.DefaultTransaction;
import org.jboss.seam.persistence.transaction.SeamTransaction;
-import org.jboss.seam.persistence.transaction.Transaction;
+import org.jboss.seam.persistence.transaction.TransactionExtension;
import org.jboss.seam.transactions.test.util.ArtifactNames;
import org.jboss.seam.transactions.test.util.Hotel;
import org.jboss.seam.transactions.test.util.ManagedPersistenceContextProvider;
@@ -38,7 +38,7 @@
WebArchive war =
ShrinkWrap.createDomain().getArchiveFactory().create(WebArchive.class,
"test.war");
war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.WELD_EXTENSIONS));
war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.SEAM_PERSISTENCE_API));
- war.addPackage(Transaction.class.getPackage());
+ war.addPackage(TransactionExtension.class.getPackage());
war.addPackage(PersistenceContextExtension.class.getPackage());
war.addClasses(ManagedPersistenceContextTest.class, Hotel.class,
ManagedPersistenceContextProvider.class);
war.addWebResource("META-INF/persistence.xml",
"classes/META-INF/persistence.xml");
Modified:
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionInterceptorTest.java
===================================================================
---
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionInterceptorTest.java 2010-07-23
11:52:57 UTC (rev 13488)
+++
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionInterceptorTest.java 2010-07-23
12:23:58 UTC (rev 13489)
@@ -38,7 +38,7 @@
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.seam.persistence.transaction.DefaultTransaction;
import org.jboss.seam.persistence.transaction.SeamTransaction;
-import org.jboss.seam.persistence.transaction.Transaction;
+import org.jboss.seam.persistence.transaction.TransactionExtension;
import org.jboss.seam.persistence.transaction.TransactionInterceptor;
import org.jboss.seam.transactions.test.util.ArtifactNames;
import org.jboss.seam.transactions.test.util.DontRollBackException;
@@ -68,7 +68,7 @@
WebArchive war =
ShrinkWrap.createDomain().getArchiveFactory().create(WebArchive.class,
"test.war");
war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.WELD_EXTENSIONS));
war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.SEAM_PERSISTENCE_API));
- war.addPackage(Transaction.class.getPackage());
+ war.addPackage(TransactionExtension.class.getPackage());
war.addClasses(TransactionInterceptorTest.class, TransactionManagedBean.class,
Hotel.class, EntityManagerProvider.class, DontRollBackException.class);
war.addWebResource("META-INF/persistence.xml",
"classes/META-INF/persistence.xml");
war.addWebResource(new
ByteArrayAsset(("<beans><interceptors><class>" +
TransactionInterceptor.class.getName() +
"</class></interceptors></beans>").getBytes()),
"beans.xml");
Modified:
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionScopedTest.java
===================================================================
---
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionScopedTest.java 2010-07-23
11:52:57 UTC (rev 13488)
+++
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionScopedTest.java 2010-07-23
12:23:58 UTC (rev 13489)
@@ -15,7 +15,7 @@
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.seam.persistence.transaction.DefaultTransaction;
import org.jboss.seam.persistence.transaction.SeamTransaction;
-import org.jboss.seam.persistence.transaction.Transaction;
+import org.jboss.seam.persistence.transaction.TransactionExtension;
import org.jboss.seam.persistence.transaction.scope.TransactionScopeExtension;
import org.jboss.seam.transactions.test.util.ArtifactNames;
import org.jboss.seam.transactions.test.util.Hotel;
@@ -36,7 +36,7 @@
WebArchive war =
ShrinkWrap.createDomain().getArchiveFactory().create(WebArchive.class,
"test.war");
war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.WELD_EXTENSIONS));
war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.SEAM_PERSISTENCE_API));
- war.addPackage(Transaction.class.getPackage());
+ war.addPackage(TransactionExtension.class.getPackage());
war.addPackage(TransactionScopeExtension.class.getPackage());
war.addClasses(TransactionScopedTest.class, Hotel.class,
TransactionScopedObject.class);
war.addWebResource("META-INF/persistence.xml",
"classes/META-INF/persistence.xml");
Modified:
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/UserTransactionTest.java
===================================================================
---
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/UserTransactionTest.java 2010-07-23
11:52:57 UTC (rev 13488)
+++
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/UserTransactionTest.java 2010-07-23
12:23:58 UTC (rev 13489)
@@ -17,7 +17,7 @@
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.seam.persistence.transaction.DefaultTransaction;
import org.jboss.seam.persistence.transaction.SeamTransaction;
-import org.jboss.seam.persistence.transaction.Transaction;
+import org.jboss.seam.persistence.transaction.TransactionExtension;
import org.jboss.seam.transactions.test.util.ArtifactNames;
import org.jboss.seam.transactions.test.util.Hotel;
import org.jboss.seam.transactions.test.util.MavenArtifactResolver;
@@ -37,7 +37,7 @@
WebArchive war =
ShrinkWrap.createDomain().getArchiveFactory().create(WebArchive.class,
"test.war");
war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.WELD_EXTENSIONS));
war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.SEAM_PERSISTENCE_API));
- war.addPackage(Transaction.class.getPackage());
+ war.addPackage(TransactionExtension.class.getPackage());
war.addClasses(UserTransactionTest.class, Hotel.class);
war.addWebResource("META-INF/persistence.xml",
"classes/META-INF/persistence.xml");
war.addWebResource(new ByteArrayAsset(new byte[0]), "beans.xml");