cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r524995 - in /cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src: main/java/org/apache/cayenne/access/jdbc/ test/java/org/apache/cayenne/access/ test/java/org/apache/cayenne/unit/ test/resources/ddl/mysql/
Date Tue, 03 Apr 2007 01:45:58 GMT
Author: aadamchik
Date: Mon Apr  2 18:45:56 2007
New Revision: 524995

URL: http://svn.apache.org/viewvc?view=rev&rev=524995
Log:
CAY-773: MySQL stored procedure support
unit tests

Added:
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/ddl/mysql/
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/ddl/mysql/create-out-sp.sql
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/ddl/mysql/create-select-sp.sql
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/ddl/mysql/create-update-sp.sql
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/ddl/mysql/create-update-sp2.sql
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/ddl/mysql/drop-out-sp.sql
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/ddl/mysql/drop-select-sp.sql
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/ddl/mysql/drop-update-sp.sql
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/ddl/mysql/drop-update-sp2.sql
Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/ProcedureAction.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextProcedureQueryTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/unit/MySQLStackAdapter.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/ProcedureAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/ProcedureAction.java?view=diff&rev=524995&r1=524994&r2=524995
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/ProcedureAction.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/ProcedureAction.java
Mon Apr  2 18:45:56 2007
@@ -75,6 +75,10 @@
             // stored procedure may contain a mixture of update counts and result sets,
             // and out parameters. Read out parameters first, then
             // iterate until we exhaust all results
