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:28:51 GMT
Repository: cayenne
Updated Branches:
  refs/heads/STABLE-4.0 e448b4f64 -> 9495e30b1


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

(cherry picked from commit 8047c588442692992c752bdf5ad5710f32eb18b7)


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

Branch: refs/heads/STABLE-4.0
Commit: 9495e30b1b3502f710019b36e683be3ab873b3ad
Parents: e448b4f
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:24:30 2018 +0300

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


http://git-wip-us.apache.org/repos/asf/cayenne/blob/9495e30b/RELEASE-NOTES.txt
----------------------------------------------------------------------
diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt
index dfcad7f..0b9b8a3 100644
--- a/RELEASE-NOTES.txt
+++ b/RELEASE-NOTES.txt
@@ -22,6 +22,7 @@ CAY-2454 Modeler: Unable to read validation message if it's truncated
 CAY-2459 Modeler: DataMap Paste function is not working
 CAY-2462 Modeler: Clipboard holds old content after application was reloaded
 CAY-2464 ClassCastException when returning PRUNED_NODE in expression transformer
+CAY-2470 Can't bind SQLExec parameters in a loop
 
 ----------------------------------
 Release: 4.0

http://git-wip-us.apache.org/repos/asf/cayenne/blob/9495e30b/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 57f7cc5..b46ff0f 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
@@ -94,14 +94,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;
     }
@@ -133,10 +131,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/9495e30b/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 4591022..d899d8a 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,8 +18,8 @@
  ****************************************************************/
 package org.apache.cayenne.query;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.apache.cayenne.DataRow;
 import org.apache.cayenne.QueryResult;
@@ -32,6 +32,9 @@ import org.apache.cayenne.unit.di.server.ServerCase;
 import org.apache.cayenne.unit.di.server.UseServerRuntime;
 import org.junit.Test;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
 @UseServerRuntime(CayenneProjects.TESTMAP_PROJECT)
 public class SQLExecIT extends ServerCase {
 
@@ -100,4 +103,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