[jboss-cvs] JBossAS SVN: r79921 - in projects/jpa/trunk/deployers/src: main/java/org/jboss/jpa/resolvers and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Oct 22 08:50:41 EDT 2008
Author: wolfc
Date: 2008-10-22 08:50:41 -0400 (Wed, 22 Oct 2008)
New Revision: 79921
Added:
projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/resolvers/DefaultXPCResolver.java
projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/spi/XPCResolver.java
Removed:
projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/spi/XPCAware.java
Modified:
projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployment/PersistenceUnitDeployment.java
projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/spi/PersistenceUnit.java
projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/tx/TransactionScopedEntityManager.java
projects/jpa/trunk/deployers/src/test/resources/org/jboss/jpa/deployers/test/common/jpa-deployers-beans.xml
Log:
JBAS-6093: configurable XPC resolver
Modified: projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployment/PersistenceUnitDeployment.java
===================================================================
--- projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployment/PersistenceUnitDeployment.java 2008-10-22 12:16:20 UTC (rev 79920)
+++ projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployment/PersistenceUnitDeployment.java 2008-10-22 12:50:41 UTC (rev 79921)
@@ -32,15 +32,18 @@
import java.util.Set;
import javax.naming.InitialContext;
+import javax.naming.NamingException;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.spi.PersistenceProvider;
import org.hibernate.ejb.HibernatePersistence;
+import org.jboss.beans.metadata.api.annotations.Inject;
import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
import org.jboss.jpa.injection.InjectedEntityManagerFactory;
import org.jboss.jpa.spi.PersistenceUnit;
import org.jboss.jpa.spi.PersistenceUnitRegistry;
+import org.jboss.jpa.spi.XPCResolver;
import org.jboss.jpa.tx.TransactionScopedEntityManager;
import org.jboss.logging.Logger;
import org.jboss.metadata.jpa.spec.PersistenceUnitMetaData;
@@ -68,6 +71,7 @@
protected String kernelName;
protected PersistenceDeployment deployment;
private Properties defaultPersistenceProperties;
+ private XPCResolver xpcResolver;
public PersistenceUnitDeployment(InitialContext initialContext, PersistenceDeployment deployment, List<String> explicitEntityClasses, PersistenceUnitMetaData metadata, String kernelName, VFSDeploymentUnit deploymentUnit, Properties defaultPersistenceProperties)
{
@@ -199,6 +203,19 @@
}
}
+ public XPCResolver getXPCResolver()
+ {
+ assert xpcResolver != null : "xpcResolver is null";
+ return xpcResolver;
+ }
+
+ @Inject
+ public void setXPCResolver(XPCResolver xpcResolver)
+ {
+ assert xpcResolver != null : "xpcResolver is null";
+ this.xpcResolver = xpcResolver;
+ }
+
// public void addDependencies(DependencyPolicy policy)
// {
// Map<String, String> props = getProperties();
@@ -311,17 +328,22 @@
{
log.info("Stopping persistence unit " + kernelName);
- // FIXME: reinstate
-// String entityManagerJndiName = getProperties().get("jboss.entity.manager.jndi.name");
-// if (entityManagerJndiName != null)
-// {
-// NonSerializableFactory.unbind(initialContext, entityManagerJndiName);
-// }
-// String entityManagerFactoryJndiName = getProperties().get("jboss.entity.manager.factory.jndi.name");
-// if (entityManagerFactoryJndiName != null)
-// {
-// NonSerializableFactory.unbind(initialContext, entityManagerFactoryJndiName);
-// }
+ String entityManagerJndiName = getProperties().get("jboss.entity.manager.jndi.name");
+ if (entityManagerJndiName != null)
+ {
+ unbind(entityManagerJndiName);
+ }
+ String entityManagerFactoryJndiName = getProperties().get("jboss.entity.manager.factory.jndi.name");
+ if (entityManagerFactoryJndiName != null)
+ {
+ unbind(entityManagerFactoryJndiName);
+ }
managedFactory.destroy();
}
+
+ private void unbind(String name) throws NamingException
+ {
+ NonSerializableFactory.unbind(name);
+ initialContext.unbind(name);
+ }
}
Added: projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/resolvers/DefaultXPCResolver.java
===================================================================
--- projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/resolvers/DefaultXPCResolver.java (rev 0)
+++ projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/resolvers/DefaultXPCResolver.java 2008-10-22 12:50:41 UTC (rev 79921)
@@ -0,0 +1,41 @@
+/*
+ * 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.jpa.resolvers;
+
+import javax.persistence.EntityManager;
+
+import org.jboss.jpa.spi.XPCResolver;
+
+/**
+ * The default XPC resolver is only useful in an environment where
+ * there are no XPC aware components.
+ *
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class DefaultXPCResolver implements XPCResolver
+{
+ public EntityManager getExtendedPersistenceContext(String kernelName)
+ {
+ return null;
+ }
+}
Modified: projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/spi/PersistenceUnit.java
===================================================================
--- projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/spi/PersistenceUnit.java 2008-10-22 12:16:20 UTC (rev 79920)
+++ projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/spi/PersistenceUnit.java 2008-10-22 12:50:41 UTC (rev 79921)
@@ -40,4 +40,12 @@
EntityManagerFactory getContainerEntityManagerFactory();
String getName();
+
+ /**
+ * The extended persistence context resolver associated with
+ * this persistence unit.
+ *
+ * @return the XPC resolver
+ */
+ XPCResolver getXPCResolver();
}
Deleted: projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/spi/XPCAware.java
===================================================================
--- projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/spi/XPCAware.java 2008-10-22 12:16:20 UTC (rev 79920)
+++ projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/spi/XPCAware.java 2008-10-22 12:50:41 UTC (rev 79921)
@@ -1,81 +0,0 @@
-/*
- * 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.jpa.spi;
-
-import java.util.List;
-import java.util.Map;
-
-import javax.persistence.EntityManager;
-
-import org.jboss.jpa.util.ThreadLocalStack;
-
-/**
- * XPC aware components use this registry to subscribe to XPCs.
- *
- * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
- * @version $Revision: $
- */
-public class XPCAware
-{
- /*
- * I would rather call out on some SPI to ask for the current context, but
- * since this is mostly static stuff there is no real way to configure this class.
- */
-
- private static ThreadLocalStack<Map<String, EntityManager>> currentXPCs = new ThreadLocalStack<Map<String, EntityManager>>();
-
- /**
- * Return the identified XPC, if it is active.
- *
- * @param id the id of the XPC
- * @return the XPC or null if none is found
- */
- public static EntityManager getExtendedPersistenceContext(String id)
- {
- List<Map<String, EntityManager>> list = currentXPCs.getList();
- if(list == null)
- return null;
- for(Map<String, EntityManager> xpcs : list)
- {
- EntityManager em = xpcs.get(id);
- if(em != null)
- return em;
- }
- return null;
- }
-
- public static Map<String, EntityManager> popXPCs()
- {
- return currentXPCs.pop();
- }
-
- /**
- * Called by an XPC consumer to make the call stack aware of XPCs.
- * @param xpcs the XPCs initiated by the XPC consumer
- */
- public static void pushXPCs(Map<String, EntityManager> xpcs)
- {
- assert xpcs != null : "xpcs is null";
-
- currentXPCs.push(xpcs);
- }
-}
Added: projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/spi/XPCResolver.java
===================================================================
--- projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/spi/XPCResolver.java (rev 0)
+++ projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/spi/XPCResolver.java 2008-10-22 12:50:41 UTC (rev 79921)
@@ -0,0 +1,44 @@
+/*
+ * 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.jpa.spi;
+
+import javax.persistence.EntityManager;
+
+/**
+ * Query the current context for extended persistence contexts.
+ *
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface XPCResolver
+{
+ /**
+ * Get an extended persistence context within the current context.
+ *
+ * Note that the full kernel name must be specified to resolve ambiguity
+ * with persistence units in different modules.
+ *
+ * @param kernelName the identification of the persistence context
+ * @return the extended persistence context or null
+ */
+ EntityManager getExtendedPersistenceContext(String kernelName);
+}
Modified: projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/tx/TransactionScopedEntityManager.java
===================================================================
--- projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/tx/TransactionScopedEntityManager.java 2008-10-22 12:16:20 UTC (rev 79920)
+++ projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/tx/TransactionScopedEntityManager.java 2008-10-22 12:50:41 UTC (rev 79921)
@@ -35,7 +35,9 @@
import org.hibernate.Session;
import org.hibernate.ejb.HibernateEntityManager;
import org.jboss.jpa.deployment.ManagedEntityManagerFactory;
-import org.jboss.jpa.spi.XPCAware;
+import org.jboss.jpa.spi.PersistenceUnit;
+import org.jboss.jpa.spi.PersistenceUnitRegistry;
+import org.jboss.jpa.spi.XPCResolver;
import org.jboss.jpa.util.ManagedEntityManagerFactoryHelper;
import org.jboss.logging.Logger;
@@ -246,8 +248,10 @@
}
}
*/
- String id = factory.getKernelName();
- EntityManager em = XPCAware.getExtendedPersistenceContext(id);
+ String kernelName = factory.getKernelName();
+ PersistenceUnit pu = PersistenceUnitRegistry.getPersistenceUnit(kernelName);
+ XPCResolver xpcResolver = pu.getXPCResolver();
+ EntityManager em = xpcResolver.getExtendedPersistenceContext(kernelName);
if(em != null)
return em;
Modified: projects/jpa/trunk/deployers/src/test/resources/org/jboss/jpa/deployers/test/common/jpa-deployers-beans.xml
===================================================================
--- projects/jpa/trunk/deployers/src/test/resources/org/jboss/jpa/deployers/test/common/jpa-deployers-beans.xml 2008-10-22 12:16:20 UTC (rev 79920)
+++ projects/jpa/trunk/deployers/src/test/resources/org/jboss/jpa/deployers/test/common/jpa-deployers-beans.xml 2008-10-22 12:50:41 UTC (rev 79921)
@@ -6,6 +6,9 @@
<bean name="PersistenceUnitDependencyResolver" class="org.jboss.jpa.resolvers.DefaultPersistenceUnitDependencyResolver"/>
+ <!-- Do not use this one in a JavaEE environment -->
+ <bean name="XPCResolver" class="org.jboss.jpa.resolvers.DefaultXPCResolver"/>
+
<bean name="PersistenceParsingDeployer" class="org.jboss.jpa.deployers.PersistenceParsingDeployer"/>
<bean name="PersistenceDeployer" class="org.jboss.jpa.deployers.PersistenceDeployer"/>
More information about the jboss-cvs-commits
mailing list