db-jdo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mad...@apache.org
Subject svn commit: r570635 - in /db/jdo/trunk: api2-legacy/src/java/javax/jdo/Bundle.properties api2-legacy/src/java/javax/jdo/JDOHelper.java api2/src/java/javax/jdo/Bundle.properties api2/src/java/javax/jdo/JDOHelper.java
Date Wed, 29 Aug 2007 04:43:46 GMT
Author: madams
Date: Tue Aug 28 21:43:45 2007
New Revision: 570635

URL: http://svn.apache.org/viewvc?rev=570635&view=rev
Log:
JDO-523, Misleading error msg raised by JDOHelper.getPersistenceManagerFactory(arg) if the
resource in arg does not exist

Modified:
    db/jdo/trunk/api2-legacy/src/java/javax/jdo/Bundle.properties
    db/jdo/trunk/api2-legacy/src/java/javax/jdo/JDOHelper.java
    db/jdo/trunk/api2/src/java/javax/jdo/Bundle.properties
    db/jdo/trunk/api2/src/java/javax/jdo/JDOHelper.java

Modified: db/jdo/trunk/api2-legacy/src/java/javax/jdo/Bundle.properties
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2-legacy/src/java/javax/jdo/Bundle.properties?rev=570635&r1=570634&r2=570635&view=diff
==============================================================================
--- db/jdo/trunk/api2-legacy/src/java/javax/jdo/Bundle.properties (original)
+++ db/jdo/trunk/api2-legacy/src/java/javax/jdo/Bundle.properties Tue Aug 28 21:43:45 2007
@@ -112,5 +112,8 @@
 "listener" missing value in {0}
 EXC_InvalidJDOConfigNoRoot:  No root <jdoconfig> element found in {0}
 EXC_NoPMFConfigurableViaPropertiesOrXML: No PersistenceManagerFactory \
-configurable via properties resource "{0}" or no named PMF or persistence unit\
+configurable via properties resource "{0}" or no named PMF or persistence unit \
 named "{0}" found using resource loader {1}
+EXC_JavaxPersistencePersistenceAbsentOrNoPUFound=\
+Class javax.persistence.Persistence or one of its dependencies was not found, \
+or the given persistence unit name "{0}" was not found.

Modified: db/jdo/trunk/api2-legacy/src/java/javax/jdo/JDOHelper.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2-legacy/src/java/javax/jdo/JDOHelper.java?rev=570635&r1=570634&r2=570635&view=diff
==============================================================================
--- db/jdo/trunk/api2-legacy/src/java/javax/jdo/JDOHelper.java (original)
+++ db/jdo/trunk/api2-legacy/src/java/javax/jdo/JDOHelper.java Tue Aug 28 21:43:45 2007
@@ -768,13 +768,22 @@
         }
         
         // else no PMF class name given; check PU name
-        String puName = (String) props.get(
-                PROPERTY_PERSISTENCE_UNIT_NAME);
+        String puName = (String) props.get(PROPERTY_PERSISTENCE_UNIT_NAME);
 
         if (puName != null && !"".equals(puName.trim())) {
-            return getPMFFromEMF(puName, props, pmfClassLoader);
-        }
+            PersistenceManagerFactory pmf =
+                    getPMFFromEMF(puName, props, pmfClassLoader);
 
+            if (pmf != null) {
+                return pmf;
+            }
+            // else pmf was null, which means that
+            // either javax.persistence.Persistence wasn't on classpath
+            // or there was no PU found with the given name
+            throw new JDOFatalUserException(msg.msg(
+                    "EXC_JavaxPersistencePersistenceAbsentOrNoPUFound"),
+                    puName);
+        }
         // else no PMF class name or PU name
         throw new JDOFatalUserException(msg.msg(
                 "EXC_GetPMFNoPMFClassNamePropertyOrPUNameProperty"));
