[jboss-cvs] JBossAS SVN: r94772 - in projects/jpa/trunk/deployers/src: main/java/org/jboss/jpa/builder and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Oct 13 10:18:31 EDT 2009
Author: wolfc
Date: 2009-10-13 10:18:30 -0400 (Tue, 13 Oct 2009)
New Revision: 94772
Added:
projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/builder/
projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/builder/CEMFBuilder.java
projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/builder/DefaultCEMFBuilder.java
Modified:
projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployment/PersistenceUnitDeployment.java
projects/jpa/trunk/deployers/src/test/resources/org/jboss/jpa/deployers/test/common/jpa-deployers-beans.xml
Log:
JBJPA-15: added CEMFBuilder
Added: projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/builder/CEMFBuilder.java
===================================================================
--- projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/builder/CEMFBuilder.java (rev 0)
+++ projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/builder/CEMFBuilder.java 2009-10-13 14:18:30 UTC (rev 94772)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.builder;
+
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.spi.PersistenceUnitInfo;
+
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+
+/**
+ * INTERNAL / EXPERIMENTAL
+ *
+ * Create a container entity manager factory with the right setup (either JPA 1 or JPA 2).
+ *
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface CEMFBuilder
+{
+ EntityManagerFactory build(DeploymentUnit deploymentUnit, PersistenceUnitInfo persistenceUnitInfo);
+}
Added: projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/builder/DefaultCEMFBuilder.java
===================================================================
--- projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/builder/DefaultCEMFBuilder.java (rev 0)
+++ projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/builder/DefaultCEMFBuilder.java 2009-10-13 14:18:30 UTC (rev 94772)
@@ -0,0 +1,63 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.builder;
+
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.spi.PersistenceProvider;
+import javax.persistence.spi.PersistenceUnitInfo;
+
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+
+/**
+ * INTERNAL
+ *
+ * Builds a JPA 1 ContainerEntityManagerFactory.
+ *
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class DefaultCEMFBuilder implements CEMFBuilder
+{
+ public EntityManagerFactory build(DeploymentUnit deploymentUnit, PersistenceUnitInfo persistenceUnitInfo)
+ {
+ try
+ {
+ Class<?> providerClass = Thread.currentThread().getContextClassLoader().loadClass(persistenceUnitInfo.getPersistenceProviderClassName());
+
+ PersistenceProvider pp = (PersistenceProvider) providerClass.newInstance();
+ EntityManagerFactory cemf = pp.createContainerEntityManagerFactory(persistenceUnitInfo, null);
+ return cemf;
+ }
+ catch(ClassNotFoundException e)
+ {
+ throw new RuntimeException(e);
+ }
+ catch (InstantiationException e)
+ {
+ throw new RuntimeException(e);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+}
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 2009-10-13 14:12:13 UTC (rev 94771)
+++ projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployment/PersistenceUnitDeployment.java 2009-10-13 14:18:30 UTC (rev 94772)
@@ -35,11 +35,11 @@
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.builder.CEMFBuilder;
import org.jboss.jpa.impl.deployment.PersistenceUnitInfoImpl;
import org.jboss.jpa.injection.InjectedEntityManagerFactory;
import org.jboss.jpa.spi.PersistenceUnit;
@@ -72,6 +72,7 @@
protected String kernelName;
protected PersistenceDeployment deployment;
private Properties defaultPersistenceProperties;
+ private CEMFBuilder cemfBuilder;
private XPCResolver xpcResolver;
public PersistenceUnitDeployment(InitialContext initialContext, PersistenceDeployment deployment, List<String> explicitEntityClasses, PersistenceUnitMetaData metadata, String kernelName, VFSDeploymentUnit deploymentUnit, Properties defaultPersistenceProperties)
@@ -228,6 +229,12 @@
}
@Inject
+ public void setCEMFBuilder(CEMFBuilder builder)
+ {
+ this.cemfBuilder = builder;
+ }
+
+ @Inject
public void setXPCResolver(XPCResolver xpcResolver)
{
// Do not check for null, because MC does uninstall with null
@@ -293,8 +300,6 @@
pi.setManagedClassnames(classes);
}
- Class<?> providerClass = Thread.currentThread().getContextClassLoader().loadClass(pi.getPersistenceProviderClassName());
-
// EJBTHREE-893
if(!pi.getProperties().containsKey("hibernate.session_factory_name"))
{
@@ -308,8 +313,7 @@
pi.getProperties().setProperty("hibernate.cache.region_prefix", kernelName);
}
- PersistenceProvider pp = (PersistenceProvider) providerClass.newInstance();
- actualFactory = pp.createContainerEntityManagerFactory(pi, null);
+ actualFactory = cemfBuilder.build(di, pi);
managedFactory = new ManagedEntityManagerFactory(this);
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 2009-10-13 14:12:13 UTC (rev 94771)
+++ projects/jpa/trunk/deployers/src/test/resources/org/jboss/jpa/deployers/test/common/jpa-deployers-beans.xml 2009-10-13 14:18:30 UTC (rev 94772)
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<deployment xmlns="urn:jboss:bean-deployer:2.0">
+ <bean name="CEMFBuilder" class="org.jboss.jpa.builder.DefaultCEMFBuilder"/>
+
<bean name="DataSourceDependencyResolver" class="org.jboss.jpa.deployers.test.common.SimpleDataSourceDependencyResolver"/>
<bean name="JavaEEModuleInformer" class="org.jboss.jpa.deployers.test.common.SimpleJavaEEModuleInformer"/>
More information about the jboss-cvs-commits
mailing list