cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r504910 - in /cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne: access/jdbc/ProcedureAction.java dba/postgres/PostgresProcedureAction.java dba/sqlserver/SQLServerProcedureAction.java
Date Thu, 08 Feb 2007 14:29:24 GMT
Author: aadamchik
Date: Thu Feb  8 06:29:23 2007
New Revision: 504910

URL: http://svn.apache.org/viewvc?view=rev&rev=504910
Log:
CAY-750 Stored procedures without parameters fail on Postgres 8
(fix for 3.0)

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/main/java/org/apache/cayenne/dba/postgres/PostgresProcedureAction.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/sqlserver/SQLServerProcedureAction.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=504910&r1=504909&r2=504910
==============================================================================
--- 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
Thu Feb  8 06:29:23 2007
@@ -125,12 +125,12 @@
      * @param connection JDBC connection
      */
     protected ProcedureTranslator createTranslator(Connection connection) {
-        ProcedureTranslator transl = new ProcedureTranslator();
-        transl.setAdapter(getAdapter());
-        transl.setQuery(query);
-        transl.setEntityResolver(getEntityResolver());
-        transl.setConnection(connection);
-        return transl;
+        ProcedureTranslator translator = new ProcedureTranslator();
+        translator.setAdapter(getAdapter());
+        translator.setQuery(query);
+        translator.setEntityResolver(getEntityResolver());
+        translator.setConnection(connection);
+        return translator;
     }
 
     /**

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/postgres/PostgresProcedureAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/postgres/PostgresProcedureAction.java?view=diff&rev=504910&r1=504909&r2=504910
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/postgres/PostgresProcedureAction.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/postgres/PostgresProcedureAction.java
Thu Feb  8 06:29:23 2007
@@ -19,6 +19,9 @@
 
 package org.apache.cayenne.dba.postgres;
 
+import java.sql.Connection;
+
+import org.apache.cayenne.access.trans.ProcedureTranslator;
 import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.dba.sqlserver.SQLServerProcedureAction;
 import org.apache.cayenne.map.EntityResolver;
@@ -38,5 +41,33 @@
     PostgresProcedureAction(ProcedureQuery query, DbAdapter adapter,
             EntityResolver entityResolver) {
         super(query, adapter, entityResolver);
+    }
+
+    /**
+     * Creates a translator that adds parenthesis to no-param queries.
+     */
+    // see CAY-750 for the problem description
+    protected ProcedureTranslator createTranslator(Connection connection) {
+        ProcedureTranslator translator = new PostgresProcedureTranslator();
+        translator.setAdapter(getAdapter());
+        translator.setQuery(query);
+        translator.setEntityResolver(getEntityResolver());
+        translator.setConnection(connection);
+        return translator;
+    }
+
+    static class PostgresProcedureTranslator extends ProcedureTranslator {
+
+        protected String createSqlString() {
+
+            String sql = super.createSqlString();
+
+            // add empty parameter parenthesis
+            if (sql.endsWith("}") && !sql.endsWith(")}")) {
+                sql = sql.substring(0, sql.length() - 1) + "()}";
+            }
+
+            return sql;
+        }
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/sqlserver/SQLServerProcedureAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/sqlserver/SQLServerProcedureAction.java?view=diff&rev=504910&r1=504909&r2=504910
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/sqlserver/SQLServerProcedureAction.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/sqlserver/SQLServerProcedureAction.java
Thu Feb  8 06:29:23 2007
@@ -59,12 +59,7 @@
     public void performAction(Connection connection, OperationObserver observer)
             throws SQLException, Exception {
 
-        ProcedureTranslator transl = new ProcedureTranslator();
-        transl.setAdapter(getAdapter());
-        transl.setQuery(query);
-        transl.setEntityResolver(this.getEntityResolver());
-        transl.setConnection(connection);
-
+        ProcedureTranslator transl = createTranslator(connection);
         CallableStatement statement = (CallableStatement) transl.createStatement();
 
         try {



Mime
View raw message