cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject [2/4] cayenne git commit: CAY-1966 SQLTemplate/SQLSelect positional parameter binding
Date Sat, 17 Jan 2015 08:05:44 GMT
CAY-1966 SQLTemplate/SQLSelect positional parameter binding

* incorrect positional params translation from SQLSelect to SQLTemplate


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

Branch: refs/heads/master
Commit: 60f3f154fae265e971eb6c040bb0508ab86fc2a0
Parents: 44642ea
Author: aadamchik <aadamchik@apache.org>
Authored: Fri Jan 16 09:19:09 2015 +0300
Committer: aadamchik <aadamchik@apache.org>
Committed: Fri Jan 16 09:19:09 2015 +0300

----------------------------------------------------------------------
 .../org/apache/cayenne/query/SQLSelect.java     |  2 +-
 .../org/apache/cayenne/query/SQLSelectIT.java   | 46 +++++++++++++-------
 .../org/apache/cayenne/query/SQLSelectTest.java | 34 +++++++++++++--
 3 files changed, 62 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/60f3f154/cayenne-server/src/main/java/org/apache/cayenne/query/SQLSelect.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/query/SQLSelect.java b/cayenne-server/src/main/java/org/apache/cayenne/query/SQLSelect.java
index ebd5d58..754c4b6 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/query/SQLSelect.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/query/SQLSelect.java
@@ -243,7 +243,7 @@ public class SQLSelect<T> extends IndirectQuery implements Select<T>
{
 		template.setCacheStrategy(cacheStrategy);
 
 		if (positionalParams != null) {
-			template.setParamsArray(positionalParams);
+			template.setParamsList(positionalParams);
 		} else {
 			template.setParams(params);
 		}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/60f3f154/cayenne-server/src/test/java/org/apache/cayenne/query/SQLSelectIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/query/SQLSelectIT.java b/cayenne-server/src/test/java/org/apache/cayenne/query/SQLSelectIT.java
index b16c846..c17f153 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/query/SQLSelectIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/query/SQLSelectIT.java
@@ -55,7 +55,7 @@ public class SQLSelectIT extends ServerCase {
 		}
 	}
 
