From jdo-commits-return-1877-apmail-db-jdo-commits-archive=www.apache.org@db.apache.org Thu Aug 09 21:21:30 2007 Return-Path: Delivered-To: apmail-db-jdo-commits-archive@www.apache.org Received: (qmail 67119 invoked from network); 9 Aug 2007 21:21:30 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 9 Aug 2007 21:21:30 -0000 Received: (qmail 65587 invoked by uid 500); 9 Aug 2007 21:21:29 -0000 Mailing-List: contact jdo-commits-help@db.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: jdo-dev@db.apache.org Delivered-To: mailing list jdo-commits@db.apache.org Received: (qmail 65565 invoked by uid 99); 9 Aug 2007 21:21:28 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 09 Aug 2007 14:21:28 -0700 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 09 Aug 2007 21:21:27 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id E5D041A981F; Thu, 9 Aug 2007 14:21:06 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r564384 [2/3] - in /db/jdo/trunk: api2-legacy/src/java/javax/jdo/ api2-legacy/src/schema/javax/jdo/ api2-legacy/test/java/javax/jdo/ api2-legacy/test/schema/jdoconfig/Negative0/ api2-legacy/test/schema/jdoconfig/Negative00/ api2-legacy/test... Date: Thu, 09 Aug 2007 21:20:55 -0000 To: jdo-commits@db.apache.org From: madams@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070809212106.E5D041A981F@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Negative07/META-INF/services/javax.jdo.PersistenceManagerFactory URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Negative07/META-INF/services/javax.jdo.PersistenceManagerFactory?view=auto&rev=564384 ============================================================================== (empty) Added: db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Negative08/META-INF/services/javax.jdo.PersistenceManagerFactory URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Negative08/META-INF/services/javax.jdo.PersistenceManagerFactory?view=auto&rev=564384 ============================================================================== --- db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Negative08/META-INF/services/javax.jdo.PersistenceManagerFactory (added) +++ db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Negative08/META-INF/services/javax.jdo.PersistenceManagerFactory Thu Aug 9 14:20:35 2007 @@ -0,0 +1,3 @@ +# there are +# only comments +# in this file \ No newline at end of file Added: db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Positive00/META-INF/jdoconfig.xml URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Positive00/META-INF/jdoconfig.xml?view=auto&rev=564384 ============================================================================== --- db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Positive00/META-INF/jdoconfig.xml (added) +++ db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Positive00/META-INF/jdoconfig.xml Thu Aug 9 14:20:35 2007 @@ -0,0 +1,260 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Added: db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Positive01/1a/META-INF/jdoconfig.xml URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Positive01/1a/META-INF/jdoconfig.xml?view=auto&rev=564384 ============================================================================== --- db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Positive01/1a/META-INF/jdoconfig.xml (added) +++ db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Positive01/1a/META-INF/jdoconfig.xml Thu Aug 9 14:20:35 2007 @@ -0,0 +1,17 @@ + + + + + + + + + + Added: db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Positive01/1b/META-INF/jdoconfig.xml URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Positive01/1b/META-INF/jdoconfig.xml?view=auto&rev=564384 ============================================================================== --- db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Positive01/1b/META-INF/jdoconfig.xml (added) +++ db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Positive01/1b/META-INF/jdoconfig.xml Thu Aug 9 14:20:35 2007 @@ -0,0 +1,15 @@ + + + + + + + + Added: db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Positive03/META-INF/jdoconfig.xml URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Positive03/META-INF/jdoconfig.xml?view=auto&rev=564384 ============================================================================== --- db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Positive03/META-INF/jdoconfig.xml (added) +++ db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Positive03/META-INF/jdoconfig.xml Thu Aug 9 14:20:35 2007 @@ -0,0 +1,13 @@ + + + + + + + Added: db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Positive03/META-INF/services/javax.jdo.PersistenceManagerFactory URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Positive03/META-INF/services/javax.jdo.PersistenceManagerFactory?view=auto&rev=564384 ============================================================================== --- db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Positive03/META-INF/services/javax.jdo.PersistenceManagerFactory (added) +++ db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Positive03/META-INF/services/javax.jdo.PersistenceManagerFactory Thu Aug 9 14:20:35 2007 @@ -0,0 +1 @@ +class.positive03.pmf0 \ No newline at end of file Added: db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Positive04/META-INF/jdoconfig.xml URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Positive04/META-INF/jdoconfig.xml?view=auto&rev=564384 ============================================================================== --- db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Positive04/META-INF/jdoconfig.xml (added) +++ db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Positive04/META-INF/jdoconfig.xml Thu Aug 9 14:20:35 2007 @@ -0,0 +1,13 @@ + + + + + + + Added: db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Positive04/META-INF/services/javax.jdo.PersistenceManagerFactory URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Positive04/META-INF/services/javax.jdo.PersistenceManagerFactory?view=auto&rev=564384 ============================================================================== --- db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Positive04/META-INF/services/javax.jdo.PersistenceManagerFactory (added) +++ db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Positive04/META-INF/services/javax.jdo.PersistenceManagerFactory Thu Aug 9 14:20:35 2007 @@ -0,0 +1,3 @@ + +#this is a comment +class.positive04.pmf0 # this is another comment \ No newline at end of file Added: db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Positive05/META-INF/jdoconfig.xml URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Positive05/META-INF/jdoconfig.xml?view=auto&rev=564384 ============================================================================== --- db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Positive05/META-INF/jdoconfig.xml (added) +++ db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Positive05/META-INF/jdoconfig.xml Thu Aug 9 14:20:35 2007 @@ -0,0 +1,13 @@ + + + + + + + Added: db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Positive05/META-INF/services/javax.jdo.PersistenceManagerFactory URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Positive05/META-INF/services/javax.jdo.PersistenceManagerFactory?view=auto&rev=564384 ============================================================================== --- db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Positive05/META-INF/services/javax.jdo.PersistenceManagerFactory (added) +++ db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Positive05/META-INF/services/javax.jdo.PersistenceManagerFactory Thu Aug 9 14:20:35 2007 @@ -0,0 +1 @@ +class.positive05.pmf0# this is a comment without whitespace separating it from the uncommented text \ No newline at end of file Added: db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Positive06/META-INF/jdoconfig.xml URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Positive06/META-INF/jdoconfig.xml?view=auto&rev=564384 ============================================================================== --- db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Positive06/META-INF/jdoconfig.xml (added) +++ db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Positive06/META-INF/jdoconfig.xml Thu Aug 9 14:20:35 2007 @@ -0,0 +1,43 @@ + + + + + + + + + + + Added: db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Positive07/META-INF/jdoconfig.xml URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Positive07/META-INF/jdoconfig.xml?view=auto&rev=564384 ============================================================================== --- db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Positive07/META-INF/jdoconfig.xml (added) +++ db/jdo/trunk/api2-legacy/test/schema/jdoconfig/Positive07/META-INF/jdoconfig.xml Thu Aug 9 14:20:35 2007 @@ -0,0 +1,45 @@ + + + + + + + + + + + + Modified: db/jdo/trunk/api2/src/java/javax/jdo/Bundle.properties URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2/src/java/javax/jdo/Bundle.properties?view=diff&rev=564384&r1=564383&r2=564384 ============================================================================== --- db/jdo/trunk/api2/src/java/javax/jdo/Bundle.properties (original) +++ db/jdo/trunk/api2/src/java/javax/jdo/Bundle.properties Thu Aug 9 14:20:35 2007 @@ -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} Modified: db/jdo/trunk/api2/src/java/javax/jdo/Constants.java URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2/src/java/javax/jdo/Constants.java?view=diff&rev=564384&r1=564383&r2=564384 ============================================================================== --- db/jdo/trunk/api2/src/java/javax/jdo/Constants.java (original) +++ db/jdo/trunk/api2/src/java/javax/jdo/Constants.java Thu Aug 9 14:20:35 2007 @@ -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" Modified: db/jdo/trunk/api2/src/java/javax/jdo/JDOHelper.java URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2/src/java/javax/jdo/JDOHelper.java?view=diff&rev=564384&r1=564383&r2=564384 ============================================================================== --- db/jdo/trunk/api2/src/java/javax/jdo/JDOHelper.java (original) +++ db/jdo/trunk/api2/src/java/javax/jdo/JDOHelper.java Thu Aug 9 14:20:35 2007 @@ -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); + } + + 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 PU found + // 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( - 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( + protected static Map getNamedPMFProperties( 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,36 +1256,20 @@ * 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; - } - - public void fatalError(SAXParseException exception) - throws SAXException { - throw exception; - } - - public void warning(SAXParseException exception) - throws SAXException { - // gulp - } - }); + builder.setErrorHandler(getErrorHandler()); 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); - - String puName = null; - if (nullOrBlank(puNameFromAtts)) { - // no PU name attribute given - if (!nullOrBlank(puNameFromElem)) { - // PU name element was given - puName = puNameFromElem; + // for informative error handling, get name (or names) now + String pmfNameFromAtts = + pmfPropertiesFromAttributes.getProperty(PROPERTY_NAME); + String pmfNameFromElem = + pmfPropertiesFromElements.getProperty(PROPERTY_NAME); + + 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 ( Modified: db/jdo/trunk/api2/src/java/javax/jdo/PersistenceManagerFactory.java URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2/src/java/javax/jdo/PersistenceManagerFactory.java?view=diff&rev=564384&r1=564383&r2=564384 ============================================================================== --- db/jdo/trunk/api2/src/java/javax/jdo/PersistenceManagerFactory.java (original) +++ db/jdo/trunk/api2/src/java/javax/jdo/PersistenceManagerFactory.java Thu Aug 9 14:20:35 2007 @@ -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,6 +356,19 @@ */ 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. Modified: db/jdo/trunk/api2/src/schema/javax/jdo/jdoconfig_2_1.xsd URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2/src/schema/javax/jdo/jdoconfig_2_1.xsd?view=diff&rev=564384&r1=564383&r2=564384 ============================================================================== --- db/jdo/trunk/api2/src/schema/javax/jdo/jdoconfig_2_1.xsd (original) +++ db/jdo/trunk/api2/src/schema/javax/jdo/jdoconfig_2_1.xsd Thu Aug 9 14:20:35 2007 @@ -119,7 +119,9 @@ - + + +