openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From curti...@apache.org
Subject svn commit: r1197994 [9/10] - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/ant/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ openjpa-jdbc/src/main/java/org/...
Date Sat, 05 Nov 2011 17:17:33 GMT
Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestClassMetaData.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestClassMetaData.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestClassMetaData.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestClassMetaData.java Sat Nov  5 17:17:26 2011
@@ -60,11 +60,11 @@ public class TestClassMetaData
     public void setUp()
         throws Exception {
         _repos = getRepository();
-        _metaTest5 = _repos.getMetaData(MetaTest5.class, true);
-        _metaTest3 = _repos.getMetaData(MetaTest3.class, true);
-        _metaTest2 = _repos.getMetaData(MetaTest2.class, true);
-        _metaTest1 = _repos.getMetaData(MetaTest1.class, true);
-        _metaTest6 = _repos.getMetaData(MetaTest6.class, true);
+        _metaTest5 = _repos.getMetaData(MetaTest5.class, null, true);
+        _metaTest3 = _repos.getMetaData(MetaTest3.class, null, true);
+        _metaTest2 = _repos.getMetaData(MetaTest2.class, null, true);
+        _metaTest1 = _repos.getMetaData(MetaTest1.class, null, true);
+        _metaTest6 = _repos.getMetaData(MetaTest6.class, null, true);
     }
 
     protected MetaDataRepository getRepository()
@@ -274,7 +274,7 @@ public class TestClassMetaData
      * Test that metadata on inner classes is available.
      */
     public void testStaticInnerClasses() {
-        assertNotNull(_repos.getMetaData(MetaTest1.Inner.class, true));
+        assertNotNull(_repos.getMetaData(MetaTest1.Inner.class, null, true));
     }
 
     /**

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestFactoryMethod.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestFactoryMethod.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestFactoryMethod.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestFactoryMethod.java Sat Nov  5 17:17:26 2011
@@ -48,7 +48,7 @@ public class TestFactoryMethod extends A
 
     public void setUp() throws Exception {
         _repos = getRepository();
-        _metaTest7 = _repos.getMetaData(MetaTest7.class, true);
+        _metaTest7 = _repos.getMetaData(MetaTest7.class, null, true);
     }
 
     protected MetaDataRepository getRepository() throws Exception {

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestNonPersistentFields.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestNonPersistentFields.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestNonPersistentFields.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestNonPersistentFields.java Sat Nov  5 17:17:26 2011
@@ -43,7 +43,7 @@ public class TestNonPersistentFields
     public void setUp() {
         MetaDataRepository repos = new OpenJPAConfigurationImpl().
             newMetaDataRepositoryInstance();
-        _meta = repos.getMetaData(NonPersistentFieldsPC.class, true);
+        _meta = repos.getMetaData(NonPersistentFieldsPC.class, null, true);
     }
 
     public void testNonPersistentFields() {

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestPersistentClasses.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestPersistentClasses.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestPersistentClasses.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestPersistentClasses.java Sat Nov  5 17:17:26 2011
@@ -45,7 +45,8 @@ public class TestPersistentClasses
     private void assertClass(String clsName, OpenJPAConfiguration conf,
         boolean shouldExist) {
 
-        Collection names = conf.getMetaDataRepositoryInstance().getPersistentTypeNames(false);
+        Collection names = conf.getMetaDataRepositoryInstance().
+            getPersistentTypeNames(false, null);
 
         if (shouldExist)
             assertTrue("expected element " + clsName + " was not found in "
@@ -64,7 +65,7 @@ public class TestPersistentClasses
         assertNull(((OpenJPAEntityManagerFactorySPI) pmf).getConfiguration()
             .getMetaDataRepositoryInstance().
 
-            getPersistentTypeNames(false));
+            getPersistentTypeNames(false, null));
 
         pmf.close();
     }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestQueryTypeAliasRegistration.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestQueryTypeAliasRegistration.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestQueryTypeAliasRegistration.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestQueryTypeAliasRegistration.java Sat Nov  5 17:17:26 2011
@@ -94,7 +94,7 @@ public class TestQueryTypeAliasRegistrat
         @Override
         public void run() {
             try {
-                repo.getMetaData("MdrTestEntity", true);
+                repo.getMetaData("MdrTestEntity", Thread.currentThread().getContextClassLoader(), true);
             } catch (Exception e) {
                 ex = e;
                 e.printStackTrace();

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestValueStrategies.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestValueStrategies.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestValueStrategies.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestValueStrategies.java Sat Nov  5 17:17:26 2011
@@ -231,7 +231,7 @@ public class TestValueStrategies
         pm.persist(pc);
         ClassMetaData meta = getConfiguration()
             .getMetaDataRepositoryInstance().
-            getMetaData(pc.getClass(), false);
+            getMetaData(pc.getClass(), null, false);
         assertNotNull(meta.getVersionField());
         assertEquals("version", meta.getVersionField().getName());
         assertEquals(0, pc.getVersion());

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestXMLPersistenceMetaDataSerializer.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestXMLPersistenceMetaDataSerializer.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestXMLPersistenceMetaDataSerializer.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestXMLPersistenceMetaDataSerializer.java Sat Nov  5 17:17:26 2011
@@ -53,11 +53,11 @@ public class TestXMLPersistenceMetaDataS
         throws Exception {
         OpenJPAConfiguration conf = new OpenJPAConfigurationImpl();
         MetaDataRepository repos = conf.newMetaDataRepositoryInstance();
-        repos.getMetaData(MetaTest5.class, true);
-        repos.getMetaData(MetaTest3.class, true);
-        repos.getMetaData(MetaTest2.class, true);
-        repos.getMetaData(MetaTest1.class, true);
-        repos.getMetaData(MetaTest6.class, true);
+        repos.getMetaData(MetaTest5.class, null, true);
+        repos.getMetaData(MetaTest3.class, null, true);
+        repos.getMetaData(MetaTest2.class, null, true);
+        repos.getMetaData(MetaTest1.class, null, true);
+        repos.getMetaData(MetaTest6.class, null, true);
 
         XMLPersistenceMetaDataSerializer ser =
             new XMLPersistenceMetaDataSerializer(conf);

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestAccessPathsOfSubqueries.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestAccessPathsOfSubqueries.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestAccessPathsOfSubqueries.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestAccessPathsOfSubqueries.java Sat Nov  5 17:17:26 2011
@@ -38,7 +38,6 @@ import org.apache.openjpa.kernel.Broker;
 import org.apache.openjpa.kernel.Query;
 import org.apache.openjpa.kernel.jpql.JPQLParser;
 import org.apache.openjpa.meta.ClassMetaData;
-import org.apache.openjpa.meta.MetaDataRepository;
 
 public class TestAccessPathsOfSubqueries extends BaseQueryTest {
 
@@ -58,9 +57,12 @@ public class TestAccessPathsOfSubqueries
             + "WHERE rt5.name IS NOT NULL)");
         ClassMetaData[] metas = q.getAccessPathMetaDatas();
         Collection c = Arrays.asList(metas);
-        MetaDataRepository repos = broker.getConfiguration().getMetaDataRepositoryInstance();
-        ClassMetaData rt1 = repos.getMetaData(RuntimeTest1.class,true);
-        ClassMetaData rt5 = repos.getMetaData(RuntimeTest5.class,true);
+        ClassMetaData rt1 = broker.getConfiguration().
+            getMetaDataRepositoryInstance().getMetaData(RuntimeTest1.class,
+            broker.getClassLoader(), true);
+        ClassMetaData rt5 = broker.getConfiguration().
+            getMetaDataRepositoryInstance().getMetaData(RuntimeTest5.class,
+            broker.getClassLoader(), true);
         assertTrue(c.contains(rt1));
         assertTrue(c.contains(rt5));
         assertEquals(2, c.size());
@@ -75,10 +77,15 @@ public class TestAccessPathsOfSubqueries
 
         ClassMetaData[] metas = q.getAccessPathMetaDatas();
         Collection c = Arrays.asList(metas);
-        MetaDataRepository repos = broker.getConfiguration().getMetaDataRepositoryInstance();
-        ClassMetaData rt1 = repos.getMetaData(RuntimeTest1.class, true);
-        ClassMetaData rt4 = repos.getMetaData(RuntimeTest4.class, true);
-        ClassMetaData rt5 = repos.getMetaData(RuntimeTest5.class, true);
+        ClassMetaData rt1 = broker.getConfiguration().
+            getMetaDataRepositoryInstance().getMetaData(RuntimeTest1.class,
+            broker.getClassLoader(), true);
+        ClassMetaData rt4 = broker.getConfiguration().
+            getMetaDataRepositoryInstance().getMetaData(RuntimeTest4.class,
+            broker.getClassLoader(), true);
+        ClassMetaData rt5 = broker.getConfiguration().
+            getMetaDataRepositoryInstance().getMetaData(RuntimeTest5.class,
+            broker.getClassLoader(), true);
         assertTrue(c.contains(rt1));
         assertTrue(c.contains(rt4));
         assertTrue(c.contains(rt5));

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestNamedQueries.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestNamedQueries.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestNamedQueries.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestNamedQueries.java Sat Nov  5 17:17:26 2011
@@ -86,7 +86,8 @@ public class TestNamedQueries extends Ba
         assertEquals("num", query.getGrouping());
         */
         QueryMetaData meta = ((OpenJPAEntityManagerSPI) pm).getConfiguration().
