[jboss-cvs] JBossAS SVN: r84471 - in projects/jpa/trunk/deployers: src/main/java/org/jboss/jpa/deployment and 5 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Feb 19 11:16:00 EST 2009
Author: ALRubinger
Date: 2009-02-19 11:16:00 -0500 (Thu, 19 Feb 2009)
New Revision: 84471
Added:
projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/jbjpa6/
projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/jbjpa6/PersistenceUnitJNDIBindingsTestCase.java
projects/jpa/trunk/deployers/src/test/resources/org/jboss/jpa/deployers/test/jbjpa6/
projects/jpa/trunk/deployers/src/test/resources/org/jboss/jpa/deployers/test/jbjpa6/META-INF/
projects/jpa/trunk/deployers/src/test/resources/org/jboss/jpa/deployers/test/jbjpa6/META-INF/persistence.xml
Modified:
projects/jpa/trunk/deployers/pom.xml
projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployment/PersistenceUnitDeployment.java
Log:
[JBJPA-6] Bind subcontexts for EM and EMF as necessary. Submitted for community contributor Matt Carter.
Modified: projects/jpa/trunk/deployers/pom.xml
===================================================================
--- projects/jpa/trunk/deployers/pom.xml 2009-02-19 16:08:51 UTC (rev 84470)
+++ projects/jpa/trunk/deployers/pom.xml 2009-02-19 16:16:00 UTC (rev 84471)
@@ -119,5 +119,12 @@
<scope>test</scope>
</dependency>
+ <!-- jboss-common-core (For JNDI Utils) -->
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-common-core</artifactId>
+ <version>2.2.11-SNAPSHOT</version>
+ </dependency>
+
</dependencies>
</project>
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-02-19 16:08:51 UTC (rev 84470)
+++ projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployment/PersistenceUnitDeployment.java 2009-02-19 16:16:00 UTC (rev 84471)
@@ -306,13 +306,13 @@
if (entityManagerJndiName != null)
{
EntityManager injectedManager = new TransactionScopedEntityManager(managedFactory);
- NonSerializableFactory.rebind(initialContext, entityManagerJndiName, injectedManager);
+ NonSerializableFactory.rebind(initialContext, entityManagerJndiName, injectedManager, true);
}
String entityManagerFactoryJndiName = (String) props.get("jboss.entity.manager.factory.jndi.name");
if (entityManagerFactoryJndiName != null)
{
EntityManagerFactory injectedFactory = new InjectedEntityManagerFactory(managedFactory);
- NonSerializableFactory.rebind(initialContext, entityManagerFactoryJndiName, injectedFactory);
+ NonSerializableFactory.rebind(initialContext, entityManagerFactoryJndiName, injectedFactory, true);
}
}
Property changes on: projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/jbjpa6
___________________________________________________________________
Name: svn:mergeinfo
+
Added: projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/jbjpa6/PersistenceUnitJNDIBindingsTestCase.java
===================================================================
--- projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/jbjpa6/PersistenceUnitJNDIBindingsTestCase.java (rev 0)
+++ projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/jbjpa6/PersistenceUnitJNDIBindingsTestCase.java 2009-02-19 16:16:00 UTC (rev 84471)
@@ -0,0 +1,153 @@
+/*
+ * 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.deployers.test.jbjpa6;
+
+import static org.junit.Assert.fail;
+
+import javax.naming.InitialContext;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.transaction.TransactionManager;
+
+import org.hibernate.SessionFactory;
+import org.jboss.jpa.deployers.test.common.PersistenceTestCase;
+import org.jboss.jpa.deployers.test.common.Person;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Test for JBJPA-6 compliance.
+ *
+ * Tests that Persistence Unit related JNDI bindings
+ * work and auto-create sub-contexts if they don't exist.
+ *
+ * @author Matt Carter
+ *
+ * @version $Revision: $
+ */
+public class PersistenceUnitJNDIBindingsTestCase extends PersistenceTestCase
+{
+ /** One new subcontext and EM binding test */
+ public static final String EM_PATH = "em-path1/JndiEM";
+
+ /** One existing subcontext and EMF binding test */
+ public static final String EMF_PATH = "existing-path/JndiEMF";
+
+ /** Two new subcontexts and SF binding test */
+ public static final String SF_PATH = "sf-path1/sf-path2/JndiSF";
+
+ @BeforeClass
+ public static void beforeClass() throws Exception
+ {
+ PersistenceTestCase.beforeClass();
+
+ InitialContext ctx = new InitialContext();
+ ctx.createSubcontext("existing-path");
+
+ deploy(PersistenceUnitJNDIBindingsTestCase.class.getResource("/org/jboss/jpa/deployers/test/jbjpa6"));
+ }
+
+ @Test
+ public void testEM() throws Exception
+ {
+ InitialContext ctx = new InitialContext();
+ TransactionManager tm = (TransactionManager) ctx.lookup("java:/TransactionManager");
+ EntityManager em = null;
+ try
+ {
+ em = (EntityManager) ctx.lookup(EM_PATH);
+ }
+ catch (Exception e)
+ {
+ fail("EntityManager binding failed");
+ }
+ try
+ {
+ tm.begin();
+ try
+ {
+ Person p = new Person();
+ p.setName("Emma");
+ em.persist(p);
+ }
+ finally
+ {
+ tm.rollback();
+ }
+ }
+ catch (Exception e)
+ {
+ fail("EntityManager test invocation failed");
+ }
+ }
+
+ @Test
+ public void testEMF() throws Exception
+ {
+ InitialContext ctx = new InitialContext();
+ EntityManagerFactory emf = null;
+ try
+ {
+ emf = (EntityManagerFactory) ctx.lookup(EMF_PATH);
+ }
+ catch (Exception e)
+ {
+ fail("EntityManagerFactory binding failed");
+ }
+ try
+ {
+ EntityManager em = emf.createEntityManager();
+ Person p = new Person();
+ p.setName("Emma");
+ em.persist(p);
+ }
+ catch (Exception e)
+ {
+ fail("EntityManagerFactory test invocation failed");
+ }
+ }
+
+ @Test
+ public void testSF() throws Exception
+ {
+ InitialContext ctx = new InitialContext();
+ SessionFactory sf = null;
+ try
+ {
+ sf = (SessionFactory) ctx.lookup(SF_PATH);
+ }
+ catch (Exception e)
+ {
+ fail("SessionFactory binding failed");
+ }
+ try
+ {
+ sf.isClosed();
+ }
+ catch (Exception e)
+ {
+ fail("SessionFactory test invocation failed");
+ }
+
+ }
+
+}
Property changes on: projects/jpa/trunk/deployers/src/test/resources/org/jboss/jpa/deployers/test/jbjpa6
___________________________________________________________________
Name: svn:mergeinfo
+
Added: projects/jpa/trunk/deployers/src/test/resources/org/jboss/jpa/deployers/test/jbjpa6/META-INF/persistence.xml
===================================================================
--- projects/jpa/trunk/deployers/src/test/resources/org/jboss/jpa/deployers/test/jbjpa6/META-INF/persistence.xml (rev 0)
+++ projects/jpa/trunk/deployers/src/test/resources/org/jboss/jpa/deployers/test/jbjpa6/META-INF/persistence.xml 2009-02-19 16:16:00 UTC (rev 84471)
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
+ <persistence-unit name="ejbthree1685">
+ <jta-data-source>java:/DefaultDS</jta-data-source>
+ <class>org.jboss.jpa.deployers.test.common.Person</class>
+ <properties>
+ <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
+ <property name="jboss.entity.manager.jndi.name" value="JndiEM"/>
+ <property name="jboss.entity.manager.factory.jndi.name" value="JndiEMF"/>
+ <property name="jboss.entity.manager.jndi.name" value="em-path1/JndiEM"/>
+ <property name="jboss.entity.manager.factory.jndi.name" value="existing-path/JndiEMF"/>
+ <property name="hibernate.session_factory_name" value="sf-path1/sf-path2/JndiSF"/>
+ </properties>
+ </persistence-unit>
+</persistence>
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list