cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1525613 - in /cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne: access/jdbc/ProcedureAction.java dba/db2/DB2ActionBuilder.java dba/db2/DB2Adapter.java dba/db2/DB2ProcedureAction.java
Date Mon, 23 Sep 2013 15:00:00 GMT
Author: aadamchik
Date: Mon Sep 23 15:00:00 2013
New Revision: 1525613

URL: http://svn.apache.org/r1525613
Log:
CAY-1874 DB2 Procedure action ignores the first result set

Added:
    cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/db2/DB2ActionBuilder.java
    cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/db2/DB2ProcedureAction.java
Modified:
    cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/ProcedureAction.java
    cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/db2/DB2Adapter.java

Modified: cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/ProcedureAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/ProcedureAction.java?rev=1525613&r1=1525612&r2=1525613&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/ProcedureAction.java
(original)
+++ cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/ProcedureAction.java
Mon Sep 23 15:00:00 2013
@@ -79,6 +79,12 @@ public class ProcedureAction extends Bas
             // return value of this method and avoid calling 'getMoreResults' if it is
             // true.
             // some db's handle this well, some don't (MySQL).
+            
+            // 09/23/2013: almost all adapters except Oracle (and maybe a few
+            // more?) are actually using the correct strategy, so making it a
+            // default in the superclass, and isolating hack to subclasses is
+            // probably a good idea
+
             statement.execute();
 
             // read out parameters
@@ -236,7 +242,7 @@ public class ProcedureAction extends Bas
      * 
      * @throws Exception
      */
-    void initStatement(CallableStatement statement) throws Exception {
+    protected void initStatement(CallableStatement statement) throws Exception {
         int statementFetchSize = query
                 .getMetaData(getEntityResolver())
                 .getStatementFetchSize();

Added: cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/db2/DB2ActionBuilder.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/db2/DB2ActionBuilder.java?rev=1525613&view=auto
==============================================================================
--- cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/db2/DB2ActionBuilder.java
(added)
+++ cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/db2/DB2ActionBuilder.java
Mon Sep 23 15:00:00 2013
@@ -0,0 +1,40 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.dba.db2;
+
+import org.apache.cayenne.dba.JdbcActionBuilder;
+import org.apache.cayenne.dba.JdbcAdapter;
+import org.apache.cayenne.map.EntityResolver;
+import org.apache.cayenne.query.ProcedureQuery;
+import org.apache.cayenne.query.SQLAction;
+
+/**
+ * @since 3.1
+ */
+public class DB2ActionBuilder extends JdbcActionBuilder {
+
+    DB2ActionBuilder(JdbcAdapter adapter, EntityResolver resolver) {
+        super(adapter, resolver);
+    }
+
+    @Override
+    public SQLAction procedureAction(ProcedureQuery query) {
+        return new DB2ProcedureAction(query, getAdapter(), getEntityResolver());
+    }
+}

Modified: cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/db2/DB2Adapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/db2/DB2Adapter.java?rev=1525613&r1=1525612&r2=1525613&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/db2/DB2Adapter.java
(original)
+++ cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/db2/DB2Adapter.java
Mon Sep 23 15:00:00 2013
@@ -26,6 +26,7 @@ import java.util.Iterator;
 import java.util.List;
 
 import org.apache.cayenne.CayenneRuntimeException;
+import org.apache.cayenne.access.DataNode;
 import org.apache.cayenne.access.trans.QualifierTranslator;
 import org.apache.cayenne.access.trans.QueryAssembler;
 import org.apache.cayenne.access.types.BooleanType;
@@ -44,6 +45,8 @@ import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.merge.MergerFactory;
+import org.apache.cayenne.query.Query;
+import org.apache.cayenne.query.SQLAction;
 
 /**
  * DbAdapter implementation for the <a href="http://www.ibm.com/db2/"> DB2 RDBMS </a>.
@@ -252,5 +255,14 @@ public class DB2Adapter extends JdbcAdap
             super.bindParameter(statement, object, pos, sqlType, precision);
         }
     }
-
+    
+    /**
+     * Uses special action builder to create the right action.
+     * 
+     * @since 3.1
+     */
+    @Override
+    public SQLAction getAction(Query query, DataNode node) {
+        return query.createSQLAction(new DB2ActionBuilder(this, node.getEntityResolver()));
+    }
 }

Added: cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/db2/DB2ProcedureAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/db2/DB2ProcedureAction.java?rev=1525613&view=auto
==============================================================================
--- cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/db2/DB2ProcedureAction.java
(added)
+++ cayenne/main/branches/STABLE-3.1/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/db2/DB2ProcedureAction.java
Mon Sep 23 15:00:00 2013
@@ -0,0 +1,94 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.dba.db2;
+
+import java.sql.CallableStatement;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import org.apache.cayenne.access.OperationObserver;
+import org.apache.cayenne.access.jdbc.ProcedureAction;
+import org.apache.cayenne.access.jdbc.RowDescriptor;
+import org.apache.cayenne.access.trans.ProcedureTranslator;
+import org.apache.cayenne.dba.JdbcAdapter;
+import org.apache.cayenne.map.EntityResolver;
+import org.apache.cayenne.query.ProcedureQuery;
+
+/**
+ * @since 3.1
+ */
+class DB2ProcedureAction extends ProcedureAction {
+
+    DB2ProcedureAction(ProcedureQuery query, JdbcAdapter adapter, EntityResolver entityResolver)
{
+        super(query, adapter, entityResolver);
+    }
+
+    @Override
+    public void performAction(Connection connection, OperationObserver observer) throws SQLException,
Exception {
+
+        // cloned from super except for result processing consistent with
+        // CAY-1874
+        
+        processedResultSets = 0;
+
+        ProcedureTranslator transl = createTranslator(connection);
+
+        CallableStatement statement = (CallableStatement) transl.createStatement();
+
+        try {
+            initStatement(statement);
+            boolean hasResultSet = statement.execute();
+
+            // read out parameters
+            readProcedureOutParameters(statement, observer);
+
+            // read the rest of the query
+            while (true) {
+                if (hasResultSet) {
+                    ResultSet rs = statement.getResultSet();
+
+                    try {
+                        RowDescriptor descriptor = describeResultSet(rs, processedResultSets++);
+                        readResultSet(rs, descriptor, query, observer);
+                    } finally {
+                        try {
+                            rs.close();
+                        } catch (SQLException ex) {
+                        }
+                    }
+                } else {
+                    int updateCount = statement.getUpdateCount();
+                    if (updateCount == -1) {
+                        break;
+                    }
+                    adapter.getJdbcEventLogger().logUpdateCount(updateCount);
+                    observer.nextCount(query, updateCount);
+                }
+                hasResultSet = statement.getMoreResults();
+            }
+        } finally {
+            try {
+                statement.close();
+            } catch (SQLException ex) {
+
+            }
+        }
+    }
+}



Mime
View raw message