cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abulat...@apache.org
Subject [cayenne] branch master updated: CAY-2563 Deprecate old scalarQuery methods in SQLSelect
Date Thu, 11 Apr 2019 13:53:14 GMT
This is an automated email from the ASF dual-hosted git repository.

abulatski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cayenne.git


The following commit(s) were added to refs/heads/master by this push:
     new 933e42f  CAY-2563 Deprecate old scalarQuery methods in SQLSelect
933e42f is described below

commit 933e42f40b3a09e074d5297fcd62d97add6efdca
Author: Arseni Bulatski <ancarseni@gmail.com>
AuthorDate: Thu Apr 11 16:49:16 2019 +0300

    CAY-2563 Deprecate old scalarQuery methods in SQLSelect
---
 RELEASE-NOTES.txt                                  |  1 +
 UPGRADE.txt                                        |  3 ++
 .../java/org/apache/cayenne/query/SQLSelect.java   | 18 ++++++----
 .../org/apache/cayenne/OneWayRelationshipsIT.java  | 20 +++++------
 .../java/org/apache/cayenne/query/SQLSelectIT.java | 39 ++++++++++++----------
 5 files changed, 46 insertions(+), 35 deletions(-)

diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt
index 22f05c8..357de43 100644
--- a/RELEASE-NOTES.txt
+++ b/RELEASE-NOTES.txt
@@ -28,6 +28,7 @@ CAY-2542 Modeler: redesign ObjRelationship editor dialog
 CAY-2543 Move ResultSetMapping generation from metadata to translator
 CAY-2549 Modeler: Redesign ObjAttribute editor dialog
 CAY-2555 Use explicit ArcId in GraphChangeHandler methods
+CAY-2563 Deprecate old scalarQuery methods in SQLSelect
 
 Bug Fixes:
 
diff --git a/UPGRADE.txt b/UPGRADE.txt
index 8e080ab..fb61f25 100644
--- a/UPGRADE.txt
+++ b/UPGRADE.txt
@@ -15,6 +15,9 @@ UPGRADING TO 4.2.M1
 * Per CAY-2467 Property class is replaced with a type-aware Property API, it's mostly backwards
compatible.
     To take advantage of this new API you should regenerate code via Modeler ("Tools" ->
"Generate Classes") or cgen tools.
 
+* Per CAY-2563 SQLSelect.scalarQuery(Class<T>, String) and SQLSelect.scalarQuery(Class<T>,
String, String) methods
+    were deprecated.
+
 UPGRADING TO 4.1.M3
 
 * Per CAY-2514 SERVER_CONTEXTS_SYNC_PROPERTY default value was set to false.
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 c276a78..f2538a4 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
@@ -18,6 +18,13 @@
  ****************************************************************/
 package org.apache.cayenne.query;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.DataRow;
 import org.apache.cayenne.ObjectContext;
@@ -27,13 +34,6 @@ import org.apache.cayenne.ResultIteratorCallback;
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.EntityResolver;
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
 /**
  * A selecting query based on raw SQL and featuring fluent API.
  * 
@@ -93,7 +93,9 @@ public class SQLSelect<T> extends IndirectQuery implements Select<T>
{
 
 	/**
 	 * Creates a query that selects scalar values and uses default routing.
+	 * @deprecated since 4.2. Use {@link #scalarQuery(String, Class<T>)} method.
 	 */
+	@Deprecated
 	public static <T> SQLSelect<T> scalarQuery(Class<T> type, String sql)
{
 		return scalarQuery(sql, type);
 	}