-            getMetaDataRepositoryInstance().getQueryMetaData(null, "named", true);
+            getMetaDataRepositoryInstance().getQueryMetaData(null,
+            "named", pm.getClassLoader(), true);
         assertNotNull(meta);
         assertEquals("SELECT o FROM QueryTest1 o", meta.getQueryString());
         assertEquals(null, meta.getResultType());

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/ContainerEMFTest.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/ContainerEMFTest.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/ContainerEMFTest.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/ContainerEMFTest.java Sat Nov  5 17:17:26 2011
@@ -85,7 +85,7 @@ public abstract class ContainerEMFTest e
             clist = (List<Class<?>>)map.remove(PERSISTENT_CLASS_LIST);
         }
         PersistenceProductDerivation.ConfigurationParser cfgParser = 
-            new PersistenceProductDerivation.ConfigurationParser(this.getClass().getClassLoader(), config);
+            new PersistenceProductDerivation.ConfigurationParser(config);
         try {
             URL url = getResourceURL(persistenceFile);
             cfgParser.parse(url);

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SingleEMFTestCase.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SingleEMFTestCase.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SingleEMFTestCase.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SingleEMFTestCase.java Sat Nov  5 17:17:26 2011
@@ -25,7 +25,6 @@ import javax.persistence.EntityManager;
 import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
 import org.apache.openjpa.jdbc.meta.ClassMapping;
 import org.apache.openjpa.jdbc.sql.DBDictionary;
-import org.apache.openjpa.lib.conf.ProductDerivations;
 import org.apache.openjpa.lib.log.Log;
 import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
 import org.apache.openjpa.persistence.OpenJPAEntityManagerSPI;
@@ -104,7 +103,8 @@ public abstract class SingleEMFTestCase
      */
     protected ClassMapping getMapping(String name) {
         return (ClassMapping) emf.getConfiguration()
-                .getMetaDataRepositoryInstance().getMetaData(name, true);
+                .getMetaDataRepositoryInstance().getMetaData(name,
+                        getClass().getClassLoader(), true);
     }
     
     /**
@@ -117,7 +117,8 @@ public abstract class SingleEMFTestCase
      */
     protected ClassMapping getMapping(Class<?> entityClass) {
         return (ClassMapping) emf.getConfiguration()
-                .getMetaDataRepositoryInstance().getMetaData(entityClass, true);
+                .getMetaDataRepositoryInstance().getMetaData(entityClass,
+                        getClass().getClassLoader(), true);
     }
     
     /**
@@ -159,7 +160,7 @@ public abstract class SingleEMFTestCase
     
     public String getAlias(Class<?> t) {
         return emf.getConfiguration().getMetaDataRepositoryInstance()
-            .getMetaData(t, true).getTypeAlias();
+            .getMetaData(t, null, true).getTypeAlias();
     }
 
     protected ClassMapping [] getMappings() {

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/util/TestJPAFacadeHelper.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/util/TestJPAFacadeHelper.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/util/TestJPAFacadeHelper.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/util/TestJPAFacadeHelper.java Sat Nov  5 17:17:26 2011
@@ -57,7 +57,7 @@ public class TestJPAFacadeHelper extends
     }
 
     public void testEmbeddedId() throws Exception {
-        ClassMetaData cmd = repo.getMetaData(EmbeddedIdEntity.class, true);
+        ClassMetaData cmd = repo.getMetaData(EmbeddedIdEntity.class, null, true);
         try {
             JPAFacadeHelper.toOpenJPAObjectId(cmd, new EmbeddedIdEntity());
             fail("Didn't fail!");
@@ -70,7 +70,7 @@ public class TestJPAFacadeHelper extends
     }
 
     public void testCompositeId() throws Exception {
-        ClassMetaData cmd = repo.getMetaData(EntityWithCompositeId.class, true);
+        ClassMetaData cmd = repo.getMetaData(EntityWithCompositeId.class, null, true);
         try {
             JPAFacadeHelper.toOpenJPAObjectId(cmd, new EntityWithCompositeId());
             fail("Didn't fail!");
@@ -83,7 +83,7 @@ public class TestJPAFacadeHelper extends
     }
 
     public void testBasic() throws Exception {
-        ClassMetaData cmd = repo.getMetaData(BasicEntity.class, true);
+        ClassMetaData cmd = repo.getMetaData(BasicEntity.class, null, true);
         try {
             JPAFacadeHelper.toOpenJPAObjectId(cmd, new BasicEntity());
             fail("Didn't fail!");
@@ -103,7 +103,7 @@ public class TestJPAFacadeHelper extends
     }
 
     public void testDerivedId() throws Exception {
-        ClassMetaData cmd = repo.getMetaData(EDSQLDateID.class, true);
+        ClassMetaData cmd = repo.getMetaData(EDSQLDateID.class, null, true);
         try {
             JPAFacadeHelper.toOpenJPAObjectId(cmd, new EDSQLDateID());
             fail("Didn't fail!");
@@ -116,7 +116,7 @@ public class TestJPAFacadeHelper extends
     }
 
     public void testNoId() throws Exception {
-        ClassMetaData cmd = repo.getMetaData(AllFieldTypes.class, true);
+        ClassMetaData cmd = repo.getMetaData(AllFieldTypes.class, null, true);
         try {
             // Don't parameterize this collection to force the JVM to use the 
             // ...(ClassMetaData meta, Collection<Object> oids) method sig.

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/TestXmlOverrideEntity.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/TestXmlOverrideEntity.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/TestXmlOverrideEntity.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/TestXmlOverrideEntity.java Sat Nov  5 17:17:26 2011
@@ -60,11 +60,13 @@ public class TestXmlOverrideEntity exten
 
     public void testOverriddenEntityName() {
         emf.createEntityManager().close();
-        ClassMetaData meta = JPAFacadeHelper.getMetaData(emf, XmlOverrideEntity.class);
+        ClassMetaData meta = JPAFacadeHelper.getMetaData(emf,
+            XmlOverrideEntity.class);
         assertEquals("XmlOverride", meta.getTypeAlias());
         MetaDataRepository repo = emf.getConfiguration()
             .getMetaDataRepositoryInstance();
-        assertEquals(meta, repo.getMetaData("XmlOverride", true));
+        assertEquals(meta, repo.getMetaData("XmlOverride",
+            XmlOverrideEntity.class.getClassLoader(), true));
     }
 
     /**

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java (original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java Sat Nov  5 17:17:26 2011
@@ -181,9 +181,11 @@ import serp.util.Strings;
 public class AnnotationPersistenceMetaDataParser
     implements MetaDataModes {
 
-    private static final Localizer _loc = Localizer.forPackage(AnnotationPersistenceMetaDataParser.class);
+    private static final Localizer _loc = Localizer.forPackage
+        (AnnotationPersistenceMetaDataParser.class);
 
-    private static final Map<Class<?>, MetaDataTag> _tags = new HashMap<Class<?>, MetaDataTag>();
+    private static final Map<Class<?>, MetaDataTag> _tags =
+        new HashMap<Class<?>, MetaDataTag>();
 
     static {
         _tags.put(Access.class, ACCESS);
@@ -191,7 +193,8 @@ public class AnnotationPersistenceMetaDa
         _tags.put(EmbeddedId.class, EMBEDDED_ID);
         _tags.put(EntityListeners.class, ENTITY_LISTENERS);
         _tags.put(ExcludeDefaultListeners.class, EXCLUDE_DEFAULT_LISTENERS);
-        _tags.put(ExcludeSuperclassListeners.class, EXCLUDE_SUPERCLASS_LISTENERS);
+        _tags.put(ExcludeSuperclassListeners.class,
+            EXCLUDE_SUPERCLASS_LISTENERS);
         _tags.put(FlushModeType.class, FLUSH_MODE);
         _tags.put(GeneratedValue.class, GENERATED_VALUE);
         _tags.put(Id.class, ID);
@@ -237,6 +240,7 @@ public class AnnotationPersistenceMetaDa
     private final OpenJPAConfiguration _conf;
     private final Log _log;
     private MetaDataRepository _repos = null;
+    private ClassLoader _envLoader = null;
     private boolean _override = false;
     private int _mode = MODE_NONE;
 
@@ -294,6 +298,21 @@ public class AnnotationPersistenceMetaDa
         _repos = repos;
     }
 
+    /**
+     * Return the environmental class loader to pass on to parsed
+     * metadata instances.
+     */
+    public ClassLoader getEnvClassLoader() {
+        return _envLoader;
+    }
+
+    /**
+     * Set the environmental class loader to pass on to parsed
+     * metadata instances.
+     */
+    public void setEnvClassLoader(ClassLoader loader) {
+        _envLoader = loader;
+    }
 
     /**
      * Whether to allow later parses of mapping information to override
@@ -731,6 +750,7 @@ public class AnnotationPersistenceMetaDa
 
         if (meta == null) {
             meta = getRepository().addMetaData(_cls, getAccessCode(_cls));
+            meta.setEnvClassLoader(_envLoader);
             meta.setSourceMode(MODE_NONE);
             meta.setSource(getSourceFile(), SourceTracker.SRC_ANNOTATIONS, getSourceFile() == null ? ""
                 : getSourceFile().getPath());

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerFactoryValue.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerFactoryValue.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerFactoryValue.java (original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerFactoryValue.java Sat Nov  5 17:17:26 2011
@@ -18,8 +18,6 @@
  */
 package org.apache.openjpa.persistence;
 
-import javax.persistence.EntityManagerFactory;
-
 import org.apache.openjpa.conf.OpenJPAConfiguration;
 import org.apache.openjpa.kernel.BrokerFactory;
 import org.apache.openjpa.lib.conf.PluginValue;
@@ -31,7 +29,7 @@ import org.apache.openjpa.lib.conf.Plugi
  * @nojavadoc
  */
 public class EntityManagerFactoryValue
-    extends PluginValue<OpenJPAEntityManagerFactory> {
+    extends PluginValue {
 
     /**
      * Configuration property key.
@@ -47,16 +45,17 @@ public class EntityManagerFactoryValue
      */
     public static OpenJPAEntityManagerFactory newFactory(BrokerFactory bf) {
         OpenJPAConfiguration conf = bf.getConfiguration();
-        PluginValue<OpenJPAEntityManagerFactory> val = (PluginValue<OpenJPAEntityManagerFactory>) conf.getValue(KEY); 
+        PluginValue val = (PluginValue) conf.getValue(KEY); 
         if (val == null)
             return null;
-        EntityManagerFactoryImpl emf = (EntityManagerFactoryImpl)val.instantiate(conf, true);
+        EntityManagerFactoryImpl emf = (EntityManagerFactoryImpl) val.
+            instantiate(EntityManagerFactoryImpl.class, conf, true);
         emf.setBrokerFactory(bf);
         return emf;
     }
 
     public EntityManagerFactoryValue() {
-        super(OpenJPAEntityManagerFactory.class, KEY, false);
+        super(KEY, false);
         setAliases(ALIASES);
         setDefault(ALIASES[0]);
         setClassName(ALIASES[1]);

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java (original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java Sat Nov  5 17:17:26 2011
@@ -219,6 +219,10 @@ public class EntityManagerImpl
         _broker.setSyncWithManagedTransactions(sync);
     }
 
+    public ClassLoader getClassLoader() {
+        return _broker.getClassLoader();
+    }
+
     public String getConnectionUserName() {
         return _broker.getConnectionUserName();
     }
@@ -919,8 +923,9 @@ public class EntityManagerImpl
         assertNotCloseInvoked();
         try {
             SequenceMetaData meta = _broker.getConfiguration().
-                getMetaDataRepositoryInstance().getSequenceMetaData(name, true);
-            Seq seq = meta.getInstance();
+                getMetaDataRepositoryInstance().getSequenceMetaData(name,
+                _broker.getClassLoader(), true);
+            Seq seq = meta.getInstance(_broker.getClassLoader());
             return new GeneratorImpl(seq, name, _broker, null);
         } catch (RuntimeException re) {
             throw PersistenceExceptions.toPersistenceException(re);
@@ -931,7 +936,8 @@ public class EntityManagerImpl
         assertNotCloseInvoked();
         try {
             ClassMetaData meta = _broker.getConfiguration().
-                getMetaDataRepositoryInstance().getMetaData(forClass, true);
+                getMetaDataRepositoryInstance().getMetaData(forClass,
+                _broker.getClassLoader(), true);
             Seq seq = _broker.getIdentitySequence(meta);
             return (seq == null) ? null : new GeneratorImpl(seq, null, _broker,
                 meta);
@@ -944,7 +950,8 @@ public class EntityManagerImpl
         assertNotCloseInvoked();
         try {
             ClassMetaData meta = _broker.getConfiguration().
-                getMetaDataRepositoryInstance().getMetaData(forClass, true);
+                getMetaDataRepositoryInstance().getMetaData(forClass,
+                _broker.getClassLoader(), true);
             FieldMetaData fmd = meta.getField(fieldName);
             if (fmd == null)
                 throw new ArgumentException(_loc.get("no-named-field",
@@ -1015,7 +1022,8 @@ public class EntityManagerImpl
         _broker.assertOpen();
         try {
             QueryMetaData meta = _broker.getConfiguration().
-                getMetaDataRepositoryInstance().getQueryMetaData(null, name, true);
+                getMetaDataRepositoryInstance().getQueryMetaData(null, name,
+                _broker.getClassLoader(), true);
             String qid = meta.getQueryString();
             
             PreparedQuery pq = JPQLParser.LANG_JPQL.equals(meta.getLanguage()) ? getPreparedQuery(qid) : null;

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/HintHandler.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/HintHandler.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/HintHandler.java (original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/HintHandler.java Sat Nov  5 17:17:26 2011
@@ -145,7 +145,7 @@ public class HintHandler  {
             return;
         }
         
-        ClassLoader loader = owner.getDelegate().getBroker().getConfiguration().getClassLoader();
+        ClassLoader loader = owner.getDelegate().getBroker().getClassLoader();
         if (QueryHints.HINT_SUBCLASSES.equals(key)) {
             if (value instanceof String)
                 value = Boolean.valueOf((String) value);

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/JPAFacadeHelper.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/JPAFacadeHelper.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/JPAFacadeHelper.java (original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/JPAFacadeHelper.java Sat Nov  5 17:17:26 2011
@@ -177,7 +177,7 @@ public class JPAFacadeHelper {
             OpenJPAPersistence.cast(em);
         try {
             return kem.getConfiguration().getMetaDataRepositoryInstance().
-                getMetaData(cls, false);
+                getMetaData(cls, kem.getClassLoader(), false);
         } catch (Exception e) {
             throw PersistenceExceptions.toPersistenceException(e);
         }
@@ -196,7 +196,7 @@ public class JPAFacadeHelper {
             (OpenJPAEntityManagerFactorySPI) OpenJPAPersistence.cast(emf);
         try {
             return emfSPI.getConfiguration().getMetaDataRepositoryInstance().
-                getMetaData(cls, false);
+                getMetaData(cls, null, false);
         } catch (Exception e) {
             throw PersistenceExceptions.toPersistenceException(e);
         }

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/OpenJPAEntityManager.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/OpenJPAEntityManager.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/OpenJPAEntityManager.java (original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/OpenJPAEntityManager.java Sat Nov  5 17:17:26 2011
@@ -110,6 +110,12 @@ public interface OpenJPAEntityManager
     public void setSyncWithManagedTransactions(boolean resync);
 
     /**
+     * Return the current thread's class loader at the time this entity
+     * manager was obtained from the factory.
+     */
+    public ClassLoader getClassLoader();
+
+    /**
      * Return the connection user name.
      */
     public String getConnectionUserName();

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/OpenJPAPersistence.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/OpenJPAPersistence.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/OpenJPAPersistence.java (original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/OpenJPAPersistence.java Sat Nov  5 17:17:26 2011
@@ -86,9 +86,11 @@ public class OpenJPAPersistence {
      * overrides.
      */
     public static OpenJPAEntityManagerFactory getEntityManagerFactory(Map map) {
-        ConfigurationProvider cp = new PersistenceProductDerivation.ConfigurationProviderImpl(map);
+        ConfigurationProvider cp = new PersistenceProductDerivation.
+            ConfigurationProviderImpl(map);
         try {
-            return JPAFacadeHelper.toEntityManagerFactory(Bootstrap.getBrokerFactory(cp));
+            return JPAFacadeHelper.toEntityManagerFactory(
+                Bootstrap.getBrokerFactory(cp, null));
         } catch (Exception e) {
             throw PersistenceExceptions.toPersistenceException(e);
         }

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java (original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java Sat Nov  5 17:17:26 2011
@@ -309,7 +309,7 @@ public class PersistenceMetaDataDefaults
     	MetaDataRepository repos = meta.getRepository();
     	ClassMetaData supMeta = repos.getCachedMetaData(sup);
     	if (supMeta == null)
-    		supMeta = repos.getMetaData(sup, false);
+    		supMeta = repos.getMetaData(sup, null, false);
     	return supMeta;
     }
 

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataFactory.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataFactory.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataFactory.java (original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataFactory.java Sat Nov  5 17:17:26 2011
@@ -75,9 +75,11 @@ public class PersistenceMetaDataFactory
     extends AbstractCFMetaDataFactory
     implements Configurable, GenericConfigurable {
 
-    private static final Localizer _loc = Localizer.forPackage(PersistenceMetaDataFactory.class);
+    private static final Localizer _loc = Localizer.forPackage
+        (PersistenceMetaDataFactory.class);
 
-    private final PersistenceMetaDataDefaults _def = new PersistenceMetaDataDefaults();
+    private final PersistenceMetaDataDefaults _def = 
+        new PersistenceMetaDataDefaults();
     private AnnotationPersistenceMetaDataParser _annoParser = null;
     private AnnotationPersistenceXMLMetaDataParser _annoXMLParser = null;
     private XMLPersistenceMetaDataParser _xmlParser = null;
@@ -85,7 +87,8 @@ public class PersistenceMetaDataFactory
     private Set<URL> _unparsed = null; // xml rsrc
     private boolean _fieldOverride = true;
 
-    protected Stack<XMLPersistenceMetaDataParser> _stack = new Stack<XMLPersistenceMetaDataParser>();
+    protected Stack<XMLPersistenceMetaDataParser> _stack = 
+        new Stack<XMLPersistenceMetaDataParser>();
 
     /**
      * Whether to use field-level override or class-level override.
@@ -117,7 +120,8 @@ public class PersistenceMetaDataFactory
     /**
      * Set the metadata parser.
      */
-    public void setAnnotationParser(AnnotationPersistenceMetaDataParser parser) {
+    public void setAnnotationParser(
+        AnnotationPersistenceMetaDataParser parser) {
         if (_annoParser != null)
             _annoParser.setRepository(null);
         if (parser != null)
@@ -129,7 +133,8 @@ public class PersistenceMetaDataFactory
      * Create a new metadata parser.
      */
     protected AnnotationPersistenceMetaDataParser newAnnotationParser() {
-        return new AnnotationPersistenceMetaDataParser(repos.getConfiguration());
+        return new AnnotationPersistenceMetaDataParser
+            (repos.getConfiguration());
     }
 
     /**
@@ -200,7 +205,7 @@ public class PersistenceMetaDataFactory
         return new XMLPersistenceMetaDataSerializer(repos.getConfiguration());
     }
     
-    public void load(Class<?> cls, int mode) {
+    public void load(Class<?> cls, int mode, ClassLoader envLoader) {
         if (mode == MODE_NONE)
             return;
         if (!strict && (mode & MODE_META) != 0)
@@ -209,7 +214,7 @@ public class PersistenceMetaDataFactory
         // getting the list of persistent types runs callbacks to
         // mapPersistentTypeNames if it hasn't been called already, which
         // caches XML resources
-        getPersistentTypeNames(false);
+        getPersistentTypeNames(false, envLoader);
         URL xml = findXML(cls);
 
         // we have to parse metadata up-front to register persistence unit
@@ -220,7 +225,7 @@ public class PersistenceMetaDataFactory
             && (mode & MODE_META) != 0) {
             Set<URL> unparsed = new HashSet<URL>(_unparsed);
             for (URL url : unparsed) {
-                parseXML(url, cls, mode);
+                parseXML(url, cls, mode, envLoader);
             }
             parsedXML = unparsed.contains(xml);
              _unparsed.clear();
@@ -240,7 +245,7 @@ public class PersistenceMetaDataFactory
         // we may still need to parse XML if this is a redeploy of a class, or
         // if we're in strict query-only mode
         if (!parsedXML && xml != null) {
-            parseXML(xml, cls, mode);
+            parseXML(xml, cls, mode, envLoader);
             // XML process check
             meta = repos.getCachedMetaData(cls);
             if (meta != null && (meta.getSourceMode() & mode) == mode) {
@@ -250,6 +255,7 @@ public class PersistenceMetaDataFactory
         }
 
         AnnotationPersistenceMetaDataParser parser = getAnnotationParser();
+        parser.setEnvClassLoader(envLoader);
         parser.setMode(mode);
         parser.parse(cls);
 
@@ -261,11 +267,27 @@ public class PersistenceMetaDataFactory
     /**
      * Parse the given XML resource.
      */
-    private void parseXML(URL xml, Class<?> cls, int mode) {
+    private void parseXML(URL xml, Class<?> cls, int mode, 
+    	ClassLoader envLoader) {
         // spring needs to use the envLoader first for all class resolution,
         // but we must still fall back on application loader
+        ClassLoader loader = repos.getConfiguration().
+            getClassResolverInstance().getClassLoader(cls, null);
+        if (envLoader != null && envLoader != loader) {
+          MultiClassLoader mult = new MultiClassLoader();
+          mult.addClassLoader(envLoader);
+
+          // loader from resolver is usually a multi loader itself
+          if (loader instanceof MultiClassLoader)
+            mult.addClassLoaders((MultiClassLoader)loader);
+          else
+            mult.addClassLoader(loader);
+          loader = mult;
+        }
     
         XMLPersistenceMetaDataParser xmlParser = getXMLParser();
+        xmlParser.setClassLoader(loader);
+        xmlParser.setEnvClassLoader(envLoader);
         xmlParser.setMode(mode);
         try {
             xmlParser.parse(xml);
@@ -322,10 +344,10 @@ public class PersistenceMetaDataFactory
     }
 
     @Override
-    public Class<?> getQueryScope(String queryName) {
+    public Class<?> getQueryScope(String queryName, ClassLoader loader) {
         if (queryName == null)
             return null;
-        Collection<Class<?>> classes = repos.loadPersistentTypes(false);
+        Collection<Class<?>> classes = repos.loadPersistentTypes(false, loader);
         for (Class<?> cls :  classes) {
             if ((AccessController.doPrivileged(J2DoPrivHelper
                 .isAnnotationPresentAction(cls, NamedQuery.class)))
@@ -355,11 +377,12 @@ public class PersistenceMetaDataFactory
     }
 
     @Override
-    public Class<?> getResultSetMappingScope(String rsMappingName) {
+    public Class<?> getResultSetMappingScope(String rsMappingName,
+        ClassLoader loader) {
         if (rsMappingName == null)
             return null;
         
-        Collection<Class<?>> classes = repos.loadPersistentTypes(false);
+        Collection<Class<?>> classes = repos.loadPersistentTypes(false, loader);
         for (Class<?> cls : classes) {
 
             if ((AccessController.doPrivileged(J2DoPrivHelper
@@ -488,7 +511,8 @@ public class PersistenceMetaDataFactory
      * Look for META-INF/orm.xml, and if it doesn't exist, choose a default.
      */
     private File defaultXMLFile() {
-        ClassLoader loader = repos.getConfiguration().getClassLoader();
+        ClassLoader loader = repos.getConfiguration().
+            getClassResolverInstance().getClassLoader(getClass(), null);
         URL rsrc = AccessController.doPrivileged(
             J2DoPrivHelper.getResourceAction(loader, "META-INF/orm.xml"));
         if (rsrc != null) {

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java (original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProductDerivation.java Sat Nov  5 17:17:26 2011
@@ -48,6 +48,7 @@ import org.apache.openjpa.conf.OpenJPACo
 import org.apache.openjpa.conf.OpenJPAProductDerivation;
 import org.apache.openjpa.conf.Specification;
 import org.apache.openjpa.datacache.DataCacheMode;
+import org.apache.openjpa.kernel.MixedLockLevels;
 import org.apache.openjpa.kernel.QueryHints;
 import org.apache.openjpa.lib.conf.AbstractProductDerivation;
 import org.apache.openjpa.lib.conf.Configuration;
@@ -60,12 +61,9 @@ import org.apache.openjpa.lib.meta.XMLMe
 import org.apache.openjpa.lib.meta.XMLVersionParser;
 import org.apache.openjpa.lib.util.J2DoPrivHelper;
 import org.apache.openjpa.lib.util.Localizer;
-import org.apache.openjpa.lib.util.MultiClassLoader;
-import org.apache.openjpa.persistence.osgi.BundleUtils;
-import org.apache.openjpa.validation.Validator;
 import org.xml.sax.Attributes;
 import org.xml.sax.SAXException;
-import static org.apache.openjpa.kernel.MixedLockLevels.*;
+
 
 /**
  * Sets JPA specification defaults and parses JPA specification XML files.
@@ -80,7 +78,6 @@ import static org.apache.openjpa.kernel.
  * a named one).
  *
  * @author Abe White
- * @author Pinaki Poddar
  * @nojavadoc
  */
 public class PersistenceProductDerivation 
@@ -93,8 +90,11 @@ public class PersistenceProductDerivatio
     public static final String RSRC_DEFAULT = "META-INF/persistence.xml";
     public static final BigDecimal VERSION_1_0 = BigDecimal.valueOf(1.0);
 
-    private static final Localizer _loc = Localizer.forPackage(PersistenceProductDerivation.class);
+    private static final Localizer _loc = Localizer.forPackage
+        (PersistenceProductDerivation.class);
 
+    private HashMap<String, PUNameCollision> _puNameCollisions
+        = new HashMap<String,PUNameCollision>();
     
     public static final String PREFIX = "javax.persistence"; 
     
@@ -104,11 +104,8 @@ public class PersistenceProductDerivatio
     
     private static Set<String> _hints = new HashSet<String>();
     
-    /**
-     * The loader used to load resources and classes by name and eventually set into
-     * the configuration.
-     */
-    private final MultiClassLoader _loader;
+    // Provider name to filter out PUs that don't belong to this derivation.
+    protected String _providerImplName;
 
     static {
         _hints.add("javax.persistence.lock.timeout");
@@ -152,21 +149,8 @@ public class PersistenceProductDerivatio
         _hints = Collections.unmodifiableSet(_hints);
     }
     
-    public PersistenceProductDerivation() {
-    	this(false);
-    }
-    
-    /**
-     * Constructs and configures a class loader to be used for loading
-     * resources and classes by their names.
-     */
-	public PersistenceProductDerivation(boolean osgi) {
-		_loader = AccessController.doPrivileged(J2DoPrivHelper.newMultiClassLoaderAction());
-		if (osgi) 
-			_loader.addClassLoader(BundleUtils.getBundleClassLoader());
-		_loader.addClassLoader(MultiClassLoader.THREAD_LOADER);
-		_loader.addClassLoader(this.getClass().getClassLoader());
-		_loader.addClassLoader(MultiClassLoader.SYSTEM_LOADER);
+	public PersistenceProductDerivation() {
+		_providerImplName = PersistenceProviderImpl.class.getName();
 	}
     
     public void putBrokerFactoryAliases(Map<String, String> m) {
@@ -187,7 +171,8 @@ public class PersistenceProductDerivatio
     }
 
     @Override
-    public void validate() throws Exception {
+    public void validate()
+        throws Exception {
         // make sure JPA is available
         AccessController.doPrivileged(J2DoPrivHelper.getClassLoaderAction(
             javax.persistence.EntityManagerFactory.class));
@@ -204,17 +189,26 @@ public class PersistenceProductDerivatio
         
         conf.addValue(new EntityManagerFactoryValue());
         
-        conf.readLockLevel.setAlias("optimistic",                  String.valueOf(LOCK_OPTIMISTIC));
-        conf.readLockLevel.setAlias("optimistic-force-increment",  String.valueOf(LOCK_OPTIMISTIC_FORCE_INCREMENT));
-        conf.readLockLevel.setAlias("pessimistic-read",            String.valueOf(LOCK_PESSIMISTIC_READ));
-        conf.readLockLevel.setAlias("pessimistic-write",           String.valueOf(LOCK_PESSIMISTIC_WRITE));
-        conf.readLockLevel.setAlias("pessimistic-force-increment", String.valueOf(LOCK_PESSIMISTIC_FORCE_INCREMENT));
-
-        conf.writeLockLevel.setAlias("optimistic",                  String.valueOf(LOCK_OPTIMISTIC));
-        conf.writeLockLevel.setAlias("optimistic-force-increment",  String.valueOf(LOCK_OPTIMISTIC_FORCE_INCREMENT));
-        conf.writeLockLevel.setAlias("pessimistic-read",            String.valueOf(LOCK_PESSIMISTIC_READ));
-        conf.writeLockLevel.setAlias("pessimistic-write",           String.valueOf(LOCK_PESSIMISTIC_WRITE));
-        conf.writeLockLevel.setAlias("pessimistic-force-increment", String.valueOf(LOCK_PESSIMISTIC_FORCE_INCREMENT));
+        conf.readLockLevel.setAlias("optimistic", String.valueOf(MixedLockLevels.LOCK_OPTIMISTIC));
+        conf.readLockLevel.setAlias("optimistic-force-increment", String
+            .valueOf(MixedLockLevels.LOCK_OPTIMISTIC_FORCE_INCREMENT));
+        conf.readLockLevel.setAlias("pessimistic-read", String
+            .valueOf(MixedLockLevels.LOCK_PESSIMISTIC_READ));
+        conf.readLockLevel.setAlias("pessimistic-write", String
+            .valueOf(MixedLockLevels.LOCK_PESSIMISTIC_WRITE));
+        conf.readLockLevel.setAlias("pessimistic-force-increment", String
+            .valueOf(MixedLockLevels.LOCK_PESSIMISTIC_FORCE_INCREMENT));
+
+        conf.writeLockLevel.setAlias("optimistic", String
+            .valueOf(MixedLockLevels.LOCK_OPTIMISTIC));
+        conf.writeLockLevel.setAlias("optimistic-force-increment", String
+            .valueOf(MixedLockLevels.LOCK_OPTIMISTIC_FORCE_INCREMENT));
+        conf.writeLockLevel.setAlias("pessimistic-read", String
+            .valueOf(MixedLockLevels.LOCK_PESSIMISTIC_READ));
+        conf.writeLockLevel.setAlias("pessimistic-write", String
+            .valueOf(MixedLockLevels.LOCK_PESSIMISTIC_WRITE));
+        conf.writeLockLevel.setAlias("pessimistic-force-increment", String
+            .valueOf(MixedLockLevels.LOCK_PESSIMISTIC_FORCE_INCREMENT));
 
 
         configureBeanValidation(conf);
@@ -236,8 +230,8 @@ public class PersistenceProductDerivatio
      */
     private void configureBeanValidation(OpenJPAConfigurationImpl conf) {
         // Validation defines/adds the following plugins to OpenJPA Configuration
-        conf.validationFactory         = conf.addObject(Object.class, JPAProperties.VALIDATE_FACTORY); 
-        conf.validator                 = conf.addObject(Validator.class, "Validator");
+        conf.validationFactory         = conf.addObject(JPAProperties.VALIDATE_FACTORY); 
+        conf.validator                 = conf.addObject("Validator");
         conf.validationMode            = conf.addString(JPAProperties.VALIDATE_MODE);
         conf.validationGroupPrePersist = conf.addString(JPAProperties.VALIDATE_PRE_PERSIST);
         conf.validationGroupPreUpdate  = conf.addString(JPAProperties.VALIDATE_PRE_UPDATE);
@@ -308,10 +302,12 @@ public class PersistenceProductDerivatio
      * Load configuration from the given persistence unit with the specified
      * user properties.
      */
-    public ConfigurationProvider load(PersistenceUnitInfo pinfo, Map m) throws IOException {
+    public ConfigurationProvider load(PersistenceUnitInfo pinfo, Map m)
+        throws IOException {
         if (pinfo == null)
             return null;
-        if (!isOpenJPAPersistenceProvider(pinfo)) {
+        if (!isOpenJPAPersistenceProvider(pinfo, null)) {
+            warnUnknownProvider(pinfo);
             return null;
         }
 
@@ -337,7 +333,7 @@ public class PersistenceProductDerivatio
             rsrc = RSRC_DEFAULT;
         
         ConfigurationProviderImpl cp = new ConfigurationProviderImpl();
-        Boolean ret = load(cp, rsrc, name, m, explicit);
+        Boolean ret = load(cp, rsrc, name, m, null, explicit);
         if (ret != null)
             return (ret.booleanValue()) ? cp : null;
         if (explicit)
@@ -346,7 +342,8 @@ public class PersistenceProductDerivatio
         // persistence.xml does not exist; just load map
         PersistenceUnitInfoImpl pinfo = new PersistenceUnitInfoImpl();
         pinfo.fromUserProperties(m);
-        if (!isOpenJPAPersistenceProvider(pinfo)) {
+        if (!isOpenJPAPersistenceProvider(pinfo, null)) {
+            warnUnknownProvider(pinfo);
             return null;
         }
         cp.addProperties(pinfo.toOpenJPAProperties());
@@ -354,25 +351,27 @@ public class PersistenceProductDerivatio
     }
 
     @Override
-    public ConfigurationProvider load(String rsrc, String anchor)  throws IOException {
+    public ConfigurationProvider load(String rsrc, String anchor, 
+        ClassLoader loader)
+        throws IOException {
         if (rsrc != null && !rsrc.endsWith(".xml"))
             return null;
         ConfigurationProviderImpl cp = new ConfigurationProviderImpl();
-        if (load(cp, rsrc, anchor, null, true) == Boolean.TRUE)
+        if (load(cp, rsrc, anchor, null, loader, true) == Boolean.TRUE)
             return cp;
         return null;
     }
 
     @Override
-    public ConfigurationProvider load(File file, String anchor) throws IOException {
+    public ConfigurationProvider load(File file, String anchor) 
+        throws IOException {
         if (!file.getName().endsWith(".xml"))
             return null;
 
-        ConfigurationParser parser = new ConfigurationParser(_loader, null);
+        ConfigurationParser parser = new ConfigurationParser(null);
         parser.parse(file);
-        List<PersistenceUnitInfoImpl> units = (List<PersistenceUnitInfoImpl>) parser.getResults();
-        PersistenceUnitInfoImpl unit = findUnit(units, anchor);
-        return load(unit, null);
+        return load(findUnit((List<PersistenceUnitInfoImpl>) 
+            parser.getResults(), anchor, null), null);
     }
 
     @Override
@@ -381,8 +380,8 @@ public class PersistenceProductDerivatio
     }
 
     @Override
-    public List<String> getAnchorsInFile(File file) throws IOException {
-        ConfigurationParser parser = new ConfigurationParser(_loader, null);
+    public List getAnchorsInFile(File file) throws IOException {
+        ConfigurationParser parser = new ConfigurationParser(null);
         try {
             parser.parse(file);
             return getUnitNames(parser);
@@ -398,7 +397,7 @@ public class PersistenceProductDerivatio
         for (PersistenceUnitInfoImpl unit : units){
         	String provider = unit.getPersistenceProviderClassName();
 			// Only add the PU name if the provider it is ours or not specified.
-			if (provider == null || provider.indexOf("openjpa") != -1) {
+			if (provider == null || provider.equals(_providerImplName)) {
 				names.add(unit.getPersistenceUnitName());
 			} else {
 				// Should trace something, but logging isn't configured yet.
@@ -409,11 +408,13 @@ public class PersistenceProductDerivatio
     }
 
     @Override
-    public List<String> getAnchorsInResource(String resource) throws Exception {
-        ConfigurationParser parser = new ConfigurationParser(_loader, null);
+    public List getAnchorsInResource(String resource) throws Exception {
+        ConfigurationParser parser = new ConfigurationParser(null);
         try {
-        	List<String> results = new ArrayList<String>();
-            List<URL> urls = getResourceURLs(resource);
+        	List results = new ArrayList();
+            ClassLoader loader = AccessController.doPrivileged(
+                J2DoPrivHelper.getContextClassLoaderAction());
+            List<URL> urls = getResourceURLs(resource, loader);
             if (urls != null) {
                 for (URL url : urls) {
                     parser.parse(url);
@@ -428,7 +429,7 @@ public class PersistenceProductDerivatio
     }
 
     @Override
-    public ConfigurationProvider loadGlobals()
+    public ConfigurationProvider loadGlobals(ClassLoader loader)
         throws IOException {
         String[] prefixes = ProductDerivations.getConfigurationPrefixes();
         String rsrc = null;
@@ -450,52 +451,54 @@ public class PersistenceProductDerivatio
             return null;
 
         ConfigurationProviderImpl cp = new ConfigurationProviderImpl();
-        if (load(cp, rsrc, anchor, null, explicit) == Boolean.TRUE)
+        if (load(cp, rsrc, anchor, null, loader, explicit) == Boolean.TRUE)
             return cp;
         return null;
     }
 
     @Override
-    public ConfigurationProvider loadDefaults()
+    public ConfigurationProvider loadDefaults(ClassLoader loader)
         throws IOException {
         ConfigurationProviderImpl cp = new ConfigurationProviderImpl();
-        if (load(cp, RSRC_DEFAULT, null, null, false) == Boolean.TRUE)
+        if (load(cp, RSRC_DEFAULT, null, null, loader, false) == Boolean.TRUE)
             return cp;
         return null;
     }
 
-     private void checkPuNameCollisions(){
+      /**
+      * This method checks to see if the provided <code>puName</code> was
+      * detected in multiple resources. If a collision is detected, a warning
+      * will be logged and this method will return <code>true</code>.
+      * <p>
+      */
+     public boolean checkPuNameCollisions(Log logger,String puName){
+         PUNameCollision p = _puNameCollisions.get(puName);
+         if (p != null){
+             p.logCollision(logger);
+             return true;
+         }
+         return false;
      }
 
-    private List<URL> getResourceURLs(String rsrc)
+    private static List<URL> getResourceURLs(String rsrc, ClassLoader loader)
         throws IOException {
         Enumeration<URL> urls = null;
         try {
-            urls = AccessController.doPrivileged(J2DoPrivHelper.getResourcesAction(_loader, rsrc)); 
+            urls = AccessController.doPrivileged(J2DoPrivHelper.getResourcesAction(loader, rsrc)); 
             if (!urls.hasMoreElements()) {
                 if (!rsrc.startsWith("META-INF"))
-                  urls = AccessController.doPrivileged(J2DoPrivHelper.getResourcesAction(_loader, "META-INF/" + rsrc));
+                  urls = AccessController.doPrivileged(J2DoPrivHelper.getResourcesAction(loader, "META-INF/" + rsrc));
                 if (!urls.hasMoreElements())
                     return null;
             }
         } catch (PrivilegedActionException pae) {
             throw (IOException) pae.getException();
         }
-        List<URL> result = new ArrayList<URL>();
-        for (;urls.hasMoreElements();) {
-        	URL url = urls.nextElement();
-        	if (!result.contains(url)) {
-        		result.add(url);
-        	}
-        }
-        return result;
+
+        return Collections.list(urls);
     }
 
     /**
-     * The core load method to load the configuration resource.
-     * The class loader that loads the configuration resource is remembered by the provider
-     * and later {@link ConfigurationProvider#setInto(Configuration) set into} {@link Configuration}.
-     * <br>
      * Looks through the resources at <code>rsrc</code> for a configuration
      * file that matches <code>name</code> (or an unnamed one if
      * <code>name</code> is <code>null</code>), and loads the XML in the
@@ -505,21 +508,26 @@ public class PersistenceProductDerivatio
      * @return {@link Boolean#TRUE} if the resource was loaded, null if it
      * does not exist, or {@link Boolean#FALSE} if it is not for OpenJPA
      */
-    private Boolean load(ConfigurationProviderImpl cp, String rsrc, String name, Map m, boolean explicit)
+    private Boolean load(ConfigurationProviderImpl cp, String rsrc, 
+        String name, Map m, ClassLoader loader, boolean explicit)
         throws IOException {
-        List<URL> urls = getResourceURLs(rsrc);
+        if (loader == null)
+            loader = AccessController.doPrivileged(J2DoPrivHelper.getContextClassLoaderAction());
+
+        List<URL> urls = getResourceURLs(rsrc, loader);
         if (urls == null || urls.size() == 0)
             return null;
 
-        ConfigurationParser parser = new ConfigurationParser(_loader, m);
-        PersistenceUnitInfoImpl pinfo = parseResources(parser, urls, name);
+        ConfigurationParser parser = new ConfigurationParser(m);
+        PersistenceUnitInfoImpl pinfo = parseResources(parser, urls, name, loader);
         if (pinfo == null) {
             if (!explicit)
                 return Boolean.FALSE;
             throw new MissingResourceException(_loc.get("missing-xml-config", 
                 rsrc, String.valueOf(name)).getMessage(), getClass().getName(), rsrc);
-        } else if (!isOpenJPAPersistenceProvider(pinfo)) {
+        } else if (!isOpenJPAPersistenceProvider(pinfo, loader)) {
             if (!explicit) {
+                warnUnknownProvider(pinfo);
                 return Boolean.FALSE;
             }
             throw new MissingResourceException(_loc.get("unknown-provider", 
@@ -532,7 +540,6 @@ public class PersistenceProductDerivatio
 
         cp.addProperties(pinfo.toOpenJPAProperties());
         cp.setSource(pinfo.getPersistenceXmlFileUrl().toString());
-        
         return Boolean.TRUE;
     }
 
@@ -542,70 +549,100 @@ public class PersistenceProductDerivatio
      * no name given (preferring an unnamed OpenJPA unit to a named one).
      */
     private PersistenceUnitInfoImpl parseResources(ConfigurationParser parser,
-        List<URL> urls, String name)
+        List<URL> urls, String name, ClassLoader loader)
         throws IOException {
         List<PersistenceUnitInfoImpl> pinfos = new ArrayList<PersistenceUnitInfoImpl>();
         for (URL url : urls) {
             parser.parse(url);
             pinfos.addAll((List<PersistenceUnitInfoImpl>) parser.getResults());
-            PersistenceUnitInfoImpl pu = null;
-         }
-        return findUnit(pinfos, name);
+        }
+        return findUnit(pinfos, name, loader);
     }
 
     /**
-     * Finds the unit with the given name in the given list of persistence unit infos.
-     * Ignores any persistence unit info that does not use OpenJPA as persistence provider.
-     * If the same unit name is found in multiple units, returns the first unit but
-     * records the rest as duplicates.
+     * Find the unit with the given name, or an OpenJPA unit if no name is
+     * given (preferring an unnamed OpenJPA unit to a named one).
      */
-    private PersistenceUnitInfoImpl findUnit(List<PersistenceUnitInfoImpl> pinfos, String name) {
-        PUNameCollision _puNameCollisions = null;
+    private PersistenceUnitInfoImpl findUnit(List<PersistenceUnitInfoImpl> 
+        pinfos, String name, ClassLoader loader) {
+        PersistenceUnitInfoImpl ojpa = null;
         PersistenceUnitInfoImpl result = null;
         for (PersistenceUnitInfoImpl pinfo : pinfos) {
-        	if (!isOpenJPAPersistenceProvider(pinfo)) {
-        		continue;
-        	}
-        	if (name == null || name.equals(pinfo.getPersistenceUnitName())) {
-        		if (result == null) {
-        			result = pinfo;
-        		} else {
-        			if (_puNameCollisions == null) {
-        				_puNameCollisions = new PUNameCollision(name, result, pinfo);
-        			} else {
-        				_puNameCollisions.addDuplicate(pinfo);
-        			}
-        		}
-        	} 
-        }
-        if (_puNameCollisions != null) {
-        	_puNameCollisions.logCollision();
-        }
-        return result;
+            // found named unit?
+            if (name != null) {
+                if (name.equals(pinfo.getPersistenceUnitName())){
+                    if (result != null){
+                        this.addPuNameCollision(name, result.getPersistenceXmlFileUrl().toString(),
+                                pinfo.getPersistenceXmlFileUrl().toString());
+
+                    } else {
+                        // Grab a ref to the pinfo that matches the name we're
+                        // looking for. Keep going to look for duplicate pu names.
+                        result = pinfo;
+                    }
+                }
+                continue;
+            }
+
+            if (isOpenJPAPersistenceProvider(pinfo, loader)) {
+                // if no name given and found unnamed unit, return it.  
+                // otherwise record as default unit unless we find a better match later
+                if (StringUtils.isEmpty(pinfo.getPersistenceUnitName()))
+                    return pinfo;
+                if (ojpa == null)
+                    ojpa = pinfo;
+            }
+        }
+        if(result!=null){
+            return result;
+        }
+        return ojpa;
     }
 
     /**
-     * Affirms if the given provider is recognized as an OpenJPA provider.
-     * An empty string or a name containing <tt>"openjpa"</tt> returns true.
-     */
-    private boolean isOpenJPAPersistenceProvider(PersistenceUnitInfo pinfo) {
-    	String provider = pinfo.getPersistenceProviderClassName();
-        if (StringUtils.isEmpty(provider) || "void".equals(provider) || provider.indexOf("openjpa") != -1)
+     * Return whether the given persistence unit uses an OpenJPA provider.
+     */
+    private static boolean isOpenJPAPersistenceProvider(PersistenceUnitInfo pinfo, ClassLoader loader) {
+        String provider = pinfo.getPersistenceProviderClassName();
+        if (StringUtils.isEmpty(provider) || PersistenceProviderImpl.class.getName().equals(provider))
             return true;
 
-        log(_loc.get("unrecognized-provider", provider).getMessage());
+        if (loader == null)
+            loader = AccessController.doPrivileged(J2DoPrivHelper.getContextClassLoaderAction());
+        try {
+            if (PersistenceProviderImpl.class.isAssignableFrom(Class.forName(provider, false, loader)))
+                return true;
+        } catch (Throwable t) {
+            log(_loc.get("unloadable-provider", provider, t).getMessage());
+            return false;
+        }
         return false;
     }
 
+    /**
+     * Warn the user that we could only find an unrecognized persistence 
+     * provider.
+     */
+    private static void warnUnknownProvider(PersistenceUnitInfo pinfo) {
+        log(_loc.get("unrecognized-provider", pinfo.getPersistenceProviderClassName()).getMessage());
+    }
     
     /**
-     * Log a message on the console because no logging mechanism has been configured yet.   
+     * Log a message.   
      */
     private static void log(String msg) {
         // at this point logging isn't configured yet
-        System.err.println("WARN: " + msg);
+        System.err.println(msg);
     }
 
+    private void addPuNameCollision(String puName, String file1, String file2){
+        PUNameCollision pun = _puNameCollisions.get(puName);
+        if (pun != null){
+            pun.addCollision(file1, file2);
+        } else {
+            _puNameCollisions.put(puName, new PUNameCollision(puName, file1, file2));
+        }
+    }
     
     /**
      * Custom configuration provider.   
@@ -616,7 +653,6 @@ public class PersistenceProductDerivatio
         private String _source;
 
         public ConfigurationProviderImpl() {
-        	super();
         }
 
         public ConfigurationProviderImpl(Map props) {
@@ -630,9 +666,6 @@ public class PersistenceProductDerivatio
             _source = source;
         }
 
-        /**
-         * Sets the configuration.
-         */
         @Override
         public void setInto(Configuration conf) {
             if (conf instanceof OpenJPAConfiguration) {
@@ -661,17 +694,17 @@ public class PersistenceProductDerivatio
             }
             super.setInto(conf, null);
             
-            // At this point user properties have been loaded into the configuration. 
-            // Apply any modifications based off those.
+            // At this point user properties have been loaded into the configuration. Apply any modifications based off
+            // those.
             if (conf instanceof OpenJPAConfiguration) {
                 OpenJPAConfiguration oconf = (OpenJPAConfiguration) conf;
-                // If the data cache is enabled, make sure we have a RemoteCommitProvider
+                // If the datacache is enabled, make sure we have a RemoteCommitProvider
                 String dc = oconf.getDataCache();
                 String rcp = oconf.getRemoteCommitProvider();
-                // If the data cache is set and is something other than false
-                if (!"false".equals(dc)) {
+                // If the datacache is set and is something other than false
+                if (dc != null && dc.equals("false") == false) {
                     // If RCP is null or empty, set it to sjvm.
-                    if (StringUtils.isEmpty(rcp)) {
+                    if (rcp == null || (rcp != null && rcp.equals("") == false)) {
                         oconf.setRemoteCommitProvider("sjvm");
                     }
                 }
@@ -704,6 +737,8 @@ public class PersistenceProductDerivatio
         private static final String PERSISTENCE_XSD_1_0 = "persistence_1_0.xsd";
         private static final String PERSISTENCE_XSD_2_0 = "persistence_2_0.xsd";
 
+        private static final Localizer _loc = Localizer.forPackage
+            (ConfigurationParser.class);
 
         private final Map _map;
         private PersistenceUnitInfoImpl _info = null;
@@ -712,15 +747,7 @@ public class PersistenceProductDerivatio
         private String _schemaLocation;
         private boolean _excludeUnlistedSet = false;
 
-        /**
-         * Parse configuration information.
-         * 
-         * @param loader Class Loader to load resources. Must not be null.
-         * @param 
-         * @param map
-         */
-        public ConfigurationParser(ClassLoader loader, Map map) {
-        	super(loader);
+        public ConfigurationParser(Map map) {
             _map = map;
             setCaching(false);
             setValidating(true);
@@ -739,7 +766,8 @@ public class PersistenceProductDerivatio
                 _persistenceVersion = vp.getVersion();
                 _schemaLocation = vp.getSchemaLocation();
             } catch (Throwable t) {
-                    log(_loc.get("version-check-error", _source.toString()).toString());
+                    log(_loc.get("version-check-error", 
+                        _source.toString()).toString());
             }            
             super.parse(url);
         }
@@ -748,7 +776,8 @@ public class PersistenceProductDerivatio
         public void parse(File file)
             throws IOException {
             try {
-                _source = AccessController.doPrivileged(J2DoPrivHelper.toURLAction(file));
+                _source = AccessController.doPrivileged(J2DoPrivHelper
+                    .toURLAction(file));
             } catch (PrivilegedActionException pae) {
                 throw (MalformedURLException) pae.getException();
             }
@@ -759,22 +788,11 @@ public class PersistenceProductDerivatio
                 _persistenceVersion = vp.getVersion();
                 _schemaLocation = vp.getSchemaLocation();                
             } catch (Throwable t) {
-                    log(_loc.get("version-check-error", _source.toString()).toString());
+                    log(_loc.get("version-check-error", 
+                        _source.toString()).toString());
             }            
             super.parse(file);
         }
-        
-        boolean peek(String name, URL fileOrURL) {
-            XMLVersionParser vp = new XMLVersionParser("persistence");
-            try {
-                vp.parse(fileOrURL);
-                _persistenceVersion = vp.getVersion();
-                _schemaLocation = vp.getSchemaLocation();                
-            } catch (Throwable t) {
-                    log(_loc.get("version-check-error", _source.toString()).toString());
-            }            
-            return vp.unitNames().contains(name);
-        }
 
         @Override
         protected Object getSchemaSource() {
@@ -912,8 +930,9 @@ public class PersistenceProductDerivatio
                     return new BigDecimal(_info.getPersistenceXMLSchemaVersion());
                 }
                 catch (Throwable t) {
-                    log(_loc.get("invalid-version-attribute", _info.getPersistenceXMLSchemaVersion(),
-                        VERSION_1_0).toString());
+                    log(_loc.get("invalid-version-attribute", 
+                        _info.getPersistenceXMLSchemaVersion(),
+                        VERSION_1_0.toString()).toString());
                 }
             }
             // OpenJPA supports persistence files without a version attribute.
@@ -926,40 +945,32 @@ public class PersistenceProductDerivatio
     
     
     /**
-     * Holds the URLs of persistence configuration that contain the same unit name.
+     * This private class is used to hold onto information regarding
+     * PersistentUnit name collisions.
      */
-    private static class PUNameCollision {
-    	private final String _puName;
-        private final PersistenceUnitInfoImpl _original;
-        private final Set<PersistenceUnitInfoImpl> _duplicates;
-
-        PUNameCollision(String pu, PersistenceUnitInfoImpl original, PersistenceUnitInfoImpl duplicate) {
-        	_puName = pu;
-        	_original = original;
-        	_duplicates = new LinkedHashSet<PersistenceUnitInfoImpl>();
-        	_duplicates.add(duplicate);
+    private static class PUNameCollision{
+        private String _puName;
+        private Set<String> _resources;
 
+        PUNameCollision(String puName, String file1, String file2) {
+            _resources = new LinkedHashSet<String>();
+            _resources.add(file1);
+            _resources.add(file2);
+
+            _puName=puName;
         }
         
-        void logCollision(){
-        	String duplicates = listDuplicates();
-        	if (_puName == null) {
-        		log(_loc.get("dup-pu-unnamed", _original, duplicates).toString());
-        	} else {
-        		log(_loc.get("dup-pu", _puName, _original, duplicates).toString());
-        	}
-        }
-        
-        void addDuplicate(PersistenceUnitInfoImpl dup){
-        	_duplicates.add(dup);
+        void logCollision(Log logger){
+            if(logger.isWarnEnabled()){
+                logger.warn(_loc.getFatal("dup-pu", new Object[]{_puName,_resources.toString(),	
+                    _resources.iterator().next()}));
+            }
         }
         
-        String listDuplicates() {
-        	StringBuilder buf = new StringBuilder("\r\n");
-        	for (PersistenceUnitInfoImpl pu : _duplicates) {
-        		buf.append(pu).append("\r\n");
-        	}
-        	return buf.toString();
+        void addCollision(String file1, String file2){
+            _resources.add(file1);
+            _resources.add(file2);
         }
+
     }
 }

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java (original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java Sat Nov  5 17:17:26 2011
@@ -36,14 +36,12 @@ import org.apache.openjpa.conf.OpenJPACo
 import org.apache.openjpa.conf.OpenJPAConfigurationImpl;
 import org.apache.openjpa.enhance.PCClassFileTransformer;
 import org.apache.openjpa.enhance.PCEnhancerAgent;
-import org.apache.openjpa.enhance.RuntimeUnenhancedClassesModes;
 import org.apache.openjpa.kernel.Bootstrap;
 import org.apache.openjpa.kernel.BrokerFactory;
 import org.apache.openjpa.kernel.ConnectionRetainModes;
 import org.apache.openjpa.lib.conf.Configuration;
 import org.apache.openjpa.lib.conf.ConfigurationProvider;
 import org.apache.openjpa.lib.conf.Configurations;
-import org.apache.openjpa.lib.conf.ProductDerivations;
 import org.apache.openjpa.lib.log.Log;
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.meta.AbstractCFMetaDataFactory;
@@ -51,10 +49,12 @@ import org.apache.openjpa.meta.MetaDataM
 import org.apache.openjpa.meta.MetaDataRepository;
 import org.apache.openjpa.persistence.osgi.BundleUtils;
 import org.apache.openjpa.persistence.validation.ValidationUtils;
+import org.apache.openjpa.util.ClassResolver;
 
 
 /**
- * Bootstrapping class that allows the creation of a stand-alone {@link EntityManager}.
+ * Bootstrapping class that allows the creation of a stand-alone
+ * {@link EntityManager}.
  *
  * @see javax.persistence.Persistence#createEntityManagerFactory(String,Map)
  * @published
@@ -68,27 +68,19 @@ public class PersistenceProviderImpl
     private static final Localizer _loc = Localizer.forPackage(PersistenceProviderImpl.class);
 
     private Log _log;
-    
     /**
      * Loads the entity manager specified by <code>name</code>, applying
-     * the properties in given map <code>m</code> as overrides to the properties defined
+     * the properties in <code>m</code> as overrides to the properties defined
      * in the XML configuration file for <code>name</code>. If <code>name</code>
      * is <code>null</code>, this method loads the XML in the resource
      * identified by <code>resource</code>, and uses the first resource found
      * when doing this lookup, regardless of the name specified in the XML
      * resource or the name of the jar that the resource is contained in.
-     * <br>
-     * This does not pool EntityManagersFactories.
-     * 
-     * @param name name of the persistence unit
-     * @param resource name of the resource. Normally, <tt>META-INF/persistence.xml</tt>, but not necessarily.
-     * @param m a map of properties that overrides properties found in the resource.
-     * 
-     * @return EntityManagerFactory or null if anything goes wrong during loading resources.
+     * This does no pooling of EntityManagersFactories.
+     * @return EntityManagerFactory or null
      */
     public OpenJPAEntityManagerFactory createEntityManagerFactory(String name, String resource, Map m) {
-        PersistenceProductDerivation pd = new PersistenceProductDerivation(BundleUtils.runningUnderOSGi());
-        ProductDerivations.load(resource, name);
+        PersistenceProductDerivation pd = new PersistenceProductDerivation();
         try {
             Object poolValue = Configurations.removeProperty(EMF_POOL, m);
             ConfigurationProvider cp = pd.load(resource, name, m);
@@ -96,9 +88,10 @@ public class PersistenceProviderImpl
                 return null;
             }
 
-            BrokerFactory factory = getBrokerFactory(cp, poolValue);
+            BrokerFactory factory = getBrokerFactory(cp, poolValue, BundleUtils.getBundleClassLoader());
             OpenJPAConfiguration conf = factory.getConfiguration();
-            _log = conf.getLog(OpenJPAConfiguration.LOG_RUNTIME);  
+            _log = conf.getLog(OpenJPAConfiguration.LOG_RUNTIME);            
+            pd.checkPuNameCollisions(_log,name);
             
             // add enhancer
             loadAgent(factory);
@@ -137,11 +130,12 @@ public class PersistenceProviderImpl
         }
     }
 
-    private BrokerFactory getBrokerFactory(ConfigurationProvider cp, Object poolValue) {
+    private BrokerFactory getBrokerFactory(ConfigurationProvider cp,
+        Object poolValue, ClassLoader loader) {
         // handle "true" and "false"
         if (poolValue instanceof String
             && ("true".equalsIgnoreCase((String) poolValue)
-             || "false".equalsIgnoreCase((String) poolValue)))
+                || "false".equalsIgnoreCase((String) poolValue)))
             poolValue = Boolean.valueOf((String) poolValue);
 
         if (poolValue != null && !(poolValue instanceof Boolean)) {
@@ -149,11 +143,10 @@ public class PersistenceProviderImpl
             throw new IllegalArgumentException(poolValue.toString());
         }
         
-        if (poolValue == null || !((Boolean) poolValue).booleanValue()) {
-            return Bootstrap.newBrokerFactory(cp);
-        } else {
-            return Bootstrap.getBrokerFactory(cp);
-        }
+        if (poolValue == null || !((Boolean) poolValue).booleanValue())
+            return Bootstrap.newBrokerFactory(cp, loader);
+        else
+            return Bootstrap.getBrokerFactory(cp, loader);
     }
 
     public OpenJPAEntityManagerFactory createEntityManagerFactory(String name, Map m) {
@@ -161,7 +154,7 @@ public class PersistenceProviderImpl
     }
 
     public OpenJPAEntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo pui, Map m) {
-        PersistenceProductDerivation pd = new PersistenceProductDerivation(BundleUtils.runningUnderOSGi());
+        PersistenceProductDerivation pd = new PersistenceProductDerivation();
         try {
             Object poolValue = Configurations.removeProperty(EMF_POOL, m);
             ConfigurationProvider cp = pd.load(pui, m);
@@ -179,14 +172,20 @@ public class PersistenceProviderImpl
                 transformerException = e;
             }
 
-            // if the BrokerImpl hasn't been specified, switch to the non-finalizing one, 
-            // since anything claiming to be a container should be doing proper resource management.
+            // if the BrokerImpl hasn't been specified, switch to the
+            // non-finalizing one, since anything claiming to be a container
+            // should be doing proper resource management.
             if (!Configurations.containsProperty(BrokerValue.KEY, cp.getProperties())) {
                 cp.addProperty("openjpa." + BrokerValue.KEY, getDefaultBrokerAlias());
             }
 
-            BrokerFactory factory = getBrokerFactory(cp, poolValue);
-            
+            // OPENJPA-1491 If running under OSGi, use the Bundle's ClassLoader instead of the application one
+            BrokerFactory factory;
+            if (BundleUtils.runningUnderOSGi()) {
+                factory = getBrokerFactory(cp, poolValue, BundleUtils.getBundleClassLoader());
+            } else {
+                factory = getBrokerFactory(cp, poolValue, pui.getClassLoader());
+            }
 
             OpenJPAConfiguration conf = factory.getConfiguration();
             setPersistenceEnvironmentInfo(conf, pui);
@@ -272,34 +271,44 @@ public class PersistenceProviderImpl
             final ClassLoader tmpLoader, OpenJPAConfiguration conf) {
             cp.setInto(conf);
             // use the temporary loader for everything
-            conf.addClassLoader(tmpLoader);
+            conf.setClassResolver(new ClassResolver() {
+                public ClassLoader getClassLoader(Class<?> context, ClassLoader env) {
+                    return tmpLoader;
+                }
+            });
             conf.setReadOnly(Configuration.INIT_STATE_FREEZING);
 
             MetaDataRepository repos = conf.getMetaDataRepositoryInstance();
             repos.setResolve(MetaDataModes.MODE_MAPPING, false);
-            _trans = new PCClassFileTransformer(repos, Configurations.parseProperties(props), tmpLoader);
+            _trans = new PCClassFileTransformer(repos,
+                Configurations.parseProperties(props), tmpLoader);
         }
 
         public byte[] transform(ClassLoader cl, String name,
-        		Class<?> previousVersion, ProtectionDomain pd, byte[] bytes)
+            Class<?> previousVersion, ProtectionDomain pd, byte[] bytes)
             throws IllegalClassFormatException {
             return _trans.transform(cl, name, previousVersion, pd, bytes);
         }
 	}
     
     /**
-     * Loads the PCEnhancerAgent.
+     * This private worker method will attempt load the PCEnhancerAgent.
      */
     private void loadAgent(BrokerFactory factory) {
         OpenJPAConfiguration conf = factory.getConfiguration();
-        if (conf.getRuntimeUnenhancedClassesConstant() == RuntimeUnenhancedClassesModes.SUPPORTED
-         && conf.getDynamicEnhancementAgent()) {
-            boolean res = PCEnhancerAgent.loadDynamicAgent(conf);
-         }
+        Log log = conf.getLog(OpenJPAConfiguration.LOG_RUNTIME);
+
+        if (conf.getDynamicEnhancementAgent() == true) {
+            boolean res = PCEnhancerAgent.loadDynamicAgent(log);
+            if (log.isInfoEnabled() && res == true ){
+                log.info(_loc.get("dynamic-agent"));
+            }
+        }
     }
     
     /**
-     * Sets up the proper LifecycleEventManager type based on if the <tt>javax.validation APIs</tt> are
+     * This private worker method will attempt to setup the proper
+     * LifecycleEventManager type based on if the javax.validation APIs are
      * available and a ValidatorImpl is required by the configuration.
      * @param log
      * @param conf
@@ -309,7 +318,8 @@ public class PersistenceProviderImpl
         OpenJPAConfiguration conf = factory.getConfiguration();
         Log log = conf.getLog(OpenJPAConfiguration.LOG_RUNTIME);
 
-        if ((ValidationUtils.setupValidation(conf) == true) && log.isInfoEnabled()) {
+        if ((ValidationUtils.setupValidation(conf) == true) &&
+                log.isInfoEnabled()) {
             log.info(_loc.get("vlem-creation-info"));
         }
     }

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceUnitInfoImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceUnitInfoImpl.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceUnitInfoImpl.java (original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceUnitInfoImpl.java Sat Nov  5 17:17:26 2011
@@ -62,12 +62,14 @@ public class PersistenceUnitInfoImpl
     public static final String PERSISTENCE_VERSION = "PersistenceVersion";
     
 
-    private static final Localizer s_loc = Localizer.forPackage(PersistenceUnitInfoImpl.class);
+    private static final Localizer s_loc = Localizer.forPackage
+        (PersistenceUnitInfoImpl.class);
 
     private String _name;
     private final HashMap<Object,Object> _props = new HashMap<Object, Object>();
-    private PersistenceUnitTransactionType _transType = PersistenceUnitTransactionType.RESOURCE_LOCAL;
-    private ClassLoader _loader;
+    private PersistenceUnitTransactionType _transType =
+        PersistenceUnitTransactionType.RESOURCE_LOCAL;
+
     private String _providerClassName;
     private List<String> _mappingFileNames;
     private List<String> _entityClassNames;
@@ -96,11 +98,8 @@ public class PersistenceUnitInfoImpl
     // - an application client jar file
     private URL _root;
 
-    public PersistenceUnitInfoImpl() {
-    }
-    
     public ClassLoader getClassLoader() {
-        return _loader;
+        return null;
     }
 
     public ClassLoader getNewTempClassLoader() {
@@ -571,8 +570,4 @@ public class PersistenceUnitInfoImpl
     public void setSharedCacheMode(SharedCacheMode mode) { 
         _sharedCacheMode = mode;
     }
-    
-    public String toString() {
-    	return getPersistenceXmlFileUrl().toString() + '#' + getPersistenceUnitName();
-    }
 }

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/StoreCacheImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/StoreCacheImpl.java?rev=1197994&r1=1197993&r2=1197994&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/StoreCacheImpl.java (original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/StoreCacheImpl.java Sat Nov  5 17:17:26 2011
@@ -141,7 +141,7 @@ public class StoreCacheImpl 
      */
     private ClassMetaData getMetaData(Class cls) {
         try {
-            return _repos.getMetaData(cls, true);
+            return _repos.getMetaData(cls, null, true);
         } catch (RuntimeException re) {
             throw PersistenceExceptions.toPersistenceException(re);
         }



Mime
View raw message