cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntimof...@apache.org
Subject cayenne git commit: CAY-2470 Can't bind SQLExec parameters in a loop
Date Wed, 05 Sep 2018 09:22:55 GMT
Repository: cayenne
Updated Branches:
  refs/heads/master b8b4e00ab -> 8047c5884


CAY-2470 Can't bind SQLExec parameters in a loop


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/8047c588
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/8047c588
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/8047c588

Branch: refs/heads/master
Commit: 8047c588442692992c752bdf5ad5710f32eb18b7
Parents: b8b4e00
Author: Nikita Timofeev <stariy95@gmail.com>
Authored: Wed Sep 5 12:22:41 2018 +0300
Committer: Nikita Timofeev <stariy95@gmail.com>
Committed: Wed Sep 5 12:22:41 2018 +0300

----------------------------------------------------------------------
 RELEASE-NOTES.txt                               |  1 +
 .../java/org/apache/cayenne/query/SQLExec.java  | 11 ++++-----
 .../org/apache/cayenne/query/SQLExecIT.java     | 26 ++++++++++++++++++++
 3 files changed, 32 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/8047c588/RELEASE-NOTES.txt
----------------------------------------------------------------------
diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt
index 5821001..171a277 100644
--- a/RELEASE-NOTES.txt
+++ b/RELEASE-NOTES.txt
@@ -31,6 +31,7 @@ CAY-2459 Modeler: DataMap paste function is not working
 CAY-2462 Modeler: Clipboard holds old content after application was reloaded
 CAY-2463 Modeler: DB Schema generation doesn't work
 CAY-2464 ClassCastException when returning PRUNED_NODE in expression transformer
+CAY-2470 Can't bind SQLExec parameters in a loop
 
 ----------------------------------
 Release: 4.1.M2

http://git-wip-us.apache.org/repos/asf/cayenne/blob/8047c588/cayenne-server/src/main/java/org/apache/cayenne/query/SQLExec.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/query/SQLExec.java b/cayenne-server/src/main/java/org/apache/cayenne/query/SQLExec.java
index aaf7b40..550202c 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/query/SQLExec.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/query/SQLExec.java
@@ -95,14 +95,12 @@ public class SQLExec extends IndirectQuery {
         if (this.params == null) {
             this.params = new HashMap<>(parameters);
         } else {
-            Map bareMap = parameters;
-            this.params.putAll(bareMap);
+            this.params.putAll(parameters);
         }
 
         this.replacementQuery = null;
 
-        // since named parameters are specified, resetting positional
-        // parameters
+        // since named parameters are specified, resetting positional parameters
         this.positionalParams = null;
         return this;
     }
@@ -134,10 +132,11 @@ public class SQLExec extends IndirectQuery {
      * parameters.
      */
     public SQLExec paramsList(List<Object> params) {
+        this.positionalParams = params;
+        this.replacementQuery = null;
+
         // since named parameters are specified, resetting positional parameters
         this.params = null;
-
-        this.positionalParams = params;
         return this;
     }
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/8047c588/cayenne-server/src/test/java/org/apache/cayenne/query/SQLExecIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/query/SQLExecIT.java b/cayenne-server/src/test/java/org/apache/cayenne/query/SQLExecIT.java
index f04749e..b7f8d55 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/query/SQLExecIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/query/SQLExecIT.java
@@ -18,6 +18,9 @@
  ****************************************************************/
 package org.apache.cayenne.query;
 
+import java.util.HashMap;
+import java.util.Map;
+
 import org.apache.cayenne.DataRow;
 import org.apache.cayenne.QueryResult;
 import org.apache.cayenne.access.DataContext;
@@ -114,4 +117,27 @@ public class SQLExecIT extends ServerCase {
         assertEquals(55L, dbHelper.getLong("ARTIST", "ARTIST_ID"));
         assertEquals("a3", dbHelper.getString("ARTIST", "ARTIST_NAME").trim());
     }
+
+    @Test
+    public void test_Execute_MultipleArrayBind() throws Exception {
+        SQLExec inserter = SQLExec.query("INSERT INTO ARTIST (ARTIST_ID, ARTIST_NAME) VALUES
(#bind($id), #bind($name))");
+        for(int i = 0; i < 2; i++) {
+            QueryResult<?> result = inserter.paramsArray(i, "artist " + i).execute(context);
+            assertEquals(1, result.firstUpdateCount());
+        }
+        assertEquals(2, dbHelper.getRowCount("ARTIST"));
+    }
+
+    @Test
+    public void test_Execute_MultipleMapBind() throws Exception {
+        SQLExec inserter = SQLExec.query("INSERT INTO ARTIST (ARTIST_ID, ARTIST_NAME) VALUES
(#bind($id), #bind($name))");
+        for(int i = 0; i < 2; i++) {
+            Map<String, Object> params = new HashMap<>();
+            params.put("id", i);
+            params.put("name", "artist " + i);
+            QueryResult<?> result = inserter.params(params).execute(context);
+            assertEquals(1, result.firstUpdateCount());
+        }
+        assertEquals(2, dbHelper.getRowCount("ARTIST"));
+    }
 }


Mime
View raw message