-    @Test
+	@Test
 	public void test_DataRows_DataMapNameRoot() throws Exception {
 
 		createArtistsDataSet();
@@ -68,7 +68,7 @@ public class SQLSelectIT extends ServerCase {
 		assertTrue(result.get(0) instanceof DataRow);
 	}
 
-    @Test
+	@Test
 	public void test_DataRows_DefaultRoot() throws Exception {
 
 		createArtistsDataSet();
@@ -81,7 +81,7 @@ public class SQLSelectIT extends ServerCase {
 		assertTrue(result.get(0) instanceof DataRow);
 	}
 
-    @Test
+	@Test
 	public void test_DataRows_ClassRoot() throws Exception {
 
 		createArtistsDataSet();
@@ -93,7 +93,7 @@ public class SQLSelectIT extends ServerCase {
 		assertTrue(result.get(0) instanceof Artist);
 	}
 
-    @Test
+	@Test
 	public void test_DataRows_ClassRoot_Parameters() throws Exception {
 
 		createArtistsDataSet();
@@ -106,7 +106,7 @@ public class SQLSelectIT extends ServerCase {
 		assertEquals("artist3", a.getArtistName());
 	}
 
-    @Test
+	@Test
 	public void test_DataRows_ClassRoot_Bind() throws Exception {
 
 		createArtistsDataSet();
@@ -119,7 +119,7 @@ public class SQLSelectIT extends ServerCase {
 		assertEquals(2, result.size());
 	}
 
-    @Test
+	@Test
 	public void test_DataRows_ColumnNameCaps() throws Exception {
 
 		SQLSelect<DataRow> q1 = SQLSelect.dataRowQuery("SELECT * FROM ARTIST WHERE ARTIST_NAME
= 'artist2'");
@@ -133,7 +133,7 @@ public class SQLSelectIT extends ServerCase {
 		assertEquals(CapsStrategy.LOWER, r2.getColumnNamesCapitalization());
 	}
 
-    @Test
+	@Test
 	public void test_DataRows_FetchLimit() throws Exception {
 
 		createArtistsDataSet();
@@ -144,7 +144,7 @@ public class SQLSelectIT extends ServerCase {
 		assertEquals(5, context.select(q1).size());
 	}
 
-    @Test
+	@Test
 	public void test_DataRows_FetchOffset() throws Exception {
 
 		createArtistsDataSet();
@@ -155,7 +155,7 @@ public class SQLSelectIT extends ServerCase {
 		assertEquals(16, context.select(q1).size());
 	}
 
-    @Test
+	@Test
 	public void test_Append() throws Exception {
 
 		createArtistsDataSet();
@@ -167,7 +167,7 @@ public class SQLSelectIT extends ServerCase {
 		assertEquals(1, result.size());
 	}
 
-    @Test
+	@Test
 	public void test_Select() throws Exception {
 
 		createArtistsDataSet();
@@ -178,7 +178,7 @@ public class SQLSelectIT extends ServerCase {
 		assertEquals(1, result.size());
 	}
 
-    @Test
+	@Test
 	public void test_SelectOne() throws Exception {
 
 		createArtistsDataSet();
@@ -189,7 +189,7 @@ public class SQLSelectIT extends ServerCase {
 		assertEquals("artist3", a.getArtistName());
 	}
 
-    @Test
+	@Test
 	public void test_SelectLong() throws Exception {
 
 		createArtistsDataSet();
@@ -200,7 +200,7 @@ public class SQLSelectIT extends ServerCase {
 		assertEquals(3l, id);
 	}
 
-    @Test
+	@Test
 	public void test_SelectLongArray() throws Exception {
 
 		createArtistsDataSet();
@@ -212,7 +212,7 @@ public class SQLSelectIT extends ServerCase {
 		assertEquals(2l, ids.get(1).longValue());
 	}
 
-    @Test
+	@Test
 	public void test_SelectCount() throws Exception {
 
 		createArtistsDataSet();
@@ -222,8 +222,8 @@ public class SQLSelectIT extends ServerCase {
 		assertEquals(20, c);
 	}
 
-    @Test
-	public void testSQLTemplate_PositionalParams() throws Exception {
+	@Test
+	public void test_ParamsArray_Single() throws Exception {
 
 		createArtistsDataSet();
 
@@ -232,4 +232,18 @@ public class SQLSelectIT extends ServerCase {
 
 		assertEquals(3l, id.longValue());
 	}
+
+	@Test
+	public void test_ParamsArray_Multiple() throws Exception {
+
+		createArtistsDataSet();
+
+		List<Long> ids = SQLSelect
+				.scalarQuery(Long.class,
+						"SELECT ARTIST_ID FROM ARTIST WHERE ARTIST_NAME = #bind($a) OR ARTIST_NAME = #bind($b)
ORDER BY ARTIST_ID")
+				.paramsArray("artist3", "artist2").select(context);
+
+		assertEquals(2l, ids.get(0).longValue());
+		assertEquals(3l, ids.get(1).longValue());
+	}
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/60f3f154/cayenne-server/src/test/java/org/apache/cayenne/query/SQLSelectTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/query/SQLSelectTest.java b/cayenne-server/src/test/java/org/apache/cayenne/query/SQLSelectTest.java
index 88e1b6a..439ff44 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/query/SQLSelectTest.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/query/SQLSelectTest.java
@@ -18,17 +18,21 @@
  ****************************************************************/
 package org.apache.cayenne.query;
 
+import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
 
 import java.util.Arrays;
 
 import org.apache.cayenne.DataRow;
+import org.apache.cayenne.map.EntityResolver;
 import org.junit.Test;
 
 public class SQLSelectTest {
-	
+
 	@Test
 	public void testCacheGroups_Collection() {
 		SQLSelect<DataRow> q = SQLSelect.dataRowQuery("bla");
@@ -56,7 +60,7 @@ public class SQLSelectTest {
 		assertSame(QueryCacheStrategy.SHARED_CACHE, q.getCacheStrategy());
 		assertNull(q.getCacheGroups());
 	}
-	
+
 	@Test
 	public void testLocalCache() {
 		SQLSelect<DataRow> q = SQLSelect.dataRowQuery("bla");
@@ -72,7 +76,7 @@ public class SQLSelectTest {
 		assertSame(QueryCacheStrategy.LOCAL_CACHE, q.getCacheStrategy());
 		assertNull(q.getCacheGroups());
 	}
-	
+
 	@Test
 	public void testSharedCache() {
 		SQLSelect<DataRow> q = SQLSelect.dataRowQuery("bla");
@@ -88,4 +92,28 @@ public class SQLSelectTest {
 		assertSame(QueryCacheStrategy.SHARED_CACHE, q.getCacheStrategy());
 		assertNull(q.getCacheGroups());
 	}
+
+	@Test
+	public void testCreateReplacementQuery() {
+
+		SQLSelect<DataRow> q = SQLSelect.dataRowQuery("bla");
+		Query replacement = q.createReplacementQuery(mock(EntityResolver.class));
+		assertThat(replacement, instanceOf(SQLTemplate.class));
+	}
+
+	@Test
+	public void testCreateReplacementQuery_ParamsArray_Single() {
+
+		SQLSelect<DataRow> q = SQLSelect.dataRowQuery("bla").paramsArray("a");
+		SQLTemplate replacement = (SQLTemplate) q.createReplacementQuery(mock(EntityResolver.class));
+		assertArrayEquals(new Object[] { "a" }, replacement.getPositionalParams().toArray());
+	}
+
+	@Test
+	public void testCreateReplacementQuery_ParamsArray_Multiple() {
+
+		SQLSelect<DataRow> q = SQLSelect.dataRowQuery("bla").paramsArray("a", "b");
+		SQLTemplate replacement = (SQLTemplate) q.createReplacementQuery(mock(EntityResolver.class));
+		assertArrayEquals(new Object[] { "a", "b" }, replacement.getPositionalParams().toArray());
+	}
 }


Mime
View raw message