You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by dw...@apache.org on 2009/09/30 22:49:09 UTC

svn commit: r820440 - in /openjpa/trunk: ./ openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ openjpa-kernel/src/main/java/org/apache/openjpa/writebehind/ openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/ openjpa-persistence-jdbc/src/t...

Author: dwoods
Date: Wed Sep 30 20:49:09 2009
New Revision: 820440

URL: http://svn.apache.org/viewvc?rev=820440&view=rev
Log:
OPENJPA-1229 Reworked Persistence.createEMF() exception handling in the geronimo-jpa2 spec api (PFD2), which wraps all exceptions in a PersistenceException and can now return multiple provider exceptions.

Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/writebehind/WriteBehindConfigurationException.java
    openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/localizer.properties
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestSpecificationConfiguration.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/writebehind/TestWriteBehindConfigurations.java
    openjpa/trunk/pom.xml

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java?rev=820440&r1=820439&r2=820440&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java Wed Sep 30 20:49:09 2009
@@ -866,17 +866,19 @@
     protected void initWriteBehindCallback() { 
         WriteBehindCache cache = _conf.getWriteBehindCacheManagerInstance().getSystemWriteBehindCache();
         if (cache != null) {
-    
-            if (_conf.getDataCacheManagerInstance().getSystemDataCache() == null ||
-                _conf.getWriteBehindCallbackInstance() == null ) {
-                //
-                // Missing one or more of the following required WriteBehind configuration 
-                // parameters:
-                //
-                //   - openjpa.DataCache
-                //   - openjpa.WriteBehindCallback
-                //
-                throw new WriteBehindConfigurationException();
+            // Verify we are not missing one or more of the following required
+            // WriteBehind configuration parameters:
+            //   - openjpa.DataCache
+            //   - openjpa.WriteBehindCallback
+            if (_conf.getDataCacheManagerInstance().getSystemDataCache() == null) {
+                throw new WriteBehindConfigurationException(
+                    _loc.get("writebehind-cfg-err",
+                    "openjpa.DataCache").getMessage());
+            }
+            if (_conf.getWriteBehindCallbackInstance() == null ) {
+                throw new WriteBehindConfigurationException(
+                    _loc.get("writebehind-cfg-err",
+                    "openjpa.WriteBehindCallback").getMessage());
             }
     
             Broker broker =
@@ -899,3 +901,4 @@
         }
     }
 }
+

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/writebehind/WriteBehindConfigurationException.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/writebehind/WriteBehindConfigurationException.java?rev=820440&r1=820439&r2=820440&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/writebehind/WriteBehindConfigurationException.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/writebehind/WriteBehindConfigurationException.java Wed Sep 30 20:49:09 2009
@@ -24,6 +24,13 @@
 
     private static final long serialVersionUID = 4378466107767896762L;
 
+    /**
+     * Constructor; supply message as String.
+     */
+    public WriteBehindConfigurationException(String msg) {
+        super(msg);
+    }
+
     @Override
     public int getType() {
         return USER;

Modified: openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/localizer.properties
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/localizer.properties?rev=820440&r1=820439&r2=820440&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/localizer.properties (original)
+++ openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/kernel/localizer.properties Wed Sep 30 20:49:09 2009
@@ -444,4 +444,6 @@
 	"{1}". See nested exception for details.
 fill-factory-error: Error while fill data with factory strategy. The error \
 	occurred while invoking "{0}" with key "{1}" and value "{2}" of type "{3}". \
-	See nested exception for details.	
\ No newline at end of file
+	See nested exception for details.	
+writebehind-cfg-err: Missing required WriteBehind configuration parameter "{0}"
+

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestSpecificationConfiguration.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestSpecificationConfiguration.java?rev=820440&r1=820439&r2=820440&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestSpecificationConfiguration.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/conf/TestSpecificationConfiguration.java Wed Sep 30 20:49:09 2009
@@ -90,9 +90,13 @@
                 "openjpa.Log", "DefaultLevel=WARN");
             fail("Expected to fail with higher Spec version");
         } catch (IllegalArgumentException ex) {
-            // good
+            // prior behavior - spec api returned runtime exceptions as-is
             emf.getConfiguration().getLog("Tests").trace(
                 "Caught expected IllegalArgumentException = " + ex);
+        } catch (PersistenceException pe) {
+            // new 2.0 behavior - Geronimo spec api wraps exceptions and tries all providers
+            emf.getConfiguration().getLog("Tests").trace(
+                "Caught expected PersistenceException = " + pe);
         }
     }
     

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/writebehind/TestWriteBehindConfigurations.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/writebehind/TestWriteBehindConfigurations.java?rev=820440&r1=820439&r2=820440&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/writebehind/TestWriteBehindConfigurations.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/writebehind/TestWriteBehindConfigurations.java Wed Sep 30 20:49:09 2009
@@ -22,11 +22,12 @@
 import java.util.Map;
 import javax.persistence.EntityManagerFactory;
 import javax.persistence.Persistence;
+import javax.persistence.PersistenceException;
 
 import junit.framework.TestCase;
 
 import org.apache.openjpa.persistence.ArgumentException;
-import org.apache.openjpa.persistence.PersistenceException;
+//import org.apache.openjpa.persistence.PersistenceException;
 import org.apache.openjpa.writebehind.WriteBehindConfigurationException;
 
 