+            
+            // TODO: andrus, 4/2/2007 - according to the docs we should store the boolean
+            // return value of this method and avoid calling 'getMoreResults' if it is true.
+            // some db's handle this well, some don't (MySQL).
             statement.execute();
 
             // read out parameters

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextProcedureQueryTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextProcedureQueryTest.java?view=diff&rev=524995&r1=524994&r2=524995
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextProcedureQueryTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/access/DataContextProcedureQueryTest.java
Mon Apr  2 18:45:56 2007
@@ -51,7 +51,6 @@
     protected void setUp() throws Exception {
         super.setUp();
 
-        // Don't run this on MySQL
         if (!getAccessStackAdapter().supportsStoredProcedures()) {
             return;
         }
@@ -61,7 +60,6 @@
     }
 
     public void testUpdate() throws Exception {
-        // Don't run this on MySQL
         if (!getAccessStackAdapter().supportsStoredProcedures()) {
             return;
         }
@@ -99,7 +97,6 @@
     }
 
     public void testUpdateNoParam() throws Exception {
-        // Don't run this on MySQL
         if (!getAccessStackAdapter().supportsStoredProcedures()) {
             return;
         }
@@ -136,7 +133,6 @@
     }
 
     public void testSelect1() throws Exception {
-        // Don't run this on MySQL
         if (!getAccessStackAdapter().supportsStoredProcedures()) {
             return;
         }
@@ -165,7 +161,6 @@
     }
 
     public void testSelect2() throws Exception {
-        // Don't run this on MySQL
         if (!getAccessStackAdapter().supportsStoredProcedures()) {
             return;
         }
@@ -195,7 +190,6 @@
     }
 
     public void testSelect3() throws Exception {
-        // Don't run this on MySQL
         if (!getAccessStackAdapter().supportsStoredProcedures()) {
             return;
         }
@@ -227,7 +221,6 @@
     }
 
     public void testOutParams() throws Exception {
-        // Don't run this on MySQL
         if (!getAccessStackAdapter().supportsStoredProcedures()) {
             return;
         }
@@ -250,7 +243,6 @@
     }
 
     public void testSelectDataObject() throws Exception {
-        // Don't run this on MySQL
         if (!getAccessStackAdapter().supportsStoredProcedures()) {
             return;
         }
@@ -276,7 +268,6 @@
         // invalidate painting, it may have been updated in the proc
         ctxt.invalidateObjects(Collections.singletonList(p));
         assertEquals(1101.01, p.getEstimatedPrice().doubleValue(), 0.02);
-
     }
 
     public void testSelectWithRowDescriptor() throws Exception {

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/unit/MySQLStackAdapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/unit/MySQLStackAdapter.java?view=diff&rev=524995&r1=524994&r2=524995
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/unit/MySQLStackAdapter.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/unit/MySQLStackAdapter.java
Mon Apr  2 18:45:56 2007
@@ -28,6 +28,7 @@
 import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.DbEntity;
+import org.apache.cayenne.map.Procedure;
 
 /**
  * @author Andrus Adamchik
@@ -50,6 +51,19 @@
         return false;
     }
 
+    public boolean supportsStoredProcedures() {
+        return true;
+    }
+
+    public void createdTables(Connection con, DataMap map) throws Exception {
+        if (map.getProcedureMap().containsKey("cayenne_tst_select_proc")) {
+            executeDDL(con, "mysql", "create-select-sp.sql");
+            executeDDL(con, "mysql", "create-update-sp.sql");
+            executeDDL(con, "mysql", "create-update-sp2.sql");
+            executeDDL(con, "mysql", "create-out-sp.sql");
+        }
+    }
+
     public void willDropTables(Connection conn, DataMap map, Collection tablesToDrop)
             throws Exception {
         // special DROP CONSTRAINT syntax for MySQL
@@ -75,6 +89,14 @@
                     executeDDL(conn, drop.toString());
                 }
             }
+        }
+
+        Procedure proc = map.getProcedure("cayenne_tst_select_proc");
+        if (proc != null && proc.getDataMap() == map) {
+            executeDDL(conn, "mysql", "drop-select-sp.sql");
+            executeDDL(conn, "mysql", "drop-update-sp.sql");
+            executeDDL(conn, "mysql", "drop-update-sp2.sql");
+            executeDDL(conn, "mysql", "drop-out-sp.sql");
         }
     }
 

Added: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/ddl/mysql/create-out-sp.sql
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/ddl/mysql/create-out-sp.sql?view=auto&rev=524995
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/ddl/mysql/create-out-sp.sql
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/ddl/mysql/create-out-sp.sql
Mon Apr  2 18:45:56 2007
@@ -0,0 +1,4 @@
+CREATE PROCEDURE cayenne_tst_out_proc (IN p1 INT, OUT p2 INT) 
+BEGIN
+    SELECT p1 * 2 INTO p2;
+END

Added: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/ddl/mysql/create-select-sp.sql
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/ddl/mysql/create-select-sp.sql?view=auto&rev=524995
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/ddl/mysql/create-select-sp.sql
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/ddl/mysql/create-select-sp.sql
Mon Apr  2 18:45:56 2007
@@ -0,0 +1,11 @@
+CREATE PROCEDURE cayenne_tst_select_proc (IN p1 varchar(200), IN p2 DECIMAL) 
+BEGIN
+     UPDATE PAINTING SET ESTIMATED_PRICE = ESTIMATED_PRICE * 2
+     WHERE ESTIMATED_PRICE < p2;
+ 
+     SELECT DISTINCT A.ARTIST_ID, A.ARTIST_NAME, A.DATE_OF_BIRTH
+     FROM ARTIST A, PAINTING P
+     WHERE A.ARTIST_ID = P.ARTIST_ID AND
+     RTRIM(A.ARTIST_NAME) = p1
+     ORDER BY A.ARTIST_ID;
+END
\ No newline at end of file

Added: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/ddl/mysql/create-update-sp.sql
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/ddl/mysql/create-update-sp.sql?view=auto&rev=524995
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/ddl/mysql/create-update-sp.sql
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/ddl/mysql/create-update-sp.sql
Mon Apr  2 18:45:56 2007
@@ -0,0 +1,5 @@
+CREATE PROCEDURE cayenne_tst_upd_proc (IN p1 DECIMAL) 
+BEGIN
+     UPDATE PAINTING SET ESTIMATED_PRICE = ESTIMATED_PRICE * 2
+        WHERE ESTIMATED_PRICE < p1;
+END

Added: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/ddl/mysql/create-update-sp2.sql
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/ddl/mysql/create-update-sp2.sql?view=auto&rev=524995
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/ddl/mysql/create-update-sp2.sql
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/ddl/mysql/create-update-sp2.sql
Mon Apr  2 18:45:56 2007
@@ -0,0 +1,4 @@
+CREATE PROCEDURE cayenne_tst_upd_proc2 () 
+BEGIN
+     UPDATE PAINTING SET ESTIMATED_PRICE = ESTIMATED_PRICE * 2;
+END
\ No newline at end of file

Added: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/ddl/mysql/drop-out-sp.sql
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/ddl/mysql/drop-out-sp.sql?view=auto&rev=524995
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/ddl/mysql/drop-out-sp.sql
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/ddl/mysql/drop-out-sp.sql
Mon Apr  2 18:45:56 2007
@@ -0,0 +1 @@
+DROP PROCEDURE IF EXISTS cayenne_tst_out_proc;
\ No newline at end of file

Added: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/ddl/mysql/drop-select-sp.sql
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/ddl/mysql/drop-select-sp.sql?view=auto&rev=524995
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/ddl/mysql/drop-select-sp.sql
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/ddl/mysql/drop-select-sp.sql
Mon Apr  2 18:45:56 2007
@@ -0,0 +1 @@
+DROP PROCEDURE IF EXISTS cayenne_tst_select_proc;
\ No newline at end of file

Added: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/ddl/mysql/drop-update-sp.sql
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/ddl/mysql/drop-update-sp.sql?view=auto&rev=524995
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/ddl/mysql/drop-update-sp.sql
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/ddl/mysql/drop-update-sp.sql
Mon Apr  2 18:45:56 2007
@@ -0,0 +1 @@
+DROP PROCEDURE IF EXISTS cayenne_tst_upd_proc;
\ No newline at end of file

Added: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/ddl/mysql/drop-update-sp2.sql
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/ddl/mysql/drop-update-sp2.sql?view=auto&rev=524995
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/ddl/mysql/drop-update-sp2.sql
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/ddl/mysql/drop-update-sp2.sql
Mon Apr  2 18:45:56 2007
@@ -0,0 +1 @@
+DROP PROCEDURE IF EXISTS cayenne_tst_upd_proc2;
\ No newline at end of file



Mime
View raw message