openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1757064 - in /openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/procedure: TestStoredProcedure.java entity/EntityWithStoredProcedure.java
Date Sun, 21 Aug 2016 16:20:32 GMT
Author: struberg
Date: Sun Aug 21 16:20:32 2016
New Revision: 1757064

URL: http://svn.apache.org/viewvc?rev=1757064&view=rev
Log:
OPENJPA-2654 fix broken stored procedure test

Modified:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/procedure/TestStoredProcedure.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/procedure/entity/EntityWithStoredProcedure.java

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/procedure/TestStoredProcedure.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/procedure/TestStoredProcedure.java?rev=1757064&r1=1757063&r2=1757064&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/procedure/TestStoredProcedure.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/procedure/TestStoredProcedure.java
Sun Aug 21 16:20:32 2016
@@ -33,34 +33,35 @@ import javax.persistence.StoredProcedure
 public class TestStoredProcedure extends SingleEMFTestCase {
     @Override
     public void setUp() {
-        setUp(
-                "openjpa.RuntimeUnenhancedClasses", "unsupported",
-                "openjpa.DynamicEnhancementAgent", "false",
-                EntityWithStoredProcedure.class, EntityWithStoredProcedure.Mapping2.class);
+        setUp("openjpa.RuntimeUnenhancedClasses", "unsupported",
+              "openjpa.DynamicEnhancementAgent", "false",
+              EntityWithStoredProcedure.class, EntityWithStoredProcedure.Mapping2.class);
         setSupportedDatabases(DerbyDictionary.class);
     }
 
-    public void testSimple() {
+    public void testSimple() throws Exception  {
         Procedures.simpleCalled = false;
 
         EntityManager em = emf.createEntityManager();
+        exec(em, "DROP PROCEDURE TESTSIMPLE", true);
         exec(em, "CREATE PROCEDURE TESTSIMPLE() " +
                 "PARAMETER STYLE JAVA LANGUAGE JAVA EXTERNAL NAME " +
-                "'" + Procedures.class.getName() + ".simple'");
+                "'" + Procedures.class.getName() + ".simple'", false);
         StoredProcedureQuery procedure = em.createNamedStoredProcedureQuery("EntityWithStoredProcedure.simple");
         assertFalse(procedure.execute());
         em.close();
         assertTrue(Procedures.simpleCalled);
     }
 
-    public void testInParams() {
+    public void testInParams() throws Exception  {
         Procedures.inParamsInteger = -1;
         Procedures.inParamsString = null;
 
         EntityManager em = emf.createEntityManager();
-        exec(em, "CREATE PROCEDURE TESTINS(some_number INTEGER,some_string VARCHAR(255))
" +
+        exec(em, "DROP PROCEDURE TESTINS", true);
+        exec(em, "CREATE PROCEDURE TESTINS(SOME_NUMBER INTEGER,SOME_STRING VARCHAR(255))
" +
                 "PARAMETER STYLE JAVA LANGUAGE JAVA EXTERNAL NAME " +
-                "'" + Procedures.class.getName() + ".inParams'");
+                "'" + Procedures.class.getName() + ".inParams'", false);
         StoredProcedureQuery procedure = em.createNamedStoredProcedureQuery("EntityWithStoredProcedure.inParams");
         procedure.setParameter("SOME_NUMBER", 2015);
         procedure.setParameter("SOME_STRING", "openjpa");
@@ -79,11 +80,12 @@ public class TestStoredProcedure extends
         assertNull(Procedures.inParamsString);
     }
 
-    public void testOut() {
+    public void testOut() throws Exception  {
         EntityManager em = emf.createEntityManager();
-        exec(em, "CREATE PROCEDURE XTWO(IN some_number INTEGER,OUT x2 INTEGER) " +
+        exec(em, "DROP PROCEDURE XTWO", true);
+        exec(em, "CREATE PROCEDURE XTWO(IN SOME_NUMBER INTEGER,OUT x2 INTEGER) " +
                 "PARAMETER STYLE JAVA LANGUAGE JAVA EXTERNAL NAME " +
-                "'" + Procedures.class.getName() + ".x2'");
+                "'" + Procedures.class.getName() + ".x2'", false);
         StoredProcedureQuery procedure = em.createNamedStoredProcedureQuery("EntityWithStoredProcedure.x2");
         procedure.setParameter("SOME_NUMBER", 5);
         assertFalse(procedure.execute());
@@ -92,11 +94,12 @@ public class TestStoredProcedure extends
         em.close();
     }
 
-    public void testInOut() {
+    public void testInOut() throws Exception  {
         EntityManager em = emf.createEntityManager();
+        exec(em, "DROP PROCEDURE XINOUT", true);
         exec(em, "CREATE PROCEDURE XINOUT(INOUT P INTEGER) " +
                 "PARAMETER STYLE JAVA LANGUAGE JAVA EXTERNAL NAME " +
-                "'" + Procedures.class.getName() + ".inout'");
+                "'" + Procedures.class.getName() + ".inout'", false);
         StoredProcedureQuery procedure = em.createNamedStoredProcedureQuery("EntityWithStoredProcedure.inout");
         procedure.setParameter("P", 5);
         assertFalse(procedure.execute());
@@ -105,7 +108,7 @@ public class TestStoredProcedure extends
         em.close();
     }
 
-    public void testMapping() {
+    public void testMapping() throws Exception {
         EntityManager em = emf.createEntityManager();
         {
             em.getTransaction().begin();
@@ -119,9 +122,10 @@ public class TestStoredProcedure extends
             em.clear();
         }
 
+        exec(em, "DROP PROCEDURE MAPPING", true);
         exec(em, "CREATE PROCEDURE MAPPING() " +
                 "PARAMETER STYLE JAVA LANGUAGE JAVA DYNAMIC RESULT SETS 2 EXTERNAL NAME "
+
-                "'" + Procedures.class.getName() + ".mapping'");
+                "'" + Procedures.class.getName() + ".mapping'", false);
         StoredProcedureQuery procedure = em.createNamedStoredProcedureQuery("EntityWithStoredProcedure.mapping");
         assertTrue(procedure.execute());
         final Iterator r1 = procedure.getResultList().iterator();
@@ -153,19 +157,22 @@ public class TestStoredProcedure extends
         em.close();
     }
 
-    private void exec(final EntityManager em, final String proc) {
+    private void exec(final EntityManager em, final String proc, boolean ignoreExceptions)
throws Exception {
         final EntityTransaction tx = em.getTransaction();
         tx.begin();
         try {
             em.createNativeQuery(proc).executeUpdate();
             tx.commit();
-        } catch (final Exception e) { // already exists or another error
-            e.printStackTrace();
+        } catch (final Exception sqe) { // already exists or another error
             try {
                 tx.rollback();
             } catch (final Exception ignored) {
                 // no-op
             }
+            if (!ignoreExceptions) {
+                // fail(sqe.toString());
+                throw sqe;
+            }
         }
     }
 }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/procedure/entity/EntityWithStoredProcedure.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/procedure/entity/EntityWithStoredProcedure.java?rev=1757064&r1=1757063&r2=1757064&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/procedure/entity/EntityWithStoredProcedure.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/procedure/entity/EntityWithStoredProcedure.java
Sun Aug 21 16:20:32 2016
@@ -56,7 +56,7 @@ import static javax.persistence.Paramete
                 name = "EntityWithStoredProcedure.inout",
                 procedureName = "XINOUT",
                 parameters = {
-                        @StoredProcedureParameter(name = "P ", type = Integer.class, mode
= INOUT)
+                        @StoredProcedureParameter(name = "P", type = Integer.class, mode
= INOUT)
                 }
         ),
         @NamedStoredProcedureQuery(



Mime
View raw message