geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgenen...@apache.org
Subject svn commit: r398357 - /geronimo/specs/branches/jee5_exp/geronimo-spec-jpa/src/main/java/javax/persistence/Persistence.java
Date Sun, 30 Apr 2006 15:30:11 GMT
Author: jgenender
Date: Sun Apr 30 08:30:09 2006
New Revision: 398357

URL: http://svn.apache.org/viewcvs?rev=398357&view=rev
Log:
Fix exceptions in persistence

Modified:
    geronimo/specs/branches/jee5_exp/geronimo-spec-jpa/src/main/java/javax/persistence/Persistence.java

Modified: geronimo/specs/branches/jee5_exp/geronimo-spec-jpa/src/main/java/javax/persistence/Persistence.java
URL: http://svn.apache.org/viewcvs/geronimo/specs/branches/jee5_exp/geronimo-spec-jpa/src/main/java/javax/persistence/Persistence.java?rev=398357&r1=398356&r2=398357&view=diff
==============================================================================
--- geronimo/specs/branches/jee5_exp/geronimo-spec-jpa/src/main/java/javax/persistence/Persistence.java
(original)
+++ geronimo/specs/branches/jee5_exp/geronimo-spec-jpa/src/main/java/javax/persistence/Persistence.java
Sun Apr 30 08:30:09 2006
@@ -44,7 +44,7 @@
 
     static final String PERSISTENCE_PROVIDER_PROPERTY = "javax.persistence.provider";
     static final String PERSISTENCE_PROVIDER_SERVICE = "META-INF/services/"
-            + PersistenceProvider.class.getName();
+        + PersistenceProvider.class.getName();
 
     /**
      * Create and return an EntityManagerFactory for the named persistence unit.
@@ -56,7 +56,7 @@
     public static EntityManagerFactory createEntityManagerFactory(
             String persistenceUnitName) {
         return createEntityManagerFactory(persistenceUnitName, Collections.EMPTY_MAP);
-    }
+            }
 
     /**
      * Create and return an EntityManagerFactory for the named persistence unit using the
@@ -94,7 +94,7 @@
         ClassLoader loader = Thread.currentThread().getContextClassLoader();
         try {
             Enumeration<URL> providers = loader
-                    .getResources(PERSISTENCE_PROVIDER_SERVICE);
+                .getResources(PERSISTENCE_PROVIDER_SERVICE);
             while (providers.hasMoreElements()) {
 
                 String name = getProviderName(providers.nextElement());
@@ -117,13 +117,13 @@
         }
 
         return null;
-    }
+            }
 
     static String getProviderName(URL url) throws IOException {
 
         BufferedReader in = new BufferedReader(new InputStreamReader(
-                url.openStream(),
-                "UTF-8"));
+                    url.openStream(),
+                    "UTF-8"));
 
         String providerName;
 
@@ -144,18 +144,29 @@
     static EntityManagerFactory createFactory(
             String providerName,
             String persistenceUnitName,
-            Map properties) {
+            Map properties)
+        throws PersistenceException {
+
+        Class providerClass;
+        try {
+            providerClass = Class.forName(providerName, true, Thread
+                    .currentThread().getContextClassLoader());
+        } 
+        catch (Exception e) {
+            throw new PersistenceException(
+                    "Invalid or inaccessible provider class: " + providerName,
+                    e);
+        }
 
         try {
-            Class providerClass = Class.forName(providerName, true, Thread
-                    .currentThread()
-                    .getContextClassLoader());
             PersistenceProvider provider = (PersistenceProvider) providerClass
-                    .newInstance();
-            return provider.createEntityManagerFactory(persistenceUnitName, properties);
+                .newInstance();
+            return provider.createEntityManagerFactory(persistenceUnitName,
+                    properties);
         }
         catch (Exception e) {
-            return null;
+            throw new PersistenceException("Provider error. Provider: "
+                    + providerName, e);
         }
     }
 }



Mime
View raw message