@@ -948,9 +957,15 @@
         }
 
         if (properties != null) {
+            // see if there's already a name property in properties
             String nameInProperties = (String) properties.get(PROPERTY_NAME);
-            nameInProperties = nameInProperties == null ? "" : nameInProperties;
-            if (nameInProperties == null) {
+            if (nameInProperties != null) {
+                // name given in properties; go ahead & use it
+                nameInProperties = nameInProperties.trim();
+            }
+            else {
+                // no name property given; put one for the anonymous PMF
+                name = name == null ? "" : name.trim();
                 properties.put(PROPERTY_NAME, name);
             }
             return getPersistenceManagerFactory(
@@ -958,7 +973,7 @@
         }
 
         // else no properties found; next, assume name is a PU name
-        if (name != null && !"".equals(name.trim())) {
+        if (name != null && !"".equals(name = name.trim())) {
             PersistenceManagerFactory pmf =
                     getPMFFromEMF(name, null, pmfLoader);
             if (pmf != null) {
@@ -1215,8 +1230,12 @@
                 createEntityManagerFactoryMethod.invoke(
                     persistenceClass, new Object[] { name, properties });
         }
-        catch (RuntimeException x) {
-            if (persistenceExceptionClass.isAssignableFrom(x.getClass())) {
+        catch (InvocationTargetException x) {
+            Throwable cause = x.getCause();
+            if (cause != null &&
+                    persistenceExceptionClass.isAssignableFrom(
+                            cause.getClass()))
+            {
                 // named persistence unit not found
                 return null;
             }

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?rev=570635&r1=570634&r2=570635&view=diff
==============================================================================
--- db/jdo/trunk/api2/src/java/javax/jdo/Bundle.properties (original)
+++ db/jdo/trunk/api2/src/java/javax/jdo/Bundle.properties Tue Aug 28 21:43:45 2007
@@ -112,5 +112,8 @@
 "listener" missing value in {0}
 EXC_InvalidJDOConfigNoRoot:  No root <jdoconfig> element found in {0}
 EXC_NoPMFConfigurableViaPropertiesOrXML: No PersistenceManagerFactory \
-configurable via properties resource "{0}" or no named PMF or persistence unit\
+configurable via properties resource "{0}" or no named PMF or persistence unit \
 named "{0}" found using resource loader {1}
+EXC_JavaxPersistencePersistenceAbsentOrNoPUFound=\
+Class javax.persistence.Persistence or one of its dependencies was not found, \
+or the given persistence unit name "{0}" was not found.

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?rev=570635&r1=570634&r2=570635&view=diff
==============================================================================
--- db/jdo/trunk/api2/src/java/javax/jdo/JDOHelper.java (original)
+++ db/jdo/trunk/api2/src/java/javax/jdo/JDOHelper.java Tue Aug 28 21:43:45 2007
@@ -768,13 +768,22 @@
         }
         
         // else no PMF class name given; check PU name
-        String puName = (String) props.get(
-                PROPERTY_PERSISTENCE_UNIT_NAME);
+        String puName = (String) props.get(PROPERTY_PERSISTENCE_UNIT_NAME);
 
         if (puName != null && !"".equals(puName.trim())) {
-            return getPMFFromEMF(puName, props, pmfClassLoader);
-        }
+            PersistenceManagerFactory pmf =
+                    getPMFFromEMF(puName, props, pmfClassLoader);
 
+            if (pmf != null) {
+                return pmf;
+            }
+            // else pmf was null, which means that
+            // either javax.persistence.Persistence wasn't on classpath
+            // or there was no PU found with the given name
+            throw new JDOFatalUserException(msg.msg(
+                    "EXC_JavaxPersistencePersistenceAbsentOrNoPUFound"),
+                    puName);
+        }
         // else no PMF class name or PU name
         throw new JDOFatalUserException(msg.msg(
                 "EXC_GetPMFNoPMFClassNamePropertyOrPUNameProperty"));
@@ -948,9 +957,15 @@
         }
 
         if (properties != null) {
+            // see if there's already a name property in properties
             String nameInProperties = (String) properties.get(PROPERTY_NAME);
-            nameInProperties = nameInProperties == null ? "" : nameInProperties;
-            if (nameInProperties == null) {
+            if (nameInProperties != null) {
+                // name given in properties; go ahead & use it
+                nameInProperties = nameInProperties.trim();
+            }
+            else {
+                // no name property given; put one for the anonymous PMF
+                name = name == null ? "" : name.trim();
                 properties.put(PROPERTY_NAME, name);
             }
             return getPersistenceManagerFactory(
@@ -958,7 +973,7 @@
         }
 
         // else no properties found; next, assume name is a PU name
-        if (name != null && !"".equals(name.trim())) {
+        if (name != null && !"".equals(name = name.trim())) {
             PersistenceManagerFactory pmf =
                     getPMFFromEMF(name, null, pmfLoader);
             if (pmf != null) {
@@ -1215,8 +1230,12 @@
                 createEntityManagerFactoryMethod.invoke(
                     persistenceClass, new Object[] { name, properties });
         }
-        catch (RuntimeException x) {
-            if (persistenceExceptionClass.isAssignableFrom(x.getClass())) {
+        catch (InvocationTargetException x) {
+            Throwable cause = x.getCause();
+            if (cause != null &&
+                    persistenceExceptionClass.isAssignableFrom(
+                            cause.getClass()))
+            {
                 // named persistence unit not found
                 return null;
             }



Mime
View raw message