Index: api2/test/schema/jdoconfig/Negative0/META-INF/jdoconfig.xml =================================================================== --- api2/test/schema/jdoconfig/Negative0/META-INF/jdoconfig.xml (revision 562509) +++ api2/test/schema/jdoconfig/Negative0/META-INF/jdoconfig.xml (working copy) @@ -1 +0,0 @@ - Index: api2/test/schema/jdoconfig/Positive0/META-INF/jdoconfig.xml =================================================================== --- api2/test/schema/jdoconfig/Positive0/META-INF/jdoconfig.xml (revision 562509) +++ api2/test/schema/jdoconfig/Positive0/META-INF/jdoconfig.xml (working copy) @@ -1,251 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Index: api2/test/schema/jdoconfig/Negative1/META-INF/jdoconfig.xml =================================================================== --- api2/test/schema/jdoconfig/Negative1/META-INF/jdoconfig.xml (revision 562509) +++ api2/test/schema/jdoconfig/Negative1/META-INF/jdoconfig.xml (working copy) @@ -1,8 +0,0 @@ - - - - - - Index: api2/test/schema/jdoconfig/Positive1/1a/META-INF/jdoconfig.xml =================================================================== --- api2/test/schema/jdoconfig/Positive1/1a/META-INF/jdoconfig.xml (revision 562509) +++ api2/test/schema/jdoconfig/Positive1/1a/META-INF/jdoconfig.xml (working copy) @@ -1,17 +0,0 @@ - - - - - - - - - - Index: api2/test/schema/jdoconfig/Positive1/1b/META-INF/jdoconfig.xml =================================================================== --- api2/test/schema/jdoconfig/Positive1/1b/META-INF/jdoconfig.xml (revision 562509) +++ api2/test/schema/jdoconfig/Positive1/1b/META-INF/jdoconfig.xml (working copy) @@ -1,15 +0,0 @@ - - - - - - - - Index: api2/test/schema/jdoconfig/Negative2/META-INF/jdoconfig.xml =================================================================== --- api2/test/schema/jdoconfig/Negative2/META-INF/jdoconfig.xml (revision 562509) +++ api2/test/schema/jdoconfig/Negative2/META-INF/jdoconfig.xml (working copy) @@ -1,11 +0,0 @@ - - - - - - - - - \ No newline at end of file Index: api2/test/schema/jdoconfig/Negative3/META-INF/jdoconfig.xml =================================================================== --- api2/test/schema/jdoconfig/Negative3/META-INF/jdoconfig.xml (revision 562509) +++ api2/test/schema/jdoconfig/Negative3/META-INF/jdoconfig.xml (working copy) @@ -1,20 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file Index: api2/test/schema/jdoconfig/Positive3/META-INF/jdoconfig.xml =================================================================== --- api2/test/schema/jdoconfig/Positive3/META-INF/jdoconfig.xml (revision 562509) +++ api2/test/schema/jdoconfig/Positive3/META-INF/jdoconfig.xml (working copy) @@ -1,13 +0,0 @@ - - - - - - - Index: api2/test/schema/jdoconfig/Positive3/META-INF/services/javax.jdo.PersistenceManagerFactory =================================================================== --- api2/test/schema/jdoconfig/Positive3/META-INF/services/javax.jdo.PersistenceManagerFactory (revision 562509) +++ api2/test/schema/jdoconfig/Positive3/META-INF/services/javax.jdo.PersistenceManagerFactory (working copy) @@ -1 +0,0 @@ -class.positive3.pmf0 \ No newline at end of file Index: api2/test/schema/jdoconfig/Negative4/META-INF/jdoconfig.xml =================================================================== --- api2/test/schema/jdoconfig/Negative4/META-INF/jdoconfig.xml (revision 562509) +++ api2/test/schema/jdoconfig/Negative4/META-INF/jdoconfig.xml (working copy) @@ -1,21 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file Index: api2/test/schema/jdoconfig/Positive4/META-INF/jdoconfig.xml =================================================================== --- api2/test/schema/jdoconfig/Positive4/META-INF/jdoconfig.xml (revision 562509) +++ api2/test/schema/jdoconfig/Positive4/META-INF/jdoconfig.xml (working copy) @@ -1,13 +0,0 @@ - - - - - - - Index: api2/test/schema/jdoconfig/Positive4/META-INF/services/javax.jdo.PersistenceManagerFactory =================================================================== --- api2/test/schema/jdoconfig/Positive4/META-INF/services/javax.jdo.PersistenceManagerFactory (revision 562509) +++ api2/test/schema/jdoconfig/Positive4/META-INF/services/javax.jdo.PersistenceManagerFactory (working copy) @@ -1,3 +0,0 @@ - -#this is a comment -class.positive4.pmf0 # this is another comment \ No newline at end of file Index: api2/test/schema/jdoconfig/Negative5/META-INF/jdoconfig.xml =================================================================== --- api2/test/schema/jdoconfig/Negative5/META-INF/jdoconfig.xml (revision 562509) +++ api2/test/schema/jdoconfig/Negative5/META-INF/jdoconfig.xml (working copy) @@ -1,21 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file Index: api2/test/schema/jdoconfig/Positive5/META-INF/jdoconfig.xml =================================================================== --- api2/test/schema/jdoconfig/Positive5/META-INF/jdoconfig.xml (revision 562509) +++ api2/test/schema/jdoconfig/Positive5/META-INF/jdoconfig.xml (working copy) @@ -1,13 +0,0 @@ - - - - - - - Index: api2/test/schema/jdoconfig/Positive5/META-INF/services/javax.jdo.PersistenceManagerFactory =================================================================== --- api2/test/schema/jdoconfig/Positive5/META-INF/services/javax.jdo.PersistenceManagerFactory (revision 562509) +++ api2/test/schema/jdoconfig/Positive5/META-INF/services/javax.jdo.PersistenceManagerFactory (working copy) @@ -1 +0,0 @@ -class.positive5.pmf0# this is a comment without whitespace separating it from the uncommented text \ No newline at end of file Index: api2/test/schema/jdoconfig/Negative6/6a/META-INF/jdoconfig.xml =================================================================== --- api2/test/schema/jdoconfig/Negative6/6a/META-INF/jdoconfig.xml (revision 562509) +++ api2/test/schema/jdoconfig/Negative6/6a/META-INF/jdoconfig.xml (working copy) @@ -1,16 +0,0 @@ - - - - - - - - - \ No newline at end of file Index: api2/test/schema/jdoconfig/Negative6/6b/META-INF/jdoconfig.xml =================================================================== --- api2/test/schema/jdoconfig/Negative6/6b/META-INF/jdoconfig.xml (revision 562509) +++ api2/test/schema/jdoconfig/Negative6/6b/META-INF/jdoconfig.xml (working copy) @@ -1,16 +0,0 @@ - - - - - - - - - \ No newline at end of file Index: api2/test/schema/jdoconfig/Negative8/META-INF/services/javax.jdo.PersistenceManagerFactory =================================================================== --- api2/test/schema/jdoconfig/Negative8/META-INF/services/javax.jdo.PersistenceManagerFactory (revision 562509) +++ api2/test/schema/jdoconfig/Negative8/META-INF/services/javax.jdo.PersistenceManagerFactory (working copy) @@ -1,3 +0,0 @@ -# there are -# only comments -# in this file \ No newline at end of file Index: api2/test/schema/jdoconfig/Positive00/META-INF/jdoconfig.xml =================================================================== --- api2/test/schema/jdoconfig/Positive00/META-INF/jdoconfig.xml (revision 562509) +++ api2/test/schema/jdoconfig/Positive00/META-INF/jdoconfig.xml (working copy) @@ -13,32 +13,33 @@ properties. --> + class="class.positive00.pmf0" + connection-driver-name="connection-driver-name.positive00.pmf0" + connection-factory-name="connection-factory-name.positive00.pmf0" + connection-factory2-name="connection-factory2-name.positive00.pmf0" + connection-password="connection-password.positive00.pmf0" + connection-url="connection-url.positive00.pmf0" + connection-user-name="connection-user-name.positive00.pmf0" + ignore-cache="ignore-cache.positive00.pmf0" + mapping="mapping.positive00.pmf0" + multithreaded="multithreaded.positive00.pmf0" + nontransactional-read="nontransactional-read.positive00.pmf0" + nontransactional-write="nontransactional-write.positive00.pmf0" + optimistic="optimistic.positive00.pmf0" + name="name.positive00.pmf0" + persistence-unit-name="persistence-unit-name.positive00.pmf0" + restore-values="restore-values.positive00.pmf0" + retain-values="retain-values.positive00.pmf0" + detach-all-on-commit="detach-all-on-commit.positive00.pmf0" + server-time-zone-id="server-time-zone-id.positive00.pmf0"> @@ -49,66 +50,69 @@ + value="class.positive00.pmf1"/> + value="connection-driver-name.positive00.pmf1"/> + value="connection-factory-name.positive00.pmf1"/> + value="connection-factory2-name.positive00.pmf1"/> + value="connection-password.positive00.pmf1"/> + value="connection-url.positive00.pmf1"/> + value="connection-user-name.positive00.pmf1"/> + value="ignore-cache.positive00.pmf1"/> + value="mapping.positive00.pmf1"/> + value="multithreaded.positive00.pmf1"/> + value="nontransactional-read.positive00.pmf1"/> + value="nontransactional-write.positive00.pmf1"/> + value="optimistic.positive00.pmf1"/> + + value="persistence-unit-name.positive00.pmf1"/> + value="detach-all-on-commit.positive00.pmf1"/> + value="restore-values.positive00.pmf1"/> + value="retain-values.positive00.pmf1"/> + value="server-time-zone-id.positive00.pmf1"/> @@ -120,66 +124,69 @@ + value="class.positive00.pmf2"/> + value="connection-driver-name.positive00.pmf2"/> + value="connection-factory-name.positive00.pmf2"/> + value="connection-factory2-name.positive00.pmf2"/> + value="connection-password.positive00.pmf2"/> + value="connection-url.positive00.pmf2"/> + value="connection-user-name.positive00.pmf2"/> + value="ignore-cache.positive00.pmf2"/> + value="mapping.positive00.pmf2"/> + value="multithreaded.positive00.pmf2"/> + value="nontransactional-read.positive00.pmf2"/> + value="nontransactional-write.positive00.pmf2"/> + value="optimistic.positive00.pmf2"/> + + value="persistence-unit-name.positive00.pmf2"/> + value="detach-all-on-commit.positive00.pmf2"/> + value="restore-values.positive00.pmf2"/> + value="retain-values.positive00.pmf2"/> + value="server-time-zone-id.positive00.pmf2"/> @@ -188,37 +195,38 @@ elements. --> + class="class.positive00.pmf3" + connection-driver-name="connection-driver-name.positive00.pmf3" + connection-factory-name="connection-factory-name.positive00.pmf3" + connection-factory2-name="connection-factory2-name.positive00.pmf3" + connection-password="connection-password.positive00.pmf3" + connection-url="connection-url.positive00.pmf3" + connection-user-name="connection-user-name.positive00.pmf3" + ignore-cache="ignore-cache.positive00.pmf3" + mapping="mapping.positive00.pmf3" + multithreaded="multithreaded.positive00.pmf3" + nontransactional-read="nontransactional-read.positive00.pmf3" + nontransactional-write="nontransactional-write.positive00.pmf3" + optimistic="optimistic.positive00.pmf3" + name="name.positive00.pmf3" + persistence-unit-name="persistence-unit-name.positive00.pmf3" + restore-values="restore-values.positive00.pmf3" + retain-values="retain-values.positive00.pmf3" + detach-all-on-commit="detach-all-on-commit.positive00.pmf3" + server-time-zone-id="server-time-zone-id.positive00.pmf3"> - - + + @@ -226,26 +234,27 @@ PMF config using standard attributes plus nonstandard attributes. --> + property.positive00.pmf4.name0="property.positive00.pmf4.value0" + property.positive00.pmf4.name1="property.positive00.pmf4.value1"/> Index: api2/test/schema/jdoconfig/Negative01/META-INF/jdoconfig.xml =================================================================== --- api2/test/schema/jdoconfig/Negative01/META-INF/jdoconfig.xml (revision 562509) +++ api2/test/schema/jdoconfig/Negative01/META-INF/jdoconfig.xml (working copy) @@ -3,6 +3,6 @@ xmlns="http://java.sun.com/xml/ns/jdo/jdoconfig" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - + Index: api2/test/schema/jdoconfig/Positive01/1a/META-INF/jdoconfig.xml =================================================================== --- api2/test/schema/jdoconfig/Positive01/1a/META-INF/jdoconfig.xml (revision 562509) +++ api2/test/schema/jdoconfig/Positive01/1a/META-INF/jdoconfig.xml (working copy) @@ -12,6 +12,6 @@ + name="name.positive01"/> Index: api2/test/schema/jdoconfig/Positive01/1b/META-INF/jdoconfig.xml =================================================================== --- api2/test/schema/jdoconfig/Positive01/1b/META-INF/jdoconfig.xml (revision 562509) +++ api2/test/schema/jdoconfig/Positive01/1b/META-INF/jdoconfig.xml (working copy) @@ -10,6 +10,6 @@ + name="name.positive01"/> Index: api2/test/schema/jdoconfig/Negative02/META-INF/jdoconfig.xml =================================================================== --- api2/test/schema/jdoconfig/Negative02/META-INF/jdoconfig.xml (revision 562509) +++ api2/test/schema/jdoconfig/Negative02/META-INF/jdoconfig.xml (working copy) @@ -3,7 +3,7 @@ xmlns="http://java.sun.com/xml/ns/jdo/jdoconfig" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - + Index: api2/test/schema/jdoconfig/Negative03/META-INF/jdoconfig.xml =================================================================== --- api2/test/schema/jdoconfig/Negative03/META-INF/jdoconfig.xml (revision 562509) +++ api2/test/schema/jdoconfig/Negative03/META-INF/jdoconfig.xml (working copy) @@ -8,12 +8,12 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://java.sun.com/xml/ns/jdo/jdoconfig"> - + + name="name.negative3"/> + name="name.negative3"/> Index: api2/test/schema/jdoconfig/Positive03/META-INF/services/javax.jdo.PersistenceManagerFactory =================================================================== --- api2/test/schema/jdoconfig/Positive03/META-INF/services/javax.jdo.PersistenceManagerFactory (revision 562509) +++ api2/test/schema/jdoconfig/Positive03/META-INF/services/javax.jdo.PersistenceManagerFactory (working copy) @@ -1 +1 @@ -class.positive3.pmf0 \ No newline at end of file +class.positive03.pmf0 \ No newline at end of file Index: api2/test/schema/jdoconfig/Negative04/META-INF/jdoconfig.xml =================================================================== --- api2/test/schema/jdoconfig/Negative04/META-INF/jdoconfig.xml (revision 562509) +++ api2/test/schema/jdoconfig/Negative04/META-INF/jdoconfig.xml (working copy) @@ -8,12 +8,12 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://java.sun.com/xml/ns/jdo/jdoconfig"> - + + name="persistence-unit-name.negative4.value0"> + name="name" + value="name.negative4.value1"/> Index: api2/test/schema/jdoconfig/Positive04/META-INF/services/javax.jdo.PersistenceManagerFactory =================================================================== --- api2/test/schema/jdoconfig/Positive04/META-INF/services/javax.jdo.PersistenceManagerFactory (revision 562509) +++ api2/test/schema/jdoconfig/Positive04/META-INF/services/javax.jdo.PersistenceManagerFactory (working copy) @@ -1,3 +1,3 @@ #this is a comment -class.positive4.pmf0 # this is another comment \ No newline at end of file +class.positive04.pmf0 # this is another comment \ No newline at end of file Index: api2/test/schema/jdoconfig/Positive05/META-INF/services/javax.jdo.PersistenceManagerFactory =================================================================== --- api2/test/schema/jdoconfig/Positive05/META-INF/services/javax.jdo.PersistenceManagerFactory (revision 562509) +++ api2/test/schema/jdoconfig/Positive05/META-INF/services/javax.jdo.PersistenceManagerFactory (working copy) @@ -1 +1 @@ -class.positive5.pmf0# this is a comment without whitespace separating it from the uncommented text \ No newline at end of file +class.positive05.pmf0# this is a comment without whitespace separating it from the uncommented text \ No newline at end of file Index: api2/test/schema/jdoconfig/Negative06/6a/META-INF/jdoconfig.xml =================================================================== --- api2/test/schema/jdoconfig/Negative06/6a/META-INF/jdoconfig.xml (revision 562509) +++ api2/test/schema/jdoconfig/Negative06/6a/META-INF/jdoconfig.xml (working copy) @@ -8,9 +8,9 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://java.sun.com/xml/ns/jdo/jdoconfig"> - + + name="name.negative6"/> \ No newline at end of file Index: api2/test/schema/jdoconfig/Negative06/6b/META-INF/jdoconfig.xml =================================================================== --- api2/test/schema/jdoconfig/Negative06/6b/META-INF/jdoconfig.xml (revision 562509) +++ api2/test/schema/jdoconfig/Negative06/6b/META-INF/jdoconfig.xml (working copy) @@ -8,9 +8,9 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://java.sun.com/xml/ns/jdo/jdoconfig"> - + + name="name.negative6"/> \ No newline at end of file Index: api2/test/schema/jdoconfig/Positive06/META-INF/jdoconfig.xml =================================================================== --- api2/test/schema/jdoconfig/Positive06/META-INF/jdoconfig.xml (revision 0) +++ api2/test/schema/jdoconfig/Positive06/META-INF/jdoconfig.xml (revision 0) @@ -0,0 +1,43 @@ + + + + + + + + + + + Index: api2/test/schema/jdoconfig/Positive07/META-INF/jdoconfig.xml =================================================================== --- api2/test/schema/jdoconfig/Positive07/META-INF/jdoconfig.xml (revision 0) +++ api2/test/schema/jdoconfig/Positive07/META-INF/jdoconfig.xml (revision 0) @@ -0,0 +1,45 @@ + + + + + + + + + + + + Index: api2/test/java/javax/jdo/JDOHelperConfigTest.java =================================================================== --- api2/test/java/javax/jdo/JDOHelperConfigTest.java (revision 562509) +++ api2/test/java/javax/jdo/JDOHelperConfigTest.java (working copy) @@ -23,11 +23,11 @@ import javax.jdo.util.BatchTestRunner; import java.io.IOException; import java.io.InputStream; +import java.net.URLClassLoader; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Random; -import java.net.URLClassLoader; /** * Tests class javax.jdo.JDOHelper for META-INF/jdoconfig.xml compliance. @@ -42,197 +42,108 @@ return new TestSuite(JDOHelperConfigTest.class); } - protected static String JDOCONFIG_CLASSPATH_PREFIX = - System.getProperty("basedir") + "/test/schema/jdoconfig"; + protected static String JDOCONFIG_CLASSPATH_PREFIX + = initJDOConfigClasspathPrefix(); - protected static Random RANDOM = new Random(System.currentTimeMillis()); - - /** - * Tests JDOHelper.getPersistenceUnitProperties using file - * Positive0-jdoconfig.xml and PU name - * "persistence-unit-name.positive0.pmf0" - */ - public void testPositive00_PMF0_GetNamedPMFProperties() throws IOException { - - try { - URLClassLoader loader = new JDOConfigTestClassLoader( - JDOCONFIG_CLASSPATH_PREFIX, - getClass().getClassLoader()); - ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Positive0", loader); - - Map expected = prepareInitialExpectedMap("positive0.pmf0", 2); - String name = (String) expected.get(PROPERTY_PERSISTENCE_UNIT_NAME); - - Map actual = JDOHelper.getPersistenceUnitProperties(name, loader); - - assertNotNull("No properties found", actual); - assertEqualProperties(expected, actual); - } catch (Exception e) { - e.printStackTrace(); + protected static String initJDOConfigClasspathPrefix() { + String basedir = System.getProperty("basedir"); + if (basedir != null) { + if (!basedir.endsWith("/")) { + basedir += "/"; + } + } else { + basedir = ""; } + return basedir + "test/schema/jdoconfig"; } - /** - * Tests JDOHelper.getPersistenceUnitProperties using file - * Positive0-jdoconfig.xml and PU name - * "persistence-unit-name.positive0.pmf1" - */ - public void testPositive00_PMF1_GetNamedPMFProperties() throws IOException { - URLClassLoader loader = new JDOConfigTestClassLoader( - JDOCONFIG_CLASSPATH_PREFIX, - getClass().getClassLoader()); - ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Positive0", loader); + protected static Random RANDOM = new Random(System.currentTimeMillis()); - Map expected = prepareInitialExpectedMap("positive0.pmf1", 2); - String name = (String) expected.get(PROPERTY_PERSISTENCE_UNIT_NAME); - - Map actual = JDOHelper.getPersistenceUnitProperties(name, loader); - - assertNotNull("No properties found", actual); - assertEqualProperties(expected, actual); - } - - /** - * Tests JDOHelper.getPersistenceUnitProperties using file - * Positive0-jdoconfig.xml and PU name - * "persistence-unit-name.positive0.pmf2" - */ - public void testPositive00_PMF2_GetNamedPMFProperties() throws IOException { - URLClassLoader loader = new JDOConfigTestClassLoader( - JDOCONFIG_CLASSPATH_PREFIX, - getClass().getClassLoader()); - ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Positive0", loader); - - Map expected = prepareInitialExpectedMap("positive0.pmf2", 2); - String name = (String) expected.get(PROPERTY_PERSISTENCE_UNIT_NAME); - - Map actual = JDOHelper.getPersistenceUnitProperties(name, loader); - - assertNotNull("No properties found", actual); - assertEqualProperties(expected, actual); - } - - /** - * Tests JDOHelper.getPersistenceUnitProperties using file - * Positive0-jdoconfig.xml and PU name - * "persistence-unit-name.positive0.pmf3" - */ - public void testPositive00_PMF3_GetNamedPMFProperties() throws IOException { - URLClassLoader loader = new JDOConfigTestClassLoader( - JDOCONFIG_CLASSPATH_PREFIX, - getClass().getClassLoader()); - ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Positive0", loader); - - Map expected = prepareInitialExpectedMap("positive0.pmf3", 2, 2); - String name = (String) expected.get(PROPERTY_PERSISTENCE_UNIT_NAME); - - Map actual = JDOHelper.getPersistenceUnitProperties(name, loader); - - assertNotNull("No properties found", actual); - assertEqualProperties(expected, actual); - } - - /** - * Tests JDOHelper.getPersistenceUnitProperties using file - * Positive0-jdoconfig.xml and PU name - * "persistence-unit-name.positive0.pmf4" - */ - public void testPositive00_PMF4_GetNamedPMFProperties() throws IOException { - URLClassLoader loader = new JDOConfigTestClassLoader( - JDOCONFIG_CLASSPATH_PREFIX, - getClass().getClassLoader()); - ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Positive0", loader); - - Map expected = prepareInitialExpectedMap("positive0.pmf4", 0, 2); - String name = (String) expected.get(PROPERTY_PERSISTENCE_UNIT_NAME); - - Map actual = JDOHelper.getPersistenceUnitProperties(name, loader); - - assertNotNull("No properties found", actual); - assertEqualProperties(expected, actual); - } - - public Map prepareInitialExpectedMap(String testVariant) { - return prepareInitialExpectedMap(testVariant, 0, 0); - } - public Map prepareInitialExpectedMap(String testVariant, int numListeners) { - return prepareInitialExpectedMap(testVariant, numListeners, 0); - } - public Map prepareInitialExpectedMap( - String testVariant, - int numListeners, - int numProperties + protected Map prepareInitialExpectedMap( + String testVariant, + int listenerCount, + int vendorSpecificPropertyCount, + boolean excludeName, + boolean excludePUName ) { Map expected = new HashMap(); + if (!excludeName) { + expected.put( + PROPERTY_NAME, + PMF_ATTRIBUTE_NAME + "." + testVariant); + } + if (!excludePUName) { + expected.put( + PROPERTY_PERSISTENCE_UNIT_NAME, + PMF_ATTRIBUTE_PERSISTENCE_UNIT_NAME + "." + testVariant); + } + expected.put(PROPERTY_PERSISTENCE_MANAGER_FACTORY_CLASS, - PMF_ATTRIBUTE_CLASS + "." + testVariant); + PMF_ATTRIBUTE_CLASS + "." + testVariant); expected.put( - PROPERTY_CONNECTION_DRIVER_NAME, - PMF_ATTRIBUTE_CONNECTION_DRIVER_NAME + "." + testVariant); + PROPERTY_CONNECTION_DRIVER_NAME, + PMF_ATTRIBUTE_CONNECTION_DRIVER_NAME + "." + testVariant); expected.put( - PROPERTY_CONNECTION_FACTORY_NAME, - PMF_ATTRIBUTE_CONNECTION_FACTORY_NAME + "." + testVariant); + PROPERTY_CONNECTION_FACTORY_NAME, + PMF_ATTRIBUTE_CONNECTION_FACTORY_NAME + "." + testVariant); expected.put( - PROPERTY_CONNECTION_FACTORY2_NAME, - PMF_ATTRIBUTE_CONNECTION_FACTORY2_NAME + "." + testVariant); + PROPERTY_CONNECTION_FACTORY2_NAME, + PMF_ATTRIBUTE_CONNECTION_FACTORY2_NAME + "." + testVariant); expected.put( - PROPERTY_CONNECTION_PASSWORD, - PMF_ATTRIBUTE_CONNECTION_PASSWORD + "." + testVariant); + PROPERTY_CONNECTION_PASSWORD, + PMF_ATTRIBUTE_CONNECTION_PASSWORD + "." + testVariant); expected.put( - PROPERTY_CONNECTION_URL, - PMF_ATTRIBUTE_CONNECTION_URL + "." + testVariant); + PROPERTY_CONNECTION_URL, + PMF_ATTRIBUTE_CONNECTION_URL + "." + testVariant); expected.put( - PROPERTY_CONNECTION_USER_NAME, - PMF_ATTRIBUTE_CONNECTION_USER_NAME + "." + testVariant); + PROPERTY_CONNECTION_USER_NAME, + PMF_ATTRIBUTE_CONNECTION_USER_NAME + "." + testVariant); expected.put( - PROPERTY_IGNORE_CACHE, - PMF_ATTRIBUTE_IGNORE_CACHE + "." + testVariant); + PROPERTY_IGNORE_CACHE, + PMF_ATTRIBUTE_IGNORE_CACHE + "." + testVariant); expected.put( - PROPERTY_MAPPING, - PMF_ATTRIBUTE_MAPPING + "." + testVariant); + PROPERTY_MAPPING, + PMF_ATTRIBUTE_MAPPING + "." + testVariant); expected.put( - PROPERTY_MULTITHREADED, - PMF_ATTRIBUTE_MULTITHREADED + "." + testVariant); + PROPERTY_MULTITHREADED, + PMF_ATTRIBUTE_MULTITHREADED + "." + testVariant); expected.put( - PROPERTY_NONTRANSACTIONAL_READ, - PMF_ATTRIBUTE_NONTRANSACTIONAL_READ + "." + testVariant); + PROPERTY_NONTRANSACTIONAL_READ, + PMF_ATTRIBUTE_NONTRANSACTIONAL_READ + "." + testVariant); expected.put( - PROPERTY_NONTRANSACTIONAL_WRITE, - PMF_ATTRIBUTE_NONTRANSACTIONAL_WRITE + "." + testVariant); + PROPERTY_NONTRANSACTIONAL_WRITE, + PMF_ATTRIBUTE_NONTRANSACTIONAL_WRITE + "." + testVariant); expected.put( - PROPERTY_OPTIMISTIC, - PMF_ATTRIBUTE_OPTIMISTIC + "." + testVariant); + PROPERTY_OPTIMISTIC, + PMF_ATTRIBUTE_OPTIMISTIC + "." + testVariant); expected.put( - PROPERTY_PERSISTENCE_UNIT_NAME, - PMF_ATTRIBUTE_PERSISTENCE_UNIT_NAME + "." + testVariant); + PROPERTY_RESTORE_VALUES, + PMF_ATTRIBUTE_RESTORE_VALUES + "." + testVariant); expected.put( - PROPERTY_RESTORE_VALUES, - PMF_ATTRIBUTE_RESTORE_VALUES + "." + testVariant); + PROPERTY_RETAIN_VALUES, + PMF_ATTRIBUTE_RETAIN_VALUES + "." + testVariant); expected.put( - PROPERTY_RETAIN_VALUES, - PMF_ATTRIBUTE_RETAIN_VALUES + "." + testVariant); + PROPERTY_DETACH_ALL_ON_COMMIT, + PMF_ATTRIBUTE_DETACH_ALL_ON_COMMIT + "." + testVariant); expected.put( - PROPERTY_DETACH_ALL_ON_COMMIT, - PMF_ATTRIBUTE_DETACH_ALL_ON_COMMIT + "." + testVariant); - expected.put( - PROPERTY_SERVER_TIME_ZONE_ID, - PMF_ATTRIBUTE_SERVER_TIME_ZONE_ID + "." + testVariant); + PROPERTY_SERVER_TIME_ZONE_ID, + PMF_ATTRIBUTE_SERVER_TIME_ZONE_ID + "." + testVariant); // listeners - for (int i = 0; i < numListeners; i++) { + for (int i = 0; i < listenerCount; i++) { expected.put( - PROPERTY_PREFIX_INSTANCE_LIFECYCLE_LISTENER + - "listener." + testVariant + ".listener" + i, - "classes." + testVariant + ".classes" + i + PROPERTY_PREFIX_INSTANCE_LIFECYCLE_LISTENER + + "listener." + testVariant + ".listener" + i, + "classes." + testVariant + ".classes" + i ); } - // properties - for (int i = 0; i < numProperties; i++) { + // vendor-specific properties + for (int i = 0; i < vendorSpecificPropertyCount; i++) { expected.put( - "property." + testVariant + ".name" + i, - "property." + testVariant + ".value" + i + "property." + testVariant + ".name" + i, + "property." + testVariant + ".value" + i ); } @@ -248,240 +159,364 @@ String actualValue = (String) actual.get(key); assertEquals( - "Actual property at key [" + key + "] with value [" + - actualValue + "] not equal to expected value [" + - expectedValue + "]", - expectedValue, - actualValue); + "Actual property at key [" + key + "] with value [" + + actualValue + "] not equal to expected value [" + + expectedValue + "]", + expectedValue, + actualValue); } } - /** - * Tests JDOHelper.getPersistenceUnitProperties using file - * Positive0-jdoconfig.xml and PU name - * "persistence-unit-name.positive0.pmf0" - */ - public void testPositive01_DuplicatePUsInDifferentConfigFilesButNotRequested() throws IOException { - + protected void doPositiveTest( + String[] classpaths, + String testVariantName, + int listenerCount, + int vendorSpecificPropertyCount, + boolean checkEqualProperties) + throws IOException { + URLClassLoader loader = new JDOConfigTestClassLoader( JDOCONFIG_CLASSPATH_PREFIX, getClass().getClassLoader()); - ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Positive1/1a", loader); - ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Positive1/1b", loader); - Map props = JDOHelper.getPersistenceUnitProperties(null, loader); - assertNotNull(props); + for (int i = 0; i < classpaths.length; i++) { + ClasspathHelper.addFile(classpaths[i], loader); + } + + Map expected = prepareInitialExpectedMap( + testVariantName, + listenerCount, + vendorSpecificPropertyCount, + false, + false); + + String name = testVariantName == null + ? null + : (String) expected.get(PROPERTY_NAME); + + Map actual = JDOHelper.getNamedPMFProperties(name, loader); + + assertNotNull("No properties found", actual); + if (checkEqualProperties) { + assertEqualProperties(expected, actual); + } } - /** - * Tests JDOHelper.getPMFClassNameViaServiceLookup - */ - public void testPositive03_PMF0_PMFClassNameViaServicesLookup() throws IOException { + public void testPositive00_PMF0_BasicPMFConfigUsingOnlyStandardAttributesAndListeners() + throws IOException { + doPositiveTest( + new String[]{JDOCONFIG_CLASSPATH_PREFIX + "/Positive00"}, + "positive00.pmf0", + 2, + 0, + true); + } + public void testPositive00_PMF1_BasicPMFConfigUsingOnlyPropertyElementsWithStandardJavaxDotJDOProperties() + throws IOException { + doPositiveTest( + new String[]{JDOCONFIG_CLASSPATH_PREFIX + "/Positive00"}, + "positive00.pmf1", + 2, + 0, + true); + } + + public void testPositive00_PMF2_NestedPropertyElementsWithOnlyStandardAttributeNames() + throws IOException { + doPositiveTest( + new String[]{JDOCONFIG_CLASSPATH_PREFIX + "/Positive00"}, + "positive00.pmf2", + 2, + 0, + true); + } + + public void testPositive00_PMF3_StandardAttributesPlusNonstandardPropertiesInPropertyElements() + throws IOException { + doPositiveTest( + new String[]{JDOCONFIG_CLASSPATH_PREFIX + "/Positive00"}, + "positive00.pmf3", + 2, + 2, + true); + } + + public void testPositive00_PMF4_StandardAttributesPlusNonstandardAttributes() + throws IOException { + doPositiveTest( + new String[]{JDOCONFIG_CLASSPATH_PREFIX + "/Positive00"}, + "positive00.pmf4", + 0, + 2, + true); + } + + public void testPositive01_DuplicatePUsInDifferentConfigFilesButNotRequested() + throws IOException { + + doPositiveTest( + new String[]{ + JDOCONFIG_CLASSPATH_PREFIX + "/Positive01/1a", + JDOCONFIG_CLASSPATH_PREFIX + "/Positive01/1b" + }, + null, + 0, + 2, + false); + } + + public void testPositive03_PMF0_PMFClassNameViaServicesLookup() + throws IOException { + URLClassLoader loader = new JDOConfigTestClassLoader( JDOCONFIG_CLASSPATH_PREFIX, getClass().getClassLoader()); - ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Positive3", loader); + ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Positive03", loader); - String expected = "class.positive3.pmf0"; + String expected = "class.positive03.pmf0"; String actual = JDOHelper.getPMFClassNameViaServiceLookup(loader); assertNotNull("No PMF name found via services lookup", actual); assertEquals(expected, actual); } - /** - * Tests JDOHelper.getPMFClassNameViaServiceLookup - */ - public void testPositive04_PMF0_PMFClassNameViaServicesLookup() throws IOException { + public void testPositive04_PMF0_PMFClassNameViaServicesLookup() + throws IOException { URLClassLoader loader = new JDOConfigTestClassLoader( JDOCONFIG_CLASSPATH_PREFIX, getClass().getClassLoader()); - ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Positive4", loader); + ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Positive04", loader); - String expected = "class.positive4.pmf0"; + String expected = "class.positive04.pmf0"; String actual = JDOHelper.getPMFClassNameViaServiceLookup(loader); assertNotNull("No PMF name found via services lookup", actual); assertEquals(expected, actual); } - /** - * Tests JDOHelper.getPMFClassNameViaServiceLookup - */ - public void testPositive05_PMF0_PMFClassNameViaServicesLookup() throws IOException { + public void testPositive05_PMF0_PMFClassNameViaServicesLookup() + throws IOException { URLClassLoader loader = new JDOConfigTestClassLoader( JDOCONFIG_CLASSPATH_PREFIX, getClass().getClassLoader()); - ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Positive5", loader); + ClasspathHelper.addFile( + JDOCONFIG_CLASSPATH_PREFIX + "/Positive05", loader); - String expected = "class.positive5.pmf0"; + String expected = "class.positive05.pmf0"; String actual = JDOHelper.getPMFClassNameViaServiceLookup(loader); assertNotNull("No PMF name found via services lookup", actual); assertEquals(expected, actual); } - public void testNegative08_NoResourcesFound() { - String resource = "" + RANDOM.nextLong(); + public void testPositive06_PMF0_GetAnonymousPMFProperties() + throws IOException { - InputStream in = - getClass().getClassLoader().getResourceAsStream(resource); - assertNull(in); + URLClassLoader loader = new JDOConfigTestClassLoader( + JDOCONFIG_CLASSPATH_PREFIX, + getClass().getClassLoader()); - // resource pretty much guaranteed not to exist - try { - JDOHelper.getPersistenceManagerFactory(resource); - fail("JDOHelper failed to throw JDOFatalUserException"); - } - catch (JDOFatalUserException x) { - // happy path - } + ClasspathHelper.addFile( + JDOCONFIG_CLASSPATH_PREFIX + "/Positive06", loader); + + Map expected = prepareInitialExpectedMap( + "positive06.pmf0", 2, 0, true, true); + + Map actual = JDOHelper.getNamedPMFProperties(null, loader); + + assertNotNull("No properties found", actual); + assertEqualProperties(expected, actual); } - public void testNegative00_EmptyJDOConfigXML() throws IOException { + public void testPositive07_PMF0_GetAnonymousPMFPropertiesWithPUName() + throws IOException { + + URLClassLoader loader = new JDOConfigTestClassLoader( + JDOCONFIG_CLASSPATH_PREFIX, + getClass().getClassLoader()); + + ClasspathHelper.addFile( + JDOCONFIG_CLASSPATH_PREFIX + "/Positive07", loader); + + Map expected = prepareInitialExpectedMap( + "positive07.pmf0", 2, 0, true, false); + + Map actual = JDOHelper.getNamedPMFProperties(null, loader); + + assertNotNull("No properties found", actual); + assertEqualProperties(expected, actual); + } + + public void testNegative00_EmptyJDOConfigXML() throws IOException { try { URLClassLoader loader = new JDOConfigTestClassLoader( JDOCONFIG_CLASSPATH_PREFIX, getClass().getClassLoader()); - ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Negative0", loader); + ClasspathHelper.addFile( + JDOCONFIG_CLASSPATH_PREFIX + "/Negative0", loader); JDOHelper.getPersistenceManagerFactory(loader); fail("JDOHelper failed to throw JDOFatalUserException"); } catch (JDOFatalUserException x) { - // happy path + // sunny day } } - - public void testNegative01_NoPersistenceUnitsDefined() throws IOException { + + public void testNegative01_NoPersistenceUnitsDefined() throws IOException { try { URLClassLoader loader = new JDOConfigTestClassLoader( JDOCONFIG_CLASSPATH_PREFIX, getClass().getClassLoader()); - ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Negative1", loader); + ClasspathHelper.addFile( + JDOCONFIG_CLASSPATH_PREFIX + "/Negative01", loader); JDOHelper.getPersistenceManagerFactory(loader); fail("JDOHelper failed to throw JDOFatalUserException"); } catch (JDOFatalUserException x) { - // happy path + // joy, sweet joy } } public void testNegative02_DuplicateAnonymousPersistenceUnitsInSameConfig() - throws IOException - { + throws IOException { try { URLClassLoader loader = new JDOConfigTestClassLoader( JDOCONFIG_CLASSPATH_PREFIX, getClass().getClassLoader()); - ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Negative2", loader); + ClasspathHelper.addFile( + JDOCONFIG_CLASSPATH_PREFIX + "/Negative02", loader); JDOHelper.getPersistenceManagerFactory(loader); fail("JDOHelper failed to throw JDOFatalUserException"); } catch (JDOFatalUserException x) { - // happy path + // the cockles of my heart warmeth } } public void testNegative03_DuplicateNamedPersistenceUnitsInSameConfig() - throws IOException - { + throws IOException { try { URLClassLoader loader = new JDOConfigTestClassLoader( JDOCONFIG_CLASSPATH_PREFIX, getClass().getClassLoader()); - ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Negative3", loader); + ClasspathHelper.addFile( + JDOCONFIG_CLASSPATH_PREFIX + "/Negative03", loader); JDOHelper.getPersistenceManagerFactory( - "persistence-unit-name.negative3", - loader); + "name.negative03", + loader); fail("JDOHelper failed to throw JDOFatalUserException"); } catch (JDOFatalUserException x) { - // happy path + // warm fuzzies } } public void testNegative04_DuplicatePUNamePropertyInAttributeAndElement() - throws IOException - { + throws IOException { try { URLClassLoader loader = new JDOConfigTestClassLoader( JDOCONFIG_CLASSPATH_PREFIX, getClass().getClassLoader()); - ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Negative4", loader); + ClasspathHelper.addFile( + JDOCONFIG_CLASSPATH_PREFIX + "/Negative04", loader); JDOHelper.getPersistenceManagerFactory( - "persistence-unit-name.negative4.value0", - loader); + "name.negative04.value0", + loader); fail("JDOHelper failed to throw JDOFatalUserException"); } catch (JDOFatalUserException x) { - // happy path + // no cold pricklies } } public void testNegative05_DuplicatePropertyInAttributeAndElement() - throws IOException - { + throws IOException { try { URLClassLoader loader = new JDOConfigTestClassLoader( JDOCONFIG_CLASSPATH_PREFIX, getClass().getClassLoader()); - ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Negative5", loader); + ClasspathHelper.addFile( + JDOCONFIG_CLASSPATH_PREFIX + "/Negative05", loader); JDOHelper.getPersistenceManagerFactory(loader); fail("JDOHelper failed to throw JDOFatalUserException"); } catch (JDOFatalUserException x) { - // happy path + // party! } } public void testNegative06_DuplicatePUInDifferentConfigFiles() - throws IOException - { + throws IOException { try { URLClassLoader loader = new JDOConfigTestClassLoader( JDOCONFIG_CLASSPATH_PREFIX, getClass().getClassLoader()); - ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Negative6/6a", loader); - ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Negative6/6b", loader); + ClasspathHelper.addFile( + JDOCONFIG_CLASSPATH_PREFIX + "/Negative06/6a", loader); + ClasspathHelper.addFile( + JDOCONFIG_CLASSPATH_PREFIX + "/Negative06/6b", loader); JDOHelper.getPersistenceManagerFactory( - "persistence-unit-name.negative6", + "name.negative06", loader); fail("JDOHelper failed to throw JDOFatalUserException"); } catch (JDOFatalUserException x) { - // happy path + // clear blue sky } } public void testNegative07_EmptyServicesFile() - throws IOException - { - JDOConfigTestClassLoader testLoader = new JDOConfigTestClassLoader(new String[] {JDOCONFIG_CLASSPATH_PREFIX}, getClass().getClassLoader()); - ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Negative7", testLoader); - String shouldBeNull = JDOHelper.getPMFClassNameViaServiceLookup(testLoader); + throws IOException { + JDOConfigTestClassLoader testLoader = new JDOConfigTestClassLoader( + new String[]{JDOCONFIG_CLASSPATH_PREFIX}, + getClass().getClassLoader()); + ClasspathHelper.addFile( + JDOCONFIG_CLASSPATH_PREFIX + "/Negative07", testLoader); + String shouldBeNull = + JDOHelper.getPMFClassNameViaServiceLookup(testLoader); assertNull(shouldBeNull); } + public void testNegative08_NoResourcesFound() { + String resource = "" + RANDOM.nextLong(); + + InputStream in = + getClass().getClassLoader().getResourceAsStream(resource); + assertNull(in); + + // resource pretty much guaranteed not to exist + try { + JDOHelper.getPersistenceManagerFactory(resource); + fail("JDOHelper failed to throw JDOFatalUserException"); + } + catch (JDOFatalUserException x) { + // happy path + } + } + public void testNegative08_ServicesFileWithOnlyComments() - throws IOException - { - JDOConfigTestClassLoader testLoader = new JDOConfigTestClassLoader(new String[] {JDOCONFIG_CLASSPATH_PREFIX}, getClass().getClassLoader()); - ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Negative8", testLoader); - String shouldBeNull = JDOHelper.getPMFClassNameViaServiceLookup(testLoader); + throws IOException { + JDOConfigTestClassLoader testLoader = new JDOConfigTestClassLoader( + new String[]{JDOCONFIG_CLASSPATH_PREFIX}, + getClass().getClassLoader()); + ClasspathHelper.addFile( + JDOCONFIG_CLASSPATH_PREFIX + "/Negative08", testLoader); + String shouldBeNull = + JDOHelper.getPMFClassNameViaServiceLookup(testLoader); assertNull(shouldBeNull); } } Index: api2/src/schema/javax/jdo/jdoconfig_2_1.xsd =================================================================== --- api2/src/schema/javax/jdo/jdoconfig_2_1.xsd (revision 562509) +++ api2/src/schema/javax/jdo/jdoconfig_2_1.xsd (working copy) @@ -119,7 +119,9 @@ - + + + Index: api2/src/java/javax/jdo/PersistenceManagerFactory.java =================================================================== --- api2/src/java/javax/jdo/PersistenceManagerFactory.java (revision 562509) +++ api2/src/java/javax/jdo/PersistenceManagerFactory.java (working copy) @@ -22,14 +22,11 @@ package javax.jdo; -import java.util.Properties; -import java.util.Collection; - -import java.io.Serializable; - import javax.jdo.datastore.DataStoreCache; - import javax.jdo.listener.InstanceLifecycleListener; +import java.io.Serializable; +import java.util.Collection; +import java.util.Properties; /** The PersistenceManagerFactory is the interface to use to obtain * PersistenceManager instances. @@ -359,8 +356,21 @@ */ void setDetachAllOnCommit(boolean flag); + /** + * Sets the name of this PersistenceManagerFactory. + * @since 2.1 + * @param name the name of this PMF + */ + void setName(String name); /** + * Gets the name of this PersistenceManagerFactory. + * @since 2.1 + * @return the name of this PMF + */ + String getName(); + + /** * Sets the PersistenceUnitName for this PersistenceManagerFactory. * This has the same semantics as the same-named property in * JSR-220 PersistenceUnitInfo. Index: api2/src/java/javax/jdo/JDOHelper.java =================================================================== --- api2/src/java/javax/jdo/JDOHelper.java (revision 562509) +++ api2/src/java/javax/jdo/JDOHelper.java (working copy) @@ -22,10 +22,14 @@ package javax.jdo; -import org.w3c.dom.*; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; import org.xml.sax.ErrorHandler; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; +import org.w3c.dom.Node; +import org.w3c.dom.NamedNodeMap; import javax.jdo.spi.I18NHelper; import javax.jdo.spi.JDOImplHelper; @@ -41,13 +45,26 @@ import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.FactoryConfigurationError; import javax.xml.parsers.ParserConfigurationException; -import java.io.*; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.URL; import java.security.AccessController; import java.security.PrivilegedAction; -import java.util.*; +import java.util.Map; +import java.util.HashMap; +import java.util.Collections; +import java.util.Collection; +import java.util.Iterator; +import java.util.ArrayList; +import java.util.Properties; +import java.util.Enumeration; +import java.io.IOException; +import java.io.InputStream; +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; /** @@ -64,7 +81,7 @@ * * @version 2.1 */ -public class JDOHelper extends Object implements Constants { +public class JDOHelper implements Constants { /** * A mapping from jdoconfig.xsd element attributes to PMF properties. @@ -146,6 +163,9 @@ PMF_ATTRIBUTE_PERSISTENCE_UNIT_NAME, PROPERTY_PERSISTENCE_UNIT_NAME); xref.put( + PMF_ATTRIBUTE_NAME, + PROPERTY_NAME); + xref.put( PMF_ATTRIBUTE_RESTORE_VALUES, PROPERTY_RESTORE_VALUES); xref.put( @@ -628,11 +648,18 @@ * @see #getPersistenceManagerFactory(java.util.Map,ClassLoader) */ public static PersistenceManagerFactory getPersistenceManagerFactory - (Map props) { + (Map props) + { ClassLoader cl = getContextClassLoader(); return getPersistenceManagerFactory (props, cl); } + public static PersistenceManagerFactory getPersistenceManagerFactory + (Map props, ClassLoader cl) + { + return getPersistenceManagerFactory(props, cl, cl); + } + /** * Get a PersistenceManagerFactory based on a * Map instance and a class loader. @@ -654,6 +681,7 @@ *
"javax.jdo.mapping.Catalog", *
"javax.jdo.mapping.Schema", *
"javax.jdo.option.PersistenceUnitName". + *
"javax.jdo.option.Name". * * and properties of the form *
javax.jdo.option.InstanceLifecycleListener.{listenerClass}={pcClasses} @@ -682,58 +710,74 @@ * @return the PersistenceManagerFactory. * @param props a Properties instance with properties of the * PersistenceManagerFactory. - * @param cl the class loader to use to load the + * @param resourceLoader the class loader to use to load resources (if + * resource loading is necessary) + * @param pmfClassLoader the class loader to use to load the * PersistenceManagerFactory class */ public static PersistenceManagerFactory getPersistenceManagerFactory - (Map props, ClassLoader cl) { + (Map props, ClassLoader resourceLoader, ClassLoader pmfClassLoader) + { String pmfClassName = (String) props.get ( - PROPERTY_PERSISTENCE_MANAGER_FACTORY_CLASS); //NOI18N + PROPERTY_PERSISTENCE_MANAGER_FACTORY_CLASS); + if (pmfClassName == null) { + // no PMF class name property -- try to find via services lookup try { - pmfClassName = getPMFClassNameViaServiceLookup(cl); + pmfClassName = getPMFClassNameViaServiceLookup(resourceLoader); } catch (IOException e) { throw new JDOFatalInternalException(msg.msg( "EXC_IOExceptionDuringServiceLookup"), e); // NOI18N } - if (pmfClassName == null) { - throw new JDOFatalUserException(msg.msg( - "EXC_GetPMFNoClassNameProperty")); // NOI18N + } + + if (pmfClassName != null) { + try { + Class pmfClass = pmfClassLoader.loadClass (pmfClassName); + Method pmfMethod = pmfClass.getMethod( + "getPersistenceManagerFactory", //NOI18N + new Class[] {Map.class}); + return (PersistenceManagerFactory) pmfMethod.invoke ( + null, new Object[] {props}); + } catch (ClassNotFoundException cnfe) { + throw new JDOFatalUserException (msg.msg( + "EXC_GetPMFClassNotFound", pmfClassName), cnfe); //NOI18N + } catch (IllegalAccessException iae) { + throw new JDOFatalUserException (msg.msg( + "EXC_GetPMFIllegalAccess", pmfClassName), iae); //NOI18N + } catch (NoSuchMethodException nsme) { + throw new JDOFatalInternalException (msg.msg( + "EXC_GetPMFNoSuchMethod"), nsme); //NOI18N + } catch (InvocationTargetException ite) { + Throwable nested = ite.getTargetException(); + if (nested instanceof JDOException) { + throw (JDOException)nested; + } else throw new JDOFatalInternalException (msg.msg( + "EXC_GetPMFUnexpectedException"), ite); //NOI18N + } catch (NullPointerException e) { + throw new JDOFatalInternalException (msg.msg( + "EXC_GetPMFNullPointerException", pmfClassName), e); //NOI18N + } catch (ClassCastException e) { + throw new JDOFatalInternalException (msg.msg( + "EXC_GetPMFClassCastException", pmfClassName), e); //NOI18N + } catch (Exception e) { + throw new JDOFatalInternalException (msg.msg( + "EXC_GetPMFUnexpectedException"), e); //NOI18N } } - try { - Class pmfClass = cl.loadClass (pmfClassName); - Method pmfMethod = pmfClass.getMethod( - "getPersistenceManagerFactory", //NOI18N - new Class[] {Map.class}); - return (PersistenceManagerFactory) pmfMethod.invoke ( - null, new Object[] {props}); - } catch (ClassNotFoundException cnfe) { - throw new JDOFatalUserException (msg.msg( - "EXC_GetPMFClassNotFound", pmfClassName), cnfe); //NOI18N - } catch (IllegalAccessException iae) { - throw new JDOFatalUserException (msg.msg( - "EXC_GetPMFIllegalAccess", pmfClassName), iae); //NOI18N - } catch (NoSuchMethodException nsme) { - throw new JDOFatalInternalException (msg.msg( - "EXC_GetPMFNoSuchMethod"), nsme); //NOI18N - } catch (InvocationTargetException ite) { - Throwable nested = ite.getTargetException(); - if (nested instanceof JDOException) { - throw (JDOException)nested; - } else throw new JDOFatalInternalException (msg.msg( - "EXC_GetPMFUnexpectedException"), ite); //NOI18N - } catch (NullPointerException e) { - throw new JDOFatalInternalException (msg.msg( - "EXC_GetPMFNullPointerException", pmfClassName), e); //NOI18N - } catch (ClassCastException e) { - throw new JDOFatalInternalException (msg.msg( - "EXC_GetPMFClassCastException", pmfClassName), e); //NOI18N - } catch (Exception e) { - throw new JDOFatalInternalException (msg.msg( - "EXC_GetPMFUnexpectedException"), e); //NOI18N + + // else no PMF class name given; check PU name + String puName = (String) props.get( + PROPERTY_PERSISTENCE_UNIT_NAME); + + if (puName != null && !"".equals(puName.trim())) { + return getPMFFromEMF(puName, props, pmfClassLoader); } + + // else no PMF class name or PU name + throw new JDOFatalUserException(msg.msg( + "EXC_GetPMFNoPMFClassNamePropertyOrPUNameProperty")); } /** @@ -837,23 +881,30 @@ } /** - * Returns a named {@link PersistenceManagerFactory} with the given - * persistence unit name or, - * if not found, a {@link PersistenceManagerFactory} configured based + * Returns a {@link PersistenceManagerFactory} configured based * on the properties stored in the resource at - * name. Loads the Properties via + * name, or, if not found, returns a + * {@link PersistenceManagerFactory} with the given + * name or, if not found, returns a + * javax.persistence.EntityManagerFactory cast to a + * {@link PersistenceManagerFactory}. Loads the properties via * resourceLoader, and creates a {@link * PersistenceManagerFactory} with pmfLoader. Any * exceptions thrown during resource loading will * be wrapped in a {@link JDOFatalUserException}. - * If multiple persistence units with the requested name are found, a + * If multiple PMFs with the requested name are found, a * {@link JDOFatalUserException} is thrown. * @since 2.0 - * @param name the persistence unit name or resource containing the Properties - * @param resourceLoader the class loader to use to load the name + * @param name interpreted as the name of the resource containing the PMF + * properties, the name of the PMF, or the persistence unit name, in that + * order. + * @param resourceLoader the class loader to use to load properties or + * configuration file resources * @param pmfLoader the class loader to use to load the - * PersistenceManagerFactory class - * @return the PersistenceManagerFactory + * PersistenceManagerFactory or + * javax.persistence.EntityManagerFactory classes + * @return the PersistenceManagerFactory with properties in the given + * resource, with the given name, or with the given persitence unit name */ public static PersistenceManagerFactory getPersistenceManagerFactory (String name, ClassLoader resourceLoader, ClassLoader pmfLoader) { @@ -865,16 +916,16 @@ throw new JDOFatalUserException (msg.msg ( "EXC_GetPMFNullPMFLoader")); //NOI18N + Properties props = null; InputStream in = null; if (name != null) { // then try to load resources from properties file - Properties props = new Properties (); try { - in = resourceLoader.getResourceAsStream (name); + in = resourceLoader.getResourceAsStream(name); if (in != null) { // then some kind of resource was found by the given name; // assume that it's a properties file and proceed as usual - props.load (in); - return getPersistenceManagerFactory (props, pmfLoader); + props = new Properties(); + props.load(in); } } catch (IOException ioe) { @@ -889,93 +940,58 @@ } } // JDO 2.1: else name was null or no resource found by given name; - // assume name represents name of PU + // first assume that name represents name of named PMF - PersistenceManagerFactory pmf = getPersistenceUnit( - name == null ? "" : name.trim(), - resourceLoader, - pmfLoader - ); - if (pmf != null) { - return pmf; + Map properties = props; + if (properties == null) { + properties = getNamedPMFProperties(name, resourceLoader); } - // else no PU found + if (properties != null) { + String nameInProperties = (String) properties.get(PROPERTY_NAME); + nameInProperties = nameInProperties == null ? "" : nameInProperties; + if (nameInProperties == null) { + properties.put(PROPERTY_NAME, name); + } + return getPersistenceManagerFactory( + properties, resourceLoader, pmfLoader); + } + + // else no properties found; next, assume name is a PU name + if (name != null && !"".equals(name.trim())) { + PersistenceManagerFactory pmf = + getPMFFromEMF(name, null, pmfLoader); + if (pmf != null) { + return pmf; + } + } + + // else no PMF found throw new JDOFatalUserException (msg.msg ( "EXC_NoPMFConfigurableViaPropertiesOrXML", name, resourceLoader)); //NOI18N } - /** Find and return
    - *
  • a {@link PersistenceManagerFactory} with the given name,
  • - *
  • a JPA EntityManagerFactory cast to a - * {@link PersistenceManagerFactory}, or
  • - *
  • null if not found.
  • - * If name is null - * or blank, this method attempts to return the anonymous - * {@link PersistenceManagerFactory}. If multiple persistence units with - * the given name are found (including the anonymous persistence unit), - * this method will throw {@link JDOFatalUserException}. - * - * @param name The persistence unit name, or null, the empty string or a - * string only containing whitespace characters for the anonymous - * persistence unit. - * @param resourceLoader The ClassLoader used to load the standard JDO - * configuration file(s) given in the constant - * {@link Constants#JDOCONFIG_RESOURCE_NAME}. - * @param pmfLoader The loader used to load the - * {@link PersistenceManagerFactory} implementation class. - * @return A {@link PersistenceManagerFactory} corresponding to the - * persistence unit name if found, or null if not found. - * @throws JDOFatalUserException if multiple persistence units are found - * with the given name, or any other is encountered. - * @since 2.1 - */ - private static PersistenceManagerFactory getPersistenceUnit( + protected static Map getNamedPMFProperties( String name, - ClassLoader resourceLoader, - ClassLoader pmfLoader) { - Map properties = getPersistenceUnitProperties( - name, resourceLoader, JDOCONFIG_RESOURCE_NAME); - - if (properties != null) { // found requested JDO persistence unit props - return getPersistenceManagerFactory(properties, pmfLoader); - } - - // else try to return PMF from JPA EMF - if ("".equals(name)) { // no such thing as an anonymous JPA EMF - return null; - } - - // else try to return PMF from named JPA EMF - return getPMFFromEMF(name, pmfLoader); - } - - protected static Map getPersistenceUnitProperties( - String name - ) { - return getPersistenceUnitProperties( - name, getContextClassLoader(), JDOCONFIG_RESOURCE_NAME); - } - - protected static Map getPersistenceUnitProperties( - String name, ClassLoader resourceLoader ) { - return getPersistenceUnitProperties( + return getNamedPMFProperties( name, resourceLoader, JDOCONFIG_RESOURCE_NAME); } /** - * Find and return the named {@link PersistenceManagerFactory}, or null if + * Find and return the named {@link PersistenceManagerFactory}'s properties, + * or null if * not found. If name is null, return the anonymous - * {@link PersistenceManagerFactory}. If multiple persistence units with - * the given name are found (including anonymous), throw + * {@link PersistenceManagerFactory}'s properties. + * If multiple named PMF property sets with + * the given name are found (including anonymous ones), throw * {@link JDOFatalUserException}. * This method is here only to facilitate testing; the parameter * "jdoconfigResourceName" in public usage should always have the value - * given in the constant JDOCONFIG_RESOURCE_NAME. + * given in the constant {@link Constants#JDOCONFIG_RESOURCE_NAME}. * * @param name The persistence unit name, or null or blank for the * anonymous persistence unit. @@ -987,17 +1003,17 @@ * @return The named PersistenceManagerFactory properties if found, null if * not. * @since 2.1 - * @throws JDOFatalUserException if multiple persistence units are found - * with the given name, or any other exception is encountered. + * @throws JDOFatalUserException if multiple named PMF property sets are + * found with the given name, or any other exception is encountered. */ - protected static Map getPersistenceUnitProperties( + protected static Map getNamedPMFProperties( String name, ClassLoader resourceLoader, String jdoconfigResourceName ) { /* JDO 2.1: - Attempt to find & return named persistence unit here. - If name == null or name == "", then we're looking for the default PMF. + Attempt to find & return named PMF properties here. + If name == null or name == "", then we're looking for the anonymous PMF. If we can't find it, this method returns null. */ @@ -1017,12 +1033,7 @@ ArrayList processedResources = new ArrayList(); // get ready to parse XML - DocumentBuilderFactory factory = - implHelper.getRegisteredDocumentBuilderFactory(); - if (factory == null) { - factory = getDefaultDocumentBuilderFactory(); - } - + DocumentBuilderFactory factory = getDocumentBuilderFactory(); do { URL currentConfigURL = (URL) resources.nextElement(); if (processedResources.contains(currentConfigURL)) { @@ -1033,8 +1044,10 @@ } Map/**/ propertiesByNameInCurrentConfig = - readPersistenceUnitProperties( - currentConfigURL, name, factory); + readNamedPMFProperties( + currentConfigURL, + name, + factory); // try to detect duplicate requested PU if (propertiesByNameInCurrentConfig.containsKey(name)) { @@ -1045,7 +1058,7 @@ if (propertiesByNameInAllConfigs.containsKey(name)) throw new JDOFatalUserException (msg.msg( - "EXC_DuplicateRequestedPersistenceUnitFoundInDifferentConfigs", + "EXC_DuplicateRequestedNamedPMFFoundInDifferentConfigs", "".equals(name) ? "(anonymous)" : name, @@ -1073,6 +1086,15 @@ } + protected static DocumentBuilderFactory getDocumentBuilderFactory() { + DocumentBuilderFactory factory = + implHelper.getRegisteredDocumentBuilderFactory(); + if (factory == null) { + factory = getDefaultDocumentBuilderFactory(); + } + return factory; + } + protected static DocumentBuilderFactory getDefaultDocumentBuilderFactory() { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setIgnoringComments(true); @@ -1084,6 +1106,14 @@ return factory; } + protected static ErrorHandler getErrorHandler() { + ErrorHandler handler = implHelper.getRegisteredErrorHandler(); + if (handler == null) { + handler = getDefaultErrorHandler(); + } + return handler; + } + protected static ErrorHandler getDefaultErrorHandler() { return new ErrorHandler() { public void error(SAXParseException exception) @@ -1104,26 +1134,16 @@ } /** - * Convenience method for retrieving the JPA persistence unit by the given - * name. This method is equivalent to - * calling {@link #getPMFFromEMF(String,ClassLoader)} with the context ClassLoader. - * @param name The persistence unit name. - * @see #getPMFFromEMF(String,ClassLoader) - * @return The named EMF cast as a PMF. - */ - protected static PersistenceManagerFactory getPMFFromEMF(String name) { - return getPMFFromEMF(name, getContextClassLoader()); - } - - /** * Attempts to locate a javax.persistence.EntityManagerFactory * via the javax.persistence.Persistence method * createEntityManagerFactory(String) * and casts it to a {@link PersistenceManagerFactory}. It is a user error - * if his chosen JPA vendor's EntityManagerFactory + * if his chosen JPA vendor's + * javax.persistence.EntityManagerFactory * implementation class does not also implement * {@link PersistenceManagerFactory}. * @param name The persistence unit name. + * @param properties The properties of the persistence unit. * @param loader The classloader used to attempt loading of the class * javax.persistence.Persistence * and javax.persistence.PersistenceException. @@ -1151,8 +1171,8 @@ *
*/ protected static PersistenceManagerFactory getPMFFromEMF( - String name, ClassLoader loader - ) { + String name, Map properties, ClassLoader loader) + { /* This implementation uses reflection to try to get an EMF so that javax.jdo, a Java SE API, does not introduce an unnecessary @@ -1173,7 +1193,7 @@ createEntityManagerFactoryMethod = persistenceClass.getMethod( "createEntityManagerFactory", - new Class[] { String.class }); + new Class[] { String.class, Map.class }); persistenceExceptionClass = Class.forName( @@ -1193,7 +1213,7 @@ try { entityManagerFactory = createEntityManagerFactoryMethod.invoke( - persistenceClass, new Object[] { name }); + persistenceClass, new Object[] { name, properties }); } catch (RuntimeException x) { if (persistenceExceptionClass.isAssignableFrom(x.getClass())) { @@ -1228,7 +1248,7 @@ * persistence-manager-factory, then returns the map. * @param url URL of a JDO configuration file compliant with * javax/jdo/jdoconfig.xsd. - * @param requestedPersistenceUnitName The name of the requested + * @param requestedPMFName The name of the requested * persistence unit (allows for fail-fast). * @param factory The DocumentBuilderFactory to use for XML * parsing. @@ -1236,37 +1256,21 @@ * the anonymous persistence unit, the * value of the String key is the empty string, "". */ - protected static Map/**/ readPersistenceUnitProperties( + protected static Map/**/ readNamedPMFProperties( URL url, - String requestedPersistenceUnitName, + String requestedPMFName, DocumentBuilderFactory factory ) { - requestedPersistenceUnitName = requestedPersistenceUnitName == null + requestedPMFName = requestedPMFName == null ? "" - : requestedPersistenceUnitName.trim(); + : requestedPMFName.trim(); Map propertiesByName = new HashMap(); InputStream in = null; try { DocumentBuilder builder = factory.newDocumentBuilder(); - - builder.setErrorHandler(new ErrorHandler() { - public void error(SAXParseException exception) - throws SAXException { - throw exception; - } + builder.setErrorHandler(getErrorHandler()); - public void fatalError(SAXParseException exception) - throws SAXException { - throw exception; - } - - public void warning(SAXParseException exception) - throws SAXException { - // gulp - } - }); - in = url.openStream(); Document doc = builder.parse(in); @@ -1277,7 +1281,6 @@ ); } - // TODO: prefer using namespace-aware APIs NodeList pmfs = root.getElementsByTagName( ELEMENT_PERSISTENCE_MANAGER_FACTORY); @@ -1290,43 +1293,41 @@ Properties pmfPropertiesFromElements = readPropertiesFromPMFSubelements(pmfElement, url); - // for informative error handling, get PU name (or names) now - String puNameFromAtts = - pmfPropertiesFromAttributes.getProperty( - PROPERTY_PERSISTENCE_UNIT_NAME); - String puNameFromElem = - pmfPropertiesFromElements.getProperty( - PROPERTY_PERSISTENCE_UNIT_NAME); + // for informative error handling, get name (or names) now + String pmfNameFromAtts = + pmfPropertiesFromAttributes.getProperty(PROPERTY_NAME); + String pmfNameFromElem = + pmfPropertiesFromElements.getProperty(PROPERTY_NAME); - String puName = null; - if (nullOrBlank(puNameFromAtts)) { - // no PU name attribute given - if (!nullOrBlank(puNameFromElem)) { - // PU name element was given - puName = puNameFromElem; + String pmfName = null; + if (nullOrBlank(pmfNameFromAtts)) { + // no PMF name attribute given + if (!nullOrBlank(pmfNameFromElem)) { + // PMF name element was given + pmfName = pmfNameFromElem; } else { - // PU name not given at all, means the "anonymous" PU - puName = ""; + // PMF name not given at all, means the "anonymous" PMF + pmfName = ""; } } else { - // PU name given in an attribute - if (!nullOrBlank(puNameFromElem)) { - // exception -- PU name given as both att & elem + // PMF name given in an attribute + if (!nullOrBlank(pmfNameFromElem)) { + // exception -- PMF name given as both att & elem throw new JDOFatalUserException( msg.msg( - "EXC_DuplicatePersistenceUnitNamePropertyFoundWithinUnitConfig", - puNameFromAtts, - puNameFromElem, + "EXC_DuplicatePMFNamePropertyFoundWithinConfig", + pmfNameFromAtts, + pmfNameFromElem, url.toExternalForm())); } - puName = puNameFromAtts; + pmfName = pmfNameFromAtts; } - puName = puName == null ? "" : puName.trim(); + pmfName = pmfName == null ? "" : pmfName.trim(); // check for duplicate properties among atts & elems - if (requestedPersistenceUnitName.equals(puName)) { + if (requestedPMFName.equals(pmfName)) { Iterator it = pmfPropertiesFromAttributes.keySet().iterator(); while (it.hasNext()) { @@ -1336,7 +1337,7 @@ msg.msg( "EXC_DuplicatePropertyFound", property, - puName, + pmfName, url.toExternalForm())); } } @@ -1348,16 +1349,16 @@ pmfProps.putAll(pmfPropertiesFromAttributes); pmfProps.putAll(pmfPropertiesFromElements); - // check for duplicate requested PU name - if (puName.equals(requestedPersistenceUnitName) - && propertiesByName.containsKey(puName)) { + // check for duplicate requested PMF name + if (pmfName.equals(requestedPMFName) + && propertiesByName.containsKey(pmfName)) { throw new JDOFatalUserException(msg.msg( - "EXC_DuplicateRequestedPersistenceUnitFoundInSameConfig", - puName, + "EXC_DuplicateRequestedNamedPMFFoundInSameConfig", + pmfName, url.toExternalForm())); } - propertiesByName.put(puName, pmfProps); + propertiesByName.put(pmfName, pmfProps); } return propertiesByName; } @@ -1576,7 +1577,7 @@ Properties props = new Properties (); InputStream in = null; try { - in = new FileInputStream (propsFile); + in = new FileInputStream(propsFile); props.load (in); } catch (FileNotFoundException fnfe) { throw new JDOFatalUserException (msg.msg ( Index: api2/src/java/javax/jdo/Constants.java =================================================================== --- api2/src/java/javax/jdo/Constants.java (revision 562509) +++ api2/src/java/javax/jdo/Constants.java (working copy) @@ -98,6 +98,14 @@ = "class"; /** * The name of the persistence manager factory element's + * "name" attribute. + * + * @since 2.1 + */ + static String PMF_ATTRIBUTE_NAME + = "name"; + /** + * The name of the persistence manager factory element's * "persistence-unit-name" attribute. * * @since 2.1 @@ -649,6 +657,14 @@ */ static String PROPERTY_PERSISTENCE_UNIT_NAME = "javax.jdo.option.PersistenceUnitName"; + /** + * "javax.jdo.option.Name" + * + * @see PersistenceManagerFactory#getName() + * @since 2.1 + */ + static String PROPERTY_NAME + = "javax.jdo.option.Name"; /** * "javax.jdo.option.InstanceLifecycleListener" Index: api2/src/java/javax/jdo/Bundle.properties =================================================================== --- api2/src/java/javax/jdo/Bundle.properties (revision 562509) +++ api2/src/java/javax/jdo/Bundle.properties (working copy) @@ -25,8 +25,9 @@ EXC_GetPMFUnexpectedException=Unexpected exception caught. EXC_GetPMFClassNotFound=Class {0} was not found. EXC_GetPMFIllegalAccess=Illegal Access for class {0}. -EXC_GetPMFNoClassNameProperty=A property named javax.jdo.PersistenceManagerFactoryClass must be specified, \ -or the jar file with the default META-INF/services/javax.jdo.PersistenceManagerFactory entry must be in the classpath. +EXC_GetPMFNoPMFClassNamePropertyOrPUNameProperty=A property named javax.jdo.PersistenceManagerFactoryClass must be specified, \ +or a jar file with a META-INF/services/javax.jdo.PersistenceManagerFactory entry must be in the classpath, \ +or a property named javax.jdo.option.PersistenceUnitName must be specified. EXC_IOExceptionDuringServiceLookup=IO error while attempting to lookup PMF name \ via META-INF/services/javax.jdo.PersistenceManagerFactory MSG_FailedObject=FailedObject: @@ -80,10 +81,10 @@ EXC_DateStringConstructor: Error parsing Date string "{0}" at position {1} \ using date format "{2}". MSG_unknown: unknown -EXC_DuplicateRequestedPersistenceUnitFoundInDifferentConfigs: Duplicate \ -persistence unit name "{0}" found in {1} and {2}. -EXC_DuplicateRequestedPersistenceUnitFoundInSameConfig: Duplicate persistence \ -unit name "{0}" found in {1}. +EXC_DuplicateRequestedNamedPMFFoundInDifferentConfigs: Duplicate \ +PMF name "{0}" found in {1} and {2}. +EXC_DuplicateRequestedNamedPMFFoundInSameConfig: Duplicate PMF \ +name "{0}" found in {1}. EXC_UnableToInvokeCreateEMFMethod: Unable to invoke \ javax.persistence.Persistence.createEntityManagerFactory(String) EXC_UnableToCastEMFToPMF: Unable to cast EntityManagerFactory class {0} \ @@ -95,10 +96,10 @@ EXC_SAXParseException: Exception parsing configuration {0}\ at line {1}, column {2} EXC_SAXException: Exception parsing configuration {0} -EXC_DuplicatePropertyFound: Duplicate property name "{0}" found in persistence \ -unit name "{1}" found in {2}. -EXC_DuplicatePersistenceUnitNamePropertyFoundWithinUnitConfig: Duplicate \ -persistence unit name found in {2}: attribute is "{0}", element is "{1}" +EXC_DuplicatePropertyFound: Duplicate property name "{0}" found in PMF \ +configuration with name "{1}" found in {2}. +EXC_DuplicatePMFNamePropertyFoundWithinConfig: Duplicate \ +PMF name found in {2}: attribute is "{0}", element is "{1}" EXC_PropertyElementHasNoNameAttribute: Found element with no \ "name" attribute in {0} EXC_PropertyElementNameAttributeHasNoValue: Found element name \ @@ -111,5 +112,5 @@ "listener" missing value in {0} EXC_InvalidJDOConfigNoRoot: No root element found in {0} EXC_NoPMFConfigurableViaPropertiesOrXML: No PersistenceManagerFactory \ -configurable via properties resource "{0}" or no persistence unit named "{0}" \ -found using resource loader {1} +configurable via properties resource "{0}" or no named PMF or persistence unit\ +named "{0}" found using resource loader {1} Index: api2-legacy/test/schema/jdoconfig/Positive0/META-INF/jdoconfig.xml =================================================================== --- api2-legacy/test/schema/jdoconfig/Positive0/META-INF/jdoconfig.xml (revision 562509) +++ api2-legacy/test/schema/jdoconfig/Positive0/META-INF/jdoconfig.xml (working copy) @@ -1,251 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Index: api2-legacy/test/schema/jdoconfig/Negative0/META-INF/jdoconfig.xml =================================================================== --- api2-legacy/test/schema/jdoconfig/Negative0/META-INF/jdoconfig.xml (revision 562509) +++ api2-legacy/test/schema/jdoconfig/Negative0/META-INF/jdoconfig.xml (working copy) @@ -1 +0,0 @@ - Index: api2-legacy/test/schema/jdoconfig/Positive1/1a/META-INF/jdoconfig.xml =================================================================== --- api2-legacy/test/schema/jdoconfig/Positive1/1a/META-INF/jdoconfig.xml (revision 562509) +++ api2-legacy/test/schema/jdoconfig/Positive1/1a/META-INF/jdoconfig.xml (working copy) @@ -1,17 +0,0 @@ - - - - - - - - - - Index: api2-legacy/test/schema/jdoconfig/Positive1/1b/META-INF/jdoconfig.xml =================================================================== --- api2-legacy/test/schema/jdoconfig/Positive1/1b/META-INF/jdoconfig.xml (revision 562509) +++ api2-legacy/test/schema/jdoconfig/Positive1/1b/META-INF/jdoconfig.xml (working copy) @@ -1,15 +0,0 @@ - - - - - - - - Index: api2-legacy/test/schema/jdoconfig/Negative1/META-INF/jdoconfig.xml =================================================================== --- api2-legacy/test/schema/jdoconfig/Negative1/META-INF/jdoconfig.xml (revision 562509) +++ api2-legacy/test/schema/jdoconfig/Negative1/META-INF/jdoconfig.xml (working copy) @@ -1,8 +0,0 @@ - - - - - - Index: api2-legacy/test/schema/jdoconfig/Negative2/META-INF/jdoconfig.xml =================================================================== --- api2-legacy/test/schema/jdoconfig/Negative2/META-INF/jdoconfig.xml (revision 562509) +++ api2-legacy/test/schema/jdoconfig/Negative2/META-INF/jdoconfig.xml (working copy) @@ -1,11 +0,0 @@ - - - - - - - - - \ No newline at end of file Index: api2-legacy/test/schema/jdoconfig/Positive3/META-INF/jdoconfig.xml =================================================================== --- api2-legacy/test/schema/jdoconfig/Positive3/META-INF/jdoconfig.xml (revision 562509) +++ api2-legacy/test/schema/jdoconfig/Positive3/META-INF/jdoconfig.xml (working copy) @@ -1,13 +0,0 @@ - - - - - - - Index: api2-legacy/test/schema/jdoconfig/Positive3/META-INF/services/javax.jdo.PersistenceManagerFactory =================================================================== --- api2-legacy/test/schema/jdoconfig/Positive3/META-INF/services/javax.jdo.PersistenceManagerFactory (revision 562509) +++ api2-legacy/test/schema/jdoconfig/Positive3/META-INF/services/javax.jdo.PersistenceManagerFactory (working copy) @@ -1 +0,0 @@ -class.positive3.pmf0 \ No newline at end of file Index: api2-legacy/test/schema/jdoconfig/Negative3/META-INF/jdoconfig.xml =================================================================== --- api2-legacy/test/schema/jdoconfig/Negative3/META-INF/jdoconfig.xml (revision 562509) +++ api2-legacy/test/schema/jdoconfig/Negative3/META-INF/jdoconfig.xml (working copy) @@ -1,20 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file Index: api2-legacy/test/schema/jdoconfig/Positive4/META-INF/jdoconfig.xml =================================================================== --- api2-legacy/test/schema/jdoconfig/Positive4/META-INF/jdoconfig.xml (revision 562509) +++ api2-legacy/test/schema/jdoconfig/Positive4/META-INF/jdoconfig.xml (working copy) @@ -1,13 +0,0 @@ - - - - - - - Index: api2-legacy/test/schema/jdoconfig/Positive4/META-INF/services/javax.jdo.PersistenceManagerFactory =================================================================== --- api2-legacy/test/schema/jdoconfig/Positive4/META-INF/services/javax.jdo.PersistenceManagerFactory (revision 562509) +++ api2-legacy/test/schema/jdoconfig/Positive4/META-INF/services/javax.jdo.PersistenceManagerFactory (working copy) @@ -1,3 +0,0 @@ - -#this is a comment -class.positive4.pmf0 # this is another comment \ No newline at end of file Index: api2-legacy/test/schema/jdoconfig/Negative4/META-INF/jdoconfig.xml =================================================================== --- api2-legacy/test/schema/jdoconfig/Negative4/META-INF/jdoconfig.xml (revision 562509) +++ api2-legacy/test/schema/jdoconfig/Negative4/META-INF/jdoconfig.xml (working copy) @@ -1,21 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file Index: api2-legacy/test/schema/jdoconfig/Positive5/META-INF/jdoconfig.xml =================================================================== --- api2-legacy/test/schema/jdoconfig/Positive5/META-INF/jdoconfig.xml (revision 562509) +++ api2-legacy/test/schema/jdoconfig/Positive5/META-INF/jdoconfig.xml (working copy) @@ -1,13 +0,0 @@ - - - - - - - Index: api2-legacy/test/schema/jdoconfig/Positive5/META-INF/services/javax.jdo.PersistenceManagerFactory =================================================================== --- api2-legacy/test/schema/jdoconfig/Positive5/META-INF/services/javax.jdo.PersistenceManagerFactory (revision 562509) +++ api2-legacy/test/schema/jdoconfig/Positive5/META-INF/services/javax.jdo.PersistenceManagerFactory (working copy) @@ -1 +0,0 @@ -class.positive5.pmf0# this is a comment without whitespace separating it from the uncommented text \ No newline at end of file Index: api2-legacy/test/schema/jdoconfig/Negative5/META-INF/jdoconfig.xml =================================================================== --- api2-legacy/test/schema/jdoconfig/Negative5/META-INF/jdoconfig.xml (revision 562509) +++ api2-legacy/test/schema/jdoconfig/Negative5/META-INF/jdoconfig.xml (working copy) @@ -1,21 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file Index: api2-legacy/test/schema/jdoconfig/Negative6/6a/META-INF/jdoconfig.xml =================================================================== --- api2-legacy/test/schema/jdoconfig/Negative6/6a/META-INF/jdoconfig.xml (revision 562509) +++ api2-legacy/test/schema/jdoconfig/Negative6/6a/META-INF/jdoconfig.xml (working copy) @@ -1,16 +0,0 @@ - - - - - - - - - \ No newline at end of file Index: api2-legacy/test/schema/jdoconfig/Negative6/6b/META-INF/jdoconfig.xml =================================================================== --- api2-legacy/test/schema/jdoconfig/Negative6/6b/META-INF/jdoconfig.xml (revision 562509) +++ api2-legacy/test/schema/jdoconfig/Negative6/6b/META-INF/jdoconfig.xml (working copy) @@ -1,16 +0,0 @@ - - - - - - - - - \ No newline at end of file Index: api2-legacy/test/schema/jdoconfig/Negative8/META-INF/services/javax.jdo.PersistenceManagerFactory =================================================================== --- api2-legacy/test/schema/jdoconfig/Negative8/META-INF/services/javax.jdo.PersistenceManagerFactory (revision 562509) +++ api2-legacy/test/schema/jdoconfig/Negative8/META-INF/services/javax.jdo.PersistenceManagerFactory (working copy) @@ -1,3 +0,0 @@ -# there are -# only comments -# in this file \ No newline at end of file Index: api2-legacy/test/schema/jdoconfig/Negative00/META-INF/jdoconfig.xml =================================================================== --- api2-legacy/test/schema/jdoconfig/Negative00/META-INF/jdoconfig.xml (revision 0) +++ api2-legacy/test/schema/jdoconfig/Negative00/META-INF/jdoconfig.xml (revision 0) @@ -0,0 +1 @@ + Index: api2-legacy/test/schema/jdoconfig/Positive00/META-INF/jdoconfig.xml =================================================================== --- api2-legacy/test/schema/jdoconfig/Positive00/META-INF/jdoconfig.xml (revision 0) +++ api2-legacy/test/schema/jdoconfig/Positive00/META-INF/jdoconfig.xml (revision 0) @@ -0,0 +1,260 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Index: api2-legacy/test/schema/jdoconfig/Negative01/META-INF/jdoconfig.xml =================================================================== --- api2-legacy/test/schema/jdoconfig/Negative01/META-INF/jdoconfig.xml (revision 0) +++ api2-legacy/test/schema/jdoconfig/Negative01/META-INF/jdoconfig.xml (revision 0) @@ -0,0 +1,8 @@ + + + + + + Index: api2-legacy/test/schema/jdoconfig/Positive01/1a/META-INF/jdoconfig.xml =================================================================== --- api2-legacy/test/schema/jdoconfig/Positive01/1a/META-INF/jdoconfig.xml (revision 0) +++ api2-legacy/test/schema/jdoconfig/Positive01/1a/META-INF/jdoconfig.xml (revision 0) @@ -0,0 +1,17 @@ + + + + + + + + + + Index: api2-legacy/test/schema/jdoconfig/Positive01/1b/META-INF/jdoconfig.xml =================================================================== --- api2-legacy/test/schema/jdoconfig/Positive01/1b/META-INF/jdoconfig.xml (revision 0) +++ api2-legacy/test/schema/jdoconfig/Positive01/1b/META-INF/jdoconfig.xml (revision 0) @@ -0,0 +1,15 @@ + + + + + + + + Index: api2-legacy/test/schema/jdoconfig/Negative02/META-INF/jdoconfig.xml =================================================================== --- api2-legacy/test/schema/jdoconfig/Negative02/META-INF/jdoconfig.xml (revision 0) +++ api2-legacy/test/schema/jdoconfig/Negative02/META-INF/jdoconfig.xml (revision 0) @@ -0,0 +1,11 @@ + + + + + + + + + \ No newline at end of file Index: api2-legacy/test/schema/jdoconfig/Negative03/META-INF/jdoconfig.xml =================================================================== --- api2-legacy/test/schema/jdoconfig/Negative03/META-INF/jdoconfig.xml (revision 0) +++ api2-legacy/test/schema/jdoconfig/Negative03/META-INF/jdoconfig.xml (revision 0) @@ -0,0 +1,20 @@ + + + + + + + + + + + + \ No newline at end of file Index: api2-legacy/test/schema/jdoconfig/Positive03/META-INF/jdoconfig.xml =================================================================== --- api2-legacy/test/schema/jdoconfig/Positive03/META-INF/jdoconfig.xml (revision 0) +++ api2-legacy/test/schema/jdoconfig/Positive03/META-INF/jdoconfig.xml (revision 0) @@ -0,0 +1,13 @@ + + + + + + + Index: api2-legacy/test/schema/jdoconfig/Positive03/META-INF/services/javax.jdo.PersistenceManagerFactory =================================================================== --- api2-legacy/test/schema/jdoconfig/Positive03/META-INF/services/javax.jdo.PersistenceManagerFactory (revision 0) +++ api2-legacy/test/schema/jdoconfig/Positive03/META-INF/services/javax.jdo.PersistenceManagerFactory (revision 0) @@ -0,0 +1 @@ +class.positive03.pmf0 \ No newline at end of file Index: api2-legacy/test/schema/jdoconfig/Negative04/META-INF/jdoconfig.xml =================================================================== --- api2-legacy/test/schema/jdoconfig/Negative04/META-INF/jdoconfig.xml (revision 0) +++ api2-legacy/test/schema/jdoconfig/Negative04/META-INF/jdoconfig.xml (revision 0) @@ -0,0 +1,21 @@ + + + + + + + + + + + + \ No newline at end of file Index: api2-legacy/test/schema/jdoconfig/Positive04/META-INF/jdoconfig.xml =================================================================== --- api2-legacy/test/schema/jdoconfig/Positive04/META-INF/jdoconfig.xml (revision 0) +++ api2-legacy/test/schema/jdoconfig/Positive04/META-INF/jdoconfig.xml (revision 0) @@ -0,0 +1,13 @@ + + + + + + + Index: api2-legacy/test/schema/jdoconfig/Positive04/META-INF/services/javax.jdo.PersistenceManagerFactory =================================================================== --- api2-legacy/test/schema/jdoconfig/Positive04/META-INF/services/javax.jdo.PersistenceManagerFactory (revision 0) +++ api2-legacy/test/schema/jdoconfig/Positive04/META-INF/services/javax.jdo.PersistenceManagerFactory (revision 0) @@ -0,0 +1,3 @@ + +#this is a comment +class.positive04.pmf0 # this is another comment \ No newline at end of file Index: api2-legacy/test/schema/jdoconfig/Negative05/META-INF/jdoconfig.xml =================================================================== --- api2-legacy/test/schema/jdoconfig/Negative05/META-INF/jdoconfig.xml (revision 0) +++ api2-legacy/test/schema/jdoconfig/Negative05/META-INF/jdoconfig.xml (revision 0) @@ -0,0 +1,21 @@ + + + + + + + + + + + + \ No newline at end of file Index: api2-legacy/test/schema/jdoconfig/Positive05/META-INF/jdoconfig.xml =================================================================== --- api2-legacy/test/schema/jdoconfig/Positive05/META-INF/jdoconfig.xml (revision 0) +++ api2-legacy/test/schema/jdoconfig/Positive05/META-INF/jdoconfig.xml (revision 0) @@ -0,0 +1,13 @@ + + + + + + + Index: api2-legacy/test/schema/jdoconfig/Positive05/META-INF/services/javax.jdo.PersistenceManagerFactory =================================================================== --- api2-legacy/test/schema/jdoconfig/Positive05/META-INF/services/javax.jdo.PersistenceManagerFactory (revision 0) +++ api2-legacy/test/schema/jdoconfig/Positive05/META-INF/services/javax.jdo.PersistenceManagerFactory (revision 0) @@ -0,0 +1 @@ +class.positive05.pmf0# this is a comment without whitespace separating it from the uncommented text \ No newline at end of file Index: api2-legacy/test/schema/jdoconfig/Negative06/6a/META-INF/jdoconfig.xml =================================================================== --- api2-legacy/test/schema/jdoconfig/Negative06/6a/META-INF/jdoconfig.xml (revision 0) +++ api2-legacy/test/schema/jdoconfig/Negative06/6a/META-INF/jdoconfig.xml (revision 0) @@ -0,0 +1,16 @@ + + + + + + + + + \ No newline at end of file Index: api2-legacy/test/schema/jdoconfig/Negative06/6b/META-INF/jdoconfig.xml =================================================================== --- api2-legacy/test/schema/jdoconfig/Negative06/6b/META-INF/jdoconfig.xml (revision 0) +++ api2-legacy/test/schema/jdoconfig/Negative06/6b/META-INF/jdoconfig.xml (revision 0) @@ -0,0 +1,16 @@ + + + + + + + + + \ No newline at end of file Index: api2-legacy/test/schema/jdoconfig/Positive06/META-INF/jdoconfig.xml =================================================================== --- api2-legacy/test/schema/jdoconfig/Positive06/META-INF/jdoconfig.xml (revision 0) +++ api2-legacy/test/schema/jdoconfig/Positive06/META-INF/jdoconfig.xml (revision 0) @@ -0,0 +1,43 @@ + + + + + + + + + + + Index: api2-legacy/test/schema/jdoconfig/Negative07/META-INF/services/javax.jdo.PersistenceManagerFactory =================================================================== Index: api2-legacy/test/schema/jdoconfig/Positive07/META-INF/jdoconfig.xml =================================================================== --- api2-legacy/test/schema/jdoconfig/Positive07/META-INF/jdoconfig.xml (revision 0) +++ api2-legacy/test/schema/jdoconfig/Positive07/META-INF/jdoconfig.xml (revision 0) @@ -0,0 +1,45 @@ + + + + + + + + + + + + Index: api2-legacy/test/schema/jdoconfig/Negative08/META-INF/services/javax.jdo.PersistenceManagerFactory =================================================================== --- api2-legacy/test/schema/jdoconfig/Negative08/META-INF/services/javax.jdo.PersistenceManagerFactory (revision 0) +++ api2-legacy/test/schema/jdoconfig/Negative08/META-INF/services/javax.jdo.PersistenceManagerFactory (revision 0) @@ -0,0 +1,3 @@ +# there are +# only comments +# in this file \ No newline at end of file Index: api2-legacy/test/java/javax/jdo/JDOHelperConfigTest.java =================================================================== --- api2-legacy/test/java/javax/jdo/JDOHelperConfigTest.java (revision 562509) +++ api2-legacy/test/java/javax/jdo/JDOHelperConfigTest.java (working copy) @@ -23,11 +23,11 @@ import javax.jdo.util.BatchTestRunner; import java.io.IOException; import java.io.InputStream; +import java.net.URLClassLoader; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Random; -import java.net.URLClassLoader; /** * Tests class javax.jdo.JDOHelper for META-INF/jdoconfig.xml compliance. @@ -42,197 +42,108 @@ return new TestSuite(JDOHelperConfigTest.class); } - protected static String JDOCONFIG_CLASSPATH_PREFIX = - System.getProperty("basedir") + "/test/schema/jdoconfig"; + protected static String JDOCONFIG_CLASSPATH_PREFIX + = initJDOConfigClasspathPrefix(); - protected static Random RANDOM = new Random(System.currentTimeMillis()); - - /** - * Tests JDOHelper.getPersistenceUnitProperties using file - * Positive0-jdoconfig.xml and PU name - * "persistence-unit-name.positive0.pmf0" - */ - public void testPositive00_PMF0_GetNamedPMFProperties() throws IOException { - - try { - URLClassLoader loader = new JDOConfigTestClassLoader( - JDOCONFIG_CLASSPATH_PREFIX, - getClass().getClassLoader()); - ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Positive0", loader); - - Map expected = prepareInitialExpectedMap("positive0.pmf0", 2); - String name = (String) expected.get(PROPERTY_PERSISTENCE_UNIT_NAME); - - Map actual = JDOHelper.getPersistenceUnitProperties(name, loader); - - assertNotNull("No properties found", actual); - assertEqualProperties(expected, actual); - } catch (Exception e) { - e.printStackTrace(); + protected static String initJDOConfigClasspathPrefix() { + String basedir = System.getProperty("basedir"); + if (basedir != null) { + if (!basedir.endsWith("/")) { + basedir += "/"; + } + } else { + basedir = ""; } + return basedir + "test/schema/jdoconfig"; } - /** - * Tests JDOHelper.getPersistenceUnitProperties using file - * Positive0-jdoconfig.xml and PU name - * "persistence-unit-name.positive0.pmf1" - */ - public void testPositive00_PMF1_GetNamedPMFProperties() throws IOException { - URLClassLoader loader = new JDOConfigTestClassLoader( - JDOCONFIG_CLASSPATH_PREFIX, - getClass().getClassLoader()); - ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Positive0", loader); + protected static Random RANDOM = new Random(System.currentTimeMillis()); - Map expected = prepareInitialExpectedMap("positive0.pmf1", 2); - String name = (String) expected.get(PROPERTY_PERSISTENCE_UNIT_NAME); - - Map actual = JDOHelper.getPersistenceUnitProperties(name, loader); - - assertNotNull("No properties found", actual); - assertEqualProperties(expected, actual); - } - - /** - * Tests JDOHelper.getPersistenceUnitProperties using file - * Positive0-jdoconfig.xml and PU name - * "persistence-unit-name.positive0.pmf2" - */ - public void testPositive00_PMF2_GetNamedPMFProperties() throws IOException { - URLClassLoader loader = new JDOConfigTestClassLoader( - JDOCONFIG_CLASSPATH_PREFIX, - getClass().getClassLoader()); - ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Positive0", loader); - - Map expected = prepareInitialExpectedMap("positive0.pmf2", 2); - String name = (String) expected.get(PROPERTY_PERSISTENCE_UNIT_NAME); - - Map actual = JDOHelper.getPersistenceUnitProperties(name, loader); - - assertNotNull("No properties found", actual); - assertEqualProperties(expected, actual); - } - - /** - * Tests JDOHelper.getPersistenceUnitProperties using file - * Positive0-jdoconfig.xml and PU name - * "persistence-unit-name.positive0.pmf3" - */ - public void testPositive00_PMF3_GetNamedPMFProperties() throws IOException { - URLClassLoader loader = new JDOConfigTestClassLoader( - JDOCONFIG_CLASSPATH_PREFIX, - getClass().getClassLoader()); - ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Positive0", loader); - - Map expected = prepareInitialExpectedMap("positive0.pmf3", 2, 2); - String name = (String) expected.get(PROPERTY_PERSISTENCE_UNIT_NAME); - - Map actual = JDOHelper.getPersistenceUnitProperties(name, loader); - - assertNotNull("No properties found", actual); - assertEqualProperties(expected, actual); - } - - /** - * Tests JDOHelper.getPersistenceUnitProperties using file - * Positive0-jdoconfig.xml and PU name - * "persistence-unit-name.positive0.pmf4" - */ - public void testPositive00_PMF4_GetNamedPMFProperties() throws IOException { - URLClassLoader loader = new JDOConfigTestClassLoader( - JDOCONFIG_CLASSPATH_PREFIX, - getClass().getClassLoader()); - ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Positive0", loader); - - Map expected = prepareInitialExpectedMap("positive0.pmf4", 0, 2); - String name = (String) expected.get(PROPERTY_PERSISTENCE_UNIT_NAME); - - Map actual = JDOHelper.getPersistenceUnitProperties(name, loader); - - assertNotNull("No properties found", actual); - assertEqualProperties(expected, actual); - } - - public Map prepareInitialExpectedMap(String testVariant) { - return prepareInitialExpectedMap(testVariant, 0, 0); - } - public Map prepareInitialExpectedMap(String testVariant, int numListeners) { - return prepareInitialExpectedMap(testVariant, numListeners, 0); - } - public Map prepareInitialExpectedMap( - String testVariant, - int numListeners, - int numProperties + protected Map prepareInitialExpectedMap( + String testVariant, + int listenerCount, + int vendorSpecificPropertyCount, + boolean excludeName, + boolean excludePUName ) { Map expected = new HashMap(); + if (!excludeName) { + expected.put( + PROPERTY_NAME, + PMF_ATTRIBUTE_NAME + "." + testVariant); + } + if (!excludePUName) { + expected.put( + PROPERTY_PERSISTENCE_UNIT_NAME, + PMF_ATTRIBUTE_PERSISTENCE_UNIT_NAME + "." + testVariant); + } + expected.put(PROPERTY_PERSISTENCE_MANAGER_FACTORY_CLASS, - PMF_ATTRIBUTE_CLASS + "." + testVariant); + PMF_ATTRIBUTE_CLASS + "." + testVariant); expected.put( - PROPERTY_CONNECTION_DRIVER_NAME, - PMF_ATTRIBUTE_CONNECTION_DRIVER_NAME + "." + testVariant); + PROPERTY_CONNECTION_DRIVER_NAME, + PMF_ATTRIBUTE_CONNECTION_DRIVER_NAME + "." + testVariant); expected.put( - PROPERTY_CONNECTION_FACTORY_NAME, - PMF_ATTRIBUTE_CONNECTION_FACTORY_NAME + "." + testVariant); + PROPERTY_CONNECTION_FACTORY_NAME, + PMF_ATTRIBUTE_CONNECTION_FACTORY_NAME + "." + testVariant); expected.put( - PROPERTY_CONNECTION_FACTORY2_NAME, - PMF_ATTRIBUTE_CONNECTION_FACTORY2_NAME + "." + testVariant); + PROPERTY_CONNECTION_FACTORY2_NAME, + PMF_ATTRIBUTE_CONNECTION_FACTORY2_NAME + "." + testVariant); expected.put( - PROPERTY_CONNECTION_PASSWORD, - PMF_ATTRIBUTE_CONNECTION_PASSWORD + "." + testVariant); + PROPERTY_CONNECTION_PASSWORD, + PMF_ATTRIBUTE_CONNECTION_PASSWORD + "." + testVariant); expected.put( - PROPERTY_CONNECTION_URL, - PMF_ATTRIBUTE_CONNECTION_URL + "." + testVariant); + PROPERTY_CONNECTION_URL, + PMF_ATTRIBUTE_CONNECTION_URL + "." + testVariant); expected.put( - PROPERTY_CONNECTION_USER_NAME, - PMF_ATTRIBUTE_CONNECTION_USER_NAME + "." + testVariant); + PROPERTY_CONNECTION_USER_NAME, + PMF_ATTRIBUTE_CONNECTION_USER_NAME + "." + testVariant); expected.put( - PROPERTY_IGNORE_CACHE, - PMF_ATTRIBUTE_IGNORE_CACHE + "." + testVariant); + PROPERTY_IGNORE_CACHE, + PMF_ATTRIBUTE_IGNORE_CACHE + "." + testVariant); expected.put( - PROPERTY_MAPPING, - PMF_ATTRIBUTE_MAPPING + "." + testVariant); + PROPERTY_MAPPING, + PMF_ATTRIBUTE_MAPPING + "." + testVariant); expected.put( - PROPERTY_MULTITHREADED, - PMF_ATTRIBUTE_MULTITHREADED + "." + testVariant); + PROPERTY_MULTITHREADED, + PMF_ATTRIBUTE_MULTITHREADED + "." + testVariant); expected.put( - PROPERTY_NONTRANSACTIONAL_READ, - PMF_ATTRIBUTE_NONTRANSACTIONAL_READ + "." + testVariant); + PROPERTY_NONTRANSACTIONAL_READ, + PMF_ATTRIBUTE_NONTRANSACTIONAL_READ + "." + testVariant); expected.put( - PROPERTY_NONTRANSACTIONAL_WRITE, - PMF_ATTRIBUTE_NONTRANSACTIONAL_WRITE + "." + testVariant); + PROPERTY_NONTRANSACTIONAL_WRITE, + PMF_ATTRIBUTE_NONTRANSACTIONAL_WRITE + "." + testVariant); expected.put( - PROPERTY_OPTIMISTIC, - PMF_ATTRIBUTE_OPTIMISTIC + "." + testVariant); + PROPERTY_OPTIMISTIC, + PMF_ATTRIBUTE_OPTIMISTIC + "." + testVariant); expected.put( - PROPERTY_PERSISTENCE_UNIT_NAME, - PMF_ATTRIBUTE_PERSISTENCE_UNIT_NAME + "." + testVariant); + PROPERTY_RESTORE_VALUES, + PMF_ATTRIBUTE_RESTORE_VALUES + "." + testVariant); expected.put( - PROPERTY_RESTORE_VALUES, - PMF_ATTRIBUTE_RESTORE_VALUES + "." + testVariant); + PROPERTY_RETAIN_VALUES, + PMF_ATTRIBUTE_RETAIN_VALUES + "." + testVariant); expected.put( - PROPERTY_RETAIN_VALUES, - PMF_ATTRIBUTE_RETAIN_VALUES + "." + testVariant); + PROPERTY_DETACH_ALL_ON_COMMIT, + PMF_ATTRIBUTE_DETACH_ALL_ON_COMMIT + "." + testVariant); expected.put( - PROPERTY_DETACH_ALL_ON_COMMIT, - PMF_ATTRIBUTE_DETACH_ALL_ON_COMMIT + "." + testVariant); - expected.put( - PROPERTY_SERVER_TIMEZONE_ID, - PMF_ATTRIBUTE_SERVER_TIME_ZONE_ID + "." + testVariant); + PROPERTY_SERVER_TIME_ZONE_ID, + PMF_ATTRIBUTE_SERVER_TIME_ZONE_ID + "." + testVariant); // listeners - for (int i = 0; i < numListeners; i++) { + for (int i = 0; i < listenerCount; i++) { expected.put( - PROPERTY_PREFIX_INSTANCE_LIFECYCLE_LISTENER + - "listener." + testVariant + ".listener" + i, - "classes." + testVariant + ".classes" + i + PROPERTY_PREFIX_INSTANCE_LIFECYCLE_LISTENER + + "listener." + testVariant + ".listener" + i, + "classes." + testVariant + ".classes" + i ); } - // properties - for (int i = 0; i < numProperties; i++) { + // vendor-specific properties + for (int i = 0; i < vendorSpecificPropertyCount; i++) { expected.put( - "property." + testVariant + ".name" + i, - "property." + testVariant + ".value" + i + "property." + testVariant + ".name" + i, + "property." + testVariant + ".value" + i ); } @@ -248,240 +159,364 @@ String actualValue = (String) actual.get(key); assertEquals( - "Actual property at key [" + key + "] with value [" + - actualValue + "] not equal to expected value [" + - expectedValue + "]", - expectedValue, - actualValue); + "Actual property at key [" + key + "] with value [" + + actualValue + "] not equal to expected value [" + + expectedValue + "]", + expectedValue, + actualValue); } } - /** - * Tests JDOHelper.getPersistenceUnitProperties using file - * Positive0-jdoconfig.xml and PU name - * "persistence-unit-name.positive0.pmf0" - */ - public void testPositive01_DuplicatePUsInDifferentConfigFilesButNotRequested() throws IOException { - + protected void doPositiveTest( + String[] classpaths, + String testVariantName, + int listenerCount, + int vendorSpecificPropertyCount, + boolean checkEqualProperties) + throws IOException { + URLClassLoader loader = new JDOConfigTestClassLoader( JDOCONFIG_CLASSPATH_PREFIX, getClass().getClassLoader()); - ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Positive1/1a", loader); - ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Positive1/1b", loader); - Map props = JDOHelper.getPersistenceUnitProperties(null, loader); - assertNotNull(props); + for (int i = 0; i < classpaths.length; i++) { + ClasspathHelper.addFile(classpaths[i], loader); + } + + Map expected = prepareInitialExpectedMap( + testVariantName, + listenerCount, + vendorSpecificPropertyCount, + false, + false); + + String name = testVariantName == null + ? null + : (String) expected.get(PROPERTY_NAME); + + Map actual = JDOHelper.getNamedPMFProperties(name, loader); + + assertNotNull("No properties found", actual); + if (checkEqualProperties) { + assertEqualProperties(expected, actual); + } } - /** - * Tests JDOHelper.getPMFClassNameViaServiceLookup - */ - public void testPositive03_PMF0_PMFClassNameViaServicesLookup() throws IOException { + public void testPositive00_PMF0_BasicPMFConfigUsingOnlyStandardAttributesAndListeners() + throws IOException { + doPositiveTest( + new String[]{JDOCONFIG_CLASSPATH_PREFIX + "/Positive00"}, + "positive00.pmf0", + 2, + 0, + true); + } + public void testPositive00_PMF1_BasicPMFConfigUsingOnlyPropertyElementsWithStandardJavaxDotJDOProperties() + throws IOException { + doPositiveTest( + new String[]{JDOCONFIG_CLASSPATH_PREFIX + "/Positive00"}, + "positive00.pmf1", + 2, + 0, + true); + } + + public void testPositive00_PMF2_NestedPropertyElementsWithOnlyStandardAttributeNames() + throws IOException { + doPositiveTest( + new String[]{JDOCONFIG_CLASSPATH_PREFIX + "/Positive00"}, + "positive00.pmf2", + 2, + 0, + true); + } + + public void testPositive00_PMF3_StandardAttributesPlusNonstandardPropertiesInPropertyElements() + throws IOException { + doPositiveTest( + new String[]{JDOCONFIG_CLASSPATH_PREFIX + "/Positive00"}, + "positive00.pmf3", + 2, + 2, + true); + } + + public void testPositive00_PMF4_StandardAttributesPlusNonstandardAttributes() + throws IOException { + doPositiveTest( + new String[]{JDOCONFIG_CLASSPATH_PREFIX + "/Positive00"}, + "positive00.pmf4", + 0, + 2, + true); + } + + public void testPositive01_DuplicatePUsInDifferentConfigFilesButNotRequested() + throws IOException { + + doPositiveTest( + new String[]{ + JDOCONFIG_CLASSPATH_PREFIX + "/Positive01/1a", + JDOCONFIG_CLASSPATH_PREFIX + "/Positive01/1b" + }, + null, + 0, + 2, + false); + } + + public void testPositive03_PMF0_PMFClassNameViaServicesLookup() + throws IOException { + URLClassLoader loader = new JDOConfigTestClassLoader( JDOCONFIG_CLASSPATH_PREFIX, getClass().getClassLoader()); - ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Positive3", loader); + ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Positive03", loader); - String expected = "class.positive3.pmf0"; + String expected = "class.positive03.pmf0"; String actual = JDOHelper.getPMFClassNameViaServiceLookup(loader); assertNotNull("No PMF name found via services lookup", actual); assertEquals(expected, actual); } - /** - * Tests JDOHelper.getPMFClassNameViaServiceLookup - */ - public void testPositive04_PMF0_PMFClassNameViaServicesLookup() throws IOException { + public void testPositive04_PMF0_PMFClassNameViaServicesLookup() + throws IOException { URLClassLoader loader = new JDOConfigTestClassLoader( JDOCONFIG_CLASSPATH_PREFIX, getClass().getClassLoader()); - ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Positive4", loader); + ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Positive04", loader); - String expected = "class.positive4.pmf0"; + String expected = "class.positive04.pmf0"; String actual = JDOHelper.getPMFClassNameViaServiceLookup(loader); assertNotNull("No PMF name found via services lookup", actual); assertEquals(expected, actual); } - /** - * Tests JDOHelper.getPMFClassNameViaServiceLookup - */ - public void testPositive05_PMF0_PMFClassNameViaServicesLookup() throws IOException { + public void testPositive05_PMF0_PMFClassNameViaServicesLookup() + throws IOException { URLClassLoader loader = new JDOConfigTestClassLoader( JDOCONFIG_CLASSPATH_PREFIX, getClass().getClassLoader()); - ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Positive5", loader); + ClasspathHelper.addFile( + JDOCONFIG_CLASSPATH_PREFIX + "/Positive05", loader); - String expected = "class.positive5.pmf0"; + String expected = "class.positive05.pmf0"; String actual = JDOHelper.getPMFClassNameViaServiceLookup(loader); assertNotNull("No PMF name found via services lookup", actual); assertEquals(expected, actual); } - public void testNegative08_NoResourcesFound() { - String resource = "" + RANDOM.nextLong(); + public void testPositive06_PMF0_GetAnonymousPMFProperties() + throws IOException { - InputStream in = - getClass().getClassLoader().getResourceAsStream(resource); - assertNull(in); + URLClassLoader loader = new JDOConfigTestClassLoader( + JDOCONFIG_CLASSPATH_PREFIX, + getClass().getClassLoader()); - // resource pretty much guaranteed not to exist - try { - JDOHelper.getPersistenceManagerFactory(resource); - fail("JDOHelper failed to throw JDOFatalUserException"); - } - catch (JDOFatalUserException x) { - // happy path - } + ClasspathHelper.addFile( + JDOCONFIG_CLASSPATH_PREFIX + "/Positive06", loader); + + Map expected = prepareInitialExpectedMap( + "positive06.pmf0", 2, 0, true, true); + + Map actual = JDOHelper.getNamedPMFProperties(null, loader); + + assertNotNull("No properties found", actual); + assertEqualProperties(expected, actual); } - public void testNegative00_EmptyJDOConfigXML() throws IOException { + public void testPositive07_PMF0_GetAnonymousPMFPropertiesWithPUName() + throws IOException { + + URLClassLoader loader = new JDOConfigTestClassLoader( + JDOCONFIG_CLASSPATH_PREFIX, + getClass().getClassLoader()); + + ClasspathHelper.addFile( + JDOCONFIG_CLASSPATH_PREFIX + "/Positive07", loader); + + Map expected = prepareInitialExpectedMap( + "positive07.pmf0", 2, 0, true, false); + + Map actual = JDOHelper.getNamedPMFProperties(null, loader); + + assertNotNull("No properties found", actual); + assertEqualProperties(expected, actual); + } + + public void testNegative00_EmptyJDOConfigXML() throws IOException { try { URLClassLoader loader = new JDOConfigTestClassLoader( JDOCONFIG_CLASSPATH_PREFIX, getClass().getClassLoader()); - ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Negative0", loader); + ClasspathHelper.addFile( + JDOCONFIG_CLASSPATH_PREFIX + "/Negative0", loader); JDOHelper.getPersistenceManagerFactory(loader); fail("JDOHelper failed to throw JDOFatalUserException"); } catch (JDOFatalUserException x) { - // happy path + // sunny day } } - - public void testNegative01_NoPersistenceUnitsDefined() throws IOException { + + public void testNegative01_NoPersistenceUnitsDefined() throws IOException { try { URLClassLoader loader = new JDOConfigTestClassLoader( JDOCONFIG_CLASSPATH_PREFIX, getClass().getClassLoader()); - ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Negative1", loader); + ClasspathHelper.addFile( + JDOCONFIG_CLASSPATH_PREFIX + "/Negative01", loader); JDOHelper.getPersistenceManagerFactory(loader); fail("JDOHelper failed to throw JDOFatalUserException"); } catch (JDOFatalUserException x) { - // happy path + // joy, sweet joy } } public void testNegative02_DuplicateAnonymousPersistenceUnitsInSameConfig() - throws IOException - { + throws IOException { try { URLClassLoader loader = new JDOConfigTestClassLoader( JDOCONFIG_CLASSPATH_PREFIX, getClass().getClassLoader()); - ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Negative2", loader); + ClasspathHelper.addFile( + JDOCONFIG_CLASSPATH_PREFIX + "/Negative02", loader); JDOHelper.getPersistenceManagerFactory(loader); fail("JDOHelper failed to throw JDOFatalUserException"); } catch (JDOFatalUserException x) { - // happy path + // the cockles of my heart warmeth } } public void testNegative03_DuplicateNamedPersistenceUnitsInSameConfig() - throws IOException - { + throws IOException { try { URLClassLoader loader = new JDOConfigTestClassLoader( JDOCONFIG_CLASSPATH_PREFIX, getClass().getClassLoader()); - ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Negative3", loader); + ClasspathHelper.addFile( + JDOCONFIG_CLASSPATH_PREFIX + "/Negative03", loader); JDOHelper.getPersistenceManagerFactory( - "persistence-unit-name.negative3", - loader); + "name.negative03", + loader); fail("JDOHelper failed to throw JDOFatalUserException"); } catch (JDOFatalUserException x) { - // happy path + // warm fuzzies } } public void testNegative04_DuplicatePUNamePropertyInAttributeAndElement() - throws IOException - { + throws IOException { try { URLClassLoader loader = new JDOConfigTestClassLoader( JDOCONFIG_CLASSPATH_PREFIX, getClass().getClassLoader()); - ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Negative4", loader); + ClasspathHelper.addFile( + JDOCONFIG_CLASSPATH_PREFIX + "/Negative04", loader); JDOHelper.getPersistenceManagerFactory( - "persistence-unit-name.negative4.value0", - loader); + "name.negative04.value0", + loader); fail("JDOHelper failed to throw JDOFatalUserException"); } catch (JDOFatalUserException x) { - // happy path + // no cold pricklies } } public void testNegative05_DuplicatePropertyInAttributeAndElement() - throws IOException - { + throws IOException { try { URLClassLoader loader = new JDOConfigTestClassLoader( JDOCONFIG_CLASSPATH_PREFIX, getClass().getClassLoader()); - ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Negative5", loader); + ClasspathHelper.addFile( + JDOCONFIG_CLASSPATH_PREFIX + "/Negative05", loader); JDOHelper.getPersistenceManagerFactory(loader); fail("JDOHelper failed to throw JDOFatalUserException"); } catch (JDOFatalUserException x) { - // happy path + // party! } } public void testNegative06_DuplicatePUInDifferentConfigFiles() - throws IOException - { + throws IOException { try { URLClassLoader loader = new JDOConfigTestClassLoader( JDOCONFIG_CLASSPATH_PREFIX, getClass().getClassLoader()); - ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Negative6/6a", loader); - ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Negative6/6b", loader); + ClasspathHelper.addFile( + JDOCONFIG_CLASSPATH_PREFIX + "/Negative06/6a", loader); + ClasspathHelper.addFile( + JDOCONFIG_CLASSPATH_PREFIX + "/Negative06/6b", loader); JDOHelper.getPersistenceManagerFactory( - "persistence-unit-name.negative6", + "name.negative06", loader); fail("JDOHelper failed to throw JDOFatalUserException"); } catch (JDOFatalUserException x) { - // happy path + // clear blue sky } } public void testNegative07_EmptyServicesFile() - throws IOException - { - JDOConfigTestClassLoader testLoader = new JDOConfigTestClassLoader(new String[] {JDOCONFIG_CLASSPATH_PREFIX}, getClass().getClassLoader()); - ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Negative7", testLoader); - String shouldBeNull = JDOHelper.getPMFClassNameViaServiceLookup(testLoader); + throws IOException { + JDOConfigTestClassLoader testLoader = new JDOConfigTestClassLoader( + new String[]{JDOCONFIG_CLASSPATH_PREFIX}, + getClass().getClassLoader()); + ClasspathHelper.addFile( + JDOCONFIG_CLASSPATH_PREFIX + "/Negative07", testLoader); + String shouldBeNull = + JDOHelper.getPMFClassNameViaServiceLookup(testLoader); assertNull(shouldBeNull); } + public void testNegative08_NoResourcesFound() { + String resource = "" + RANDOM.nextLong(); + + InputStream in = + getClass().getClassLoader().getResourceAsStream(resource); + assertNull(in); + + // resource pretty much guaranteed not to exist + try { + JDOHelper.getPersistenceManagerFactory(resource); + fail("JDOHelper failed to throw JDOFatalUserException"); + } + catch (JDOFatalUserException x) { + // happy path + } + } + public void testNegative08_ServicesFileWithOnlyComments() - throws IOException - { - JDOConfigTestClassLoader testLoader = new JDOConfigTestClassLoader(new String[] {JDOCONFIG_CLASSPATH_PREFIX}, getClass().getClassLoader()); - ClasspathHelper.addFile(JDOCONFIG_CLASSPATH_PREFIX + "/Negative8", testLoader); - String shouldBeNull = JDOHelper.getPMFClassNameViaServiceLookup(testLoader); + throws IOException { + JDOConfigTestClassLoader testLoader = new JDOConfigTestClassLoader( + new String[]{JDOCONFIG_CLASSPATH_PREFIX}, + getClass().getClassLoader()); + ClasspathHelper.addFile( + JDOCONFIG_CLASSPATH_PREFIX + "/Negative08", testLoader); + String shouldBeNull = + JDOHelper.getPMFClassNameViaServiceLookup(testLoader); assertNull(shouldBeNull); } } Index: api2-legacy/src/schema/javax/jdo/jdoconfig_2_1.xsd =================================================================== --- api2-legacy/src/schema/javax/jdo/jdoconfig_2_1.xsd (revision 562509) +++ api2-legacy/src/schema/javax/jdo/jdoconfig_2_1.xsd (working copy) @@ -119,7 +119,9 @@ - + + + Index: api2-legacy/src/java/javax/jdo/PersistenceManagerFactory.java =================================================================== --- api2-legacy/src/java/javax/jdo/PersistenceManagerFactory.java (revision 562509) +++ api2-legacy/src/java/javax/jdo/PersistenceManagerFactory.java (working copy) @@ -22,14 +22,11 @@ package javax.jdo; -import java.util.Properties; -import java.util.Collection; - -import java.io.Serializable; - import javax.jdo.datastore.DataStoreCache; - import javax.jdo.listener.InstanceLifecycleListener; +import java.io.Serializable; +import java.util.Collection; +import java.util.Properties; /** The PersistenceManagerFactory is the interface to use to obtain * PersistenceManager instances. @@ -359,8 +356,21 @@ */ void setDetachAllOnCommit(boolean flag); + /** + * Sets the name of this PersistenceManagerFactory. + * @since 2.1 + * @param name the name of this PMF + */ + void setName(String name); /** + * Gets the name of this PersistenceManagerFactory. + * @since 2.1 + * @return the name of this PMF + */ + String getName(); + + /** * Sets the PersistenceUnitName for this PersistenceManagerFactory. * This has the same semantics as the same-named property in * JSR-220 PersistenceUnitInfo. Index: api2-legacy/src/java/javax/jdo/JDOHelper.java =================================================================== --- api2-legacy/src/java/javax/jdo/JDOHelper.java (revision 562509) +++ api2-legacy/src/java/javax/jdo/JDOHelper.java (working copy) @@ -22,10 +22,14 @@ package javax.jdo; -import org.w3c.dom.*; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; import org.xml.sax.ErrorHandler; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; +import org.w3c.dom.Node; +import org.w3c.dom.NamedNodeMap; import javax.jdo.spi.I18NHelper; import javax.jdo.spi.JDOImplHelper; @@ -41,13 +45,26 @@ import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.FactoryConfigurationError; import javax.xml.parsers.ParserConfigurationException; -import java.io.*; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.URL; import java.security.AccessController; import java.security.PrivilegedAction; -import java.util.*; +import java.util.Map; +import java.util.HashMap; +import java.util.Collections; +import java.util.Collection; +import java.util.Iterator; +import java.util.ArrayList; +import java.util.Properties; +import java.util.Enumeration; +import java.io.IOException; +import java.io.InputStream; +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; /** @@ -64,7 +81,7 @@ * * @version 2.1 */ -public class JDOHelper extends Object implements Constants { +public class JDOHelper implements Constants { /** * A mapping from jdoconfig.xsd element attributes to PMF properties. @@ -146,6 +163,9 @@ PMF_ATTRIBUTE_PERSISTENCE_UNIT_NAME, PROPERTY_PERSISTENCE_UNIT_NAME); xref.put( + PMF_ATTRIBUTE_NAME, + PROPERTY_NAME); + xref.put( PMF_ATTRIBUTE_RESTORE_VALUES, PROPERTY_RESTORE_VALUES); xref.put( @@ -155,8 +175,8 @@ PMF_ATTRIBUTE_DETACH_ALL_ON_COMMIT, PROPERTY_DETACH_ALL_ON_COMMIT); xref.put( - PMF_ATTRIBUTE_SERVER_TIME_ZONE_ID, - PROPERTY_SERVER_TIMEZONE_ID); + PMF_ATTRIBUTE_SERVER_TIME_ZONE_ID, + PROPERTY_SERVER_TIME_ZONE_ID); return Collections.unmodifiableMap(xref); } @@ -628,11 +648,18 @@ * @see #getPersistenceManagerFactory(java.util.Map,ClassLoader) */ public static PersistenceManagerFactory getPersistenceManagerFactory - (Map props) { + (Map props) + { ClassLoader cl = getContextClassLoader(); return getPersistenceManagerFactory (props, cl); } + public static PersistenceManagerFactory getPersistenceManagerFactory + (Map props, ClassLoader cl) + { + return getPersistenceManagerFactory(props, cl, cl); + } + /** * Get a PersistenceManagerFactory based on a * Map instance and a class loader. @@ -654,6 +681,7 @@ *
"javax.jdo.mapping.Catalog", *
"javax.jdo.mapping.Schema", *
"javax.jdo.option.PersistenceUnitName". + *
"javax.jdo.option.Name". * * and properties of the form *
javax.jdo.option.InstanceLifecycleListener.{listenerClass}={pcClasses} @@ -682,58 +710,74 @@ * @return the PersistenceManagerFactory. * @param props a Properties instance with properties of the * PersistenceManagerFactory. - * @param cl the class loader to use to load the + * @param resourceLoader the class loader to use to load resources (if + * resource loading is necessary) + * @param pmfClassLoader the class loader to use to load the * PersistenceManagerFactory class */ public static PersistenceManagerFactory getPersistenceManagerFactory - (Map props, ClassLoader cl) { + (Map props, ClassLoader resourceLoader, ClassLoader pmfClassLoader) + { String pmfClassName = (String) props.get ( - PROPERTY_PERSISTENCE_MANAGER_FACTORY_CLASS); //NOI18N + PROPERTY_PERSISTENCE_MANAGER_FACTORY_CLASS); + if (pmfClassName == null) { + // no PMF class name property -- try to find via services lookup try { - pmfClassName = getPMFClassNameViaServiceLookup(cl); + pmfClassName = getPMFClassNameViaServiceLookup(resourceLoader); } catch (IOException e) { throw new JDOFatalInternalException(msg.msg( "EXC_IOExceptionDuringServiceLookup"), e); // NOI18N } - if (pmfClassName == null) { - throw new JDOFatalUserException(msg.msg( - "EXC_GetPMFNoClassNameProperty")); // NOI18N + } + + if (pmfClassName != null) { + try { + Class pmfClass = pmfClassLoader.loadClass (pmfClassName); + Method pmfMethod = pmfClass.getMethod( + "getPersistenceManagerFactory", //NOI18N + new Class[] {Map.class}); + return (PersistenceManagerFactory) pmfMethod.invoke ( + null, new Object[] {props}); + } catch (ClassNotFoundException cnfe) { + throw new JDOFatalUserException (msg.msg( + "EXC_GetPMFClassNotFound", pmfClassName), cnfe); //NOI18N + } catch (IllegalAccessException iae) { + throw new JDOFatalUserException (msg.msg( + "EXC_GetPMFIllegalAccess", pmfClassName), iae); //NOI18N + } catch (NoSuchMethodException nsme) { + throw new JDOFatalInternalException (msg.msg( + "EXC_GetPMFNoSuchMethod"), nsme); //NOI18N + } catch (InvocationTargetException ite) { + Throwable nested = ite.getTargetException(); + if (nested instanceof JDOException) { + throw (JDOException)nested; + } else throw new JDOFatalInternalException (msg.msg( + "EXC_GetPMFUnexpectedException"), ite); //NOI18N + } catch (NullPointerException e) { + throw new JDOFatalInternalException (msg.msg( + "EXC_GetPMFNullPointerException", pmfClassName), e); //NOI18N + } catch (ClassCastException e) { + throw new JDOFatalInternalException (msg.msg( + "EXC_GetPMFClassCastException", pmfClassName), e); //NOI18N + } catch (Exception e) { + throw new JDOFatalInternalException (msg.msg( + "EXC_GetPMFUnexpectedException"), e); //NOI18N } } - try { - Class pmfClass = cl.loadClass (pmfClassName); - Method pmfMethod = pmfClass.getMethod( - "getPersistenceManagerFactory", //NOI18N - new Class[] {Map.class}); - return (PersistenceManagerFactory) pmfMethod.invoke ( - null, new Object[] {props}); - } catch (ClassNotFoundException cnfe) { - throw new JDOFatalUserException (msg.msg( - "EXC_GetPMFClassNotFound", pmfClassName), cnfe); //NOI18N - } catch (IllegalAccessException iae) { - throw new JDOFatalUserException (msg.msg( - "EXC_GetPMFIllegalAccess", pmfClassName), iae); //NOI18N - } catch (NoSuchMethodException nsme) { - throw new JDOFatalInternalException (msg.msg( - "EXC_GetPMFNoSuchMethod"), nsme); //NOI18N - } catch (InvocationTargetException ite) { - Throwable nested = ite.getTargetException(); - if (nested instanceof JDOException) { - throw (JDOException)nested; - } else throw new JDOFatalInternalException (msg.msg( - "EXC_GetPMFUnexpectedException"), ite); //NOI18N - } catch (NullPointerException e) { - throw new JDOFatalInternalException (msg.msg( - "EXC_GetPMFNullPointerException", pmfClassName), e); //NOI18N - } catch (ClassCastException e) { - throw new JDOFatalInternalException (msg.msg( - "EXC_GetPMFClassCastException", pmfClassName), e); //NOI18N - } catch (Exception e) { - throw new JDOFatalInternalException (msg.msg( - "EXC_GetPMFUnexpectedException"), e); //NOI18N + + // else no PMF class name given; check PU name + String puName = (String) props.get( + PROPERTY_PERSISTENCE_UNIT_NAME); + + if (puName != null && !"".equals(puName.trim())) { + return getPMFFromEMF(puName, props, pmfClassLoader); } + + // else no PMF class name or PU name + throw new JDOFatalUserException(msg.msg( + "EXC_GetPMFNoPMFClassNamePropertyOrPUNameProperty")); } /** @@ -837,23 +881,30 @@ } /** - * Returns a named {@link PersistenceManagerFactory} with the given - * persistence unit name or, - * if not found, a {@link PersistenceManagerFactory} configured based + * Returns a {@link PersistenceManagerFactory} configured based * on the properties stored in the resource at - * name. Loads the Properties via + * name, or, if not found, returns a + * {@link PersistenceManagerFactory} with the given + * name or, if not found, returns a + * javax.persistence.EntityManagerFactory cast to a + * {@link PersistenceManagerFactory}. Loads the properties via * resourceLoader, and creates a {@link * PersistenceManagerFactory} with pmfLoader. Any * exceptions thrown during resource loading will * be wrapped in a {@link JDOFatalUserException}. - * If multiple persistence units with the requested name are found, a + * If multiple PMFs with the requested name are found, a * {@link JDOFatalUserException} is thrown. * @since 2.0 - * @param name the persistence unit name or resource containing the Properties - * @param resourceLoader the class loader to use to load the name + * @param name interpreted as the name of the resource containing the PMF + * properties, the name of the PMF, or the persistence unit name, in that + * order. + * @param resourceLoader the class loader to use to load properties or + * configuration file resources * @param pmfLoader the class loader to use to load the - * PersistenceManagerFactory class - * @return the PersistenceManagerFactory + * PersistenceManagerFactory or + * javax.persistence.EntityManagerFactory classes + * @return the PersistenceManagerFactory with properties in the given + * resource, with the given name, or with the given persitence unit name */ public static PersistenceManagerFactory getPersistenceManagerFactory (String name, ClassLoader resourceLoader, ClassLoader pmfLoader) { @@ -865,16 +916,16 @@ throw new JDOFatalUserException (msg.msg ( "EXC_GetPMFNullPMFLoader")); //NOI18N + Properties props = null; InputStream in = null; if (name != null) { // then try to load resources from properties file - Properties props = new Properties (); try { - in = resourceLoader.getResourceAsStream (name); + in = resourceLoader.getResourceAsStream(name); if (in != null) { // then some kind of resource was found by the given name; // assume that it's a properties file and proceed as usual - props.load (in); - return getPersistenceManagerFactory (props, pmfLoader); + props = new Properties(); + props.load(in); } } catch (IOException ioe) { @@ -889,94 +940,58 @@ } } // JDO 2.1: else name was null or no resource found by given name; - // assume name represents name of PU + // first assume that name represents name of named PMF - PersistenceManagerFactory pmf = getPersistenceUnit( - name == null ? "" : name.trim(), - resourceLoader, - pmfLoader - ); - if (pmf != null) { - return pmf; + Map properties = props; + if (properties == null) { + properties = getNamedPMFProperties(name, resourceLoader); } - // else no PU found + if (properties != null) { + String nameInProperties = (String) properties.get(PROPERTY_NAME); + nameInProperties = nameInProperties == null ? "" : nameInProperties; + if (nameInProperties == null) { + properties.put(PROPERTY_NAME, name); + } + return getPersistenceManagerFactory( + properties, resourceLoader, pmfLoader); + } + + // else no properties found; next, assume name is a PU name + if (name != null && !"".equals(name.trim())) { + PersistenceManagerFactory pmf = + getPMFFromEMF(name, null, pmfLoader); + if (pmf != null) { + return pmf; + } + } + + // else no PMF found throw new JDOFatalUserException (msg.msg ( "EXC_NoPMFConfigurableViaPropertiesOrXML", name, resourceLoader)); //NOI18N } - /** Find and return
    - *
  • a {@link PersistenceManagerFactory} with the given name,
  • - *
  • a JPA EntityManagerFactory cast to a - * {@link PersistenceManagerFactory}, or
  • - *
  • null if not found.
  • - * If name is null - * or blank, this method attempts to return the anonymous - * {@link PersistenceManagerFactory}. If multiple persistence units with - * the given name are found (including the anonymous persistence unit), - * this method will throw {@link JDOFatalUserException}. - * - * @param name The persistence unit name, or null, the empty string or a - * string only containing whitespace characters for the anonymous - * persistence unit. - * @param resourceLoader The ClassLoader used to load the standard JDO - * configuration file(s) given in the constant - * {@link Constants#JDOCONFIG_RESOURCE_NAME}. - * @param pmfLoader The loader used to load the - * {@link PersistenceManagerFactory} implementation class. - * @return A {@link PersistenceManagerFactory} corresponding to the - * persistence unit name if found, or null if not found. - * @throws JDOFatalUserException if multiple persistence units are found - * with the given name, or any other is encountered. - * @since 2.1 - */ - public static PersistenceManagerFactory getPersistenceUnit( + protected static Map getNamedPMFProperties( String name, - ClassLoader resourceLoader, - ClassLoader pmfLoader - ) { - Map properties = getPersistenceUnitProperties( - name, resourceLoader, JDOCONFIG_RESOURCE_NAME); - - if (properties != null) { // found requested JDO persistence unit props - return getPersistenceManagerFactory(properties, pmfLoader); - } - - // else try to return PMF from JPA EMF - if ("".equals(name)) { // no such thing as an anonymous JPA EMF - return null; - } - - // else try to return PMF from named JPA EMF - return getPMFFromEMF(name, pmfLoader); - } - - protected static Map getPersistenceUnitProperties( - String name - ) { - return getPersistenceUnitProperties( - name, getContextClassLoader(), JDOCONFIG_RESOURCE_NAME); - } - - protected static Map getPersistenceUnitProperties( - String name, ClassLoader resourceLoader ) { - return getPersistenceUnitProperties( + return getNamedPMFProperties( name, resourceLoader, JDOCONFIG_RESOURCE_NAME); } /** - * Find and return the named {@link PersistenceManagerFactory}, or null if + * Find and return the named {@link PersistenceManagerFactory}'s properties, + * or null if * not found. If name is null, return the anonymous - * {@link PersistenceManagerFactory}. If multiple persistence units with - * the given name are found (including anonymous), throw + * {@link PersistenceManagerFactory}'s properties. + * If multiple named PMF property sets with + * the given name are found (including anonymous ones), throw * {@link JDOFatalUserException}. * This method is here only to facilitate testing; the parameter * "jdoconfigResourceName" in public usage should always have the value - * given in the constant JDOCONFIG_RESOURCE_NAME. + * given in the constant {@link Constants#JDOCONFIG_RESOURCE_NAME}. * * @param name The persistence unit name, or null or blank for the * anonymous persistence unit. @@ -988,17 +1003,17 @@ * @return The named PersistenceManagerFactory properties if found, null if * not. * @since 2.1 - * @throws JDOFatalUserException if multiple persistence units are found - * with the given name, or any other exception is encountered. + * @throws JDOFatalUserException if multiple named PMF property sets are + * found with the given name, or any other exception is encountered. */ - protected static Map getPersistenceUnitProperties( + protected static Map getNamedPMFProperties( String name, ClassLoader resourceLoader, String jdoconfigResourceName ) { /* JDO 2.1: - Attempt to find & return named persistence unit here. - If name == null or name == "", then we're looking for the default PMF. + Attempt to find & return named PMF properties here. + If name == null or name == "", then we're looking for the anonymous PMF. If we can't find it, this method returns null. */ @@ -1018,12 +1033,7 @@ ArrayList processedResources = new ArrayList(); // get ready to parse XML - DocumentBuilderFactory factory = - implHelper.getRegisteredDocumentBuilderFactory(); - if (factory == null) { - factory = getDefaultDocumentBuilderFactory(); - } - + DocumentBuilderFactory factory = getDocumentBuilderFactory(); do { URL currentConfigURL = (URL) resources.nextElement(); if (processedResources.contains(currentConfigURL)) { @@ -1034,8 +1044,10 @@ } Map/**/ propertiesByNameInCurrentConfig = - readPersistenceUnitProperties( - currentConfigURL, name, factory); + readNamedPMFProperties( + currentConfigURL, + name, + factory); // try to detect duplicate requested PU if (propertiesByNameInCurrentConfig.containsKey(name)) { @@ -1046,7 +1058,7 @@ if (propertiesByNameInAllConfigs.containsKey(name)) throw new JDOFatalUserException (msg.msg( - "EXC_DuplicateRequestedPersistenceUnitFoundInDifferentConfigs", + "EXC_DuplicateRequestedNamedPMFFoundInDifferentConfigs", "".equals(name) ? "(anonymous)" : name, @@ -1074,6 +1086,15 @@ } + protected static DocumentBuilderFactory getDocumentBuilderFactory() { + DocumentBuilderFactory factory = + implHelper.getRegisteredDocumentBuilderFactory(); + if (factory == null) { + factory = getDefaultDocumentBuilderFactory(); + } + return factory; + } + protected static DocumentBuilderFactory getDefaultDocumentBuilderFactory() { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setIgnoringComments(true); @@ -1085,6 +1106,14 @@ return factory; } + protected static ErrorHandler getErrorHandler() { + ErrorHandler handler = implHelper.getRegisteredErrorHandler(); + if (handler == null) { + handler = getDefaultErrorHandler(); + } + return handler; + } + protected static ErrorHandler getDefaultErrorHandler() { return new ErrorHandler() { public void error(SAXParseException exception) @@ -1105,26 +1134,16 @@ } /** - * Convenience method for retrieving the JPA persistence unit by the given - * name. This method is equivalent to - * calling {@link #getPMFFromEMF(String,ClassLoader)} with the context ClassLoader. - * @param name The persistence unit name. - * @see #getPMFFromEMF(String,ClassLoader) - * @return The named EMF cast as a PMF. - */ - protected static PersistenceManagerFactory getPMFFromEMF(String name) { - return getPMFFromEMF(name, getContextClassLoader()); - } - - /** * Attempts to locate a javax.persistence.EntityManagerFactory * via the javax.persistence.Persistence method * createEntityManagerFactory(String) * and casts it to a {@link PersistenceManagerFactory}. It is a user error - * if his chosen JPA vendor's EntityManagerFactory + * if his chosen JPA vendor's + * javax.persistence.EntityManagerFactory * implementation class does not also implement * {@link PersistenceManagerFactory}. * @param name The persistence unit name. + * @param properties The properties of the persistence unit. * @param loader The classloader used to attempt loading of the class * javax.persistence.Persistence * and javax.persistence.PersistenceException. @@ -1152,8 +1171,8 @@ *
*/ protected static PersistenceManagerFactory getPMFFromEMF( - String name, ClassLoader loader - ) { + String name, Map properties, ClassLoader loader) + { /* This implementation uses reflection to try to get an EMF so that javax.jdo, a Java SE API, does not introduce an unnecessary @@ -1174,7 +1193,7 @@ createEntityManagerFactoryMethod = persistenceClass.getMethod( "createEntityManagerFactory", - new Class[] { String.class }); + new Class[] { String.class, Map.class }); persistenceExceptionClass = Class.forName( @@ -1194,7 +1213,7 @@ try { entityManagerFactory = createEntityManagerFactoryMethod.invoke( - persistenceClass, new Object[] { name }); + persistenceClass, new Object[] { name, properties }); } catch (RuntimeException x) { if (persistenceExceptionClass.isAssignableFrom(x.getClass())) { @@ -1229,7 +1248,7 @@ * persistence-manager-factory, then returns the map. * @param url URL of a JDO configuration file compliant with * javax/jdo/jdoconfig.xsd. - * @param requestedPersistenceUnitName The name of the requested + * @param requestedPMFName The name of the requested * persistence unit (allows for fail-fast). * @param factory The DocumentBuilderFactory to use for XML * parsing. @@ -1237,37 +1256,21 @@ * the anonymous persistence unit, the * value of the String key is the empty string, "". */ - protected static Map/**/ readPersistenceUnitProperties( + protected static Map/**/ readNamedPMFProperties( URL url, - String requestedPersistenceUnitName, + String requestedPMFName, DocumentBuilderFactory factory ) { - requestedPersistenceUnitName = requestedPersistenceUnitName == null + requestedPMFName = requestedPMFName == null ? "" - : requestedPersistenceUnitName.trim(); + : requestedPMFName.trim(); Map propertiesByName = new HashMap(); InputStream in = null; try { DocumentBuilder builder = factory.newDocumentBuilder(); - - builder.setErrorHandler(new ErrorHandler() { - public void error(SAXParseException exception) - throws SAXException { - throw exception; - } + builder.setErrorHandler(getErrorHandler()); - public void fatalError(SAXParseException exception) - throws SAXException { - throw exception; - } - - public void warning(SAXParseException exception) - throws SAXException { - // gulp - } - }); - in = url.openStream(); Document doc = builder.parse(in); @@ -1278,7 +1281,6 @@ ); } - // TODO: prefer using namespace-aware APIs NodeList pmfs = root.getElementsByTagName( ELEMENT_PERSISTENCE_MANAGER_FACTORY); @@ -1291,43 +1293,41 @@ Properties pmfPropertiesFromElements = readPropertiesFromPMFSubelements(pmfElement, url); - // for informative error handling, get PU name (or names) now - String puNameFromAtts = - pmfPropertiesFromAttributes.getProperty( - PROPERTY_PERSISTENCE_UNIT_NAME); - String puNameFromElem = - pmfPropertiesFromElements.getProperty( - PROPERTY_PERSISTENCE_UNIT_NAME); + // for informative error handling, get name (or names) now + String pmfNameFromAtts = + pmfPropertiesFromAttributes.getProperty(PROPERTY_NAME); + String pmfNameFromElem = + pmfPropertiesFromElements.getProperty(PROPERTY_NAME); - String puName = null; - if (nullOrBlank(puNameFromAtts)) { - // no PU name attribute given - if (!nullOrBlank(puNameFromElem)) { - // PU name element was given - puName = puNameFromElem; + String pmfName = null; + if (nullOrBlank(pmfNameFromAtts)) { + // no PMF name attribute given + if (!nullOrBlank(pmfNameFromElem)) { + // PMF name element was given + pmfName = pmfNameFromElem; } else { - // PU name not given at all, means the "anonymous" PU - puName = ""; + // PMF name not given at all, means the "anonymous" PMF + pmfName = ""; } } else { - // PU name given in an attribute - if (!nullOrBlank(puNameFromElem)) { - // exception -- PU name given as both att & elem + // PMF name given in an attribute + if (!nullOrBlank(pmfNameFromElem)) { + // exception -- PMF name given as both att & elem throw new JDOFatalUserException( msg.msg( - "EXC_DuplicatePersistenceUnitNamePropertyFoundWithinUnitConfig", - puNameFromAtts, - puNameFromElem, + "EXC_DuplicatePMFNamePropertyFoundWithinConfig", + pmfNameFromAtts, + pmfNameFromElem, url.toExternalForm())); } - puName = puNameFromAtts; + pmfName = pmfNameFromAtts; } - puName = puName == null ? "" : puName.trim(); + pmfName = pmfName == null ? "" : pmfName.trim(); // check for duplicate properties among atts & elems - if (requestedPersistenceUnitName.equals(puName)) { + if (requestedPMFName.equals(pmfName)) { Iterator it = pmfPropertiesFromAttributes.keySet().iterator(); while (it.hasNext()) { @@ -1337,7 +1337,7 @@ msg.msg( "EXC_DuplicatePropertyFound", property, - puName, + pmfName, url.toExternalForm())); } } @@ -1349,16 +1349,16 @@ pmfProps.putAll(pmfPropertiesFromAttributes); pmfProps.putAll(pmfPropertiesFromElements); - // check for duplicate requested PU name - if (puName.equals(requestedPersistenceUnitName) - && propertiesByName.containsKey(puName)) { + // check for duplicate requested PMF name + if (pmfName.equals(requestedPMFName) + && propertiesByName.containsKey(pmfName)) { throw new JDOFatalUserException(msg.msg( - "EXC_DuplicateRequestedPersistenceUnitFoundInSameConfig", - puName, + "EXC_DuplicateRequestedNamedPMFFoundInSameConfig", + pmfName, url.toExternalForm())); } - propertiesByName.put(puName, pmfProps); + propertiesByName.put(pmfName, pmfProps); } return propertiesByName; } @@ -1577,7 +1577,7 @@ Properties props = new Properties (); InputStream in = null; try { - in = new FileInputStream (propsFile); + in = new FileInputStream(propsFile); props.load (in); } catch (FileNotFoundException fnfe) { throw new JDOFatalUserException (msg.msg ( Index: api2-legacy/src/java/javax/jdo/Constants.java =================================================================== --- api2-legacy/src/java/javax/jdo/Constants.java (revision 562509) +++ api2-legacy/src/java/javax/jdo/Constants.java (working copy) @@ -98,6 +98,14 @@ = "class"; /** * The name of the persistence manager factory element's + * "name" attribute. + * + * @since 2.1 + */ + static String PMF_ATTRIBUTE_NAME + = "name"; + /** + * The name of the persistence manager factory element's * "persistence-unit-name" attribute. * * @since 2.1 @@ -649,6 +657,14 @@ */ static String PROPERTY_PERSISTENCE_UNIT_NAME = "javax.jdo.option.PersistenceUnitName"; + /** + * "javax.jdo.option.Name" + * + * @see PersistenceManagerFactory#getName() + * @since 2.1 + */ + static String PROPERTY_NAME + = "javax.jdo.option.Name"; /** * "javax.jdo.option.InstanceLifecycleListener" @@ -703,7 +719,7 @@ * * @since 2.1 */ - static String PROPERTY_SERVER_TIMEZONE_ID + static String PROPERTY_SERVER_TIME_ZONE_ID = "javax.jdo.option.ServerTimeZoneID"; /** Index: api2-legacy/src/java/javax/jdo/Bundle.properties =================================================================== --- api2-legacy/src/java/javax/jdo/Bundle.properties (revision 562509) +++ api2-legacy/src/java/javax/jdo/Bundle.properties (working copy) @@ -25,8 +25,9 @@ EXC_GetPMFUnexpectedException=Unexpected exception caught. EXC_GetPMFClassNotFound=Class {0} was not found. EXC_GetPMFIllegalAccess=Illegal Access for class {0}. -EXC_GetPMFNoClassNameProperty=A property named javax.jdo.PersistenceManagerFactoryClass must be specified, \ -or the jar file with the default META-INF/services/javax.jdo.PersistenceManagerFactory entry must be in the classpath. +EXC_GetPMFNoPMFClassNamePropertyOrPUNameProperty=A property named javax.jdo.PersistenceManagerFactoryClass must be specified, \ +or a jar file with a META-INF/services/javax.jdo.PersistenceManagerFactory entry must be in the classpath, \ +or a property named javax.jdo.option.PersistenceUnitName must be specified. EXC_IOExceptionDuringServiceLookup=IO error while attempting to lookup PMF name \ via META-INF/services/javax.jdo.PersistenceManagerFactory MSG_FailedObject=FailedObject: @@ -80,10 +81,10 @@ EXC_DateStringConstructor: Error parsing Date string "{0}" at position {1} \ using date format "{2}". MSG_unknown: unknown -EXC_DuplicateRequestedPersistenceUnitFoundInDifferentConfigs: Duplicate \ -persistence unit name "{0}" found in {1} and {2}. -EXC_DuplicateRequestedPersistenceUnitFoundInSameConfig: Duplicate persistence \ -unit name "{0}" found in {1}. +EXC_DuplicateRequestedNamedPMFFoundInDifferentConfigs: Duplicate \ +PMF name "{0}" found in {1} and {2}. +EXC_DuplicateRequestedNamedPMFFoundInSameConfig: Duplicate PMF \ +name "{0}" found in {1}. EXC_UnableToInvokeCreateEMFMethod: Unable to invoke \ javax.persistence.Persistence.createEntityManagerFactory(String) EXC_UnableToCastEMFToPMF: Unable to cast EntityManagerFactory class {0} \ @@ -95,10 +96,10 @@ EXC_SAXParseException: Exception parsing configuration {0}\ at line {1}, column {2} EXC_SAXException: Exception parsing configuration {0} -EXC_DuplicatePropertyFound: Duplicate property name "{0}" found in persistence \ -unit name "{1}" found in {2}. -EXC_DuplicatePersistenceUnitNamePropertyFoundWithinUnitConfig: Duplicate \ -persistence unit name found in {2}: attribute is "{0}", element is "{1}" +EXC_DuplicatePropertyFound: Duplicate property name "{0}" found in PMF \ +configuration with name "{1}" found in {2}. +EXC_DuplicatePMFNamePropertyFoundWithinConfig: Duplicate \ +PMF name found in {2}: attribute is "{0}", element is "{1}" EXC_PropertyElementHasNoNameAttribute: Found element with no \ "name" attribute in {0} EXC_PropertyElementNameAttributeHasNoValue: Found element name \ @@ -111,5 +112,5 @@ "listener" missing value in {0} EXC_InvalidJDOConfigNoRoot: No root element found in {0} EXC_NoPMFConfigurableViaPropertiesOrXML: No PersistenceManagerFactory \ -configurable via properties resource "{0}" or no persistence unit named "{0}" \ -found using resource loader {1} +configurable via properties resource "{0}" or no named PMF or persistence unit\ +named "{0}" found using resource loader {1} Index: tck2/src/conf/jdo-2_1-signatures.txt =================================================================== --- tck2/src/conf/jdo-2_1-signatures.txt (revision 562577) +++ tck2/src/conf/jdo-2_1-signatures.txt (working copy) @@ -15,6 +15,8 @@ = "persistence-manager-factory"; static String PMF_ATTRIBUTE_CLASS = "class"; + static String PMF_ATTRIBUTE_NAME + = "name"; static String PMF_ATTRIBUTE_PERSISTENCE_UNIT_NAME = "persistence-unit-name"; static String PMF_ATTRIBUTE_OPTIMISTIC @@ -153,6 +155,8 @@ = "javax.jdo.option.ConnectionFactory2Name"; static String PROPERTY_MAPPING = "javax.jdo.option.Mapping"; + static String PROPERTY_NAME + = "javax.jdo.option.Name"; static String PROPERTY_PERSISTENCE_UNIT_NAME = "javax.jdo.option.PersistenceUnitName"; static String PROPERTY_INSTANCE_LIFECYCLE_LISTENER @@ -450,6 +454,7 @@ public static javax.jdo.PersistenceManagerFactory getPersistenceManagerFactory(); public static javax.jdo.PersistenceManagerFactory getPersistenceManagerFactory(java.util.Map props); public static javax.jdo.PersistenceManagerFactory getPersistenceManagerFactory(java.util.Map props, ClassLoader cl); + public static javax.jdo.PersistenceManagerFactory getPersistenceManagerFactory(java.util.Map props, ClassLoader resourceLoader, ClassLoader pmfLoader); public static javax.jdo.PersistenceManagerFactory getPersistenceManagerFactory(String propsResource); public static javax.jdo.PersistenceManagerFactory getPersistenceManagerFactory(String propsResource, ClassLoader loader); public static javax.jdo.PersistenceManagerFactory getPersistenceManagerFactory(String propsResource, ClassLoader propsLoader, ClassLoader pmfLoader); @@ -720,6 +725,8 @@ public boolean getIgnoreCache(); public boolean getDetachAllOnCommit(); public void setDetachAllOnCommit(boolean flag); + public java.lang.String getName(); + public void setName(java.lang.String); public java.lang.String getPersistenceUnitName(); public void setPersistenceUnitName(java.lang.String); public java.lang.String getServerTimeZoneID(); Index: tck2-legacy/src/conf/jdo-2_1-signatures.txt =================================================================== --- tck2-legacy/src/conf/jdo-2_1-signatures.txt (revision 562577) +++ tck2-legacy/src/conf/jdo-2_1-signatures.txt (working copy) @@ -15,6 +15,8 @@ = "persistence-manager-factory"; static String PMF_ATTRIBUTE_CLASS = "class"; + static String PMF_ATTRIBUTE_NAME + = "name"; static String PMF_ATTRIBUTE_PERSISTENCE_UNIT_NAME = "persistence-unit-name"; static String PMF_ATTRIBUTE_OPTIMISTIC @@ -153,6 +155,8 @@ = "javax.jdo.option.ConnectionFactory2Name"; static String PROPERTY_MAPPING = "javax.jdo.option.Mapping"; + static String PROPERTY_NAME + = "javax.jdo.option.Name"; static String PROPERTY_PERSISTENCE_UNIT_NAME = "javax.jdo.option.PersistenceUnitName"; static String PROPERTY_INSTANCE_LIFECYCLE_LISTENER @@ -450,6 +454,7 @@ public static javax.jdo.PersistenceManagerFactory getPersistenceManagerFactory(); public static javax.jdo.PersistenceManagerFactory getPersistenceManagerFactory(java.util.Map props); public static javax.jdo.PersistenceManagerFactory getPersistenceManagerFactory(java.util.Map props, ClassLoader cl); + public static javax.jdo.PersistenceManagerFactory getPersistenceManagerFactory(java.util.Map props, ClassLoader resourceLoader, ClassLoader pmfLoader); public static javax.jdo.PersistenceManagerFactory getPersistenceManagerFactory(String propsResource); public static javax.jdo.PersistenceManagerFactory getPersistenceManagerFactory(String propsResource, ClassLoader loader); public static javax.jdo.PersistenceManagerFactory getPersistenceManagerFactory(String propsResource, ClassLoader propsLoader, ClassLoader pmfLoader); @@ -720,6 +725,8 @@ public boolean getIgnoreCache(); public boolean getDetachAllOnCommit(); public void setDetachAllOnCommit(boolean flag); + public java.lang.String getName(); + public void setName(java.lang.String); public java.lang.String getPersistenceUnitName(); public void setPersistenceUnitName(java.lang.String); public java.lang.String getServerTimeZoneID();