Author: swd847
Date: 2010-07-30 04:30:04 -0400 (Fri, 30 Jul 2010)
New Revision: 13529
Added:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/InjectionEventListener.java
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/test/EntityInjectionTest.java
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/util/HelloService.java
modules/persistence/trunk/impl/src/test/resources/META-INF/orm.xml
modules/persistence/trunk/impl/src/test/resources/META-INF/persistence-orm.xml
Modified:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/SeamManaged.java
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/test/ManagedPersistenceContextELTest.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/TransactionAttributeInterceptorTest.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
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/util/Hotel.java
Log:
add injection into JPA entities
Added:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/InjectionEventListener.java
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/InjectionEventListener.java
(rev 0)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/InjectionEventListener.java 2010-07-30
08:30:04 UTC (rev 13529)
@@ -0,0 +1,178 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.seam.persistence;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.InjectionTarget;
+import javax.inject.Inject;
+
+import org.jboss.weld.extensions.annotated.AnnotatedTypeBuilder;
+import org.jboss.weld.extensions.beanManager.BeanManagerAccessor;
+import org.jboss.weld.extensions.util.Reflections;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Event listener that enables injection and initalizer methods for JPA entities
+ *
+ * Other CDI featues such as interceptors, observer methods and decorators are
+ * not supported
+ *
+ * TODO: should we check for the presence of invalid annotations such as @Observes
+ * and log a warning?
+ *
+ * This listener must be enabled in orm.xml
+ *
+ * @author Stuart Douglas
+ *
+ */
+public class InjectionEventListener
+{
+
+ private final static Logger log =
LoggerFactory.getLogger(InjectionEventListener.class);
+
+ private final Map<Class<?>, InjectionTarget<?>> injectionTargets =
new ConcurrentHashMap<Class<?>, InjectionTarget<?>>();
+
+ BeanManager manager;
+
+ public void load(Object entity)
+ {
+ if (manager == null)
+ {
+ this.manager = BeanManagerAccessor.getManager();
+ }
+ if (!injectionTargets.containsKey(entity.getClass()))
+ {
+ if (!injectionRequired(entity.getClass()))
+ {
+ injectionTargets.put(entity.getClass(), NULL_INJECTION_TARGET);
+ log.debug("Entity {} has no injection points so injection will not be
enabled", entity.getClass());
+ }
+ else
+ {
+ // it is ok for this code to run twice, so we don't really need to
+ // lock
+ AnnotatedTypeBuilder<?> builder = new
AnnotatedTypeBuilder().readFromType(entity.getClass());
+ InjectionTarget<?> injectionTarget =
manager.createInjectionTarget(builder.create());
+ injectionTargets.put(entity.getClass(), injectionTarget);
+ log.info("Enabling injection into entity {}", entity.getClass());
+ }
+ }
+ InjectionTarget it = injectionTargets.get(entity.getClass());
+ if (it != NULL_INJECTION_TARGET)
+ {
+ log.debug("Running CDI injection for {}", entity.getClass());
+ it.inject(entity, new CreationalContextImpl());
+ }
+
+ }
+
+ /**
+ *
+ * returns true if the class has injection points or initalizer methods
+ */
+ private boolean injectionRequired(Class<?> entityClass)
+ {
+ for (Field f : Reflections.getAllFields(entityClass))
+ {
+ if (f.isAnnotationPresent(Inject.class))
+ {
+ return true;
+ }
+ }
+
+ for (Method m : Reflections.getAllMethods(entityClass))
+ {
+ if (m.isAnnotationPresent(Inject.class))
+ {
+ return true;
+ }
+ }
+
+ for (Constructor<?> c : Reflections.getAllConstructors(entityClass))
+ {
+ if (c.isAnnotationPresent(Inject.class))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * marker used for the null value, as a ConcurrentHashMap does not support
+ * null values
+ */
+ private static final InjectionTarget NULL_INJECTION_TARGET = new InjectionTarget()
+ {
+
+ public void inject(Object instance, CreationalContext ctx)
+ {
+ }
+
+ public void postConstruct(Object instance)
+ {
+ }
+
+ public void preDestroy(Object instance)
+ {
+ }
+
+ public void dispose(Object instance)
+ {
+ }
+
+ public Set getInjectionPoints()
+ {
+ return null;
+ }
+
+ public Object produce(CreationalContext ctx)
+ {
+ return null;
+ }
+ };
+
+ // no-op creational context
+ private static class CreationalContextImpl implements CreationalContext
+ {
+
+ public void push(Object incompleteInstance)
+ {
+
+ }
+
+ public void release()
+ {
+
+ }
+
+ }
+}
Modified:
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/SeamManaged.java
===================================================================
---
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/SeamManaged.java 2010-07-28
20:40:18 UTC (rev 13528)
+++
modules/persistence/trunk/impl/src/main/java/org/jboss/seam/persistence/SeamManaged.java 2010-07-30
08:30:04 UTC (rev 13529)
@@ -48,9 +48,10 @@
* conversation scoped with the qualifier @SomeQualifier.
*
* This field still produces the EntityManagerFactory with qualifier
+ *
* @SomeQualifier, however the scope for the producer field is changed to
- * {@link Dependent}, as the specification does not allow resource producer
- * fields to have a scope other than Depedent
+ * {@link Dependent}, as the specification does not allow
+ * resource producer fields to have a scope other than Depedent
*
* @author Stuart Douglas
*
Added:
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/test/EntityInjectionTest.java
===================================================================
---
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/test/EntityInjectionTest.java
(rev 0)
+++
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/test/EntityInjectionTest.java 2010-07-30
08:30:04 UTC (rev 13529)
@@ -0,0 +1,116 @@
+/*
+ * 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.test;
+
+import javax.inject.Inject;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+import javax.transaction.SystemException;
+
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.seam.persistence.InjectionEventListener;
+import org.jboss.seam.persistence.transaction.DefaultTransaction;
+import org.jboss.seam.persistence.transaction.SeamTransaction;
+import org.jboss.seam.persistence.transaction.TransactionExtension;
+import org.jboss.seam.persistence.util.NamingUtils;
+import org.jboss.seam.transactions.test.util.ArtifactNames;
+import org.jboss.seam.transactions.test.util.HelloService;
+import org.jboss.seam.transactions.test.util.Hotel;
+import org.jboss.seam.transactions.test.util.ManagedPersistenceContextProvider;
+import org.jboss.seam.transactions.test.util.MavenArtifactResolver;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.ByteArrayAsset;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * Tests that injection is working for JPA entities
+ *
+ * @author Stuart Douglas
+ *
+ */
+(a)RunWith(Arquillian.class)
+public class EntityInjectionTest
+{
+ @Deployment
+ public static Archive<?> createTestArchive()
+ {
+ WebArchive war =
ShrinkWrap.createDomain().getArchiveFactory().create(WebArchive.class,
"test.war");
+ war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.WELD_EXTENSIONS));
+
war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.SEAM_PERSISTENCE_API));
+ war.addPackage(TransactionExtension.class.getPackage());
+ war.addPackage(InjectionEventListener.class.getPackage());
+ war.addPackage(NamingUtils.class.getPackage());
+ war.addClasses(EntityInjectionTest.class, Hotel.class,
ManagedPersistenceContextProvider.class, HelloService.class);
+
war.addWebResource("META-INF/services/javax.enterprise.inject.spi.Extension",
"classes/META-INF/services/javax.enterprise.inject.spi.Extension");
+ war.addWebResource("META-INF/persistence-orm.xml",
"classes/META-INF/persistence.xml");
+ war.addWebResource("META-INF/orm.xml",
"classes/META-INF/orm.xml");
+ war.addWebResource(new ByteArrayAsset(new byte[0]), "beans.xml");
+ return war;
+ }
+
+ @Inject
+ @DefaultTransaction
+ SeamTransaction transaction;
+
+ @Inject
+ EntityManagerFactory emf;
+
+ @Test
+ public void testInjectionIntoEntity() throws NotSupportedException, SystemException,
SecurityException, IllegalStateException, RollbackException, HeuristicMixedException,
HeuristicRollbackException
+ {
+ EntityManager em = null;
+ try
+ {
+ em = emf.createEntityManager();
+ transaction.begin();
+ em.joinTransaction();
+ Hotel h = new Hotel("Hilton", "Fake St",
"Wollongong", "NSW", "2518", "Australia");
+ em.persist(h);
+ em.flush();
+ transaction.commit();
+ em.close();
+ transaction.begin();
+ em = emf.createEntityManager();
+ em.joinTransaction();
+
+ h = (Hotel) em.createQuery("select h from Hotel h where
h.name='Hilton'").getSingleResult();
+ Assert.assertTrue(h.isInitalizerCalled());
+ Assert.assertEquals(h.sayHello(), "Hello");
+ }
+ finally
+ {
+ em.close();
+ transaction.rollback();
+ }
+
+ }
+
+}
Modified:
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/test/ManagedPersistenceContextELTest.java
===================================================================
---
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/test/ManagedPersistenceContextELTest.java 2010-07-28
20:40:18 UTC (rev 13528)
+++
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/test/ManagedPersistenceContextELTest.java 2010-07-30
08:30:04 UTC (rev 13529)
@@ -37,6 +37,7 @@
import org.jboss.seam.persistence.transaction.TransactionExtension;
import org.jboss.seam.persistence.util.NamingUtils;
import org.jboss.seam.transactions.test.util.ArtifactNames;
+import org.jboss.seam.transactions.test.util.HelloService;
import org.jboss.seam.transactions.test.util.Hotel;
import org.jboss.seam.transactions.test.util.ManagedPersistenceContextProvider;
import org.jboss.seam.transactions.test.util.MavenArtifactResolver;
@@ -60,7 +61,7 @@
war.addPackage(TransactionExtension.class.getPackage());
war.addPackage(PersistenceContextExtension.class.getPackage());
war.addPackage(NamingUtils.class.getPackage());
- war.addClasses(ManagedPersistenceContextELTest.class, Hotel.class,
ManagedPersistenceContextProvider.class, HotelNameProducer.class);
+ war.addClasses(ManagedPersistenceContextELTest.class, Hotel.class,
ManagedPersistenceContextProvider.class, HotelNameProducer.class, HelloService.class);
war.addWebResource("META-INF/persistence.xml",
"classes/META-INF/persistence.xml");
war.addWebResource(new ByteArrayAsset(new byte[0]), "beans.xml");
war.addWebResource("META-INF/services/javax.enterprise.inject.spi.Extension",
"classes/META-INF/services/javax.enterprise.inject.spi.Extension");
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-28
20:40:18 UTC (rev 13528)
+++
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/test/ManagedPersistenceContextTest.java 2010-07-30
08:30:04 UTC (rev 13529)
@@ -41,6 +41,7 @@
import org.jboss.seam.persistence.transaction.TransactionExtension;
import org.jboss.seam.persistence.util.NamingUtils;
import org.jboss.seam.transactions.test.util.ArtifactNames;
+import org.jboss.seam.transactions.test.util.HelloService;
import org.jboss.seam.transactions.test.util.Hotel;
import org.jboss.seam.transactions.test.util.ManagedPersistenceContextProvider;
import org.jboss.seam.transactions.test.util.MavenArtifactResolver;
@@ -63,7 +64,7 @@
war.addPackage(TransactionExtension.class.getPackage());
war.addPackage(PersistenceContextExtension.class.getPackage());
war.addPackage(NamingUtils.class.getPackage());
- war.addClasses(ManagedPersistenceContextTest.class, Hotel.class,
ManagedPersistenceContextProvider.class);
+ war.addClasses(ManagedPersistenceContextTest.class, Hotel.class,
ManagedPersistenceContextProvider.class, HelloService.class);
war.addWebResource("META-INF/persistence.xml",
"classes/META-INF/persistence.xml");
war.addWebResource(new ByteArrayAsset(new byte[0]), "beans.xml");
war.addWebResource("META-INF/services/javax.enterprise.inject.spi.Extension",
"classes/META-INF/services/javax.enterprise.inject.spi.Extension");
Modified:
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionAttributeInterceptorTest.java
===================================================================
---
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionAttributeInterceptorTest.java 2010-07-28
20:40:18 UTC (rev 13528)
+++
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionAttributeInterceptorTest.java 2010-07-30
08:30:04 UTC (rev 13529)
@@ -45,6 +45,7 @@
import org.jboss.seam.transactions.test.util.ArtifactNames;
import org.jboss.seam.transactions.test.util.DontRollBackException;
import org.jboss.seam.transactions.test.util.EntityManagerProvider;
+import org.jboss.seam.transactions.test.util.HelloService;
import org.jboss.seam.transactions.test.util.Hotel;
import org.jboss.seam.transactions.test.util.MavenArtifactResolver;
import org.jboss.shrinkwrap.api.Archive;
@@ -74,7 +75,7 @@
war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.SEAM_PERSISTENCE_API));
war.addPackage(TransactionExtension.class.getPackage());
war.addPackage(NamingUtils.class.getPackage());
- war.addClasses(TransactionAttributeInterceptorTest.class,
TransactionAttributeManagedBean.class, Hotel.class, EntityManagerProvider.class,
DontRollBackException.class);
+ war.addClasses(TransactionAttributeInterceptorTest.class,
TransactionAttributeManagedBean.class, HelloService.class, Hotel.class,
EntityManagerProvider.class, DontRollBackException.class);
war.addWebResource("META-INF/persistence.xml",
"classes/META-INF/persistence.xml");
war.addWebResource(new
ByteArrayAsset(("<beans><interceptors><class>" +
TransactionInterceptor.class.getName() +
"</class></interceptors></beans>").getBytes()),
"beans.xml");
war.addWebResource("META-INF/services/javax.enterprise.inject.spi.Extension",
"classes/META-INF/services/javax.enterprise.inject.spi.Extension");
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-28
20:40:18 UTC (rev 13528)
+++
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionInterceptorTest.java 2010-07-30
08:30:04 UTC (rev 13529)
@@ -45,6 +45,7 @@
import org.jboss.seam.transactions.test.util.ArtifactNames;
import org.jboss.seam.transactions.test.util.DontRollBackException;
import org.jboss.seam.transactions.test.util.EntityManagerProvider;
+import org.jboss.seam.transactions.test.util.HelloService;
import org.jboss.seam.transactions.test.util.Hotel;
import org.jboss.seam.transactions.test.util.MavenArtifactResolver;
import org.jboss.shrinkwrap.api.Archive;
@@ -74,7 +75,7 @@
war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.SEAM_PERSISTENCE_API));
war.addPackage(TransactionExtension.class.getPackage());
war.addPackage(NamingUtils.class.getPackage());
- war.addClasses(TransactionInterceptorTest.class, TransactionManagedBean.class,
Hotel.class, EntityManagerProvider.class, DontRollBackException.class);
+ war.addClasses(TransactionInterceptorTest.class, TransactionManagedBean.class,
HelloService.class, Hotel.class, EntityManagerProvider.class,
DontRollBackException.class);
war.addWebResource("META-INF/persistence.xml",
"classes/META-INF/persistence.xml");
war.addWebResource(new
ByteArrayAsset(("<beans><interceptors><class>" +
TransactionInterceptor.class.getName() +
"</class></interceptors></beans>").getBytes()),
"beans.xml");
war.addWebResource("META-INF/services/javax.enterprise.inject.spi.Extension",
"classes/META-INF/services/javax.enterprise.inject.spi.Extension");
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-28
20:40:18 UTC (rev 13528)
+++
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/TransactionScopedTest.java 2010-07-30
08:30:04 UTC (rev 13529)
@@ -19,6 +19,7 @@
import org.jboss.seam.persistence.transaction.scope.TransactionScopeExtension;
import org.jboss.seam.persistence.util.NamingUtils;
import org.jboss.seam.transactions.test.util.ArtifactNames;
+import org.jboss.seam.transactions.test.util.HelloService;
import org.jboss.seam.transactions.test.util.Hotel;
import org.jboss.seam.transactions.test.util.MavenArtifactResolver;
import org.jboss.shrinkwrap.api.Archive;
@@ -40,7 +41,7 @@
war.addPackage(TransactionExtension.class.getPackage());
war.addPackage(TransactionScopeExtension.class.getPackage());
war.addPackage(NamingUtils.class.getPackage());
- war.addClasses(TransactionScopedTest.class, Hotel.class,
TransactionScopedObject.class);
+ war.addClasses(TransactionScopedTest.class, Hotel.class, HelloService.class,
TransactionScopedObject.class);
war.addWebResource("META-INF/persistence.xml",
"classes/META-INF/persistence.xml");
war.addWebResource(new ByteArrayAsset(new byte[0]), "beans.xml");
war.addWebResource("META-INF/services/javax.enterprise.inject.spi.Extension",
"classes/META-INF/services/javax.enterprise.inject.spi.Extension");
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-28
20:40:18 UTC (rev 13528)
+++
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/persistence/transactions/test/UserTransactionTest.java 2010-07-30
08:30:04 UTC (rev 13529)
@@ -20,6 +20,7 @@
import org.jboss.seam.persistence.transaction.TransactionExtension;
import org.jboss.seam.persistence.util.NamingUtils;
import org.jboss.seam.transactions.test.util.ArtifactNames;
+import org.jboss.seam.transactions.test.util.HelloService;
import org.jboss.seam.transactions.test.util.Hotel;
import org.jboss.seam.transactions.test.util.MavenArtifactResolver;
import org.jboss.shrinkwrap.api.Archive;
@@ -39,7 +40,7 @@
war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.WELD_EXTENSIONS));
war.addLibraries(MavenArtifactResolver.resolve(ArtifactNames.SEAM_PERSISTENCE_API));
war.addPackage(TransactionExtension.class.getPackage());
- war.addClasses(UserTransactionTest.class, Hotel.class);
+ war.addClasses(UserTransactionTest.class, Hotel.class, HelloService.class);
war.addPackage(NamingUtils.class.getPackage());
war.addWebResource("META-INF/persistence.xml",
"classes/META-INF/persistence.xml");
war.addWebResource(new ByteArrayAsset(new byte[0]), "beans.xml");
Added:
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/util/HelloService.java
===================================================================
---
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/util/HelloService.java
(rev 0)
+++
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/util/HelloService.java 2010-07-30
08:30:04 UTC (rev 13529)
@@ -0,0 +1,30 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.seam.transactions.test.util;
+
+public class HelloService
+{
+ public String sayHello()
+ {
+ return "Hello";
+ }
+}
Modified:
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/util/Hotel.java
===================================================================
---
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/util/Hotel.java 2010-07-28
20:40:18 UTC (rev 13528)
+++
modules/persistence/trunk/impl/src/test/java/org/jboss/seam/transactions/test/util/Hotel.java 2010-07-30
08:30:04 UTC (rev 13529)
@@ -24,6 +24,7 @@
import java.io.Serializable;
import java.math.BigDecimal;
+import javax.inject.Inject;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
@@ -34,6 +35,7 @@
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
+
import org.jboss.weld.extensions.core.Veto;
/**
@@ -59,10 +61,26 @@
private Integer stars;
private BigDecimal price;
+ @Inject
+ private HelloService helloService;
+
+ private boolean initalizerCalled = false;
+
public Hotel()
{
}
+ @Inject
+ public void create()
+ {
+ initalizerCalled = true;
+ }
+
+ public String sayHello()
+ {
+ return helloService.sayHello();
+ }
+
public Hotel(final String name, final String address, final String city, final String
state, final String zip, final String country)
{
this.name = name;
@@ -202,4 +220,11 @@
{
return "Hotel(" + name + "," + address + "," + city +
"," + zip + ")";
}
+
+ @Transient
+ public boolean isInitalizerCalled()
+ {
+ return initalizerCalled;
+ }
+
}
Added: modules/persistence/trunk/impl/src/test/resources/META-INF/orm.xml
===================================================================
--- modules/persistence/trunk/impl/src/test/resources/META-INF/orm.xml
(rev 0)
+++ modules/persistence/trunk/impl/src/test/resources/META-INF/orm.xml 2010-07-30 08:30:04
UTC (rev 13529)
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<entity-mappings
xmlns="http://java.sun.com/xml/ns/persistence/orm"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm
orm_1_0.xsd"
+ version="1.0"
+ >
+ <persistence-unit-metadata >
+ <persistence-unit-defaults >
+ <entity-listeners>
+ <entity-listener
class="org.jboss.seam.persistence.InjectionEventListener" >
+ <post-load method-name="load" />
+
+ </entity-listener>
+ </entity-listeners>
+ </persistence-unit-defaults>
+ </persistence-unit-metadata>
+
+</entity-mappings>
\ No newline at end of file
Added: modules/persistence/trunk/impl/src/test/resources/META-INF/persistence-orm.xml
===================================================================
--- modules/persistence/trunk/impl/src/test/resources/META-INF/persistence-orm.xml
(rev 0)
+++
modules/persistence/trunk/impl/src/test/resources/META-INF/persistence-orm.xml 2010-07-30
08:30:04 UTC (rev 13529)
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<persistence
xmlns="http://java.sun.com/xml/ns/persistence"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
+ version="2.0">
+ <persistence-unit name="transactionPu">
+ <!--
+ <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
+ -->
+ <provider>org.hibernate.ejb.HibernatePersistence</provider>
+ <jta-data-source>java:/DefaultDS</jta-data-source>
+ <mapping-file>META-INF/orm.xml</mapping-file>
+ <class>org.jboss.seam.transactions.test.util.Hotel</class>
+ <exclude-unlisted-classes/>
+ <properties>
+ <!-- Properties for Hibernate (default provider for JBoss AS) -->
+ <property name="hibernate.hbm2ddl.auto"
value="create-drop"/>
+ <property name="hibernate.show_sql" value="true"/>
+ <!-- Only format when you need to debug, because it slows things down -->
+ <property name="hibernate.format_sql" value="false"/>
+
+ <!-- Properties for EclipseLink (default provider for GlassFish) -->
+ <property name="eclipselink.ddl-generation"
value="drop-and-create-tables"/>
+ <property name="eclipselink.logging.level"
value="FINE"/>
+ </properties>
+ </persistence-unit>
+</persistence>