[jboss-cvs] JBossAS SVN: r106231 - trunk/weld-int/ejb/src/main/java/org/jboss/weld/integration/persistence.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Jun 23 16:27:19 EDT 2010
Author: marius.bogoevici
Date: 2010-06-23 16:27:18 -0400 (Wed, 23 Jun 2010)
New Revision: 106231
Modified:
trunk/weld-int/ejb/src/main/java/org/jboss/weld/integration/persistence/JBossJpaServices.java
Log:
JBAS-8102: use TransactionScopedEntityManager instead of EntityManagerFactory.createEntityManager() for resolving the persistence context of an injection point.
Modified: trunk/weld-int/ejb/src/main/java/org/jboss/weld/integration/persistence/JBossJpaServices.java
===================================================================
--- trunk/weld-int/ejb/src/main/java/org/jboss/weld/integration/persistence/JBossJpaServices.java 2010-06-23 09:14:11 UTC (rev 106230)
+++ trunk/weld-int/ejb/src/main/java/org/jboss/weld/integration/persistence/JBossJpaServices.java 2010-06-23 20:27:18 UTC (rev 106231)
@@ -17,6 +17,7 @@
import org.jboss.jpa.deployment.PersistenceUnitDeployment;
import org.jboss.jpa.injection.InjectedEntityManagerFactory;
import org.jboss.jpa.resolvers.PersistenceUnitDependencyResolver;
+import org.jboss.jpa.tx.TransactionScopedEntityManager;
import org.jboss.metadata.ejb.jboss.JBossMetaData;
import org.jboss.metadata.web.jboss.JBossWebMetaData;
import org.jboss.weld.injection.spi.JpaInjectionServices;
@@ -54,7 +55,8 @@
}
try
{
- return resolvePersistenceUnit((injectionPoint.getAnnotated().getAnnotation(PersistenceContext.class).unitName())).createEntityManager();
+ String persistenceUnitName = injectionPoint.getAnnotated().getAnnotation(PersistenceContext.class).unitName();
+ return new TransactionScopedEntityManager(lookupPersistenceUnitDeployment(persistenceUnitName).getManagedFactory());
}
catch (IllegalStateException e)
{
@@ -84,6 +86,13 @@
private EntityManagerFactory resolvePersistenceUnit(String unitName)
{
+ PersistenceUnitDeployment deployment = lookupPersistenceUnitDeployment(unitName);
+ ManagedEntityManagerFactory managedFactory = deployment.getManagedFactory();
+ return new InjectedEntityManagerFactory(managedFactory);
+ }
+
+ private PersistenceUnitDeployment lookupPersistenceUnitDeployment(String unitName)
+ {
if (unitName == null)
{
throw new IllegalArgumentException("unitName is null");
@@ -94,8 +103,7 @@
throw new IllegalStateException("No persistence unit available for " + unitName);
}
PersistenceUnitDeployment deployment = jbossEjb.lookupPersistenceUnitDeployment(beanName);
- ManagedEntityManagerFactory managedFactory = deployment.getManagedFactory();
- return new InjectedEntityManagerFactory(managedFactory);
+ return deployment;
}
private static String getPersistenceUnitSupplier(DeploymentUnit deploymentUnit, PersistenceUnitDependencyResolver persistenceUnitDependencyResolver, String persistenceUnitName)
@@ -122,4 +130,4 @@
return null;
}
-}
\ No newline at end of file
+}
More information about the jboss-cvs-commits
mailing list