JPA patch - provider exception handling

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

JPA patch - provider exception handling

Andrus Adamchik
Somebody please apply this patch. It implements better exception  
handling during persistence unit loading.

Thanks
Andrus


Index: geronimo-spec-jpa/src/main/java/javax/persistence/
Persistence.java
===================================================================
--- geronimo-spec-jpa/src/main/java/javax/persistence/
Persistence.java (revision 398209)
+++ geronimo-spec-jpa/src/main/java/javax/persistence/
Persistence.java (working copy)
@@ -144,18 +144,29 @@
      static EntityManagerFactory createFactory(
              String providerName,
              String persistenceUnitName,
-            Map properties) {
+            Map properties)
+ throws PersistenceException {
-        try {
-            Class providerClass = Class.forName(providerName, true,  
Thread
-                    .currentThread()
-                    .getContextClassLoader());
-            PersistenceProvider provider = (PersistenceProvider)  
providerClass
-                    .newInstance();
-            return provider.createEntityManagerFactory
(persistenceUnitName, properties);
-        }
-        catch (Exception e) {
-            return null;
-        }
-    }
+ 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 {
+ PersistenceProvider provider = (PersistenceProvider) providerClass
+ .newInstance();
+ return provider.createEntityManagerFactory(persistenceUnitName,
+ properties);
+ }
+ catch (Exception e) {
+ throw new PersistenceException("Provider error. Provider: "
+ + providerName, e);
+ }
+ }
}

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: JPA patch - provider exception handling

Jeff Genender
Can you please attach the patch.  If I copy/paste from this email it chokes.

Thanks,

Jeff

Andrus Adamchik wrote:

> Somebody please apply this patch. It implements better exception
> handling during persistence unit loading.
>
> Thanks
> Andrus
>
>
> Index: geronimo-spec-jpa/src/main/java/javax/persistence/Persistence.java
> ===================================================================
> ---
> geronimo-spec-jpa/src/main/java/javax/persistence/Persistence.java  
> (revision 398209)
> +++
> geronimo-spec-jpa/src/main/java/javax/persistence/Persistence.java  
> (working copy)
> @@ -144,18 +144,29 @@
>      static EntityManagerFactory createFactory(
>              String providerName,
>              String persistenceUnitName,
> -            Map properties) {
> +            Map properties)
> +            throws PersistenceException {
> -        try {
> -            Class providerClass = Class.forName(providerName, true, Thread
> -                    .currentThread()
> -                    .getContextClassLoader());
> -            PersistenceProvider provider = (PersistenceProvider)
> providerClass
> -                    .newInstance();
> -            return
> provider.createEntityManagerFactory(persistenceUnitName, properties);
> -        }
> -        catch (Exception e) {
> -            return null;
> -        }
> -    }
> +        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 {
> +            PersistenceProvider provider = (PersistenceProvider)
> providerClass
> +                    .newInstance();
> +            return
> provider.createEntityManagerFactory(persistenceUnitName,
> +                    properties);
> +        }
> +        catch (Exception e) {
> +            throw new PersistenceException("Provider error. Provider: "
> +                    + providerName, e);
> +        }
> +    }
> }
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: JPA patch - provider exception handling

Andrus Adamchik
Jeff, IIRC this list used to strip attachments. So cc'ing it to your  
address as well.

Andrus





On Apr 30, 2006, at 12:03 AM, Jeff Genender wrote:

> Can you please attach the patch.  If I copy/paste from this email  
> it chokes.
>
> Thanks,
>
> Jeff
>

patch.txt (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: JPA patch - provider exception handling

Jeff Genender
Done.

Andrus Adamchik wrote:

> Jeff, IIRC this list used to strip attachments. So cc'ing it to your
> address as well.
>
> Andrus
>
>
> ------------------------------------------------------------------------
>
> Index: geronimo-spec-jpa/src/main/java/javax/persistence/Persistence.java
> ===================================================================
> --- geronimo-spec-jpa/src/main/java/javax/persistence/Persistence.java (revision 398324)
> +++ geronimo-spec-jpa/src/main/java/javax/persistence/Persistence.java (working copy)
> @@ -144,18 +144,29 @@
>      static EntityManagerFactory createFactory(
>              String providerName,
>              String persistenceUnitName,
> -            Map properties) {
> +            Map properties)
> + throws PersistenceException {
>  
> -        try {
> -            Class providerClass = Class.forName(providerName, true, Thread
> -                    .currentThread()
> -                    .getContextClassLoader());
> -            PersistenceProvider provider = (PersistenceProvider) providerClass
> -                    .newInstance();
> -            return provider.createEntityManagerFactory(persistenceUnitName, properties);
> -        }
> -        catch (Exception e) {
> -            return null;
> -        }
> -    }
> + 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 {
> + PersistenceProvider provider = (PersistenceProvider) providerClass
> + .newInstance();
> + return provider.createEntityManagerFactory(persistenceUnitName,
> + properties);
> + }
> + catch (Exception e) {
> + throw new PersistenceException("Provider error. Provider: "
> + + providerName, e);
> + }
> + }
>  }
>
>
> ------------------------------------------------------------------------
>
>
>
>
> On Apr 30, 2006, at 12:03 AM, Jeff Genender wrote:
>
>> Can you please attach the patch.  If I copy/paste from this email it
>> chokes.
>>
>> Thanks,
>>
>> Jeff
>>
Loading...