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-2378 Switch usage of SelectQuery to ObjectSelect internally
Date Mon, 12 Aug 2019 10:16:39 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 1a41280  CAY-2378 Switch usage of SelectQuery to ObjectSelect internally
1a41280 is described below

commit 1a4128057372fbf16dff799c7c435f82641b6c18
Author: Arseni Bulatski <ancarseni@gmail.com>
AuthorDate: Mon Aug 12 13:14:51 2019 +0300

    CAY-2378 Switch usage of SelectQuery to ObjectSelect internally
---
 .../cayenne/CayenneContextWithDataContextIT.java   |  43 ++---
 .../cayenne/NestedCayenneContextTooneIT.java       |  27 ++-
 .../cayenne/access/ClientServerChannelIT.java      |  33 ++--
 .../cayenne/access/ClientServerChannelQueryIT.java |  54 +++---
 .../apache/cayenne/query/ClientExpressionIT.java   | 192 +++++++++++----------
 .../cayenne/query/SelectQueryAbstractEntityIT.java |  40 ++---
 .../apache/cayenne/remote/ClientChannelTest.java   |  51 +++---
 .../cayenne/remote/NestedObjectContextLocalIT.java |  15 +-
 .../cayenne/remote/ROPPrefetchToManyMapIT.java     |  35 ++--
 .../remote/RemoteIncrementalFaultListIT.java       |  38 ++--
 .../cayenne/dbsync/merge/token/ValueForNullIT.java |  12 +-
 .../ObjectIdRelationshipHandlerTest.java           |   4 +-
 12 files changed, 263 insertions(+), 281 deletions(-)

diff --git a/cayenne-client/src/test/java/org/apache/cayenne/CayenneContextWithDataContextIT.java b/cayenne-client/src/test/java/org/apache/cayenne/CayenneContextWithDataContextIT.java
index b06dbfc..6ffb5b2 100644
--- a/cayenne-client/src/test/java/org/apache/cayenne/CayenneContextWithDataContextIT.java
+++ b/cayenne-client/src/test/java/org/apache/cayenne/CayenneContextWithDataContextIT.java
@@ -19,13 +19,15 @@
 
 package org.apache.cayenne;
 
+import java.sql.Types;
+import java.util.List;
+
 import org.apache.cayenne.access.ClientServerChannel;
 import org.apache.cayenne.access.DataContext;
 import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.map.LifecycleEvent;
 import org.apache.cayenne.query.ObjectIdQuery;
 import org.apache.cayenne.query.ObjectSelect;
-import org.apache.cayenne.query.SelectQuery;
 import org.apache.cayenne.reflect.LifecycleCallbackRegistry;
 import org.apache.cayenne.remote.RemoteIncrementalFaultList;
 import org.apache.cayenne.test.jdbc.DBHelper;
@@ -41,16 +43,7 @@ import org.apache.cayenne.unit.di.server.UseServerRuntime;
 import org.junit.Before;
 import org.junit.Test;
 
