[jboss-cvs] JBossAS SVN: r79976 - in projects/ejb3/trunk/core: src/main/java/org/jboss/ejb3 and 6 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Oct 23 10:07:20 EDT 2008
Author: wolfc
Date: 2008-10-23 10:07:20 -0400 (Thu, 23 Oct 2008)
New Revision: 79976
Added:
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/EJB3XPCResolver.java
Removed:
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/PersistenceUnitRegistry.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/ManagedEntityManagerFactoryHelper.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
Modified:
projects/ejb3/trunk/core/pom.xml
projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/ExtendedPersistenceContextPropagationInterceptor.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/hibernate/TransactionScopedSessionInvocationHandler.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
projects/ejb3/trunk/core/src/main/resources/META-INF/jpa-deployers-jboss-beans.xml
projects/ejb3/trunk/core/src/test/java/org/jboss/injection/test/common/DummyInjectionContainer.java
Log:
EJBTHREE-1526: using new jpa-deployers facilities
Modified: projects/ejb3/trunk/core/pom.xml
===================================================================
--- projects/ejb3/trunk/core/pom.xml 2008-10-23 13:26:13 UTC (rev 79975)
+++ projects/ejb3/trunk/core/pom.xml 2008-10-23 14:07:20 UTC (rev 79976)
@@ -553,7 +553,7 @@
<dependency>
<groupId>org.jboss.jpa</groupId>
<artifactId>jboss-jpa-deployers</artifactId>
- <version>0.1.1</version>
+ <version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
Deleted: 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-10-23 13:26:13 UTC (rev 79975)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/PersistenceUnitRegistry.java 2008-10-23 14:07:20 UTC (rev 79976)
@@ -1,62 +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;
-
-import java.util.Collection;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.jboss.ejb3.entity.PersistenceUnitDeployment;
-import org.jboss.logging.Logger;
-
-/**
- * @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);
-
- private static ConcurrentHashMap<String, PersistenceUnitDeployment> persistenceUnits = new ConcurrentHashMap<String, PersistenceUnitDeployment>();
-
- public static void register(PersistenceUnitDeployment container)
- {
- if (persistenceUnits.contains(container.getKernelName())) throw new RuntimeException("Persistence Unit is already registered: " + container.getKernelName());
- persistenceUnits.put(container.getKernelName(), container);
- }
-
- public static void unregister(PersistenceUnitDeployment container)
- {
- persistenceUnits.remove(container.getKernelName());
- }
-
- public static PersistenceUnitDeployment getPersistenceUnit(String kernelName)
- {
- return persistenceUnits.get(kernelName);
- }
-
- public static Collection<PersistenceUnitDeployment> getPersistenceUnits()
- {
- return persistenceUnits.values();
- }
-
-}
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-10-23 13:26:13 UTC (rev 79975)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/ExtendedPersistenceContextPropagationInterceptor.java 2008-10-23 14:07:20 UTC (rev 79976)
@@ -32,6 +32,7 @@
import org.jboss.ejb3.stateful.StatefulContainerInvocation;
import org.jboss.ejb3.tx.TxUtil;
import org.jboss.jpa.deployment.ManagedEntityManagerFactory;
+import org.jboss.jpa.util.ManagedEntityManagerFactoryHelper;
import org.jboss.logging.Logger;
/**
Deleted: 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-10-23 13:26:13 UTC (rev 79975)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/InjectedEntityManagerFactory.java 2008-10-23 14:07:20 UTC (rev 79976)
@@ -1,103 +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 java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Map;
-
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-
-import org.jboss.jpa.deployment.ManagedEntityManagerFactory;
-
-/**
- * Comment
- *
- * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
- * @version $Revision$
- */
-public class InjectedEntityManagerFactory implements EntityManagerFactory, Externalizable
-{
- private static final long serialVersionUID = -3734435119658196788L;
-
- private transient EntityManagerFactory delegate;
- private transient ManagedEntityManagerFactory managedFactory;
-
- public InjectedEntityManagerFactory() {}
-
- public InjectedEntityManagerFactory(ManagedEntityManagerFactory managedFactory)
- {
- assert managedFactory != null : "managedFactory is null";
-
- this.delegate = managedFactory.getEntityManagerFactory();
- this.managedFactory = managedFactory;
- }
-
-
- public EntityManagerFactory getDelegate()
- {
- return delegate;
- }
-
- public void writeExternal(ObjectOutput out) throws IOException
- {
- out.writeUTF(managedFactory.getKernelName());
- }
-
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- {
- String kernelName = in.readUTF();
- managedFactory = ManagedEntityManagerFactoryHelper.getManagedEntityManagerFactory(kernelName);
- if(managedFactory == null)
- throw new IOException("Unable to find persistence unit in registry: " + kernelName);
- delegate = managedFactory.getEntityManagerFactory();
- }
-
- public EntityManager createEntityManager()
- {
- return getDelegate().createEntityManager();
- }
-
- public EntityManager createEntityManager(Map map)
- {
- return delegate.createEntityManager(map);
- }
-
-
- public EntityManager getEntityManager()
- {
- return new TransactionScopedEntityManager(managedFactory);
- }
-
- public void close()
- {
- throw new IllegalStateException("It is illegal to close an injected EntityManagerFactory");
- }
-
- public boolean isOpen()
- {
- return getDelegate().isOpen();
- }
-}
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-10-23 13:26:13 UTC (rev 79975)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/InjectedSessionFactory.java 2008-10-23 14:07:20 UTC (rev 79976)
@@ -45,6 +45,7 @@
import org.hibernate.metadata.CollectionMetadata;
import org.hibernate.stat.Statistics;
import org.jboss.jpa.deployment.ManagedEntityManagerFactory;
+import org.jboss.jpa.util.ManagedEntityManagerFactoryHelper;
/**
* Comment
Deleted: 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 2008-10-23 13:26:13 UTC (rev 79975)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/ManagedEntityManagerFactoryHelper.java 2008-10-23 14:07:20 UTC (rev 79976)
@@ -1,45 +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.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;
- }
-}
Deleted: 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-10-23 13:26:13 UTC (rev 79975)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/PersistenceUnitDeployment.java 2008-10-23 14:07:20 UTC (rev 79976)
@@ -1,333 +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 java.net.URL;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-
-import javax.naming.InitialContext;
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.spi.PersistenceProvider;
-import javax.persistence.spi.PersistenceUnitTransactionType;
-
-import org.hibernate.ejb.HibernatePersistence;
-import org.jboss.ejb3.DependencyPolicy;
-import org.jboss.ejb3.DeploymentUnit;
-import org.jboss.ejb3.Ejb3Deployment;
-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;
-
-/**
- * Comment
- *
- * @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);
-
- protected InitialContext initialContext;
- protected DeploymentUnit di;
- protected List<String> explicitEntityClasses = new ArrayList<String>();
- protected ManagedEntityManagerFactory managedFactory;
- protected EntityManagerFactory actualFactory;
- protected PersistenceUnitMetaData metaData;
- protected String kernelName;
- protected Ejb3Deployment deployment;
- protected boolean scoped;
-
- public PersistenceUnitDeployment(InitialContext initialContext, Ejb3Deployment deployment, List<String> explicitEntityClasses, PersistenceUnitMetaData metadata, String ear, String jar, boolean isScoped)
- {
- super(new SimpleJavaEEModule((deployment.getEar() != null ? deployment.getEar().getShortName() : null), deployment.getDeploymentUnit().getShortName()));
-
- this.scoped = isScoped;
- this.deployment = deployment;
- this.initialContext = initialContext;
- this.di = deployment.getDeploymentUnit();
- this.explicitEntityClasses = explicitEntityClasses;
- this.metaData = metadata;
- kernelName = "persistence.units:";
- String name = getEntityManagerName();
- if (name == null || name.length() == 0)
- throw new RuntimeException("Null string is not allowed for a persistence unit name. Fix your persistence.xml file");
-
- if (ear != null)
- {
- kernelName += "ear=" + ear;
- if (!ear.endsWith(".ear")) kernelName += ".ear";
- kernelName += ",";
- }
- if (isScoped)
- {
- kernelName += "jar=" + jar;
- if (!jar.endsWith(".jar")) kernelName += ".jar";
- kernelName += ",";
- }
- kernelName += "unitName=" + name;
- }
-
- public static String getDefaultKernelName(String unitName)
- {
- int hashIndex = unitName.indexOf('#');
- if (hashIndex != -1)
- {
- String relativePath = unitName.substring(3, hashIndex);
- String name = unitName.substring(hashIndex + 1);
- return "persistence.units:jar=" + relativePath + "," + "unitName=" + name;
- }
- return "persistence.units:unitName=" + unitName;
- }
-
- public boolean isScoped()
- {
- return scoped;
- }
-
- public Ejb3Deployment getDeployment()
- {
- return deployment;
- }
-
- protected String getJaccContextId()
- {
- return di.getShortName();
- }
-
- public EntityManagerFactory getActualFactory()
- {
- return actualFactory;
- }
-
- public PersistenceUnitMetaData getXml()
- {
- return metaData;
- }
-
- public String getKernelName()
- {
- return kernelName;
- }
-
- public String getEntityManagerName()
- {
- return metaData.getName();
- }
-
- public ManagedEntityManagerFactory getManagedFactory()
- {
- if(managedFactory == null)
- log.warn("managed factory is null, persistence unit " + kernelName + " has not yet been started");
- return managedFactory;
- }
-
- protected Map<String, String> getProperties()
- {
- Map<String, String> properties = metaData.getProperties();
- return (properties != null) ? properties : Collections.<String, String>emptyMap();
- }
-
- public void addDependencies(DependencyPolicy policy)
- {
- Map<String, String> props = getProperties();
- if (!props.containsKey("jboss.no.implicit.datasource.dependency"))
- {
- if (metaData.getJtaDataSource() != null)
- {
- String ds = metaData.getJtaDataSource();
- policy.addDatasource(ds);
- }
- if (metaData.getNonJtaDataSource() != null)
- {
- String ds = metaData.getNonJtaDataSource();
- policy.addDatasource(ds);
- }
- }
- for (Object prop : props.keySet())
- {
- String property = (String)prop;
- if (property.startsWith("jboss.depends"))
- {
- policy.addDependency(props.get(property));
- }
- }
-
- }
-
- protected PersistenceUnitTransactionType getJPATransactionType()
- {
- TransactionType type = metaData.getTransactionType();
- if (type == TransactionType.RESOURCE_LOCAL)
- return PersistenceUnitTransactionType.RESOURCE_LOCAL;
- else // default or actually being JTA
- return PersistenceUnitTransactionType.JTA;
- }
-
- private List<String> safeList(Set<String> set)
- {
- return (set == null || set.isEmpty()) ? Collections.<String>emptyList() : new ArrayList<String>(set);
- }
-
- public void start() throws Exception
- {
- log.info("Starting persistence unit " + kernelName);
-
- Properties props = new Properties();
- props.putAll(di.getDefaultPersistenceProperties());
- props.put(HibernatePersistence.JACC_CONTEXT_ID, getJaccContextId());
-
- PersistenceUnitInfoImpl pi = new PersistenceUnitInfoImpl();
- log.debug("Using class loader " + di.getClassLoader());
- pi.setClassLoader(di.getClassLoader());
-
- ArrayList<URL> jarFiles = new ArrayList<URL>();
- pi.setJarFiles(jarFiles);
- pi.setPersistenceProviderClassName(HibernatePersistence.class.getName());
- log.debug("Found persistence.xml file in EJB3 jar");
- props.putAll(getProperties());
- pi.setManagedClassnames(safeList(metaData.getClasses()));
- pi.setPersistenceUnitName(metaData.getName());
- pi.setMappingFileNames(safeList(metaData.getMappingFiles()));
- pi.setExcludeUnlistedClasses(metaData.isExcludeUnlistedClasses());
- VirtualFile root = di.getRootFile();
- log.debug("Persistence root: " + root);
- // TODO - update this with VFSUtils helper method
- // hack the JPA url
- URL url = root.toURL();
- // is not nested, so direct VFS URL is not an option
- if (VFSUtils.isNestedFile(root) == false)
- {
- String urlString = url.toExternalForm();
- if (urlString.startsWith("vfs"))
- {
- // treat vfszip as file
- if (urlString.startsWith("vfszip"))
- url = new URL("file" + urlString.substring(6));
- else
- url = new URL(urlString.substring(3)); // (vfs)file and (vfs)jar are ok
- }
- }
- pi.setPersistenceUnitRootUrl(url);
- PersistenceUnitTransactionType transactionType = getJPATransactionType();
- pi.setTransactionType(transactionType);
-
- Set<String> files = metaData.getJarFiles();
- if (files != null)
- {
- for (String jar : files)
- {
- jarFiles.add(deployment.getDeploymentUnit().getRelativeURL(jar));
- }
- }
-
- if (metaData.getProvider() != null) pi.setPersistenceProviderClassName(metaData.getProvider());
- if (explicitEntityClasses.size() > 0)
- {
- List<String> classes = pi.getManagedClassNames();
- if (classes == null) classes = explicitEntityClasses;
- else classes.addAll(explicitEntityClasses);
- pi.setManagedClassnames(classes);
- }
- if (metaData.getJtaDataSource() != null)
- {
- pi.setJtaDataSource((javax.sql.DataSource) initialContext.lookup(metaData.getJtaDataSource()));
- }
- else if (transactionType == PersistenceUnitTransactionType.JTA)
- {
- throw new RuntimeException("Specification violation [EJB3 JPA 6.2.1.2] - "
- + "You have not defined a jta-data-source for a JTA enabled persistence context named: " + metaData.getName());
- }
- if (metaData.getNonJtaDataSource() != null)
- {
- pi.setNonJtaDataSource((javax.sql.DataSource) initialContext.lookup(metaData.getNonJtaDataSource()));
- }
- else if (transactionType == PersistenceUnitTransactionType.RESOURCE_LOCAL)
- {
- throw new RuntimeException("Specification violation [EJB3 JPA 6.2.1.2] - "
- + "You have not defined a non-jta-data-source for a RESOURCE_LOCAL enabled persistence context named: "
- + metaData.getName());
- }
- pi.setProperties(props);
-
- if (pi.getPersistenceUnitName() == null)
- {
- throw new RuntimeException("you must specify a name in persistence.xml");
- }
-
- Class providerClass = Thread.currentThread().getContextClassLoader().loadClass(pi.getPersistenceProviderClassName());
-
- // EJBTHREE-893
- if(!pi.getProperties().containsKey("hibernate.session_factory_name"))
- {
- pi.getProperties().put("hibernate.session_factory_name", kernelName);
- }
-
- PersistenceProvider pp = (PersistenceProvider) providerClass.newInstance();
- actualFactory = pp.createContainerEntityManagerFactory(pi, null);
-
- managedFactory = new ManagedEntityManagerFactory(actualFactory, kernelName);
-
- String entityManagerJndiName = (String) props.get("jboss.entity.manager.jndi.name");
- if (entityManagerJndiName != null)
- {
- EntityManager injectedManager = new TransactionScopedEntityManager(managedFactory);
- NonSerializableFactory.rebind(initialContext, entityManagerJndiName, injectedManager);
- }
- String entityManagerFactoryJndiName = (String) props.get("jboss.entity.manager.factory.jndi.name");
- if (entityManagerFactoryJndiName != null)
- {
- EntityManagerFactory injectedFactory = new InjectedEntityManagerFactory(managedFactory);
- NonSerializableFactory.rebind(initialContext, entityManagerFactoryJndiName, injectedFactory);
- }
- }
-
- public void stop() throws Exception
- {
- log.info("Stopping persistence unit " + kernelName);
-
- 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);
- }
- managedFactory.destroy();
- }
-}
Deleted: 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-10-23 13:26:13 UTC (rev 79975)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/TransactionScopedEntityManager.java 2008-10-23 14:07:20 UTC (rev 79976)
@@ -1,251 +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 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$
- */
-public class TransactionScopedEntityManager implements EntityManager, HibernateSession, Externalizable
-{
- private static final long serialVersionUID = 4260828563883650376L;
-
- private static final Logger log = Logger.getLogger(TransactionScopedEntityManager.class);
-
- private transient ManagedEntityManagerFactory factory;
-
- public Session getHibernateSession()
- {
- EntityManager em = factory.getTransactionScopedEntityManager();
- if (em instanceof HibernateEntityManager)
- {
- return ((HibernateEntityManager) em).getSession();
- }
- throw new RuntimeException("ILLEGAL ACTION: Not a Hibernate pe" +
- "rsistence provider");
- }
-
- public TransactionScopedEntityManager(ManagedEntityManagerFactory factory)
- {
- if (factory == null) throw new NullPointerException("factory must not be null");
- this.factory = factory;
- }
-
- public TransactionScopedEntityManager()
- {
- }
-
- public void writeExternal(ObjectOutput out) throws IOException
- {
- out.writeUTF(factory.getKernelName());
- }
-
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- {
- String kernelName = in.readUTF();
- factory = ManagedEntityManagerFactoryHelper.getManagedEntityManagerFactory(kernelName);
- if ( factory == null ) throw new IOException( "Unable to find persistence unit in registry: " + kernelName );
- }
-
- public Object getDelegate()
- {
- return getEntityManager().getDelegate();
- }
-
- public void joinTransaction()
- {
- factory.verifyInTx();
- getEntityManager().joinTransaction();
- }
-
- public void clear()
- {
- getEntityManager().clear();
- }
-
- public FlushModeType getFlushMode()
- {
- return getEntityManager().getFlushMode();
- }
-
- public void lock(Object entity, LockModeType lockMode)
- {
- factory.verifyInTx();
- getEntityManager().lock(entity, lockMode);
- }
-
- public <T> T getReference(Class<T> entityClass, Object primaryKey)
- {
- EntityManager em = getEntityManager();
- if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
- try
- {
- return em.getReference(entityClass, primaryKey);
- }
- finally
- {
- if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
- }
- }
-
- public void setFlushMode(FlushModeType flushMode)
- {
- getEntityManager().setFlushMode(flushMode);
- }
-
- public Query createQuery(String ejbqlString)
- {
- EntityManager em = getEntityManager();
- if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
- return em.createQuery(ejbqlString);
- }
-
- public Query createNamedQuery(String name)
- {
- EntityManager em = getEntityManager();
- if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
- return em.createNamedQuery(name);
- }
-
- public Query createNativeQuery(String sqlString)
- {
- EntityManager em = getEntityManager();
- if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
- return em.createNativeQuery(sqlString);
- }
-
- public Query createNativeQuery(String sqlString, Class resultClass)
- {
- EntityManager em = getEntityManager();
- if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
- return em.createNativeQuery(sqlString, resultClass);
- }
-
- public Query createNativeQuery(String sqlString, String resultSetMapping)
- {
- EntityManager em = getEntityManager();
- if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
- return em.createNativeQuery(sqlString, resultSetMapping);
- }
-
- public <A> A find(Class<A> entityClass, Object primaryKey)
- {
- EntityManager em = getEntityManager();
- if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
- try
- {
- return em.find(entityClass, primaryKey);
- }
- finally
- {
- if (!factory.isInTx()) em.clear(); // em will be closed by interceptor
- }
- }
-
- public void persist(Object entity)
- {
- factory.verifyInTx();
- getEntityManager().persist(entity);
- }
-
- public <A> A merge(A entity)
- {
- factory.verifyInTx();
- return (A) getEntityManager().merge(entity);
- }
-
- public void remove(Object entity)
- {
- factory.verifyInTx();
- getEntityManager().remove(entity);
- }
-
- public void refresh(Object entity)
- {
- factory.verifyInTx();
- getEntityManager().refresh(entity);
- }
-
- public boolean contains(Object entity)
- {
- return getEntityManager().contains(entity);
- }
-
- public void flush()
- {
- factory.verifyInTx();
- getEntityManager().flush();
- }
-
- public void close()
- {
- throw new IllegalStateException("Illegal to call this method from injected, managed EntityManager");
- }
-
- public boolean isOpen()
- {
- throw new IllegalStateException("Illegal to call this method from injected, managed EntityManager");
- }
-
- public EntityTransaction getTransaction()
- {
- throw new IllegalStateException("Illegal to call this method from injected, managed EntityManager");
- }
-
- protected EntityManager getEntityManager()
- {
- StatefulBeanContext beanContext = StatefulBeanContext.currentBean.get();
-
- EntityManager em;
- if (beanContext != null)
- {
- List<StatefulBeanContext> beanContexts = StatefulBeanContext.currentBean.getList();
- for( StatefulBeanContext bc : beanContexts)
- {
- em = bc.getExtendedPersistenceContext(factory.getKernelName());
- if (em != null)
- return em;
- }
- }
-
- return factory.getTransactionScopedEntityManager();
- }
-
-}
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-10-23 13:26:13 UTC (rev 79975)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/entity/hibernate/TransactionScopedSessionInvocationHandler.java 2008-10-23 14:07:20 UTC (rev 79976)
@@ -34,8 +34,8 @@
import org.hibernate.Session;
import org.hibernate.ejb.HibernateEntityManager;
-import org.jboss.ejb3.entity.ManagedEntityManagerFactoryHelper;
import org.jboss.jpa.deployment.ManagedEntityManagerFactory;
+import org.jboss.jpa.util.ManagedEntityManagerFactoryHelper;
/**
* Handle method execution delegation to an Hibernate session following the transaction scoped persistence context rules
Added: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/EJB3XPCResolver.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/EJB3XPCResolver.java (rev 0)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/EJB3XPCResolver.java 2008-10-23 14:07:20 UTC (rev 79976)
@@ -0,0 +1,58 @@
+/*
+ * 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.stateful;
+
+import java.util.List;
+
+import javax.persistence.EntityManager;
+
+import org.jboss.jpa.spi.XPCResolver;
+
+/**
+ * EJB 3 Stateful beans are the only XPC aware components at the moment.
+ *
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class EJB3XPCResolver implements XPCResolver
+{
+ /**
+ * Query the current stateful bean contexts for the specified XPC.
+ */
+ public EntityManager getExtendedPersistenceContext(String kernelName)
+ {
+ StatefulBeanContext beanContext = StatefulBeanContext.currentBean.get();
+
+ EntityManager em;
+ if (beanContext != null)
+ {
+ List<StatefulBeanContext> beanContexts = StatefulBeanContext.currentBean.getList();
+ for( StatefulBeanContext bc : beanContexts)
+ {
+ em = bc.getExtendedPersistenceContext(kernelName);
+ if (em != null)
+ return em;
+ }
+ }
+ return null;
+ }
+}
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-10-23 13:26:13 UTC (rev 79975)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/injection/PcEncInjector.java 2008-10-23 14:07:20 UTC (rev 79976)
@@ -30,11 +30,11 @@
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.jpa.tx.TransactionScopedEntityManager;
import org.jboss.util.naming.Util;
/**
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-10-23 13:26:13 UTC (rev 79975)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/injection/PersistenceUnitHandler.java 2008-10-23 14:07:20 UTC (rev 79976)
@@ -33,9 +33,9 @@
import org.hibernate.SessionFactory;
import org.jboss.ejb3.annotation.IgnoreDependency;
-import org.jboss.ejb3.entity.InjectedEntityManagerFactory;
import org.jboss.ejb3.entity.InjectedSessionFactory;
import org.jboss.jpa.deployment.ManagedEntityManagerFactory;
+import org.jboss.jpa.injection.InjectedEntityManagerFactory;
import org.jboss.jpa.spi.PersistenceUnitRegistry;
import org.jboss.logging.Logger;
import org.jboss.metadata.javaee.spec.PersistenceUnitReferenceMetaData;
Modified: projects/ejb3/trunk/core/src/main/resources/META-INF/jpa-deployers-jboss-beans.xml
===================================================================
--- projects/ejb3/trunk/core/src/main/resources/META-INF/jpa-deployers-jboss-beans.xml 2008-10-23 13:26:13 UTC (rev 79975)
+++ projects/ejb3/trunk/core/src/main/resources/META-INF/jpa-deployers-jboss-beans.xml 2008-10-23 14:07:20 UTC (rev 79976)
@@ -7,6 +7,8 @@
<bean name="PersistenceUnitDependencyResolver" class="org.jboss.jpa.resolvers.DefaultPersistenceUnitDependencyResolver"/>
+ <bean name="XPCResolver" class="org.jboss.ejb3.stateful.EJB3XPCResolver"/>
+
<bean name="PersistenceParsingDeployer" class="org.jboss.jpa.deployers.PersistenceParsingDeployer"/>
<bean name="PersistenceDeployer" class="org.jboss.jpa.deployers.PersistenceDeployer"/>
Modified: projects/ejb3/trunk/core/src/test/java/org/jboss/injection/test/common/DummyInjectionContainer.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/injection/test/common/DummyInjectionContainer.java 2008-10-23 13:26:13 UTC (rev 79975)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/injection/test/common/DummyInjectionContainer.java 2008-10-23 14:07:20 UTC (rev 79976)
@@ -34,7 +34,6 @@
import org.jboss.ejb3.Container;
import org.jboss.ejb3.DependencyPolicy;
-import org.jboss.ejb3.entity.PersistenceUnitDeployment;
import org.jboss.injection.EncInjector;
import org.jboss.injection.InjectionContainer;
import org.jboss.injection.Injector;
@@ -136,11 +135,6 @@
return null;
}
- public PersistenceUnitDeployment getPersistenceUnitDeployment(String unitName) throws NameNotFoundException
- {
- return null;
- }
-
public VirtualFile getRootFile()
{
return null;
More information about the jboss-cvs-commits
mailing list