geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dwo...@apache.org
Subject svn commit: r820390 - /geronimo/specs/trunk/geronimo-jpa_2.0_spec/src/main/java/javax/persistence/Persistence.java
Date Wed, 30 Sep 2009 19:02:43 GMT
Author: dwoods
Date: Wed Sep 30 19:02:42 2009
New Revision: 820390

URL: http://svn.apache.org/viewvc?rev=820390&view=rev
Log:
reworked exception handling for createEMF()

Modified:
    geronimo/specs/trunk/geronimo-jpa_2.0_spec/src/main/java/javax/persistence/Persistence.java

Modified: geronimo/specs/trunk/geronimo-jpa_2.0_spec/src/main/java/javax/persistence/Persistence.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jpa_2.0_spec/src/main/java/javax/persistence/Persistence.java?rev=820390&r1=820389&r2=820390&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-jpa_2.0_spec/src/main/java/javax/persistence/Persistence.java
(original)
+++ geronimo/specs/trunk/geronimo-jpa_2.0_spec/src/main/java/javax/persistence/Persistence.java
Wed Sep 30 19:02:42 2009
@@ -192,8 +192,8 @@
             // we encountered one or more exceptions, so format and throw as a single exception
             throw createPersistenceException(
                 "Explicit persistence provider error(s) occurred for \"" + persistenceUnitName
+
-                "\" after trying the following discovered implementations: " + foundProviders
+
-                " with the following failures:", exceptions);
+                "\" after trying the following discovered implementations: " + foundProviders,
+                exceptions);
         }
     }
 
@@ -238,7 +238,19 @@
         String newline = System.getProperty("line.separator");
         StringWriter strWriter = new StringWriter();
         strWriter.append(msg);
-        if (!failures.isEmpty()) {
+        if (failures.size() <= 1) {
+            // we caught an exception, so include it as the cause
+            Throwable t = null;
+            for (String providerName : failures.keySet()) {
+                t = failures.get(providerName);
+                strWriter.append(" from provider: ");
+                strWriter.append(providerName);
+                break;
+            }
+            return new PersistenceException(strWriter.toString(), t);                
+        } else {
+            // we caught multiple exceptions, so format them into the message string and
don't set a cause
+            strWriter.append(" with the following failures:");
             strWriter.append(newline);
             for (String providerName : failures.keySet()) {
                 strWriter.append(providerName);
@@ -246,8 +258,8 @@
                 failures.get(providerName).printStackTrace(new PrintWriter(strWriter));
             }
             strWriter.append(newline);
+            return new PersistenceException(strWriter.toString());
         }
-        return new PersistenceException(strWriter.toString());
     }
 
     /*



Mime
View raw message