[jboss-cvs] JBossAS SVN: r75613 - in projects/ejb3/trunk/core: src/main/java/org/jboss/ejb3 and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Jul 10 07:09:24 EDT 2008
Author: wolfc
Date: 2008-07-10 07:09:23 -0400 (Thu, 10 Jul 2008)
New Revision: 75613
Added:
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/ManagedEntityManagerFactoryHelper.java
projects/ejb3/trunk/core/src/main/java/org/jboss/injection/ExtendedInjectionContainer.java
Removed:
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/ManagedEntityManagerFactory.java
Modified:
projects/ejb3/trunk/core/pom.xml
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainer.java
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/Ejb3Deployment.java
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/PersistenceUnitRegistry.java
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/ExtendedPersistenceContextPropagationInterceptor.java
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/InjectedEntityManagerFactory.java
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/InjectedSessionFactory.java
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/PersistenceUnitDeployment.java
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/TransactionScopedEntityManager.java
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/TransactionScopedEntityManagerInterceptor.java
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/hibernate/TransactionScopedSessionInvocationHandler.java
projects/ejb3/trunk/core/src/main/java/org/jboss/injection/ExtendedPersistenceContextInjector.java
projects/ejb3/trunk/core/src/main/java/org/jboss/injection/InjectionContainer.java
projects/ejb3/trunk/core/src/main/java/org/jboss/injection/PcEncInjector.java
projects/ejb3/trunk/core/src/main/java/org/jboss/injection/PersistenceUnitHandler.java
Log:
EJBTHREE-1435: integrate jpa-deployers
Modified: projects/ejb3/trunk/core/pom.xml
===================================================================
--- projects/ejb3/trunk/core/pom.xml 2008-07-10 11:07:23 UTC (rev 75612)
+++ projects/ejb3/trunk/core/pom.xml 2008-07-10 11:09:23 UTC (rev 75613)
@@ -519,6 +519,12 @@
</dependency>
<dependency>
+ <groupId>org.jboss.jpa</groupId>
+ <artifactId>jboss-jpa-deployers</artifactId>
+ <version>0.1.0</version>
+ </dependency>
+
+ <dependency>
<groupId>org.jboss.microcontainer</groupId>
<artifactId>jboss-deployers-core-spi</artifactId>
</dependency>
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainer.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainer.java 2008-07-10 11:07:23 UTC (rev 75612)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/EJBContainer.java 2008-07-10 11:09:23 UTC (rev 75613)
@@ -87,7 +87,7 @@
import org.jboss.injection.DependsHandler;
import org.jboss.injection.EJBHandler;
import org.jboss.injection.EncInjector;
-import org.jboss.injection.InjectionContainer;
+import org.jboss.injection.ExtendedInjectionContainer;
import org.jboss.injection.InjectionHandler;
import org.jboss.injection.InjectionUtil;
import org.jboss.injection.Injector;
@@ -115,7 +115,7 @@
* @author <a href="mailto:bill at jboss.org">Bill Burke</a>
* @version $Revision$
*/
-public abstract class EJBContainer implements Container, IndirectContainer<EJBContainer, DirectContainer<EJBContainer>>, InjectionContainer, JavaEEComponent
+public abstract class EJBContainer implements Container, IndirectContainer<EJBContainer, DirectContainer<EJBContainer>>, ExtendedInjectionContainer, JavaEEComponent
{
private static final Logger log = Logger.getLogger(EJBContainer.class);
@@ -1329,6 +1329,11 @@
return deployment.resolveMessageDestination(link);
}
+ public String resolvePersistenceUnitSupplier(String unitName)
+ {
+ return getDeployment().resolvePersistenceUnitSupplier(unitName);
+ }
+
public <T extends Annotation> T getAnnotation(Class<T> annotationType)
{
if (this.getAnnotations().isDisabled(annotationType))
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/Ejb3Deployment.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/Ejb3Deployment.java 2008-07-10 11:07:23 UTC (rev 75612)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/Ejb3Deployment.java 2008-07-10 11:09:23 UTC (rev 75613)
@@ -31,6 +31,9 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+
+import javassist.bytecode.ClassFile;
+
import javax.management.MBeanServer;
import javax.management.ObjectName;
import javax.naming.InitialContext;
@@ -39,7 +42,7 @@
import javax.persistence.Entity;
import javax.security.jacc.PolicyConfiguration;
-import javassist.bytecode.ClassFile;
+import org.jboss.beans.metadata.api.annotations.Inject;
import org.jboss.deployers.spi.DeploymentException;
import org.jboss.ejb3.cache.CacheFactoryRegistry;
import org.jboss.ejb3.cache.persistence.PersistenceManagerFactoryRegistry;
@@ -57,6 +60,7 @@
import org.jboss.ejb3.proxy.factory.ProxyFactoryHelper;
import org.jboss.ejb3.proxy.factory.RemoteProxyFactoryRegistry;
import org.jboss.injection.InjectionHandler;
+import org.jboss.jpa.resolvers.PersistenceUnitDependencyResolver;
import org.jboss.logging.Logger;
import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
import org.jboss.metadata.ejb.jboss.JBossGenericBeanMetaData;
@@ -95,6 +99,7 @@
protected LinkedHashMap<ObjectName, Container> ejbContainers = new LinkedHashMap<ObjectName, Container>();
+ private boolean processPersistenceUnits = true;
protected boolean hasEntities;
protected List<String> explicitEntityClasses = new ArrayList<String>();
@@ -132,6 +137,11 @@
protected boolean reinitialize = false;
+ private org.jboss.deployers.structure.spi.DeploymentUnit deploymentUnit;
+
+ private PersistenceUnitDependencyResolver persistenceUnitDependencyResolver;
+
+ @Deprecated
public Ejb3Deployment(DeploymentUnit unit, DeploymentScope deploymentScope, JBossMetaData metaData, PersistenceMetaData persistenceUnitsMetaData)
{
assert unit != null : "unit is null";
@@ -154,6 +164,23 @@
destinations = metaData.getAssemblyDescriptor().getMessageDestinations();
messageDestinationResolver = new MessageDestinationResolver(deploymentScope, destinations);
}
+
+ /**
+ * Do not deploy persistence unit anymore.
+ *
+ * @param deploymentUnit
+ * @param unit
+ * @param deploymentScope
+ * @param metaData
+ */
+ public Ejb3Deployment(org.jboss.deployers.structure.spi.DeploymentUnit deploymentUnit, DeploymentUnit unit, DeploymentScope deploymentScope, JBossMetaData metaData)
+ {
+ this(unit, deploymentScope, metaData, null);
+
+ assert deploymentUnit != null : "deploymentUnit is null";
+
+ this.deploymentUnit = deploymentUnit;
+ }
public JavaEEApplication getApplication()
{
@@ -217,6 +244,12 @@
this.persistenceManagerFactoryRegistry = registry;
}
+ @Inject
+ public void setPersistenceUnitDependencyResolver(PersistenceUnitDependencyResolver resolver)
+ {
+ this.persistenceUnitDependencyResolver = resolver;
+ }
+
public PoolFactoryRegistry getPoolFactoryRegistry()
{
return poolFactoryRegistry;
@@ -226,6 +259,11 @@
this.poolFactoryRegistry = poolFactoryRegistry;
}
+ public void setProcessPersistenceUnits(boolean b)
+ {
+ this.processPersistenceUnits = b;
+ }
+
/**
* Returns a partial MBean attribute name of the form
* ",ear=foo.ear,jar=foo.jar"
@@ -665,7 +703,7 @@
protected void initializePersistenceUnits() throws Exception
{
- hasEntities = persistenceUnitsMetaData != null;
+ hasEntities = persistenceUnitsMetaData != null && processPersistenceUnits;
if (!hasEntities)
return;
@@ -839,6 +877,11 @@
return messageDestinationResolver.resolveMessageDestination(link);
}
+ protected String resolvePersistenceUnitSupplier(String persistenceUnitName)
+ {
+ return persistenceUnitDependencyResolver.resolvePersistenceUnitSupplier(deploymentUnit, persistenceUnitName);
+ }
+
public MessageDestinationResolver getMessageDestinationResolver()
{
return messageDestinationResolver;
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/PersistenceUnitRegistry.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/PersistenceUnitRegistry.java 2008-07-10 11:07:23 UTC (rev 75612)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/PersistenceUnitRegistry.java 2008-07-10 11:09:23 UTC (rev 75613)
@@ -21,15 +21,17 @@
*/
package org.jboss.ejb3;
+import java.util.Collection;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.Collection;
+
+import org.jboss.ejb3.entity.PersistenceUnitDeployment;
import org.jboss.logging.Logger;
-import org.jboss.ejb3.entity.PersistenceUnitDeployment;
/**
* @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
* @version <tt>$Revision$</tt>
*/
+ at Deprecated
public class PersistenceUnitRegistry
{
private static final Logger log = Logger.getLogger(PersistenceUnitRegistry.class);
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/ExtendedPersistenceContextPropagationInterceptor.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/ExtendedPersistenceContextPropagationInterceptor.java 2008-07-10 11:07:23 UTC (rev 75612)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/ExtendedPersistenceContextPropagationInterceptor.java 2008-07-10 11:09:23 UTC (rev 75613)
@@ -22,14 +22,16 @@
package org.jboss.ejb3.entity;
import java.util.Map;
+
import javax.persistence.EntityManager;
import javax.transaction.TransactionManager;
+
import org.jboss.aop.advice.Interceptor;
import org.jboss.aop.joinpoint.Invocation;
-import org.jboss.ejb3.PersistenceUnitRegistry;
import org.jboss.ejb3.stateful.StatefulBeanContext;
import org.jboss.ejb3.stateful.StatefulContainerInvocation;
import org.jboss.ejb3.tx.TxUtil;
+import org.jboss.jpa.deployment.ManagedEntityManagerFactory;
import org.jboss.logging.Logger;
/**
@@ -63,7 +65,7 @@
for (String kernelname : extendedPCs.keySet())
{
EntityManager manager = extendedPCs.get(kernelname);
- ManagedEntityManagerFactory factory = PersistenceUnitRegistry.getPersistenceUnit(kernelname).getManagedFactory();
+ ManagedEntityManagerFactory factory = ManagedEntityManagerFactoryHelper.getManagedEntityManagerFactory(kernelname);
factory.registerExtendedWithTransaction(manager);
}
}
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/InjectedEntityManagerFactory.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/InjectedEntityManagerFactory.java 2008-07-10 11:07:23 UTC (rev 75612)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/InjectedEntityManagerFactory.java 2008-07-10 11:09:23 UTC (rev 75613)
@@ -26,10 +26,12 @@
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.Map;
+
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
-import org.jboss.ejb3.PersistenceUnitRegistry;
+import org.jboss.jpa.deployment.ManagedEntityManagerFactory;
+
/**
* Comment
*
@@ -67,9 +69,9 @@
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
{
String kernelName = in.readUTF();
- PersistenceUnitDeployment deployment = PersistenceUnitRegistry.getPersistenceUnit(kernelName);
- if (deployment == null) throw new IOException("Unable to find persistence unit in registry: " + kernelName);
- managedFactory = deployment.getManagedFactory();
+ managedFactory = ManagedEntityManagerFactoryHelper.getManagedEntityManagerFactory(kernelName);
+ if(managedFactory == null)
+ throw new IOException("Unable to find persistence unit in registry: " + kernelName);
delegate = managedFactory.getEntityManagerFactory();
}
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/InjectedSessionFactory.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/InjectedSessionFactory.java 2008-07-10 11:07:23 UTC (rev 75612)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/InjectedSessionFactory.java 2008-07-10 11:09:23 UTC (rev 75613)
@@ -29,9 +29,11 @@
import java.sql.Connection;
import java.util.Map;
import java.util.Set;
+
import javax.naming.NamingException;
import javax.naming.Reference;
import javax.persistence.EntityManagerFactory;
+
import org.hibernate.HibernateException;
import org.hibernate.Interceptor;
import org.hibernate.SessionFactory;
@@ -42,7 +44,7 @@
import org.hibernate.metadata.ClassMetadata;
import org.hibernate.metadata.CollectionMetadata;
import org.hibernate.stat.Statistics;
-import org.jboss.ejb3.PersistenceUnitRegistry;
+import org.jboss.jpa.deployment.ManagedEntityManagerFactory;
/**
* Comment
@@ -73,9 +75,8 @@
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
{
String kernelName = in.readUTF();
- PersistenceUnitDeployment deployment = PersistenceUnitRegistry.getPersistenceUnit(kernelName);
- if (deployment == null) throw new IOException("Unable to find persistence unit in registry: " + kernelName);
- managedFactory = deployment.getManagedFactory();
+ managedFactory = ManagedEntityManagerFactoryHelper.getManagedEntityManagerFactory(kernelName);
+ if (managedFactory == null) throw new IOException("Unable to find persistence unit in registry: " + kernelName);
delegate = managedFactory.getEntityManagerFactory();
}
Deleted: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/ManagedEntityManagerFactory.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/ManagedEntityManagerFactory.java 2008-07-10 11:07:23 UTC (rev 75612)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/ManagedEntityManagerFactory.java 2008-07-10 11:09:23 UTC (rev 75613)
@@ -1,203 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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.ejb3.entity;
-
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.PersistenceContextType;
-import javax.persistence.TransactionRequiredException;
-import javax.transaction.RollbackException;
-import javax.transaction.Synchronization;
-import javax.transaction.SystemException;
-import javax.transaction.Transaction;
-import org.jboss.logging.Logger;
-import org.jboss.tm.TransactionLocal;
-import org.jboss.tm.TxUtils;
-import org.jboss.ejb3.ThreadLocalStack;
-import org.jboss.ejb3.tx.TxUtil;
-
-import java.util.IdentityHashMap;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @author <a href="mailto:gavine at hibernate.org">Gavin King</a>
- * @version $Revision$
- */
-public class ManagedEntityManagerFactory
-{
- private static final Logger log = Logger.getLogger(ManagedEntityManagerFactory.class);
-
- protected EntityManagerFactory entityManagerFactory;
- protected TransactionLocal session = new TransactionLocal(TxUtil.getTransactionManager());
- protected String kernelName;
-
- public static ThreadLocalStack<Map> nonTxStack = new ThreadLocalStack<Map>();
-
- public EntityManager getNonTxEntityManager()
- {
- Map map = nonTxStack.get();
-
- EntityManager em = null;
- if (map != null)
- em = (EntityManager)map.get(this);
- else
- {
- map = new HashMap();
- nonTxStack.push(map);
- }
-
- if (em == null)
- {
- em = entityManagerFactory.createEntityManager();
- map.put(this, em);
- }
- return em;
- }
-
- public ManagedEntityManagerFactory(EntityManagerFactory sf, String kernelName)
- {
- this.entityManagerFactory = sf;
- this.kernelName = kernelName;
- }
-
- public EntityManagerFactory getEntityManagerFactory()
- {
- return entityManagerFactory;
- }
-
- public String getKernelName()
- {
- return kernelName;
- }
-
- public void destroy()
- {
- entityManagerFactory.close();
- }
-
- private static class SessionSynchronization implements Synchronization
- {
- private EntityManager manager;
- private Transaction tx;
- private boolean closeAtTxCompletion;
-
- public SessionSynchronization(EntityManager session, Transaction tx, boolean close)
- {
- this.manager = session;
- this.tx = tx;
- closeAtTxCompletion = close;
- }
-
- public void beforeCompletion()
- {
- /* IF THIS GETS REACTIVATED THEN YOU MUST remove the if(closeAtTxCompletion) block in getSession()
- try
- {
- int status = tx.getStatus();
- if (status != Status.STATUS_ROLLEDBACK && status != Status.STATUS_ROLLING_BACK && status != Status.STATUS_MARKED_ROLLBACK)
- {
- if (FlushModeInterceptor.getTxFlushMode() != FlushModeType.NEVER)
- {
- log.debug("************** flushing.....");
- manager.flush();
- }
- }
- }
- catch (SystemException e)
- {
- throw new RuntimeException(e);
- }
- */
- }
-
- public void afterCompletion(int status)
- {
- if (closeAtTxCompletion)
- {
- log.debug("************** closing entity managersession **************");
- manager.close();
- }
- }
- }
-
- public static ThreadLocal longLivedSession = new ThreadLocal();
-
- public TransactionLocal getTransactionSession()
- {
- return session;
- }
-
- public void registerExtendedWithTransaction(EntityManager pc)
- {
- pc.joinTransaction();
- session.set(pc);
- }
-
- public void verifyInTx()
- {
- Transaction tx = session.getTransaction();
- if (tx == null || !TxUtils.isActive(tx)) throw new TransactionRequiredException("EntityManager must be access within a transaction");
- if (!TxUtils.isActive(tx))
- throw new TransactionRequiredException("Transaction must be active to access EntityManager");
- }
- public boolean isInTx()
- {
- Transaction tx = session.getTransaction();
- if (tx == null || !TxUtils.isActive(tx)) return false;
- return true;
- }
-
- public EntityManager getTransactionScopedEntityManager()
- {
- Transaction tx = session.getTransaction();
- if (tx == null || !TxUtils.isActive(tx)) return getNonTxEntityManager();
-
- EntityManager rtnSession = (EntityManager) session.get();
- if (rtnSession == null)
- {
- rtnSession = createEntityManager();
- try
- {
- tx.registerSynchronization(new SessionSynchronization(rtnSession, tx, true));
- }
- catch (RollbackException e)
- {
- throw new RuntimeException(e); //To change body of catch statement use Options | File Templates.
- }
- catch (SystemException e)
- {
- throw new RuntimeException(e); //To change body of catch statement use Options | File Templates.
- }
- session.set(rtnSession);
- rtnSession.joinTransaction(); // force registration with TX
- }
- return rtnSession;
- }
-
- public EntityManager createEntityManager()
- {
- return entityManagerFactory.createEntityManager();
- }
-
-
-}
Added: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/ManagedEntityManagerFactoryHelper.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/ManagedEntityManagerFactoryHelper.java (rev 0)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/ManagedEntityManagerFactoryHelper.java 2008-07-10 11:09:23 UTC (rev 75613)
@@ -0,0 +1,45 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ejb3.entity;
+
+import org.jboss.jpa.deployment.ManagedEntityManagerFactory;
+import org.jboss.jpa.deployment.PersistenceUnitDeployment;
+import org.jboss.jpa.spi.PersistenceUnitRegistry;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class ManagedEntityManagerFactoryHelper
+{
+ public static ManagedEntityManagerFactory getManagedEntityManagerFactory(String kernelName)
+ {
+ PersistenceUnitDeployment pu = (PersistenceUnitDeployment) PersistenceUnitRegistry.getPersistenceUnit(kernelName);
+ if(pu != null)
+ return pu.getManagedFactory();
+ // Legacy
+ org.jboss.ejb3.entity.PersistenceUnitDeployment oldPu = org.jboss.ejb3.PersistenceUnitRegistry.getPersistenceUnit(kernelName);
+ if(oldPu != null)
+ return oldPu.getManagedFactory();
+ return null;
+ }
+}
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/PersistenceUnitDeployment.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/PersistenceUnitDeployment.java 2008-07-10 11:07:23 UTC (rev 75612)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/PersistenceUnitDeployment.java 2008-07-10 11:09:23 UTC (rev 75613)
@@ -28,6 +28,7 @@
import java.util.Map;
import java.util.Properties;
import java.util.Set;
+
import javax.naming.InitialContext;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
@@ -41,11 +42,12 @@
import org.jboss.ejb3.NonSerializableFactory;
import org.jboss.ejb3.javaee.AbstractJavaEEComponent;
import org.jboss.ejb3.javaee.SimpleJavaEEModule;
+import org.jboss.jpa.deployment.ManagedEntityManagerFactory;
import org.jboss.logging.Logger;
import org.jboss.metadata.jpa.spec.PersistenceUnitMetaData;
import org.jboss.metadata.jpa.spec.TransactionType;
+import org.jboss.virtual.VFSUtils;
import org.jboss.virtual.VirtualFile;
-import org.jboss.virtual.VFSUtils;
/**
* Comment
@@ -53,6 +55,7 @@
* @author <a href="mailto:bill at jboss.org">Bill Burke</a>
* @version $Revision$
*/
+ at Deprecated
public class PersistenceUnitDeployment extends AbstractJavaEEComponent
{
private static final Logger log = Logger.getLogger(PersistenceUnitDeployment.class);
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/TransactionScopedEntityManager.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/TransactionScopedEntityManager.java 2008-07-10 11:07:23 UTC (rev 75612)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/TransactionScopedEntityManager.java 2008-07-10 11:09:23 UTC (rev 75613)
@@ -21,20 +21,24 @@
*/
package org.jboss.ejb3.entity;
-import org.hibernate.Session;
-import org.hibernate.ejb.HibernateEntityManager;
-import org.jboss.ejb3.PersistenceUnitRegistry;
-import org.jboss.ejb3.stateful.StatefulBeanContext;
-import org.jboss.logging.Logger;
-
-import javax.persistence.*;
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
-
import java.util.List;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityTransaction;
+import javax.persistence.FlushModeType;
+import javax.persistence.LockModeType;
+import javax.persistence.Query;
+
+import org.hibernate.Session;
+import org.hibernate.ejb.HibernateEntityManager;
+import org.jboss.ejb3.stateful.StatefulBeanContext;
+import org.jboss.jpa.deployment.ManagedEntityManagerFactory;
+import org.jboss.logging.Logger;
+
/**
* @author <a href="mailto:bill at jboss.org">Bill Burke</a>
* @version $Revision$
@@ -76,9 +80,8 @@
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
{
String kernelName = in.readUTF();
- PersistenceUnitDeployment deployment = PersistenceUnitRegistry.getPersistenceUnit(kernelName);
- if (deployment == null) throw new IOException("Unable to find persistence unit in registry: " + kernelName);
- factory = deployment.getManagedFactory();
+ factory = ManagedEntityManagerFactoryHelper.getManagedEntityManagerFactory(kernelName);
+ if ( factory == null ) throw new IOException( "Unable to find persistence unit in registry: " + kernelName );
}
public Object getDelegate()
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/TransactionScopedEntityManagerInterceptor.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/TransactionScopedEntityManagerInterceptor.java 2008-07-10 11:07:23 UTC (rev 75612)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/TransactionScopedEntityManagerInterceptor.java 2008-07-10 11:09:23 UTC (rev 75613)
@@ -21,14 +21,16 @@
*/
package org.jboss.ejb3.entity;
+import java.util.IdentityHashMap;
+import java.util.Map;
+
+import javax.persistence.EntityManager;
+
import org.jboss.aop.advice.Interceptor;
import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.jpa.deployment.ManagedEntityManagerFactory;
import org.jboss.logging.Logger;
-import javax.persistence.EntityManager;
-import java.util.IdentityHashMap;
-import java.util.Map;
-
/**
* If a transaction-scoped entitymanager is accessed outside of a transaction
* an entitymanager is created for the duration of the current EJB method call
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/hibernate/TransactionScopedSessionInvocationHandler.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/hibernate/TransactionScopedSessionInvocationHandler.java 2008-07-10 11:07:23 UTC (rev 75612)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/hibernate/TransactionScopedSessionInvocationHandler.java 2008-07-10 11:09:23 UTC (rev 75613)
@@ -22,20 +22,20 @@
*/
package org.jboss.ejb3.entity.hibernate;
-import java.io.ObjectOutput;
+import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
-import java.io.Externalizable;
+import java.io.ObjectOutput;
import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
import javax.persistence.EntityManager;
-import org.jboss.ejb3.entity.ManagedEntityManagerFactory;
-import org.jboss.ejb3.entity.PersistenceUnitDeployment;
-import org.jboss.ejb3.PersistenceUnitRegistry;
import org.hibernate.Session;
import org.hibernate.ejb.HibernateEntityManager;
+import org.jboss.ejb3.entity.ManagedEntityManagerFactoryHelper;
+import org.jboss.jpa.deployment.ManagedEntityManagerFactory;
/**
* Handle method execution delegation to an Hibernate session following the transaction scoped persistence context rules
@@ -82,9 +82,8 @@
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
{
String kernelName = in.readUTF();
- PersistenceUnitDeployment deployment = PersistenceUnitRegistry.getPersistenceUnit( kernelName );
- if ( deployment == null ) throw new IOException( "Unable to find persistence unit in registry: " + kernelName );
- factory = deployment.getManagedFactory();
+ factory = ManagedEntityManagerFactoryHelper.getManagedEntityManagerFactory(kernelName);
+ if ( factory == null ) throw new IOException( "Unable to find persistence unit in registry: " + kernelName );
}
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
Added: projects/ejb3/trunk/core/src/main/java/org/jboss/injection/ExtendedInjectionContainer.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/injection/ExtendedInjectionContainer.java (rev 0)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/injection/ExtendedInjectionContainer.java 2008-07-10 11:09:23 UTC (rev 75613)
@@ -0,0 +1,31 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.injection;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface ExtendedInjectionContainer extends InjectionContainer
+{
+ String resolvePersistenceUnitSupplier(String unitName);
+}
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/injection/ExtendedPersistenceContextInjector.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/injection/ExtendedPersistenceContextInjector.java 2008-07-10 11:07:23 UTC (rev 75612)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/injection/ExtendedPersistenceContextInjector.java 2008-07-10 11:09:23 UTC (rev 75613)
@@ -22,9 +22,10 @@
package org.jboss.injection;
import javax.persistence.EntityManager;
+
import org.jboss.ejb3.BeanContext;
-import org.jboss.ejb3.entity.ManagedEntityManagerFactory;
import org.jboss.ejb3.stateful.StatefulBeanContext;
+import org.jboss.jpa.deployment.ManagedEntityManagerFactory;
import org.jboss.logging.Logger;
/**
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/injection/InjectionContainer.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/injection/InjectionContainer.java 2008-07-10 11:07:23 UTC (rev 75612)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/injection/InjectionContainer.java 2008-07-10 11:09:23 UTC (rev 75613)
@@ -34,7 +34,6 @@
import org.jboss.ejb3.Container;
import org.jboss.ejb3.DependencyPolicy;
import org.jboss.ejb3.entity.PersistenceUnitDeployment;
-import org.jboss.metadata.javaee.spec.Environment;
import org.jboss.metadata.javaee.spec.RemoteEnvironment;
import org.jboss.virtual.VirtualFile;
@@ -68,6 +67,7 @@
Context getEnc();
+ @Deprecated
PersistenceUnitDeployment getPersistenceUnitDeployment(String unitName) throws NameNotFoundException;
Container resolveEjbContainer(String link, Class<?> businessIntf);
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/injection/PcEncInjector.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/injection/PcEncInjector.java 2008-07-10 11:07:23 UTC (rev 75612)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/injection/PcEncInjector.java 2008-07-10 11:09:23 UTC (rev 75613)
@@ -23,20 +23,20 @@
import java.lang.reflect.Proxy;
-import org.jboss.ejb3.entity.ManagedEntityManagerFactory;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContextType;
+
+import org.hibernate.Session;
import org.jboss.ejb3.entity.ExtendedEntityManager;
import org.jboss.ejb3.entity.TransactionScopedEntityManager;
import org.jboss.ejb3.entity.hibernate.ExtendedSessionInvocationHandler;
import org.jboss.ejb3.entity.hibernate.TransactionScopedSessionInvocationHandler;
import org.jboss.ejb3.stateful.StatefulContainer;
+import org.jboss.jpa.deployment.ManagedEntityManagerFactory;
import org.jboss.util.naming.Util;
-import org.hibernate.Session;
-import javax.persistence.PersistenceContextType;
-import javax.persistence.EntityManager;
-import javax.naming.NameNotFoundException;
-import javax.naming.NamingException;
-
/**
* Comment
*
Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/injection/PersistenceUnitHandler.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/injection/PersistenceUnitHandler.java 2008-07-10 11:07:23 UTC (rev 75612)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/injection/PersistenceUnitHandler.java 2008-07-10 11:09:23 UTC (rev 75613)
@@ -35,8 +35,9 @@
import org.jboss.ejb3.annotation.IgnoreDependency;
import org.jboss.ejb3.entity.InjectedEntityManagerFactory;
import org.jboss.ejb3.entity.InjectedSessionFactory;
-import org.jboss.ejb3.entity.ManagedEntityManagerFactory;
import org.jboss.ejb3.entity.PersistenceUnitDeployment;
+import org.jboss.jpa.deployment.ManagedEntityManagerFactory;
+import org.jboss.jpa.spi.PersistenceUnitRegistry;
import org.jboss.logging.Logger;
import org.jboss.metadata.javaee.spec.PersistenceUnitReferenceMetaData;
import org.jboss.metadata.javaee.spec.RemoteEnvironment;
@@ -117,6 +118,14 @@
public static void addPUDependency(String unitName, InjectionContainer container) throws NameNotFoundException
{
+ if(container instanceof ExtendedInjectionContainer)
+ {
+ ExtendedInjectionContainer eic = (ExtendedInjectionContainer) container;
+ String dependency = eic.resolvePersistenceUnitSupplier(unitName);
+ container.getDependencyPolicy().addDependency(dependency);
+ return;
+ }
+ log.warn("Container " + container + " does not implement ExtendedInjectionContainer, doing old style PersistenceUnit resolving");
PersistenceUnitDeployment deployment = null;
// look in EAR first
deployment = container.getPersistenceUnitDeployment(unitName);
@@ -135,17 +144,22 @@
public static ManagedEntityManagerFactory getManagedEntityManagerFactory(InjectionContainer container, String unitName)
throws NameNotFoundException
{
- ManagedEntityManagerFactory factory;
+ if(container instanceof ExtendedInjectionContainer)
+ {
+ ExtendedInjectionContainer eic = (ExtendedInjectionContainer) container;
+ String beanName = eic.resolvePersistenceUnitSupplier(unitName);
+ return ((org.jboss.jpa.deployment.PersistenceUnitDeployment) PersistenceUnitRegistry.getPersistenceUnit(beanName)).getManagedFactory();
+ }
+ log.warn("Container " + container + " does not implement ExtendedInjectionContainer");
PersistenceUnitDeployment deployment = container.getPersistenceUnitDeployment(unitName);
if (deployment != null)
{
- factory = deployment.getManagedFactory();
+ return deployment.getManagedFactory();
}
else
{
throw new NameNotFoundException("Unable to find persistence unit: " + unitName + " for deployment: " + container.getIdentifier());
}
- return factory;
}
@@ -163,33 +177,47 @@
public static EntityManagerFactory getEntityManagerFactory(String unitName, InjectionContainer container) throws NameNotFoundException
{
- ManagedEntityManagerFactory managedFactory;
+ if(container instanceof ExtendedInjectionContainer)
+ {
+ ExtendedInjectionContainer eic = (ExtendedInjectionContainer) container;
+ String beanName = eic.resolvePersistenceUnitSupplier(unitName);
+ ManagedEntityManagerFactory managedFactory = ((org.jboss.jpa.deployment.PersistenceUnitDeployment) PersistenceUnitRegistry.getPersistenceUnit(beanName)).getManagedFactory();
+ return new InjectedEntityManagerFactory(managedFactory);
+ }
+ log.warn("Container " + container + " does not implement ExtendedInjectionContainer");
PersistenceUnitDeployment deployment = container.getPersistenceUnitDeployment(unitName);
if (deployment != null)
{
- managedFactory = deployment.getManagedFactory();
+ ManagedEntityManagerFactory managedFactory = deployment.getManagedFactory();
+ return new InjectedEntityManagerFactory(managedFactory);
}
else
{
return null;
}
- return new InjectedEntityManagerFactory(managedFactory);
}
private static SessionFactory getSessionFactory(String ref, InjectionContainer container) throws NameNotFoundException
{
- ManagedEntityManagerFactory managedFactory;
+ if(container instanceof ExtendedInjectionContainer)
+ {
+ ExtendedInjectionContainer eic = (ExtendedInjectionContainer) container;
+ String beanName = eic.resolvePersistenceUnitSupplier(ref);
+ ManagedEntityManagerFactory managedFactory = ((org.jboss.jpa.deployment.PersistenceUnitDeployment) PersistenceUnitRegistry.getPersistenceUnit(beanName)).getManagedFactory();
+ return new InjectedSessionFactory(managedFactory);
+ }
+ log.warn("Container " + container + " does not implement ExtendedInjectionContainer");
PersistenceUnitDeployment deployment = container.getPersistenceUnitDeployment(ref);
if (deployment != null)
{
- managedFactory = deployment.getManagedFactory();
+ ManagedEntityManagerFactory managedFactory = deployment.getManagedFactory();
+ return new InjectedSessionFactory(managedFactory);
}
else
{
return null;
}
- return new InjectedSessionFactory(managedFactory);
}
public void handleMethodAnnotations(Method method, InjectionContainer container, Map<AccessibleObject, Injector> injectors)
More information about the jboss-cvs-commits
mailing list