-import java.sql.Types;
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.*;
 
 @UseServerRuntime(CayenneProjects.MULTI_TIER_PROJECT)
 public class CayenneContextWithDataContextIT extends ClientCase {
@@ -339,9 +332,9 @@ public class CayenneContextWithDataContextIT extends ClientCase {
                 MtTable1.TABLE1_ID_PK_COLUMN,
                 1);
 
-        SelectQuery<ClientMtTable2> q = new SelectQuery<>(ClientMtTable2.class);
-        q.addOrdering(ClientMtTable2.GLOBAL_ATTRIBUTE.asc());
-        q.addPrefetch(ClientMtTable2.TABLE1.disjoint());
+        ObjectSelect<ClientMtTable2> q = ObjectSelect.query(ClientMtTable2.class)
+                .orderBy(ClientMtTable2.GLOBAL_ATTRIBUTE.asc())
+                .prefetch(ClientMtTable2.TABLE1.disjoint());
 
         final List<ClientMtTable2> results = q.select(clientContext);
 
@@ -365,8 +358,8 @@ public class CayenneContextWithDataContextIT extends ClientCase {
     public void testPrefetchingToOneNull() throws Exception {
         tMtTable2.insert(15, null, "g3");
 
-        SelectQuery<ClientMtTable2> q = new SelectQuery<>(ClientMtTable2.class);
-        q.addPrefetch(ClientMtTable2.TABLE1.disjoint());
+        ObjectSelect<ClientMtTable2> q = ObjectSelect.query(ClientMtTable2.class)
+                .prefetch(ClientMtTable2.TABLE1.disjoint());
 
         final List<ClientMtTable2> results = q.select(clientContext);
 
@@ -385,9 +378,9 @@ public class CayenneContextWithDataContextIT extends ClientCase {
     public void testPrefetchingToMany() throws Exception {
         createTwoMtTable1sAnd2sDataSet();
 
-        SelectQuery<ClientMtTable1> q = new SelectQuery<>(ClientMtTable1.class);
-        q.addOrdering(ClientMtTable1.GLOBAL_ATTRIBUTE1.asc());
-        q.addPrefetch(ClientMtTable1.TABLE2ARRAY.joint());
+        ObjectSelect<ClientMtTable1> q = ObjectSelect.query(ClientMtTable1.class)
+                .orderBy(ClientMtTable1.GLOBAL_ATTRIBUTE1.asc())
+                .prefetch(ClientMtTable1.TABLE2ARRAY.joint());
 
         final List<ClientMtTable1> results = q.select(clientContext);
 
@@ -415,8 +408,8 @@ public class CayenneContextWithDataContextIT extends ClientCase {
     public void testPerformPaginatedQuery() throws Exception {
         createEightMtTable1s();
 
-        SelectQuery<ClientMtTable1> query = new SelectQuery<>(ClientMtTable1.class);
-        query.setPageSize(5);
+        ObjectSelect<ClientMtTable1> query = ObjectSelect.query(ClientMtTable1.class)
+                .pageSize(5);
         List<ClientMtTable1> objects = query.select(clientContext);
         assertNotNull(objects);
         assertTrue(objects instanceof RemoteIncrementalFaultList);
@@ -425,10 +418,10 @@ public class CayenneContextWithDataContextIT extends ClientCase {
     @Test
     public void testPrefetchingToManyEmpty() throws Exception {
         createTwoMtTable1sAnd2sDataSet();
-
-        SelectQuery<ClientMtTable1> q = new SelectQuery<>(ClientMtTable1.class);
-        q.addOrdering(ClientMtTable1.GLOBAL_ATTRIBUTE1.asc());
-        q.addPrefetch(ClientMtTable1.TABLE2ARRAY.joint());
+        
+        ObjectSelect<ClientMtTable1> q = ObjectSelect.query(ClientMtTable1.class)
+                .orderBy(ClientMtTable1.GLOBAL_ATTRIBUTE1.asc())
+                .prefetch(ClientMtTable1.TABLE2ARRAY.joint());
 
         final List<ClientMtTable1> results = q.select(clientContext);
 
diff --git a/cayenne-client/src/test/java/org/apache/cayenne/NestedCayenneContextTooneIT.java b/cayenne-client/src/test/java/org/apache/cayenne/NestedCayenneContextTooneIT.java
index 643984c..c63eff7 100644
--- a/cayenne-client/src/test/java/org/apache/cayenne/NestedCayenneContextTooneIT.java
+++ b/cayenne-client/src/test/java/org/apache/cayenne/NestedCayenneContextTooneIT.java
@@ -19,12 +19,16 @@
 
 package org.apache.cayenne;
 
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
 import org.apache.cayenne.configuration.rop.client.ClientRuntime;
 import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.graph.ArcId;
 import org.apache.cayenne.graph.GraphChangeHandler;
 import org.apache.cayenne.graph.GraphDiff;
-import org.apache.cayenne.query.SelectQuery;
+import org.apache.cayenne.query.ObjectSelect;
 import org.apache.cayenne.remote.RemoteCayenneCase;
 import org.apache.cayenne.remote.service.LocalConnection;
 import org.apache.cayenne.testdo.toone.ClientTooneDep;
@@ -36,10 +40,6 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
 
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertSame;
@@ -82,13 +82,12 @@ public class NestedCayenneContextTooneIT extends RemoteCayenneCase {
 
         ObjectContext child = runtime.newContext(clientContext);
 
-        SelectQuery<ClientTooneMaster> query = new SelectQuery<ClientTooneMaster>(
-                ClientTooneMaster.class);
+        ObjectSelect<ClientTooneMaster> query = ObjectSelect.query(ClientTooneMaster.class);
         List<ClientTooneMaster> objects = child.select(query);
 
         assertEquals(1, objects.size());
 
-        ClientTooneMaster childDeleted = (ClientTooneMaster) objects.get(0);
+        ClientTooneMaster childDeleted = objects.get(0);
 
         child.deleteObjects(childDeleted);
 
@@ -103,8 +102,7 @@ public class NestedCayenneContextTooneIT extends RemoteCayenneCase {
 
         clientContext.commitChanges();
 
-        SelectQuery<ClientTooneMaster> query2 = new SelectQuery<ClientTooneMaster>(
-                ClientTooneMaster.class);
+        ObjectSelect<ClientTooneMaster> query2 = ObjectSelect.query(ClientTooneMaster.class);
         List<ClientTooneMaster> objects2 = child.select(query2);
 
         assertEquals(0, objects2.size());
@@ -124,8 +122,7 @@ public class NestedCayenneContextTooneIT extends RemoteCayenneCase {
 
         ObjectContext child = runtime.newContext(clientContext);
 
-        SelectQuery<ClientTooneDep> queryB = new SelectQuery<ClientTooneDep>(
-                ClientTooneDep.class);
+        ObjectSelect<ClientTooneDep> queryB = ObjectSelect.query(ClientTooneDep.class);
         List<?> objectsB = child.performQuery(queryB);
 
         assertEquals(1, objectsB.size());
@@ -133,8 +130,7 @@ public class NestedCayenneContextTooneIT extends RemoteCayenneCase {
         ClientTooneDep childBDeleted = (ClientTooneDep) objectsB.get(0);
         child.deleteObjects(childBDeleted);
 
-        SelectQuery<ClientTooneMaster> query = new SelectQuery<ClientTooneMaster>(
-                ClientTooneMaster.class);
+        ObjectSelect<ClientTooneMaster> query = ObjectSelect.query(ClientTooneMaster.class);
         List<ClientTooneMaster> objects = child.select(query);
 
         assertEquals(1, objects.size());
@@ -154,8 +150,7 @@ public class NestedCayenneContextTooneIT extends RemoteCayenneCase {
 
         clientContext.commitChanges();
 
-        SelectQuery<ClientTooneMaster> query2 = new SelectQuery<ClientTooneMaster>(
-                ClientTooneMaster.class);
+        ObjectSelect<ClientTooneMaster> query2 = ObjectSelect.query(ClientTooneMaster.class);
         List<ClientTooneMaster> objects2 = child.select(query2);
 
         assertEquals(0, objects2.size());
diff --git a/cayenne-client/src/test/java/org/apache/cayenne/access/ClientServerChannelIT.java b/cayenne-client/src/test/java/org/apache/cayenne/access/ClientServerChannelIT.java
index 0487a57..1429de5 100644
--- a/cayenne-client/src/test/java/org/apache/cayenne/access/ClientServerChannelIT.java
+++ b/cayenne-client/src/test/java/org/apache/cayenne/access/ClientServerChannelIT.java
@@ -19,13 +19,6 @@
 
 package org.apache.cayenne.access;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-
 import java.util.List;
 
 import org.apache.cayenne.DataChannel;
@@ -41,8 +34,8 @@ import org.apache.cayenne.graph.NodeCreateOperation;
 import org.apache.cayenne.log.JdbcEventLogger;
 import org.apache.cayenne.map.EntityResolver;
 import org.apache.cayenne.query.MockQuery;
+import org.apache.cayenne.query.ObjectSelect;
 import org.apache.cayenne.query.Query;
-import org.apache.cayenne.query.SelectQuery;
 import org.apache.cayenne.remote.QueryMessage;
 import org.apache.cayenne.test.jdbc.DBHelper;
 import org.apache.cayenne.test.jdbc.TableHelper;
@@ -51,6 +44,7 @@ import org.apache.cayenne.testdo.mt.ClientMtTable1Subclass1;
 import org.apache.cayenne.testdo.mt.ClientMtTable2;
 import org.apache.cayenne.testdo.mt.ClientMtTable3;
 import org.apache.cayenne.testdo.mt.MtTable1;
+import org.apache.cayenne.testdo.mt.MtTable3;
 import org.apache.cayenne.unit.di.DataChannelInterceptor;
 import org.apache.cayenne.unit.di.client.ClientCase;
 import org.apache.cayenne.unit.di.server.CayenneProjects;
@@ -59,6 +53,9 @@ import org.apache.cayenne.util.EqualsBuilder;
 import org.junit.Before;
 import org.junit.Test;
 
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.mock;
+
 @UseServerRuntime(CayenneProjects.MULTI_TIER_PROJECT)
 public class ClientServerChannelIT extends ClientCase {
 
@@ -116,7 +113,7 @@ public class ClientServerChannelIT extends ClientCase {
 	@Test
 	public void testSynchronizeCommit() {
 
-		SelectQuery<MtTable1> query = new SelectQuery<>(MtTable1.class);
+		ObjectSelect<MtTable1> query = ObjectSelect.query(MtTable1.class);
 
 		// no changes...
 		clientServerChannel.onSync(serverContext, mock(GraphDiff.class), DataChannel.FLUSH_CASCADE_SYNC);
@@ -135,7 +132,7 @@ public class ClientServerChannelIT extends ClientCase {
 	public void testPerformQueryObjectIDInjection() throws Exception {
 		tMtTable1.insert(55, "g1", "s1");
 
-		Query query = new SelectQuery("MtTable1");
+		Query query = ObjectSelect.query(MtTable1.class);
 		QueryResponse response = clientServerChannel.onQuery(null, query);
 
 		assertNotNull(response);
@@ -160,7 +157,7 @@ public class ClientServerChannelIT extends ClientCase {
 
 		tMtTable3.insert(1, bytes, "abc", 4);
 
-		Query query = new SelectQuery("MtTable3");
+		Query query = ObjectSelect.query(MtTable3.class);
 		QueryResponse response = clientServerChannel.onQuery(null, query);
 
 		assertNotNull(response);
@@ -184,7 +181,7 @@ public class ClientServerChannelIT extends ClientCase {
 
 		tMtTable1.insert(65, "sub1", "xyz");
 
-		SelectQuery<ClientMtTable1> query = new SelectQuery<>(ClientMtTable1.class);
+		ObjectSelect<ClientMtTable1> query = ObjectSelect.query(ClientMtTable1.class);
 		QueryResponse response = clientServerChannel.onQuery(null, query);
 
 		assertNotNull(response);
@@ -224,9 +221,9 @@ public class ClientServerChannelIT extends ClientCase {
 	public void testOnQueryPrefetchingToMany() throws Exception {
 		createTwoMtTable1sAnd2sDataSet();
 
-		SelectQuery<ClientMtTable1> query = new SelectQuery<>(ClientMtTable1.class);
-		query.addOrdering(ClientMtTable1.GLOBAL_ATTRIBUTE1.asc());
-		query.addPrefetch(ClientMtTable1.TABLE2ARRAY.joint());
+		ObjectSelect<ClientMtTable1> query = ObjectSelect.query(ClientMtTable1.class)
+				.orderBy(ClientMtTable1.GLOBAL_ATTRIBUTE1.asc())
+				.prefetch(ClientMtTable1.TABLE2ARRAY.joint());
 
 		final List<?> results = clientServerChannel.onQuery(null, query).firstList();
 
@@ -247,9 +244,9 @@ public class ClientServerChannelIT extends ClientCase {
 	public void testOnQueryPrefetchingToManyEmpty() throws Exception {
 		createTwoMtTable1sAnd2sDataSet();
 
-		SelectQuery<ClientMtTable1> q = new SelectQuery<>(ClientMtTable1.class);
-		q.addOrdering(ClientMtTable1.GLOBAL_ATTRIBUTE1.asc());
-		q.addPrefetch(ClientMtTable1.TABLE2ARRAY.joint());
+		ObjectSelect<ClientMtTable1> q = ObjectSelect.query(ClientMtTable1.class)
+				.orderBy(ClientMtTable1.GLOBAL_ATTRIBUTE1.asc())
+				.prefetch(ClientMtTable1.TABLE2ARRAY.joint());
 
 		final List<?> results = clientServerChannel.onQuery(null, q).firstList();
 
diff --git a/cayenne-client/src/test/java/org/apache/cayenne/access/ClientServerChannelQueryIT.java b/cayenne-client/src/test/java/org/apache/cayenne/access/ClientServerChannelQueryIT.java
index a91190e..5d26fb4 100644
--- a/cayenne-client/src/test/java/org/apache/cayenne/access/ClientServerChannelQueryIT.java
+++ b/cayenne-client/src/test/java/org/apache/cayenne/access/ClientServerChannelQueryIT.java
@@ -19,18 +19,18 @@
 
 package org.apache.cayenne.access;
 
+import java.util.List;
+
 import org.apache.cayenne.ObjectContext;
 import org.apache.cayenne.ValueHolder;
-import org.apache.cayenne.cache.QueryCache;
 import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.exp.ExpressionFactory;
 import org.apache.cayenne.query.MappedSelect;
-import org.apache.cayenne.query.SelectQuery;
-import org.apache.cayenne.query.SortOrder;
+import org.apache.cayenne.query.ObjectSelect;
 import org.apache.cayenne.test.jdbc.DBHelper;
 import org.apache.cayenne.test.jdbc.TableHelper;
 import org.apache.cayenne.testdo.mt.ClientMtTable1;
 import org.apache.cayenne.testdo.mt.ClientMtTable2;
+import org.apache.cayenne.testdo.mt.MtTable1;
 import org.apache.cayenne.unit.di.client.ClientCase;
 import org.apache.cayenne.unit.di.server.CayenneProjects;
 import org.apache.cayenne.unit.di.server.UseServerRuntime;
@@ -39,9 +39,10 @@ import org.apache.cayenne.util.PersistentObjectList;
 import org.junit.Before;
 import org.junit.Test;
 
-import java.util.List;
-
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 
 @UseServerRuntime(CayenneProjects.MULTI_TIER_PROJECT)
 public class ClientServerChannelQueryIT extends ClientCase {
@@ -88,9 +89,9 @@ public class ClientServerChannelQueryIT extends ClientCase {
     public void testPaginatedQueryServerCacheOverflow() throws Exception {
         createSevenMtTable1sDataSet();
 
-        SelectQuery<ClientMtTable1> query = new SelectQuery<>(ClientMtTable1.class);
-        query.addOrdering(ClientMtTable1.GLOBAL_ATTRIBUTE1.asc());
-        query.setPageSize(3);
+        ObjectSelect<ClientMtTable1> query = ObjectSelect.query(ClientMtTable1.class)
+                .orderBy(ClientMtTable1.GLOBAL_ATTRIBUTE1.asc())
+                .pageSize(3);
 
         List<?> results = context.performQuery(query);
 
@@ -123,7 +124,7 @@ public class ClientServerChannelQueryIT extends ClientCase {
     public void testSelectQueryEntityNameRoot() throws Exception {
         createTwoMtTable1sAnd2sDataSet();
 
-        SelectQuery q = new SelectQuery("MtTable1");
+        ObjectSelect q = ObjectSelect.query(MtTable1.class);
         List<?> results = context.performQuery(q);
 
         assertEquals(2, results.size());
@@ -135,7 +136,7 @@ public class ClientServerChannelQueryIT extends ClientCase {
     public void testSelectQueryClientClassRoot() throws Exception {
         createTwoMtTable1sAnd2sDataSet();
 
-        SelectQuery<ClientMtTable1> q = new SelectQuery<>(ClientMtTable1.class);
+        ObjectSelect<ClientMtTable1> q = ObjectSelect.query(ClientMtTable1.class);
         List<?> results = context.performQuery(q);
 
         assertEquals(2, results.size());
@@ -146,8 +147,8 @@ public class ClientServerChannelQueryIT extends ClientCase {
     public void testSelectQuerySimpleQualifier() throws Exception {
         createTwoMtTable1sAnd2sDataSet();
 
-        SelectQuery<ClientMtTable1> q = new SelectQuery<>(ClientMtTable1.class
-                , ExpressionFactory.exp("globalAttribute1 = 'g1'"));
+        ObjectSelect<ClientMtTable1> q = ObjectSelect.query(ClientMtTable1.class)
+                .where(ClientMtTable1.GLOBAL_ATTRIBUTE1.eq("g1"));
         List<?> results = context.performQuery(q);
 
         assertEquals(1, results.size());
@@ -159,8 +160,8 @@ public class ClientServerChannelQueryIT extends ClientCase {
     public void testSelectQueryToManyRelationshipQualifier() throws Exception {
         createTwoMtTable1sAnd2sDataSet();
 
-        SelectQuery<ClientMtTable1> q = new SelectQuery<>(ClientMtTable1.class
-                , ExpressionFactory.exp("table2Array.globalAttribute = 'g1'"));
+        ObjectSelect<ClientMtTable1> q = ObjectSelect.query(ClientMtTable1.class)
+                .where(ClientMtTable1.TABLE2ARRAY.dot(ClientMtTable2.GLOBAL_ATTRIBUTE).eq("g1"));
         List<?> results = context.performQuery(q);
 
         assertEquals(1, results.size());
@@ -171,8 +172,8 @@ public class ClientServerChannelQueryIT extends ClientCase {
     public void testSelectQueryOrdering() throws Exception {
         createTwoMtTable1sAnd2sDataSet();
 
-        SelectQuery q = new SelectQuery("MtTable1");
-        q.addOrdering(ClientMtTable1.GLOBAL_ATTRIBUTE1.asc());
+        ObjectSelect q = ObjectSelect.query(MtTable1.class)
+                .orderBy(ClientMtTable1.GLOBAL_ATTRIBUTE1.asc());
         List<?> results = context.performQuery(q);
 
         assertEquals(2, results.size());
@@ -183,9 +184,8 @@ public class ClientServerChannelQueryIT extends ClientCase {
 
         // now run the same query with reverse ordering to check that the first ordering
         // result wasn't coincidental.
-
-        q.clearOrderings();
-        q.addOrdering(ClientMtTable1.GLOBAL_ATTRIBUTE1.desc());
+        q.getOrderings().clear();
+        q.orderBy(ClientMtTable1.GLOBAL_ATTRIBUTE1.desc());
         List<?> results1 = context.performQuery(q);
 
         assertEquals(2, results1.size());
@@ -199,9 +199,9 @@ public class ClientServerChannelQueryIT extends ClientCase {
     public void testSelectQueryPrefetchToOne() throws Exception {
         createTwoMtTable1sAnd2sDataSet();
 
-        SelectQuery<ClientMtTable2> q = new SelectQuery<>(ClientMtTable2.class
-                , ExpressionFactory.exp("globalAttribute = 'g1'"));
-        q.addPrefetch(ClientMtTable2.TABLE1.disjoint());
+        ObjectSelect<ClientMtTable2> q = ObjectSelect.query(ClientMtTable2.class)
+                .where(ClientMtTable2.GLOBAL_ATTRIBUTE.eq("g1"))
+                .prefetch(ClientMtTable2.TABLE1.disjoint());
         List<?> results = context.performQuery(q);
 
         assertEquals(1, results.size());
@@ -222,9 +222,9 @@ public class ClientServerChannelQueryIT extends ClientCase {
     public void testSelectQueryPrefetchToMany() throws Exception {
         createTwoMtTable1sAnd2sDataSet();
 
-        SelectQuery<ClientMtTable1> q = new SelectQuery<>(ClientMtTable1.class
-                , ExpressionFactory.exp("globalAttribute1 = 'g1'"));
-        q.addPrefetch(ClientMtTable1.TABLE2ARRAY.joint());
+        ObjectSelect<ClientMtTable1> q = ObjectSelect.query(ClientMtTable1.class)
+                .where(ClientMtTable1.GLOBAL_ATTRIBUTE1.eq("g1"))
+                .prefetch(ClientMtTable1.TABLE2ARRAY.joint());
         List<?> results = context.performQuery(q);
 
         assertEquals(1, results.size());
diff --git a/cayenne-client/src/test/java/org/apache/cayenne/query/ClientExpressionIT.java b/cayenne-client/src/test/java/org/apache/cayenne/query/ClientExpressionIT.java
index 5f7b071..9681b2a 100644
--- a/cayenne-client/src/test/java/org/apache/cayenne/query/ClientExpressionIT.java
+++ b/cayenne-client/src/test/java/org/apache/cayenne/query/ClientExpressionIT.java
@@ -18,6 +18,11 @@
  ****************************************************************/
 package org.apache.cayenne.query;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
 import org.apache.cayenne.CayenneContext;
 import org.apache.cayenne.ObjectId;
 import org.apache.cayenne.di.Inject;
@@ -35,24 +40,19 @@ import org.apache.cayenne.unit.di.server.UseServerRuntime;
 import org.junit.Before;
 import org.junit.Test;
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNotSame;
 
 @UseServerRuntime(CayenneProjects.MULTI_TIER_PROJECT)
 public class ClientExpressionIT extends ClientCase {
-    
+
     @Inject
     private CayenneContext context;
-    
+
     @Inject
     private DBHelper dbHelper;
-    
+
     private TableHelper tMtTable1;
     private TableHelper tMtTable2;
 
@@ -60,11 +60,11 @@ public class ClientExpressionIT extends ClientCase {
     public void setUp() throws Exception {
         tMtTable1 = new TableHelper(dbHelper, "MT_TABLE1");
         tMtTable1.setColumns("TABLE1_ID", "GLOBAL_ATTRIBUTE1", "SERVER_ATTRIBUTE1");
-        
+
         tMtTable2 = new TableHelper(dbHelper, "MT_TABLE2");
         tMtTable2.setColumns("TABLE2_ID", "TABLE1_ID", "GLOBAL_ATTRIBUTE");
     }
-    
+
     private void createDataSet() throws Exception {
         for(int i = 1; i <= 10; i++) {
             tMtTable1.insert(i ,"1_global" + i, "server" + i);
@@ -77,12 +77,12 @@ public class ClientExpressionIT extends ClientCase {
     public void testPersistentValueInExpression() {
         ClientMtTable1 t1 = context.newObject(ClientMtTable1.class);
         ClientMtTable1 t2 = context.newObject(ClientMtTable1.class);
-        
+
         context.commitChanges();
-        
+
         Expression scalar = ExpressionFactory.matchExp((String)null, t1);
         Expression list = ExpressionFactory.matchAllExp("|", Arrays.asList(t1, t2));
-        
+
         assertEquals(t1.getObjectId(), scalar.getOperand(1));
         assertEquals(t1.getObjectId(), ((ASTEqual)list.getOperand(0)).getOperand(1));
         assertEquals(t2.getObjectId(), ((ASTEqual)list.getOperand(1)).getOperand(1));
@@ -92,20 +92,20 @@ public class ClientExpressionIT extends ClientCase {
     public void testListInASTList() {
         ClientMtTable1 t1 = context.newObject(ClientMtTable1.class);
         ClientMtTable1 t2 = context.newObject(ClientMtTable1.class);
-        
+
         context.commitChanges();
-        
+
         List<ClientMtTable1> table1List = new ArrayList<>();
         table1List.add(t1);
         table1List.add(t2);
-        
+
         // send list in expression factory
         Expression list = ClientMtTable2.TABLE1.in(table1List);
-        
+
         Object[] values = (Object[])((ASTList)list.getOperand(1)).getOperand(0);
         assertEquals(t1.getObjectId(), values[0]);
         assertEquals(t2.getObjectId(), values[1]);
-        
+
         ObjectId t1Id = ObjectId.of("MtTable1", "TABLE1_ID", 1);
         ObjectId t2Id = ObjectId.of("MtTable1", "TABLE1_ID", 2);
         t1.setObjectId(t1Id);
@@ -121,28 +121,28 @@ public class ClientExpressionIT extends ClientCase {
         ClientMtTable1 t1 = context.newObject(ClientMtTable1.class);
         ClientMtTable1 t2 = context.newObject(ClientMtTable1.class);
         ClientMtTable1 t3 = context.newObject(ClientMtTable1.class);
-        
+
         context.commitChanges();
 
         Object[] tArray = new Object[3];
         tArray[0] = t1;
         tArray[1] = t2;
-        
+
         // send array in expression factory
         Expression list = ExpressionFactory.inExp(ClientMtTable2.TABLE1.getName(), tArray);
         tArray[2] = t3;
-        
+
         Object[] values = (Object[])((ASTList)list.getOperand(1)).getOperand(0);
         assertEquals(tArray.length, values.length);
         assertNotSame(tArray[2], values[2]);
         assertEquals(t1.getObjectId(), values[0]);
         assertEquals(t2.getObjectId(), values[1]);
-        
+
         ObjectId t1Id = ObjectId.of("MtTable1", "TABLE1_ID", 1);
         ObjectId t2Id = ObjectId.of("MtTable1", "TABLE1_ID", 2);
         t1.setObjectId(t1Id);
         t2.setObjectId(t2Id);
-        
+
         // Expression and client have different arrays
         assertNotSame(t1.getObjectId(), values[0]);
         assertNotSame(t2.getObjectId(), values[1]);
@@ -152,8 +152,8 @@ public class ClientExpressionIT extends ClientCase {
     public void testExpressionFactoryMatch() throws Exception {
         createDataSet();
 
-        SelectQuery<ClientMtTable1> table1Query = new SelectQuery<>(ClientMtTable1.class);
-        table1Query.addOrdering(new Ordering("db:TABLE1_ID", SortOrder.ASCENDING));
+        ObjectSelect<ClientMtTable1> table1Query = ObjectSelect.query(ClientMtTable1.class)
+                .orderBy(new Ordering("db:TABLE1_ID", SortOrder.ASCENDING));
         List<ClientMtTable1> table1List = table1Query.select(context);
 
         assertNotNull(table1List);
@@ -162,14 +162,16 @@ public class ClientExpressionIT extends ClientCase {
         ClientMtTable1 element_2 = table1List.get(1);
 
         Expression exp = ClientMtTable2.TABLE1.eq(element_1);
-        SelectQuery<ClientMtTable2> table2Query = new SelectQuery<>(ClientMtTable2.class, exp);
+        ObjectSelect<ClientMtTable2> table2Query = ObjectSelect.query(ClientMtTable2.class)
+                .where(exp);
         List<ClientMtTable2> table2List = table2Query.select(context);
 
         assertNotNull(table2List);
         assertEquals(2, table2List.size());
 
         exp = ExpressionFactory.matchExp(element_2);
-        table2Query = new SelectQuery<>(ClientMtTable2.class, exp);
+        table2Query = ObjectSelect.query(ClientMtTable2.class)
+                .where(exp);
         table2List = context.select(table2Query);
 
         assertNotNull(table2List);
@@ -179,154 +181,166 @@ public class ClientExpressionIT extends ClientCase {
     @Test
     public void testExpressionFactoryMatchAll() throws Exception {
         createDataSet();
-        
-        SelectQuery<ClientMtTable2> table2Query = new SelectQuery<>(ClientMtTable2.class);
-        table2Query.addOrdering(new Ordering("db:TABLE2_ID", SortOrder.ASCENDING));
+
+        ObjectSelect<ClientMtTable2> table2Query = ObjectSelect.query(ClientMtTable2.class)
+                .orderBy(new Ordering("db:TABLE2_ID", SortOrder.ASCENDING));
         List<ClientMtTable2> table2List = context.select(table2Query);
-        
+
         ClientMtTable2 element_1 = table2List.get(0);
         ClientMtTable2 element_2 = table2List.get(10);
-        
+
         assertEquals(element_1.getTable1(), element_2.getTable1());
-        
-        Expression exp = ExpressionFactory.matchAllExp("|"+ClientMtTable1.TABLE2ARRAY.getName(), Arrays.asList(element_1, element_2));
-        SelectQuery<ClientMtTable1> table1Query = new SelectQuery<>(ClientMtTable1.class, exp);
+
+        Expression exp = ExpressionFactory.matchAllExp("|" + ClientMtTable1.TABLE2ARRAY.getName(), Arrays.asList(element_1, element_2));
+        ObjectSelect<ClientMtTable1> table1Query = ObjectSelect.query(ClientMtTable1.class)
+                .where(exp);
         List<ClientMtTable1> table1List = table1Query.select(context);
-        
+
         assertEquals(1, table1List.size());
     }
 
     @Test
     public void testExpressionFactoryMatchAny() throws Exception {
         createDataSet();
-        
-        SelectQuery<ClientMtTable2> table2Query = new SelectQuery<>(ClientMtTable2.class);
-        table2Query.addOrdering(new Ordering("db:TABLE2_ID", SortOrder.ASCENDING));
+
+        ObjectSelect<ClientMtTable2> table2Query = ObjectSelect.query(ClientMtTable2.class)
+                .orderBy(new Ordering("db:TABLE2_ID", SortOrder.ASCENDING));
         List<ClientMtTable2> table2List = context.select(table2Query);
-        
+
         ClientMtTable2 element_1 = table2List.get(0);
         ClientMtTable2 element_2 = table2List.get(10);
-        
+
         Expression exp = ExpressionFactory.matchAnyExp(element_1, element_2);
-        table2Query = new SelectQuery<>(ClientMtTable2.class, exp);
+        table2Query = ObjectSelect.query(ClientMtTable2.class)
+                .where(exp);
         table2List = context.select(table2Query);
-        
+
         assertEquals(2, table2List.size());
     }
 
     @Test
     public void testExpressionFactoryIn() throws Exception {
         createDataSet();
-        
-        SelectQuery<ClientMtTable1> table1Query = new SelectQuery<>(ClientMtTable1.class);
-        table1Query.addOrdering(new Ordering("db:TABLE1_ID", SortOrder.ASCENDING));
+
+        ObjectSelect<ClientMtTable1> table1Query = ObjectSelect.query(ClientMtTable1.class)
+                .orderBy(new Ordering("db:TABLE1_ID", SortOrder.ASCENDING));
         List<ClientMtTable1> table1List = context.select(table1Query);
-        
+
         ClientMtTable1 element_3 = table1List.get(2);
         ClientMtTable1 element_8 = table1List.get(7);
-        
+
         // IN expression via Collection
         Expression exp = ExpressionFactory.inExp(ClientMtTable2.TABLE1.getName(), table1List.subList(3, 6));
-        SelectQuery<ClientMtTable2> table2Query = new SelectQuery<>(ClientMtTable2.class, exp);
+        ObjectSelect<ClientMtTable2> table2Query = ObjectSelect.query(ClientMtTable2.class)
+                .where(exp);
         List<ClientMtTable2> table2List = context.select(table2Query);
-        
+
         assertEquals(6, table2List.size());
-        
+
         // IN expression via Array
         exp = ExpressionFactory.inExp(ClientMtTable2.TABLE1.getName(), element_3, element_8);
-        table2Query = new SelectQuery<>(ClientMtTable2.class, exp);
+        table2Query = ObjectSelect.query(ClientMtTable2.class)
+                .where(exp);
         table2List = context.select(table2Query);
-        
+
         assertEquals(4, table2List.size());
     }
 
     @Test
     public void testExpressionFactoryBetween() throws Exception {
         createDataSet();
-        
-        SelectQuery<ClientMtTable1> table1Query = new SelectQuery<>(ClientMtTable1.class);
-        table1Query.addOrdering(new Ordering("db:TABLE1_ID", SortOrder.ASCENDING));
+
+        ObjectSelect<ClientMtTable1> table1Query = ObjectSelect.query(ClientMtTable1.class)
+                .orderBy(new Ordering("db:TABLE1_ID", SortOrder.ASCENDING));
         List<ClientMtTable1> table1List = context.select(table1Query);
-        
+
         ClientMtTable1 element_1 = table1List.get(0);
         ClientMtTable1 element_7 = table1List.get(6);
-        
+
         // between
         Expression exp = ExpressionFactory.betweenExp(ClientMtTable2.TABLE1.getName(), element_1, element_7);
-        SelectQuery<ClientMtTable2> table2Query = new SelectQuery<>(ClientMtTable2.class, exp);
+        ObjectSelect<ClientMtTable2> table2Query = ObjectSelect.query(ClientMtTable2.class)
+                .where(exp);
         List<ClientMtTable2> table2List = context.select(table2Query);
-        
+
         assertEquals(14, table2List.size());
-        
+
         // not between
         exp = ExpressionFactory.notBetweenExp(ClientMtTable2.TABLE1.getName(), element_1, element_7);
-        table2Query = new SelectQuery<>(ClientMtTable2.class, exp);
+        table2Query = ObjectSelect.query(ClientMtTable2.class)
+                .where(exp);
         table2List = context.select(table2Query);
-        
+
         assertEquals(6, table2List.size());
     }
 
     @Test
     public void testExpressionFactoryOperators() throws Exception {
         createDataSet();
-        
-        SelectQuery<ClientMtTable1> table1Query = new SelectQuery<>(ClientMtTable1.class);
-        table1Query.addOrdering(new Ordering("db:TABLE1_ID", SortOrder.ASCENDING));
+
+        ObjectSelect<ClientMtTable1> table1Query = ObjectSelect.query(ClientMtTable1.class)
+                .orderBy(new Ordering("db:TABLE1_ID", SortOrder.ASCENDING));
         List<ClientMtTable1> table1List = context.select(table1Query);
-        
+
         ClientMtTable1 element_7 = table1List.get(6);
-        
+
         // greater than, ">"
         Expression exp = ExpressionFactory.greaterExp(ClientMtTable2.TABLE1.getName(), element_7);
-        SelectQuery<ClientMtTable2> table2Query = new SelectQuery<>(ClientMtTable2.class, exp);
+        ObjectSelect<ClientMtTable2> table2Query = ObjectSelect.query(ClientMtTable2.class)
+                .where(exp);
         List<ClientMtTable2> table2List = context.select(table2Query);
-        
+
         assertEquals(6, table2List.size());
-        
+
         // greater than or equal, ">="
         exp = ExpressionFactory.greaterOrEqualExp(ClientMtTable2.TABLE1.getName(), element_7);
-        table2Query = new SelectQuery<>(ClientMtTable2.class, exp);
+        table2Query = ObjectSelect.query(ClientMtTable2.class)
+                .where(exp);
         table2List = context.select(table2Query);
-        
+
         assertEquals(8, table2List.size());
-        
+
         // less than, "<"
         exp = ExpressionFactory.lessExp(ClientMtTable2.TABLE1.getName(), element_7);
-        table2Query = new SelectQuery<>(ClientMtTable2.class, exp);
+        table2Query = ObjectSelect.query(ClientMtTable2.class)
+                .where(exp);
         table2List = context.select(table2Query);
-        
+
         assertEquals(12, table2List.size());
-        
+
         // less than or equal, "<="
         exp = ExpressionFactory.lessOrEqualExp(ClientMtTable2.TABLE1.getName(), element_7);
-        table2Query = new SelectQuery<>(ClientMtTable2.class, exp);
+        table2Query = ObjectSelect.query(ClientMtTable2.class)
+                .where(exp);
         table2List = context.select(table2Query);
-        
+
         assertEquals(14, table2List.size());
     }
 
     @Test
     public void testParams() throws Exception {
         createDataSet();
-        
-        SelectQuery<ClientMtTable1> table1Query = new SelectQuery<>(ClientMtTable1.class);
-        table1Query.addOrdering(new Ordering("db:TABLE1_ID", SortOrder.ASCENDING));
+
+        ObjectSelect<ClientMtTable1> table1Query = ObjectSelect.query(ClientMtTable1.class)
+                .orderBy(new Ordering("db:TABLE1_ID", SortOrder.ASCENDING));
         List<ClientMtTable1> table1List = context.select(table1Query);
-        
+
         ClientMtTable1 element_1 = table1List.get(0);
         ClientMtTable1 element_5 = table1List.get(4);
-        
+
         Expression exp = ExpressionFactory.exp("table1 = $attr");
         exp = exp.params(Collections.singletonMap("attr", element_1));
-        SelectQuery<ClientMtTable2> table2Query = new SelectQuery<>(ClientMtTable2.class, exp);
+        ObjectSelect<ClientMtTable2> table2Query = ObjectSelect.query(ClientMtTable2.class)
+                .where(exp);
         List<ClientMtTable2> table2List = context.select(table2Query);
-        
+
         assertEquals(2, table2List.size());
-        
+
         exp = exp.andExp(ExpressionFactory.exp("table1 = $attr")).params(Collections.singletonMap("attr", element_5));
-        table2Query = new SelectQuery<>(ClientMtTable2.class, exp);
+        table2Query = ObjectSelect.query(ClientMtTable2.class)
+                .where(exp);
         table2List = context.select(table2Query);
-        
+
         assertEquals(0, table2List.size());
     }
 }
diff --git a/cayenne-client/src/test/java/org/apache/cayenne/query/SelectQueryAbstractEntityIT.java b/cayenne-client/src/test/java/org/apache/cayenne/query/SelectQueryAbstractEntityIT.java
index c0b0f21..a347a2a 100644
--- a/cayenne-client/src/test/java/org/apache/cayenne/query/SelectQueryAbstractEntityIT.java
+++ b/cayenne-client/src/test/java/org/apache/cayenne/query/SelectQueryAbstractEntityIT.java
@@ -18,6 +18,8 @@
  ****************************************************************/
 package org.apache.cayenne.query;
 
+import java.util.List;
+
 import org.apache.cayenne.ObjectContext;
 import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.test.jdbc.DBHelper;
@@ -31,19 +33,17 @@ import org.apache.cayenne.unit.di.server.UseServerRuntime;
 import org.junit.Before;
 import org.junit.Test;
 
-import java.util.List;
-
 import static org.junit.Assert.assertNotNull;
 
 @UseServerRuntime(CayenneProjects.MULTI_TIER_PROJECT)
 public class SelectQueryAbstractEntityIT extends ServerCase {
-    
+
     @Inject
     private ObjectContext context;
 
     @Inject
     private DBHelper dbHelper;
-    
+
     private TableHelper mtTable;
 
     @Before
@@ -51,31 +51,29 @@ public class SelectQueryAbstractEntityIT extends ServerCase {
         mtTable = new TableHelper(dbHelper, "MT_TABLE1");
         mtTable.setColumns("TABLE1_ID", "GLOBAL_ATTRIBUTE1", "SERVER_ATTRIBUTE1", "SUBCLASS_ATTRIBUTE1");
     }
-    
-    protected void createDataSet() throws Exception{     
+
+    protected void createDataSet() throws Exception{
 
         for (int i = 1; i <= 10; i++){
             mtTable.insert(i, "sub2", "sub2_" + i, "sub2attr");
         }
-        
+
         for (int i = 11; i <= 20; i++){
             mtTable.insert(i, "sub1", "sub1_" + i, "sub1attr");
         }
-       
+
     }
 
     @Test
     public void testSublclassEntitySelect() throws Exception{
         createDataSet();
-        
-        SelectQuery<MtTable1Subclass1> query = 
-                new SelectQuery<MtTable1Subclass1>(MtTable1Subclass1.class);
+
+        ObjectSelect<MtTable1Subclass1> query = ObjectSelect.query(MtTable1Subclass1.class);
         final List<MtTable1Subclass1> sub1List = context.select(query);
-        
-        SelectQuery<MtTable1Subclass2> query2 = 
-                new SelectQuery<MtTable1Subclass2>(MtTable1Subclass2.class);
+
+        ObjectSelect<MtTable1Subclass2> query2 = ObjectSelect.query(MtTable1Subclass2.class);
         final List<MtTable1Subclass2> sub2List = context.select(query2);
-        
+
         assertNotNull(sub1List);
         assertNotNull(sub2List);
     }
@@ -84,7 +82,7 @@ public class SelectQueryAbstractEntityIT extends ServerCase {
     public void test1AbstractEntitySelect() throws Exception{
         createDataSet();
 
-        SelectQuery<MtTable1> query = new SelectQuery<MtTable1>(MtTable1.class);
+        ObjectSelect<MtTable1> query = ObjectSelect.query(MtTable1.class);
         final List<MtTable1> list = context.select(query);
 
         assertNotNull(list);
@@ -99,17 +97,17 @@ public class SelectQueryAbstractEntityIT extends ServerCase {
     @Test
     public void test2AbstractEntitySelect() throws Exception{
         createDataSet();
-        
-        SelectQuery<MtTable1> query = new SelectQuery<MtTable1>(MtTable1.class);
+
+        ObjectSelect<MtTable1> query = ObjectSelect.query(MtTable1.class);
         final List<MtTable1> list = context.select(query);
-        
+
         assertNotNull(list);
-        
+
         for (MtTable1 sub : list){
             if(sub instanceof MtTable1Subclass2){
                 assertNotNull(((MtTable1Subclass2) sub).getSubclass2Attribute1());
             }
         }
     }
-    
+
 }
diff --git a/cayenne-client/src/test/java/org/apache/cayenne/remote/ClientChannelTest.java b/cayenne-client/src/test/java/org/apache/cayenne/remote/ClientChannelTest.java
index 32b8313..d1b0de3 100644
--- a/cayenne-client/src/test/java/org/apache/cayenne/remote/ClientChannelTest.java
+++ b/cayenne-client/src/test/java/org/apache/cayenne/remote/ClientChannelTest.java
@@ -19,6 +19,12 @@
 
 package org.apache.cayenne.remote;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
 import org.apache.cayenne.CayenneContext;
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.MockPersistentObject;
@@ -33,24 +39,12 @@ import org.apache.cayenne.event.MockEventManager;
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.EntityResolver;
 import org.apache.cayenne.map.ObjEntity;
-import org.apache.cayenne.query.SelectQuery;
+import org.apache.cayenne.query.ObjectSelect;
 import org.apache.cayenne.util.GenericResponse;
 import org.junit.After;
 import org.junit.Test;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.*;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
@@ -78,18 +72,15 @@ public class ClientChannelTest {
         o1.setObjectId(oid1);
 
         ClientConnection connection = mock(ClientConnection.class);
-        when(connection.sendMessage((ClientMessage) any())).thenAnswer(
-                new Answer<Object>() {
-
-                    public Object answer(InvocationOnMock invocation) {
-                        ClientMessage arg = (ClientMessage) invocation.getArguments()[0];
-
-                        if (arg instanceof BootstrapMessage) {
-                            return new EntityResolver();
-                        }
-                        else {
-                            return new GenericResponse(Arrays.asList(o1));
-                        }
+        when(connection.sendMessage(any())).thenAnswer(
+                invocation -> {
+                    ClientMessage arg = (ClientMessage) invocation.getArguments()[0];
+
+                    if (arg instanceof BootstrapMessage) {
+                        return new EntityResolver();
+                    }
+                    else {
+                        return new GenericResponse(Arrays.asList(o1));
                     }
                 });
 
@@ -108,7 +99,7 @@ public class ClientChannelTest {
         Collection<DataMap> entities = Collections.singleton(dataMap);
         context.setEntityResolver(new EntityResolver(entities));
 
-        QueryResponse response = channel.onQuery(context, new SelectQuery("test_entity"));
+        QueryResponse response = channel.onQuery(context, ObjectSelect.query(MockPersistentObject.class));
         assertNotNull(response);
         List<?> list = response.firstList();
         assertNotNull(list);
@@ -155,7 +146,7 @@ public class ClientChannelTest {
                 false);
 
         context.setChannel(channel);
-        QueryResponse response = channel.onQuery(context, new SelectQuery("test_entity"));
+        QueryResponse response = channel.onQuery(context, ObjectSelect.query(MockPersistentObject.class));
         assertNotNull(response);
 
         List<?> list = response.firstList();
@@ -196,7 +187,7 @@ public class ClientChannelTest {
                 false);
 
         context.setChannel(channel);
-        QueryResponse response = channel.onQuery(context, new SelectQuery("test_entity"));
+        QueryResponse response = channel.onQuery(context, ObjectSelect.query(MockPersistentObject.class));
         assertNotNull(response);
         assertEquals(1, response.size());
         List<?> list = response.firstList();
@@ -212,7 +203,7 @@ public class ClientChannelTest {
 
             @Override
             public EventBridge getServerEventBridge() throws CayenneRuntimeException {
-                return new EventBridge(Collections.EMPTY_LIST, "ext") {
+                return new EventBridge(Collections.emptyList(), "ext") {
 
                     @Override
                     protected void sendExternalEvent(CayenneEvent localEvent)
diff --git a/cayenne-client/src/test/java/org/apache/cayenne/remote/NestedObjectContextLocalIT.java b/cayenne-client/src/test/java/org/apache/cayenne/remote/NestedObjectContextLocalIT.java
index 82de93d..08164c0 100644
--- a/cayenne-client/src/test/java/org/apache/cayenne/remote/NestedObjectContextLocalIT.java
+++ b/cayenne-client/src/test/java/org/apache/cayenne/remote/NestedObjectContextLocalIT.java
@@ -18,11 +18,15 @@
  ****************************************************************/
 package org.apache.cayenne.remote;
 
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
 import org.apache.cayenne.BaseContext;
 import org.apache.cayenne.configuration.rop.client.ClientRuntime;
 import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.query.ObjectSelect;
 import org.apache.cayenne.query.QueryCacheStrategy;
-import org.apache.cayenne.query.SelectQuery;
 import org.apache.cayenne.remote.service.LocalConnection;
 import org.apache.cayenne.testdo.mt.ClientMtTable1;
 import org.apache.cayenne.unit.di.server.CayenneProjects;
@@ -32,10 +36,6 @@ import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
 import org.junit.runners.Parameterized.Parameters;
 
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertSame;
 
@@ -62,8 +62,9 @@ public class NestedObjectContextLocalIT extends RemoteCayenneCase {
     @Test
     public void testLocalCacheStaysLocal() {
 
-        SelectQuery<ClientMtTable1> query = new SelectQuery<ClientMtTable1>(ClientMtTable1.class);
-        query.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
+        ObjectSelect<ClientMtTable1> query = ObjectSelect
+                .query(ClientMtTable1.class)
+                .cacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
 
         BaseContext child1 = (BaseContext) runtime.newContext(clientContext);
 
diff --git a/cayenne-client/src/test/java/org/apache/cayenne/remote/ROPPrefetchToManyMapIT.java b/cayenne-client/src/test/java/org/apache/cayenne/remote/ROPPrefetchToManyMapIT.java
index a0cda62..6a869ae 100644
--- a/cayenne-client/src/test/java/org/apache/cayenne/remote/ROPPrefetchToManyMapIT.java
+++ b/cayenne-client/src/test/java/org/apache/cayenne/remote/ROPPrefetchToManyMapIT.java
@@ -18,16 +18,19 @@
  ****************************************************************/
 package org.apache.cayenne.remote;
 
+import java.util.Arrays;
+import java.util.Collection;
+
 import org.apache.cayenne.Cayenne;
 import org.apache.cayenne.ObjectContext;
 import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.query.ObjectSelect;
+import org.apache.cayenne.query.PrefetchTreeNode;
 import org.apache.cayenne.query.RefreshQuery;
-import org.apache.cayenne.query.SelectQuery;
 import org.apache.cayenne.remote.service.LocalConnection;
 import org.apache.cayenne.testdo.map_to_many.ClientIdMapToMany;
 import org.apache.cayenne.testdo.map_to_many.ClientIdMapToManyTarget;
 import org.apache.cayenne.unit.di.DataChannelInterceptor;
-import org.apache.cayenne.unit.di.UnitTestClosure;
 import org.apache.cayenne.unit.di.server.CayenneProjects;
 import org.apache.cayenne.unit.di.server.UseServerRuntime;
 import org.junit.Test;
@@ -35,15 +38,12 @@ import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
 import org.junit.runners.Parameterized.Parameters;
 
-import java.util.Arrays;
-import java.util.Collection;
-
 import static org.junit.Assert.assertEquals;
 
 @UseServerRuntime(CayenneProjects.MAP_TO_MANY_PROJECT)
 @RunWith(value=Parameterized.class)
 public class ROPPrefetchToManyMapIT extends RemoteCayenneCase {
-    
+
     @Inject
     private DataChannelInterceptor queryInterceptor;
 
@@ -61,26 +61,21 @@ public class ROPPrefetchToManyMapIT extends RemoteCayenneCase {
     }
 
     @Test
-    public void test() throws Exception {
+    public void test() {
         ObjectContext context = createROPContext();
-        
+
         ClientIdMapToMany map = context.newObject(ClientIdMapToMany.class);
         ClientIdMapToManyTarget target = context.newObject(ClientIdMapToManyTarget.class);
         target.setMapToMany(map);
         context.commitChanges();
-        
+
         context.performQuery(new RefreshQuery());
-        
-        SelectQuery<ClientIdMapToMany> query = new SelectQuery<ClientIdMapToMany>(ClientIdMapToMany.class);
-        query.addPrefetch("targets");
-        
+
+        ObjectSelect<ClientIdMapToMany> query = ObjectSelect.query(ClientIdMapToMany.class)
+                .prefetch("targets", PrefetchTreeNode.UNDEFINED_SEMANTICS);
+
         final ClientIdMapToMany mapToMany = (ClientIdMapToMany) Cayenne.objectForQuery(context, query);
-        
-        queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
-            
-            public void execute() {
-                assertEquals(mapToMany.getTargets().size(), 1);
-            }
-        });
+
+        queryInterceptor.runWithQueriesBlocked(() -> assertEquals(mapToMany.getTargets().size(), 1));
     }
 }
diff --git a/cayenne-client/src/test/java/org/apache/cayenne/remote/RemoteIncrementalFaultListIT.java b/cayenne-client/src/test/java/org/apache/cayenne/remote/RemoteIncrementalFaultListIT.java
index de8a272..7ac88b5 100644
--- a/cayenne-client/src/test/java/org/apache/cayenne/remote/RemoteIncrementalFaultListIT.java
+++ b/cayenne-client/src/test/java/org/apache/cayenne/remote/RemoteIncrementalFaultListIT.java
@@ -19,11 +19,14 @@
 
 package org.apache.cayenne.remote;
 
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+
 import org.apache.cayenne.CayenneContext;
 import org.apache.cayenne.Persistent;
 import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.exp.Expression;
-import org.apache.cayenne.query.SelectQuery;
+import org.apache.cayenne.query.ObjectSelect;
 import org.apache.cayenne.query.SortOrder;
 import org.apache.cayenne.test.jdbc.DBHelper;
 import org.apache.cayenne.test.jdbc.TableHelper;
@@ -35,15 +38,7 @@ import org.apache.cayenne.unit.di.server.UseServerRuntime;
 import org.junit.Before;
 import org.junit.Test;
 
-import java.util.Iterator;
-import java.util.List;
-import java.util.ListIterator;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.*;
 
 @UseServerRuntime(CayenneProjects.MULTI_TIER_PROJECT)
 public class RemoteIncrementalFaultListIT extends ClientCase {
@@ -99,12 +94,12 @@ public class RemoteIncrementalFaultListIT extends ClientCase {
 
 		createObjectsDataSet();
 
-		SelectQuery<ClientMtTable1> query = new SelectQuery<>(ClientMtTable1.class);
-
-		// make sure total number of objects is not divisable
-		// by the page size, to test the last smaller page
-		query.setPageSize(pageSize);
-		query.addOrdering("db:" + MtTable1.TABLE1_ID_PK_COLUMN, SortOrder.ASCENDING);
+		ObjectSelect<ClientMtTable1> query = ObjectSelect
+				.query(ClientMtTable1.class)
+				// make sure total number of objects is not divisable
+				// by the page size, to test the last smaller page
+				.pageSize(pageSize)
+				.orderBy("db:" + MtTable1.TABLE1_ID_PK_COLUMN, SortOrder.ASCENDING);
 
 		list = new RemoteIncrementalFaultList(clientContext, query);
 	}
@@ -224,8 +219,9 @@ public class RemoteIncrementalFaultListIT extends ClientCase {
 	public void testIndexOf() throws Exception {
 		prepareList(6);
 
-		Expression qual = ClientMtTable1.GLOBAL_ATTRIBUTE1.eq("g20");
-		SelectQuery<ClientMtTable1> query = new SelectQuery<>(ClientMtTable1.class, qual);
+		ObjectSelect<ClientMtTable1> query = ObjectSelect
+				.query(ClientMtTable1.class)
+				.where(ClientMtTable1.GLOBAL_ATTRIBUTE1.eq("g20"));
 		List<?> artists = list.context.performQuery(query);
 
 		assertEquals(1, artists.size());
@@ -238,8 +234,8 @@ public class RemoteIncrementalFaultListIT extends ClientCase {
 	@Test
 	public void testLastIndexOf() throws Exception {
 		prepareList(6);
-		Expression qual = ClientMtTable1.GLOBAL_ATTRIBUTE1.eq("g20");
-		SelectQuery<ClientMtTable1> query = new SelectQuery<>(ClientMtTable1.class, qual);
+		ObjectSelect<ClientMtTable1> query = ObjectSelect.query(ClientMtTable1.class)
+				.where(ClientMtTable1.GLOBAL_ATTRIBUTE1.eq("g20"));
 		List<?> objects = list.context.performQuery(query);
 
 		assertEquals(1, objects.size());
diff --git a/cayenne-dbsync/src/test/java/org/apache/cayenne/dbsync/merge/token/ValueForNullIT.java b/cayenne-dbsync/src/test/java/org/apache/cayenne/dbsync/merge/token/ValueForNullIT.java
index c0f2303..701e6fc 100644
--- a/cayenne-dbsync/src/test/java/org/apache/cayenne/dbsync/merge/token/ValueForNullIT.java
+++ b/cayenne-dbsync/src/test/java/org/apache/cayenne/dbsync/merge/token/ValueForNullIT.java
@@ -19,6 +19,9 @@
 
 package org.apache.cayenne.dbsync.merge.token;
 
+import java.sql.Types;
+import java.util.List;
+
 import junit.framework.AssertionFailedError;
 import org.apache.cayenne.DataObject;
 import org.apache.cayenne.Persistent;
@@ -33,12 +36,10 @@ import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.ObjAttribute;
 import org.apache.cayenne.map.ObjEntity;
-import org.apache.cayenne.query.SelectQuery;
+import org.apache.cayenne.query.ObjectSelect;
+import org.apache.cayenne.testdo.testmap.Painting;
 import org.junit.Test;
 
-import java.sql.Types;
-import java.util.List;
-
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
@@ -94,7 +95,8 @@ public class ValueForNullIT extends MergeCase {
 
         // check values for null
         Expression qual = ExpressionFactory.matchExp(objAttr.getName(), DEFAULT_VALUE_STRING);
-        SelectQuery query = new SelectQuery("Painting", qual);
+        ObjectSelect query = ObjectSelect.query(Painting.class)
+                .where(qual);
         @SuppressWarnings("unchecked")
         List<Persistent> rows = context.performQuery(query);
         assertEquals(nrows, rows.size());
diff --git a/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/relationship/ObjectIdRelationshipHandlerTest.java b/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/relationship/ObjectIdRelationshipHandlerTest.java
index 4d55064..12cc2fe 100644
--- a/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/relationship/ObjectIdRelationshipHandlerTest.java
+++ b/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/relationship/ObjectIdRelationshipHandlerTest.java
@@ -24,7 +24,7 @@ import org.apache.cayenne.configuration.server.ServerRuntime;
 import org.apache.cayenne.lifecycle.db.E1;
 import org.apache.cayenne.lifecycle.db.UuidRoot1;
 import org.apache.cayenne.lifecycle.id.IdCoder;
-import org.apache.cayenne.query.SelectQuery;
+import org.apache.cayenne.query.ObjectSelect;
 import org.apache.cayenne.test.jdbc.DBHelper;
 import org.apache.cayenne.test.jdbc.TableHelper;
 import org.junit.After;
@@ -71,7 +71,7 @@ public class ObjectIdRelationshipHandlerTest {
         e1Table.insert(1);
 
         ObjectContext context = runtime.newContext();
-        E1 e1 = (E1) Cayenne.objectForQuery(context, new SelectQuery<>(E1.class));
+        E1 e1 = (E1) Cayenne.objectForQuery(context, ObjectSelect.query(E1.class));
 
         UuidRoot1 r1 = context.newObject(UuidRoot1.class);
 


Mime
View raw message