@@ -50,19 +51,14 @@
         try {
             emf01 = Persistence.createEntityManagerFactory("empty-pu", map);
             fail("testInvalidConfiguration01: Exception expected but not thrown");
-        }
-        catch (ArgumentException ae) {
-        }
-        catch (PersistenceException pe) {
-        }
-        catch (WriteBehindConfigurationException wbce) {
-        }
-        catch (Exception e) {
+        } catch (ArgumentException ae) {
+            // prior behavior - spec api returned runtime exceptions as-is
+        } catch (PersistenceException pe) {
+            // new 2.0 behavior - Geronimo spec api wraps exceptions and tries all providers
+        } catch (Exception e) {
             fail("testInvalidConfiguration01: Caught unexpected exception: " + e);
             e.printStackTrace();
-        }
-        finally {
-            assertNull(emf01);
+        } finally {
             if (emf01 != null) {
                 emf01.close();
             }
@@ -83,19 +79,14 @@
         try {
             emf02 = Persistence.createEntityManagerFactory("empty-pu", map);
             fail("testInvalidConfiguration02: Exception expected but not thrown");
-        }
-        catch (ArgumentException ae) {
-        }
-        catch (PersistenceException pe) {
-        }
-        catch (WriteBehindConfigurationException wbce) {
-        }
-        catch (Exception e) {
+        } catch (ArgumentException ae) {
+            // prior behavior - spec api returned runtime exceptions as-is
+        } catch (PersistenceException pe) {
+            // new 2.0 behavior - Geronimo spec api wraps exceptions and tries all providers
+        } catch (Exception e) {
             fail("testInvalidConfiguration02: Caught unexpected exception: " + e);
             e.printStackTrace();
-        }
-        finally {
-            assertNull(emf02);
+        } finally {
             if (emf02 != null) {
                 emf02.close();
             }
@@ -116,19 +107,14 @@
         try {
             emf03 = Persistence.createEntityManagerFactory("empty-pu", map);
             fail("testInvalidConfiguration03: Exception not thrown");
-        }
-        catch (ArgumentException ae) {
-        }
-        catch (PersistenceException pe) {
-        }
-        catch (WriteBehindConfigurationException wbce) {
-        }
-        catch (Exception e) {
+        } catch (ArgumentException ae) {
+            // prior behavior - spec api returned runtime exceptions as-is
+        } catch (PersistenceException pe) {
+            // new 2.0 behavior - Geronimo spec api wraps exceptions and tries all providers
+        } catch (Exception e) {
             fail("testInvalidConfiguration03: Caught unexpected exception: " + e);
             e.printStackTrace();
-        }
-        finally {
-            assertNull(emf03);
+        } finally {
             if (emf03 != null) {
                 emf03.close();
             }
@@ -148,19 +134,14 @@
         try {
             emf04 = Persistence.createEntityManagerFactory("empty-pu", map);
             fail("testInvalidConfiguration04: Exception not thrown");
-        }
-        catch (ArgumentException ae) {
-        }
-        catch (PersistenceException pe) {
-        }
-        catch (WriteBehindConfigurationException wbce) {
-        }
-        catch (Exception e) {
+        } catch (ArgumentException ae) {
+            // prior behavior - spec api returned runtime exceptions as-is
+        } catch (PersistenceException pe) {
+            // new 2.0 behavior - Geronimo spec api wraps exceptions and tries all providers
+        } catch (Exception e) {
             fail("testInvalidConfiguration04: Caught unexpected exception: " + e);
             e.printStackTrace();
-        }
-        finally {
-            assertNull(emf04);
+        } finally {
             if (emf04 != null) {
                 emf04.close();
             }
@@ -181,12 +162,10 @@
         map.put( "openjpa.RuntimeUnenhancedClasses", "unsupported" );
         try {
             emf05 = Persistence.createEntityManagerFactory("empty-pu", map);
-        }
-        catch (Exception e) {
+        } catch (Exception e) {
             fail("testValidConfiguration01: Caught unexpected exception: " + e);
             e.printStackTrace();
-        }
-        finally {
+        } finally {
             assertNotNull(emf05);
             if (emf05 != null) {
                 emf05.close();
@@ -208,12 +187,10 @@
         map.put( "openjpa.RuntimeUnenhancedClasses", "supported" );
         try {
             emf06 = Persistence.createEntityManagerFactory("empty-pu", map);
-        }
-        catch (Exception e) {
+        } catch (Exception e) {
             fail("testValidConfiguration02: Caught unexpected exception: " + e);
             e.printStackTrace();
-        }
-        finally {
+        } finally {
             assertNotNull(emf06);
             if (emf06 != null) {
                 emf06.close();
@@ -235,12 +212,10 @@
         map.put( "openjpa.RuntimeUnenhancedClasses", "warn" );
         try {
             emf07 = Persistence.createEntityManagerFactory("empty-pu", map);
-        }
-        catch (Exception e) {
+        } catch (Exception e) {
             fail("testValidConfiguration03: Caught unexpected exception: " + e);
             e.printStackTrace();
-        }                                   
-        finally {
+        } finally {
             assertNotNull(emf07);
             if (emf07 != null) {
                 emf07.close();

Modified: openjpa/trunk/pom.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/pom.xml?rev=820440&r1=820439&r2=820440&view=diff
==============================================================================
--- openjpa/trunk/pom.xml (original)
+++ openjpa/trunk/pom.xml Wed Sep 30 20:49:09 2009
@@ -494,7 +494,7 @@
             <dependency>
                 <groupId>org.apache.geronimo.specs</groupId>
                 <artifactId>geronimo-jpa_2.0_spec</artifactId>
-                <version>1.0-EA8-SNAPSHOT</version>
+                <version>1.0-PFD2-SNAPSHOT</version>
             </dependency>
             <dependency>
                 <groupId>org.apache.geronimo.specs</groupId>