@@ -101,7 +103,9 @@ public class SQLSelect<T> extends IndirectQuery implements Select<T>
{
 	/**
 	 * Creates a query that selects scalar values and uses routing based on the
 	 * provided DataMap name.
+	 * @deprecated since 4.2. Use {@link #scalarQuery(String, String, Class<T>)} method.
 	 */
+	@Deprecated
 	public static <T> SQLSelect<T> scalarQuery(Class<T> type, String dataMapName,
String sql) {
 		SQLSelect<T> query = new SQLSelect<>(sql);
 		query.dataMapName = dataMapName;
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/OneWayRelationshipsIT.java b/cayenne-server/src/test/java/org/apache/cayenne/OneWayRelationshipsIT.java
index dd5fbc5..68e7007 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/OneWayRelationshipsIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/OneWayRelationshipsIT.java
@@ -18,6 +18,10 @@
  ****************************************************************/
 package org.apache.cayenne;
 
+import java.sql.SQLException;
+import java.sql.Types;
+import java.util.List;
+
 import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.query.SQLSelect;
 import org.apache.cayenne.test.jdbc.DBHelper;
@@ -32,10 +36,6 @@ import org.apache.cayenne.unit.di.server.UseServerRuntime;
 import org.junit.Before;
 import org.junit.Test;
 
-import java.sql.SQLException;
-import java.sql.Types;
-import java.util.List;
-
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertSame;
@@ -157,8 +157,8 @@ public class OneWayRelationshipsIT extends ServerCase {
 
 		assertEquals(2, t3.getToManyOneWayDb().size());
 
-		SQLSelect<Integer> fksQuery = SQLSelect.scalarQuery(Integer.class, "oneway-rels",
-				"SELECT TABLE3_ID FROM oneway_table4");
+		SQLSelect<Integer> fksQuery = SQLSelect.scalarQuery("SELECT TABLE3_ID FROM oneway_table4",
+				"oneway-rels",Integer.class);
 
 		List<Integer> fks = context.select(fksQuery);
 		assertEquals(2, fks.size());
@@ -186,8 +186,8 @@ public class OneWayRelationshipsIT extends ServerCase {
 
 		assertEquals(2, t3.getToManyOneWayDb().size());
 
-		SQLSelect<Integer> fksQuery = SQLSelect.scalarQuery(Integer.class, "oneway-rels",
-				"SELECT TABLE3_ID FROM oneway_table4");
+		SQLSelect<Integer> fksQuery = SQLSelect.scalarQuery("SELECT TABLE3_ID FROM oneway_table4",
+				"oneway-rels", Integer.class);
 
 		List<Integer> fks = context.select(fksQuery);
 		assertEquals(2, fks.size());
@@ -216,8 +216,8 @@ public class OneWayRelationshipsIT extends ServerCase {
 
 		assertEquals(1, t3.getToManyOneWayDb().size());
 
-		SQLSelect<Integer> fksQuery = SQLSelect.scalarQuery(Integer.class, "oneway-rels",
-				"SELECT TABLE3_ID FROM oneway_table4");
+		SQLSelect<Integer> fksQuery = SQLSelect.scalarQuery("SELECT TABLE3_ID FROM oneway_table4",
+				"oneway-rels", Integer.class);
 
 		List<Integer> fks = context.select(fksQuery);
 		assertEquals(2, fks.size());
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 51dbc48..0f67474 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
@@ -18,6 +18,14 @@
  ****************************************************************/
 package org.apache.cayenne.query;
 
+import java.sql.Date;
+import java.sql.SQLException;
+import java.sql.Types;
+import java.time.LocalDateTime;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.DataRow;
 import org.apache.cayenne.ResultBatchIterator;
@@ -35,14 +43,6 @@ import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
 
-import java.sql.Date;
-import java.sql.SQLException;
-import java.sql.Types;
-import java.time.LocalDateTime;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
 import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.junit.Assert.*;
 
@@ -404,7 +404,8 @@ public class SQLSelectIT extends ServerCase {
 		createPaintingsDataSet();
 
 		long id = SQLSelect
-				.scalarQuery(Integer.class, "SELECT PAINTING_ID FROM PAINTING WHERE PAINTING_TITLE =
#bind($a)")
+				.scalarQuery( "SELECT PAINTING_ID FROM PAINTING WHERE PAINTING_TITLE = #bind($a)",
+						Integer.class)
 				.params("a", "painting3").selectOne(context);
 
 		assertEquals(3l, id);
@@ -414,8 +415,8 @@ public class SQLSelectIT extends ServerCase {
 	public void test_SelectLongArray() throws Exception {
 		createPaintingsDataSet();
 
-		List<Integer> ids = SQLSelect.scalarQuery(Integer.class,
-				"SELECT PAINTING_ID FROM PAINTING ORDER BY PAINTING_ID").select(context);
+		List<Integer> ids = SQLSelect.scalarQuery("SELECT PAINTING_ID FROM PAINTING ORDER
BY PAINTING_ID",
+				Integer.class).select(context);
 
 		assertEquals(20, ids.size());
 		assertEquals(2l, ids.get(1).intValue());
@@ -435,7 +436,8 @@ public class SQLSelectIT extends ServerCase {
 		createPaintingsDataSet();
 
 		Integer id = SQLSelect
-				.scalarQuery(Integer.class, "SELECT PAINTING_ID FROM PAINTING WHERE PAINTING_TITLE =
#bind($a)")
+				.scalarQuery( "SELECT PAINTING_ID FROM PAINTING WHERE PAINTING_TITLE = #bind($a)",
+						Integer.class)
 				.paramsArray("painting3").selectOne(context);
 
 		assertEquals(3l, id.intValue());
@@ -446,8 +448,9 @@ public class SQLSelectIT extends ServerCase {
 		createPaintingsDataSet();
 
 		List<Integer> ids = SQLSelect
-				.scalarQuery(Integer.class,
-						"SELECT PAINTING_ID FROM PAINTING WHERE PAINTING_TITLE = #bind($a) OR PAINTING_TITLE
= #bind($b) ORDER BY PAINTING_ID")
+				.scalarQuery("SELECT PAINTING_ID FROM PAINTING WHERE PAINTING_TITLE = #bind($a) " +
+						"OR PAINTING_TITLE = #bind($b) ORDER BY PAINTING_ID",
+						Integer.class)
 				.paramsArray("painting3", "painting2").select(context);
 
 		assertEquals(2l, ids.get(0).intValue());
@@ -463,10 +466,10 @@ public class SQLSelectIT extends ServerCase {
 
 		List<Integer> ids = SQLSelect
 				.scalarQuery(
-						Integer.class,
 						"SELECT PAINTING_ID FROM PAINTING #chain('OR' 'WHERE') "
 								+ "#chunk($a) ESTIMATED_PRICE #bindEqual($a) #end "
-								+ "#chunk($b) PAINTING_TITLE #bindEqual($b) #end #end ORDER BY PAINTING_ID")
+								+ "#chunk($b) PAINTING_TITLE #bindEqual($b) #end #end ORDER BY PAINTING_ID",
+						Integer.class)
 				.paramsArray(null, "painting1").select(context);
 
 		assertEquals(1, ids.size());
@@ -486,10 +489,10 @@ public class SQLSelectIT extends ServerCase {
 
 		List<Integer> ids = SQLSelect
 				.scalarQuery(
-						Integer.class,
 						"SELECT PAINTING_ID FROM PAINTING #chain('OR' 'WHERE') "
 								+ "#chunk($a) ESTIMATED_PRICE #bindEqual($a) #end "
-								+ "#chunk($b) PAINTING_TITLE #bindEqual($b) #end #end ORDER BY PAINTING_ID")
+								+ "#chunk($b) PAINTING_TITLE #bindEqual($b) #end #end ORDER BY PAINTING_ID",
+						Integer.class)
 				.params(params).select(context);
 
 		assertEquals(1, ids.size());


Mime
View raw message