cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntimof...@apache.org
Subject [cayenne] branch master updated: CAY-2378 Switch usage of SelectQuery to ObjectSelect internally
Date Fri, 09 Aug 2019 15:05:24 GMT
This is an automated email from the ASF dual-hosted git repository.

ntimofeev 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 99f4195  CAY-2378 Switch usage of SelectQuery to ObjectSelect internally
99f4195 is described below

commit 99f419557b9b127bab2e9494f97bff017463a2d9
Author: Nikita Timofeev <stariy95@gmail.com>
AuthorDate: Fri Aug 9 18:05:13 2019 +0300

    CAY-2378 Switch usage of SelectQuery to ObjectSelect internally
---
 .../cayenne/CayenneContextInheritanceIT.java       |  15 +--
 .../cayenne/CayenneContextMeaningfulPKIT.java      |   9 +-
 .../CayenneContextPaginatedListCachingIT.java      |  15 +--
 .../apache/cayenne/CayenneContextPrimitiveIT.java  |   8 +-
 .../cayenne/CayenneContextWithDataContextIT.java   |  12 +-
 .../org/apache/cayenne/NestedCayenneContextIT.java |  31 ++---
 .../query/ClientSelectQueryExpressionIT.java       |   4 +-
 .../cayenne/crypto/Runtime_AES128_GZIP_IT.java     |   5 +-
 .../apache/cayenne/crypto/Runtime_AES128_IT.java   |   7 +-
 .../test/java/org/apache/cayenne/CayenneIT.java    |  19 ++-
 .../cayenne/access/DataContextCompoundRelIT.java   |  18 ++-
 .../access/DataContextDisjointByIdPrefetchIT.java  |  32 +++---
 .../DataContextDisjointByIdPrefetch_ExtrasIT.java  |  49 ++++----
 .../access/DataContextFlattenedAttributesIT.java   |  18 ++-
 .../org/apache/cayenne/access/DataContextIT.java   | 127 ++++++++-------------
 .../cayenne/access/DataContextIteratedQueryIT.java |  50 +++-----
 .../cayenne/access/DataContextJoinAliasesIT.java   |   9 +-
 .../apache/cayenne/access/DataContextNoPkIT.java   |  22 +---
 .../cayenne/access/DataContextOuterJoinsIT.java    |  60 +++++-----
 .../access/DataContextPrefetchMultistepIT.java     |  88 ++++++--------
 .../cayenne/access/DataContextQueryCachingIT.java  |  19 ++-
 .../DataContextSelectQuerySplitAliasesIT.java      |   4 +
 .../org/apache/cayenne/access/EmbeddingIT.java     |  40 +++----
 .../org/apache/cayenne/access/JointPrefetchIT.java |  82 ++++++-------
 .../cayenne/access/NestedDataContextReadIT.java    |  37 +++---
 .../apache/cayenne/access/QuotedIdentifiersIT.java |  29 ++---
 .../SimpleIdIncrementalFaultListDataRowsIT.java    |  48 +++-----
 .../cayenne/map/SelectQueryDescriptorTest.java     |  12 +-
 .../org/apache/cayenne/query/SelectQueryTest.java  |   1 +
 29 files changed, 343 insertions(+), 527 deletions(-)

diff --git a/cayenne-client/src/test/java/org/apache/cayenne/CayenneContextInheritanceIT.java b/cayenne-client/src/test/java/org/apache/cayenne/CayenneContextInheritanceIT.java
index 15c5a6a..f164a0a 100644
--- a/cayenne-client/src/test/java/org/apache/cayenne/CayenneContextInheritanceIT.java
+++ b/cayenne-client/src/test/java/org/apache/cayenne/CayenneContextInheritanceIT.java
@@ -19,8 +19,7 @@
 package org.apache.cayenne;
 
 import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.exp.ExpressionFactory;
-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.apache.cayenne.testdo.mt.ClientMtTable1;
@@ -84,8 +83,7 @@ public class CayenneContextInheritanceIT extends ClientCase {
         tMtTable1.insert(2, "sub1", "zzz", "sa1");
         tMtTable1.insert(3, "1111", "aaa", null);
 
-        SelectQuery<ClientMtTable1Subclass1> query = new SelectQuery<>(ClientMtTable1Subclass1.class);
-        List<ClientMtTable1Subclass1> objects = query.select(context);
+        List<ClientMtTable1Subclass1> objects = ObjectSelect.query(ClientMtTable1Subclass1.class).select(context);
 
         assertEquals(1, objects.size());
         assertEquals("sa1", objects.get(0).getSubclass1Attribute1());
@@ -98,8 +96,7 @@ public class CayenneContextInheritanceIT extends ClientCase {
         tMtTable1.insert(2, "sub1", "zzz", "sa1");
         tMtTable1.insert(3, "z", "aaa", null);
 
-        SelectQuery<ClientMtTable1> query = new SelectQuery<>(ClientMtTable1.class);
-        List<ClientMtTable1> objects = query.select(context);
+        List<ClientMtTable1> objects = ObjectSelect.query(ClientMtTable1.class).select(context);
 
         assertEquals(3, objects.size());
 
@@ -125,9 +122,9 @@ public class CayenneContextInheritanceIT extends ClientCase {
         tMtTable1.insert(2, "sub1", "XXA", "sa1");
         tMtTable1.insert(3, "z", "MM", null);
 
-        SelectQuery<ClientMtTable1> query = new SelectQuery<>(ClientMtTable1.class);
-        query.andQualifier(ClientMtTable1.SERVER_ATTRIBUTE1.like("X%"));
-        List<ClientMtTable1> objects = query.select(context);
+        List<ClientMtTable1> objects = ObjectSelect.query(ClientMtTable1.class)
+                .where(ClientMtTable1.SERVER_ATTRIBUTE1.like("X%"))
+                .select(context);
 
         assertEquals(2, objects.size());
 
diff --git a/cayenne-client/src/test/java/org/apache/cayenne/CayenneContextMeaningfulPKIT.java b/cayenne-client/src/test/java/org/apache/cayenne/CayenneContextMeaningfulPKIT.java
index a88c718..12d30f2 100644
--- a/cayenne-client/src/test/java/org/apache/cayenne/CayenneContextMeaningfulPKIT.java
+++ b/cayenne-client/src/test/java/org/apache/cayenne/CayenneContextMeaningfulPKIT.java
@@ -20,7 +20,7 @@
 package org.apache.cayenne;
 
 import org.apache.cayenne.di.Inject;
-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;
@@ -62,10 +62,9 @@ public class CayenneContextMeaningfulPKIT extends ClientCase {
     public void testMeaningfulPK() throws Exception {
         deleteAndCreateTwoMeaningfulPKsDataSet();
 
-        SelectQuery query = new SelectQuery(ClientMeaningfulPk.class);
-        query.addOrdering(ClientMeaningfulPk.PK_PROPERTY, SortOrder.DESCENDING);
-
-        List<?> results = clientContext.performQuery(query);
+        List<?> results = ObjectSelect.query(ClientMeaningfulPk.class)
+                .orderBy(ClientMeaningfulPk.PK_PROPERTY, SortOrder.DESCENDING)
+                .select(clientContext);
         assertEquals(2, results.size());
     }
 
diff --git a/cayenne-client/src/test/java/org/apache/cayenne/CayenneContextPaginatedListCachingIT.java b/cayenne-client/src/test/java/org/apache/cayenne/CayenneContextPaginatedListCachingIT.java
index 7b89932..d63ac95 100644
--- a/cayenne-client/src/test/java/org/apache/cayenne/CayenneContextPaginatedListCachingIT.java
+++ b/cayenne-client/src/test/java/org/apache/cayenne/CayenneContextPaginatedListCachingIT.java
@@ -19,9 +19,7 @@
 package org.apache.cayenne;
 
 import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.query.QueryCacheStrategy;
-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;
@@ -62,12 +60,11 @@ public class CayenneContextPaginatedListCachingIT extends ClientCase {
     public void testLocalCache() throws Exception {
         createSevenMtTable1sDataSet();
 
-        SelectQuery<ClientMtTable1> query = new SelectQuery<>(ClientMtTable1.class);
-        query.addOrdering(ClientMtTable1.GLOBAL_ATTRIBUTE1.asc());
-        query.setPageSize(3);
-        query.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
-
-        List<ClientMtTable1> result1 = query.select(context);
+        List<ClientMtTable1> result1 = ObjectSelect.query(ClientMtTable1.class)
+                .orderBy(ClientMtTable1.GLOBAL_ATTRIBUTE1.asc())
+                .pageSize(3)
+                .localCache()
+                .select(context);
         assertEquals(7, result1.size());
 
         // ensure we can resolve all objects without a failure...
diff --git a/cayenne-client/src/test/java/org/apache/cayenne/CayenneContextPrimitiveIT.java b/cayenne-client/src/test/java/org/apache/cayenne/CayenneContextPrimitiveIT.java
index afdd024..efb0e24 100644
--- a/cayenne-client/src/test/java/org/apache/cayenne/CayenneContextPrimitiveIT.java
+++ b/cayenne-client/src/test/java/org/apache/cayenne/CayenneContextPrimitiveIT.java
@@ -20,7 +20,6 @@ package org.apache.cayenne;
 
 import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.query.ObjectSelect;
-import org.apache.cayenne.query.SelectQuery;
 import org.apache.cayenne.query.SortOrder;
 import org.apache.cayenne.test.jdbc.DBHelper;
 import org.apache.cayenne.test.jdbc.TableHelper;
@@ -74,10 +73,9 @@ public class CayenneContextPrimitiveIT extends ClientCase {
     public void testSelectPrimitives() throws Exception {
         createTwoPrimitivesDataSet();
 
-        SelectQuery query = new SelectQuery(ClientTablePrimitives.class);
-        query.addOrdering("db:" + TablePrimitives.ID_PK_COLUMN, SortOrder.ASCENDING);
-
-        List<ClientTablePrimitives> results = context.performQuery(query);
+        List<ClientTablePrimitives> results = ObjectSelect.query(ClientTablePrimitives.class)
+                .orderBy("db:" + TablePrimitives.ID_PK_COLUMN, SortOrder.ASCENDING)
+                .select(context);
         assertTrue(results.get(0).isBooleanColumn());
         assertFalse(results.get(1).isBooleanColumn());
 
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 4648a0a..b06dbfc 100644
--- a/cayenne-client/src/test/java/org/apache/cayenne/CayenneContextWithDataContextIT.java
+++ b/cayenne-client/src/test/java/org/apache/cayenne/CayenneContextWithDataContextIT.java
@@ -24,7 +24,7 @@ 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.QueryCacheStrategy;
+import org.apache.cayenne.query.ObjectSelect;
 import org.apache.cayenne.query.SelectQuery;
 import org.apache.cayenne.reflect.LifecycleCallbackRegistry;
 import org.apache.cayenne.remote.RemoteIncrementalFaultList;
@@ -96,14 +96,10 @@ public class CayenneContextWithDataContextIT extends ClientCase {
 
     @Test
     public void testLocalCacheStaysLocal() {
-        SelectQuery<ClientMtTable1> query = new SelectQuery<>(ClientMtTable1.class);
-        query.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
-
-        List<?> results = clientContext.performQuery(query);
-
-        assertSame(results, clientContext.getQueryCache().get(
-                query.getMetaData(clientContext.getEntityResolver())));
+        ObjectSelect<ClientMtTable1> query = ObjectSelect.query(ClientMtTable1.class).localCache();
+        List<?> results = query.select(clientContext);
 
+        assertSame(results, clientContext.getQueryCache().get(query.getMetaData(clientContext.getEntityResolver())));
     }
 
     @Test
diff --git a/cayenne-client/src/test/java/org/apache/cayenne/NestedCayenneContextIT.java b/cayenne-client/src/test/java/org/apache/cayenne/NestedCayenneContextIT.java
index aded314..e746e93 100644
--- a/cayenne-client/src/test/java/org/apache/cayenne/NestedCayenneContextIT.java
+++ b/cayenne-client/src/test/java/org/apache/cayenne/NestedCayenneContextIT.java
@@ -23,8 +23,8 @@ 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.ObjectSelect;
 import org.apache.cayenne.query.SelectById;
-import org.apache.cayenne.query.SelectQuery;
 import org.apache.cayenne.query.SortOrder;
 import org.apache.cayenne.remote.RemoteCayenneCase;
 import org.apache.cayenne.remote.service.LocalConnection;
@@ -110,8 +110,7 @@ public class NestedCayenneContextIT extends RemoteCayenneCase {
 		assertEquals(PersistenceState.DELETED, deleted.getPersistenceState());
 		assertEquals(PersistenceState.NEW, _new.getPersistenceState());
 
-		List<ClientMtTable1> objects = child
-				.select(new SelectQuery<>(ClientMtTable1.class));
+		List<ClientMtTable1> objects = ObjectSelect.query(ClientMtTable1.class).select(child);
 		assertEquals("All but NEW object must have been included", 3, objects.size());
 
 		for (ClientMtTable1 next : objects) {
@@ -138,10 +137,9 @@ public class NestedCayenneContextIT extends RemoteCayenneCase {
 
 		final ObjectContext child = runtime.newContext(clientContext);
 
-		SelectQuery<ClientMtTable2> q = new SelectQuery<>(ClientMtTable2.class);
-		q.addPrefetch(ClientMtTable2.TABLE1.getName());
-
-		final List<ClientMtTable2> results = child.select(q);
+		final List<ClientMtTable2> results = ObjectSelect.query(ClientMtTable2.class)
+				.prefetch(ClientMtTable2.TABLE1.joint())
+				.select(child);
 
 		queryInterceptor.runWithQueriesBlocked(() -> {
 			assertEquals(2, results.size());
@@ -176,12 +174,10 @@ public class NestedCayenneContextIT extends RemoteCayenneCase {
 
 		final ObjectContext child = runtime.newContext(clientContext);
 
-		SelectQuery<ClientMtTable1> q = new SelectQuery<>(
-				ClientMtTable1.class);
-		q.addOrdering("globalAttribute1", SortOrder.ASCENDING);
-		q.addPrefetch(ClientMtTable1.TABLE2ARRAY.joint());
-
-		final List<ClientMtTable1> results = child.select(q);
+		final List<ClientMtTable1> results = ObjectSelect.query(ClientMtTable1.class)
+				.prefetch(ClientMtTable1.TABLE2ARRAY.joint())
+				.orderBy(ClientMtTable1.GLOBAL_ATTRIBUTE1.asc())
+				.select(child);
 
 		queryInterceptor.runWithQueriesBlocked(() -> {
 			ClientMtTable1 o1 = results.get(0);
@@ -304,8 +300,7 @@ public class NestedCayenneContextIT extends RemoteCayenneCase {
 
 		final ObjectContext child = runtime.newContext(clientContext);
 
-		SelectQuery<ClientMtTable1> query = new SelectQuery<>(ClientMtTable1.class);
-		List<ClientMtTable1> objects = child.select(query);
+		List<ClientMtTable1> objects = ObjectSelect.query(ClientMtTable1.class).select(child);
 
 		assertEquals(4, objects.size());
 
@@ -405,8 +400,7 @@ public class NestedCayenneContextIT extends RemoteCayenneCase {
 		ObjectContext child = runtime.newContext(clientContext);
 
 		// make sure we fetch in predictable order
-		SelectQuery<ClientMtTable1> query = new SelectQuery<>(ClientMtTable1.class);
-		List<ClientMtTable1> objects = child.select(query);
+		List<ClientMtTable1> objects = ObjectSelect.query(ClientMtTable1.class).select(child);
 
 		assertEquals(4, objects.size());
 
@@ -445,8 +439,7 @@ public class NestedCayenneContextIT extends RemoteCayenneCase {
 		ObjectContext child = runtime.newContext(clientContext);
 
 		// make sure we fetch in predictable order
-		SelectQuery<ClientMtTable1> query = new SelectQuery<>(ClientMtTable1.class);
-		List<ClientMtTable1> objects = child.select(query);
+		List<ClientMtTable1> objects = ObjectSelect.query(ClientMtTable1.class).select(child);
 
 		assertEquals(4, objects.size());
 
diff --git a/cayenne-client/src/test/java/org/apache/cayenne/query/ClientSelectQueryExpressionIT.java b/cayenne-client/src/test/java/org/apache/cayenne/query/ClientSelectQueryExpressionIT.java
index e3943fa..935cd5b 100644
--- a/cayenne-client/src/test/java/org/apache/cayenne/query/ClientSelectQueryExpressionIT.java
+++ b/cayenne-client/src/test/java/org/apache/cayenne/query/ClientSelectQueryExpressionIT.java
@@ -61,12 +61,12 @@ public class ClientSelectQueryExpressionIT extends ClientCase {
     public void testDoubleSelectLikeExpression() throws Exception {
         createMtTable1DataSet();
 
-        List<ClientMtTable1> mtTable1List = context.select(SelectQuery.query(ClientMtTable1.class));
+        List<ClientMtTable1> mtTable1List = context.select(ObjectSelect.query(ClientMtTable1.class));
 
         Expression exp = ClientMtTable1.GLOBAL_ATTRIBUTE1.like("globalAttr1%");
         exp.filterObjects(mtTable1List);
 
-        List<ClientMtTable1> matchingMtTableList = context.select(SelectQuery.query(ClientMtTable1.class, exp));
+        List<ClientMtTable1> matchingMtTableList = context.select(ObjectSelect.query(ClientMtTable1.class, exp));
 
         assertEquals(11, matchingMtTableList.size());
     }
diff --git a/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/Runtime_AES128_GZIP_IT.java b/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/Runtime_AES128_GZIP_IT.java
index 48903ad..85ea220 100644
--- a/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/Runtime_AES128_GZIP_IT.java
+++ b/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/Runtime_AES128_GZIP_IT.java
@@ -24,7 +24,6 @@ import org.apache.cayenne.crypto.db.Table8;
 import org.apache.cayenne.crypto.transformer.bytes.Header;
 import org.apache.cayenne.crypto.unit.CryptoUnitUtils;
 import org.apache.cayenne.query.ObjectSelect;
-import org.apache.cayenne.query.SelectQuery;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -154,8 +153,8 @@ public class Runtime_AES128_GZIP_IT extends Runtime_AES128_Base {
 
         context.commitChanges();
 
-        SelectQuery<Table2> select = SelectQuery.query(Table2.class);
-        select.addOrdering(Table2.PLAIN_BYTES.asc());
+        ObjectSelect<Table2> select = ObjectSelect.query(Table2.class)
+                .orderBy(Table2.PLAIN_BYTES.asc());
 
         List<Table2> result = runtime.newContext().select(select);
 
diff --git a/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/Runtime_AES128_IT.java b/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/Runtime_AES128_IT.java
index 88b3072..46be128 100644
--- a/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/Runtime_AES128_IT.java
+++ b/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/Runtime_AES128_IT.java
@@ -31,7 +31,6 @@ import org.apache.cayenne.crypto.transformer.value.IntegerConverter;
 import org.apache.cayenne.crypto.unit.CryptoUnitUtils;
 import org.apache.cayenne.exp.property.PropertyFactory;
 import org.apache.cayenne.query.ObjectSelect;
-import org.apache.cayenne.query.SelectQuery;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -130,8 +129,8 @@ public class Runtime_AES128_IT extends Runtime_AES128_Base {
 
         context.commitChanges();
 
-        SelectQuery<Table2> select = SelectQuery.query(Table2.class);
-        select.addOrdering(Table2.PLAIN_BYTES.asc());
+        ObjectSelect<Table2> select = ObjectSelect.query(Table2.class)
+                .orderBy(Table2.PLAIN_BYTES.asc());
 
         List<Table2> result = runtime.newContext().select(select);
 
@@ -153,7 +152,7 @@ public class Runtime_AES128_IT extends Runtime_AES128_Base {
 
         context.commitChanges();
 
-        List<Table1> result = SelectQuery.query(Table1.class).select(runtime.newContext());
+        List<Table1> result = ObjectSelect.query(Table1.class).select(runtime.newContext());
 
         assertEquals(1, result.size());
         assertEquals(59, result.get(0).getPlainInt());
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/CayenneIT.java b/cayenne-server/src/test/java/org/apache/cayenne/CayenneIT.java
index 80ad28b..a332f85 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/CayenneIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/CayenneIT.java
@@ -28,8 +28,8 @@ import org.apache.cayenne.map.SQLResult;
 import org.apache.cayenne.query.CapsStrategy;
 import org.apache.cayenne.query.EJBQLQuery;
 import org.apache.cayenne.query.ObjectIdQuery;
+import org.apache.cayenne.query.ObjectSelect;
 import org.apache.cayenne.query.SQLTemplate;
-import org.apache.cayenne.query.SelectQuery;
 import org.apache.cayenne.test.jdbc.DBHelper;
 import org.apache.cayenne.test.jdbc.TableHelper;
 import org.apache.cayenne.testdo.testmap.Artist;
@@ -167,13 +167,12 @@ public class CayenneIT extends ServerCase {
     public void testObjectForSelect() throws Exception {
         createOneArtist();
 
-        SelectQuery<Artist> query = SelectQuery.query(Artist.class, ExpressionFactory.matchDbExp("ARTIST_NAME", "artist2"));
+        ObjectSelect<Artist> query = ObjectSelect.query(Artist.class, ExpressionFactory.matchDbExp("ARTIST_NAME", "artist2"));
 
         Artist object = context.selectOne(query);
 
         assertNotNull(object);
-        assertTrue(object instanceof Artist);
-        assertEquals("artist2", ((Artist) object).getArtistName());
+        assertEquals("artist2", object.getArtistName());
     }
 
     @Test
@@ -259,9 +258,9 @@ public class CayenneIT extends ServerCase {
     public void testIntPKForObject() throws Exception {
         createOneArtist();
 
-        List<?> objects = context.performQuery(new SelectQuery(Artist.class));
+        List<Artist> objects = ObjectSelect.query(Artist.class).select(context);
         assertEquals(1, objects.size());
-        DataObject object = (DataObject) objects.get(0);
+        DataObject object = objects.get(0);
 
         assertEquals(33002, Cayenne.intPKForObject(object));
     }
@@ -270,11 +269,11 @@ public class CayenneIT extends ServerCase {
     public void testPKForObject() throws Exception {
         createOneArtist();
 
-        List<?> objects = context.performQuery(new SelectQuery(Artist.class));
+        List<Artist> objects = ObjectSelect.query(Artist.class).select(context);
         assertEquals(1, objects.size());
-        DataObject object = (DataObject) objects.get(0);
+        DataObject object = objects.get(0);
 
-        assertEquals(new Long(33002), Cayenne.pkForObject(object));
+        assertEquals(33002L, Cayenne.pkForObject(object));
     }
 
     @Test
@@ -285,7 +284,7 @@ public class CayenneIT extends ServerCase {
         assertEquals(1, objects.size());
         Artist object = (Artist) objects.get(0);
 
-        assertEquals(new Long(33002), Cayenne.pkForObject(object));
+        assertEquals(33002L, Cayenne.pkForObject(object));
     }
 
 }
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextCompoundRelIT.java b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextCompoundRelIT.java
index 25af2ce..d496b41 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextCompoundRelIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextCompoundRelIT.java
@@ -20,10 +20,7 @@
 package org.apache.cayenne.access;
 
 import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.exp.Expression;
-import org.apache.cayenne.exp.ExpressionFactory;
 import org.apache.cayenne.query.ObjectSelect;
-import org.apache.cayenne.query.SelectQuery;
 import org.apache.cayenne.testdo.compound.CompoundFkTestEntity;
 import org.apache.cayenne.testdo.compound.CompoundOrder;
 import org.apache.cayenne.testdo.compound.CompoundOrderLine;
@@ -64,8 +61,7 @@ public class DataContextCompoundRelIT extends ServerCase {
         context.commitChanges();
         context.invalidateObjects(master, detail);
 
-        SelectQuery<CompoundPkTestEntity> q = SelectQuery.query(CompoundPkTestEntity.class);
-        List<CompoundPkTestEntity> objs = q.select(context1);
+        List<CompoundPkTestEntity> objs = ObjectSelect.query(CompoundPkTestEntity.class).select(context1);
 
         assertEquals(1, objs.size());
         assertEquals("m1", objs.get(0).getName());
@@ -99,9 +95,9 @@ public class DataContextCompoundRelIT extends ServerCase {
         context.commitChanges();
         context.invalidateObjects(master, master1, detail, detail1);
 
-        Expression qual = ExpressionFactory.matchExp("toCompoundPk", master);
-        SelectQuery<CompoundFkTestEntity> q = SelectQuery.query(CompoundFkTestEntity.class, qual);
-        List<CompoundFkTestEntity> objs = q.select(context1);
+        List<CompoundFkTestEntity> objs = ObjectSelect.query(CompoundFkTestEntity.class)
+                .where(CompoundFkTestEntity.TO_COMPOUND_PK.eq(master))
+                .select(context1);
 
         assertEquals(1, objs.size());
         assertEquals("d1", objs.get(0).getName());
@@ -160,9 +156,9 @@ public class DataContextCompoundRelIT extends ServerCase {
         context.commitChanges();
         context.invalidateObjects(master, master1, detail, detail1);
 
-        Expression qual = ExpressionFactory.matchExp("compoundFkArray", detail1);
-        SelectQuery<CompoundPkTestEntity> q = SelectQuery.query(CompoundPkTestEntity.class, qual);
-        List<CompoundPkTestEntity> objs = q.select(context1);
+        List<CompoundPkTestEntity> objs = ObjectSelect.query(CompoundPkTestEntity.class)
+                .where(CompoundPkTestEntity.COMPOUND_FK_ARRAY.contains(detail1))
+                .select(context1);
 
         assertEquals(1, objs.size());
         assertEquals("m2", objs.get(0).getName());
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextDisjointByIdPrefetchIT.java b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextDisjointByIdPrefetchIT.java
index b569e1a..cede796 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextDisjointByIdPrefetchIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextDisjointByIdPrefetchIT.java
@@ -21,7 +21,7 @@ package org.apache.cayenne.access;
 import org.apache.cayenne.PersistenceState;
 import org.apache.cayenne.ValueHolder;
 import org.apache.cayenne.di.Inject;
-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;
@@ -114,9 +114,9 @@ public class DataContextDisjointByIdPrefetchIT extends ServerCase {
     public void testOneToMany() throws Exception {
         createArtistWithTwoPaintingsDataSet();
 
-        SelectQuery<Artist> query = SelectQuery.query(Artist.class);
-        query.addPrefetch(Artist.PAINTING_ARRAY.disjointById());
-        List<Artist> result = query.select(context);
+        List<Artist> result = ObjectSelect.query(Artist.class)
+                .prefetch(Artist.PAINTING_ARRAY.disjointById())
+                .select(context);
 
         queryInterceptor.runWithQueriesBlocked(() -> {
             assertFalse(result.isEmpty());
@@ -142,10 +142,10 @@ public class DataContextDisjointByIdPrefetchIT extends ServerCase {
     public void testManyToOne() throws Exception {
         createArtistWithTwoPaintingsDataSet();
 
-        SelectQuery<Painting> query = SelectQuery.query(Painting.class);
-        query.addPrefetch(Painting.TO_ARTIST.disjointById());
+        final List<Painting> result = ObjectSelect.query(Painting.class)
+                .prefetch(Painting.TO_ARTIST.disjointById())
+                .select(context);
 
-        final List<Painting> result = query.select(context);
         queryInterceptor.runWithQueriesBlocked(() -> {
             assertFalse(result.isEmpty());
             Painting b1 = result.get(0);
@@ -159,16 +159,14 @@ public class DataContextDisjointByIdPrefetchIT extends ServerCase {
     public void testFetchLimit() throws Exception {
         createThreeArtistsWithPlentyOfPaintingsDataSet();
 
-        SelectQuery<Artist> query = SelectQuery.query(Artist.class);
-        query.addPrefetch(Artist.PAINTING_ARRAY.disjointById());
-        query.addOrdering("db:" + Artist.ARTIST_ID_PK_COLUMN, SortOrder.ASCENDING);
-
-        query.setFetchLimit(2);
-
         // There will be only 2 bags in a result. The first bag has 5 boxes and
         // the second has 2. So we are expecting exactly 9 snapshots in the data
         // row store after performing the query.
-        final List<Artist> bags = query.select(context);
+        final List<Artist> bags = ObjectSelect.query(Artist.class)
+                .prefetch(Artist.PAINTING_ARRAY.disjointById())
+                .orderBy("db:" + Artist.ARTIST_ID_PK_COLUMN, SortOrder.ASCENDING)
+                .limit(2)
+                .select(context);
 
         queryInterceptor.runWithQueriesBlocked(() -> {
 
@@ -190,9 +188,9 @@ public class DataContextDisjointByIdPrefetchIT extends ServerCase {
     public void testOneToOneRelationship() throws Exception {
         createTwoPaintingsWithInfosDataSet();
 
-        SelectQuery<Painting> query = SelectQuery.query(Painting.class);
-        query.addPrefetch(Painting.TO_PAINTING_INFO.disjointById());
-        final List<Painting> result = query.select(context);
+        final List<Painting> result = ObjectSelect.query(Painting.class)
+                .prefetch(Painting.TO_PAINTING_INFO.disjointById())
+                .select(context);
         queryInterceptor.runWithQueriesBlocked(() -> {
             assertFalse(result.isEmpty());
             List<String> boxColors = new ArrayList<>();
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextDisjointByIdPrefetch_ExtrasIT.java b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextDisjointByIdPrefetch_ExtrasIT.java
index 88c1061..1124ee0 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextDisjointByIdPrefetch_ExtrasIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextDisjointByIdPrefetch_ExtrasIT.java
@@ -22,7 +22,7 @@ import org.apache.cayenne.PersistenceState;
 import org.apache.cayenne.ValueHolder;
 import org.apache.cayenne.configuration.server.ServerRuntime;
 import org.apache.cayenne.di.Inject;
-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.apache.cayenne.testdo.things.Bag;
@@ -123,10 +123,9 @@ public class DataContextDisjointByIdPrefetch_ExtrasIT extends ServerCase {
     public void testFlattenedRelationship() throws Exception {
         createBagWithTwoBoxesAndPlentyOfBallsDataSet();
 
-        SelectQuery<Bag> query = SelectQuery.query(Bag.class);
-        query.addPrefetch(Bag.BALLS.disjointById());
-
-        final List<Bag> result = query.select(context);
+        final List<Bag> result = ObjectSelect.query(Bag.class)
+                .prefetch(Bag.BALLS.disjointById())
+                .select(context);
 
         queryInterceptor.runWithQueriesBlocked(() -> {
             assertFalse(result.isEmpty());
@@ -150,9 +149,9 @@ public class DataContextDisjointByIdPrefetch_ExtrasIT extends ServerCase {
     public void testFlattenedMultiColumnRelationship() throws Exception {
         createBagWithTwoBoxesAndPlentyOfBallsDataSet();
 
-        SelectQuery<Box> query = new SelectQuery<>(Box.class);
-        query.addPrefetch(Box.THINGS.disjointById());
-        final List<Box> result = query.select(context);
+        final List<Box> result = ObjectSelect.query(Box.class)
+                .prefetch(Box.THINGS.disjointById())
+                .select(context);
 
         queryInterceptor.runWithQueriesBlocked(() -> {
             assertFalse(result.isEmpty());
@@ -176,9 +175,9 @@ public class DataContextDisjointByIdPrefetch_ExtrasIT extends ServerCase {
     public void testLongFlattenedRelationship() throws Exception {
         createBagWithTwoBoxesAndPlentyOfBallsDataSet();
 
-        SelectQuery<Bag> query = new SelectQuery<>(Bag.class);
-        query.addPrefetch(Bag.THINGS.disjointById());
-        final List<Bag> result = query.select(context);
+        final List<Bag> result = ObjectSelect.query(Bag.class)
+                .prefetch(Box.THINGS.disjointById())
+                .select(context);
 
         queryInterceptor.runWithQueriesBlocked(() -> {
             assertFalse(result.isEmpty());
@@ -202,13 +201,11 @@ public class DataContextDisjointByIdPrefetch_ExtrasIT extends ServerCase {
     public void testMultiColumnRelationship() throws Exception {
         createBagWithTwoBoxesAndPlentyOfBallsDataSet();
 
-        SelectQuery<Ball> query = SelectQuery.query(Ball.class);
-        query.orQualifier(Ball.THING_VOLUME.eq(40).andExp(Ball.THING_WEIGHT.eq(30)));
-        query.orQualifier(Ball.THING_VOLUME.eq(20).andExp(Ball.THING_WEIGHT.eq(10)));
-
-        query.addPrefetch(Ball.THING.disjointById());
-
-        final List<Ball> balls = query.select(context);
+        final List<Ball> balls = ObjectSelect.query(Ball.class)
+                .or(Ball.THING_VOLUME.eq(40).andExp(Ball.THING_WEIGHT.eq(30)))
+                .or(Ball.THING_VOLUME.eq(20).andExp(Ball.THING_WEIGHT.eq(10)))
+                .prefetch(Ball.THING.disjointById())
+                .select(context);
 
         queryInterceptor.runWithQueriesBlocked(() -> {
             assertEquals(2, balls.size());
@@ -223,10 +220,10 @@ public class DataContextDisjointByIdPrefetch_ExtrasIT extends ServerCase {
     public void testJointPrefetchInParent() throws Exception {
         createBagWithTwoBoxesAndPlentyOfBallsDataSet();
 
-        SelectQuery<Box> query = new SelectQuery<>(Box.class);
-        query.addPrefetch(Box.BALLS.disjointById());
-        query.addPrefetch(Box.BALLS.dot(Ball.THING).disjointById());
-        final List<Box> result = query.select(context);
+        final List<Box> result = ObjectSelect.query(Box.class)
+                .prefetch(Box.BALLS.disjointById())
+                .prefetch(Box.BALLS.dot(Ball.THING).disjointById())
+                .select(context);
 
         queryInterceptor.runWithQueriesBlocked(() -> {
             assertFalse(result.isEmpty());
@@ -252,10 +249,10 @@ public class DataContextDisjointByIdPrefetch_ExtrasIT extends ServerCase {
     public void testJointPrefetchInChild() throws Exception {
         createBagWithTwoBoxesAndPlentyOfBallsDataSet();
 
-        SelectQuery<Bag> query = new SelectQuery<>(Bag.class);
-        query.addPrefetch(Bag.BOXES.disjointById());
-        query.addPrefetch(Bag.BOXES.dot(Box.BALLS).joint());
-        final List<Bag> result = context.select(query);
+        final List<Bag> result = ObjectSelect.query(Bag.class)
+                .prefetch(Bag.BOXES.disjointById())
+                .prefetch(Bag.BOXES.dot(Box.BALLS).joint())
+                .select(context);
 
         queryInterceptor.runWithQueriesBlocked(() -> {
             assertFalse(result.isEmpty());
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextFlattenedAttributesIT.java b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextFlattenedAttributesIT.java
index f3bf267..adb152b 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextFlattenedAttributesIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextFlattenedAttributesIT.java
@@ -24,10 +24,9 @@ import org.apache.cayenne.ObjectContext;
 import org.apache.cayenne.PersistenceState;
 import org.apache.cayenne.configuration.server.ServerRuntime;
 import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.exp.ExpressionFactory;
 import org.apache.cayenne.query.EJBQLQuery;
+import org.apache.cayenne.query.ObjectSelect;
 import org.apache.cayenne.query.SelectById;
-import org.apache.cayenne.query.SelectQuery;
 import org.apache.cayenne.reflect.PersistentDescriptor;
 import org.apache.cayenne.test.jdbc.DBHelper;
 import org.apache.cayenne.test.jdbc.TableHelper;
@@ -117,12 +116,11 @@ public class DataContextFlattenedAttributesIT extends ServerCase {
     @Test
     public void testSelectCompound1() throws Exception {
         createTestDataSet();
-        SelectQuery<CompoundPainting> query = SelectQuery.query(CompoundPainting.class);
-        List<CompoundPainting> objects = query.select(context);
+        List<CompoundPainting> objects = ObjectSelect.query(CompoundPainting.class).select(context);
 
         assertNotNull(objects);
         assertEquals(8, objects.size());
-        assertTrue("CompoundPainting expected, got null", objects.get(0) != null);
+        assertNotNull("CompoundPainting expected, got null", objects.get(0));
 
         for (CompoundPainting painting : objects) {
             Number id = (Number) painting.getObjectId().getIdSnapshot().get("PAINTING_ID");
@@ -159,10 +157,9 @@ public class DataContextFlattenedAttributesIT extends ServerCase {
     @Test
     public void testSelectCompound2() throws Exception {
         createTestDataSet();
-        SelectQuery<CompoundPainting> query = SelectQuery.query(
-                CompoundPainting.class,
-                ExpressionFactory.matchExp("artistName", "artist2"));
-        List<CompoundPainting> objects = query.select(context);
+
+        List<CompoundPainting> objects = ObjectSelect.query(CompoundPainting.class, CompoundPainting.ARTIST_NAME.eq("artist2"))
+                .select(context);
 
         assertNotNull(objects);
         assertEquals(2, objects.size());
@@ -191,9 +188,8 @@ public class DataContextFlattenedAttributesIT extends ServerCase {
     @Test
     public void testSelectCompoundLongNames() throws Exception {
         createTestDataSet();
-        SelectQuery<CompoundPaintingLongNames> query = SelectQuery.query(CompoundPaintingLongNames.class);
         // the error was thrown on query execution
-        List<?> objects = context.performQuery(query);
+        List<?> objects = ObjectSelect.query(CompoundPaintingLongNames.class).select(context);
         assertNotNull(objects);
     }
 
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextIT.java b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextIT.java
index 70aefd9..4b91c39 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextIT.java
@@ -26,16 +26,15 @@ import org.apache.cayenne.Fault;
 import org.apache.cayenne.ObjectId;
 import org.apache.cayenne.PersistenceState;
 import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.exp.Expression;
 import org.apache.cayenne.exp.ExpressionFactory;
 import org.apache.cayenne.map.EntityResolver;
 import org.apache.cayenne.query.EJBQLQuery;
 import org.apache.cayenne.query.ObjectIdQuery;
+import org.apache.cayenne.query.ObjectSelect;
 import org.apache.cayenne.query.Query;
 import org.apache.cayenne.query.QueryMetadata;
 import org.apache.cayenne.query.QueryRouter;
 import org.apache.cayenne.query.SQLTemplate;
-import org.apache.cayenne.query.SelectQuery;
 import org.apache.cayenne.test.jdbc.DBHelper;
 import org.apache.cayenne.test.jdbc.TableHelper;
 import org.apache.cayenne.testdo.testmap.Artist;
@@ -45,7 +44,6 @@ import org.apache.cayenne.testdo.testmap.Painting;
 import org.apache.cayenne.testdo.testmap.ROArtist;
 import org.apache.cayenne.unit.UnitDbAdapter;
 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.ServerCase;
 import org.apache.cayenne.unit.di.server.ServerCaseDataSourceFactory;
@@ -55,7 +53,6 @@ import org.junit.Test;
 
 import java.math.BigDecimal;
 import java.sql.Timestamp;
-import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Date;
 import java.util.HashMap;
@@ -63,9 +60,7 @@ import java.util.List;
 import java.util.Map;
 
 import static org.junit.Assert.*;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.ArgumentMatchers.isNull;
+import static org.mockito.ArgumentMatchers.*;
 import static org.mockito.Mockito.*;
 
 @UseServerRuntime(CayenneProjects.TESTMAP_PROJECT)
@@ -157,8 +152,7 @@ public class DataContextIT extends ServerCase {
 	public void testCurrentSnapshot1() throws Exception {
 		createSingleArtistDataSet();
 
-		SelectQuery query = new SelectQuery(Artist.class, Artist.ARTIST_NAME.eq("artist1"));
-		Artist artist = (Artist) context.performQuery(query).get(0);
+		Artist artist = ObjectSelect.query(Artist.class, Artist.ARTIST_NAME.eq("artist1")).selectFirst(context);
 
 		DataRow snapshot = context.currentSnapshot(artist);
 		assertEquals(artist.getArtistName(), snapshot.get("ARTIST_NAME"));
@@ -171,8 +165,7 @@ public class DataContextIT extends ServerCase {
 		createSingleArtistDataSet();
 
 		// test null values
-		SelectQuery<Artist> query = new SelectQuery<>(Artist.class, Artist.ARTIST_NAME.eq("artist1"));
-		Artist artist = (Artist) context.performQuery(query).get(0);
+		Artist artist = ObjectSelect.query(Artist.class, Artist.ARTIST_NAME.eq("artist1")).selectFirst(context);
 
 		artist.setArtistName(null);
 		artist.setDateOfBirth(null);
@@ -192,8 +185,7 @@ public class DataContextIT extends ServerCase {
 		createSingleArtistDataSet();
 
 		// test null values
-		SelectQuery query = new SelectQuery(Artist.class, Artist.ARTIST_NAME.eq("artist1"));
-		Artist artist = (Artist) context.performQuery(query).get(0);
+		Artist artist = ObjectSelect.query(Artist.class, Artist.ARTIST_NAME.eq("artist1")).selectFirst(context);
 
 		// test FK relationship snapshotting
 		Painting p1 = new Painting();
@@ -230,7 +222,7 @@ public class DataContextIT extends ServerCase {
 		// relationship
 		// is still a Fault
 		assertTrue(e.readPropertyDirectly(Exhibit.TO_GALLERY.getName()) instanceof Fault);
-		assertEquals(new Integer(33002), snapshot.get("GALLERY_ID"));
+		assertEquals(33002, snapshot.get("GALLERY_ID"));
 	}
 
 	/**
@@ -242,9 +234,8 @@ public class DataContextIT extends ServerCase {
 	public void testCharFetch() throws Exception {
 		createSingleArtistDataSet();
 
-		SelectQuery query = new SelectQuery(Artist.class);
-		Artist a = (Artist) context.performQuery(query).get(0);
-		assertEquals(a.getArtistName().trim(), a.getArtistName());
+		Artist artist = ObjectSelect.query(Artist.class).selectFirst(context);
+		assertEquals(artist.getArtistName().trim(), artist.getArtistName());
 	}
 
 	/**
@@ -256,9 +247,7 @@ public class DataContextIT extends ServerCase {
 	public void testCharInQualifier() throws Exception {
 		createArtistsDataSet();
 
-		Expression e = ExpressionFactory.matchExp("artistName", "artist1");
-		SelectQuery q = new SelectQuery(Artist.class, e);
-		List<Artist> artists = context.performQuery(q);
+		List<Artist> artists = ObjectSelect.query(Artist.class, Artist.ARTIST_NAME.eq("artist1")).select(context);
 		assertEquals(1, artists.size());
 	}
 
@@ -270,10 +259,10 @@ public class DataContextIT extends ServerCase {
 	public void testMultiObjRelFetch() throws Exception {
 		createArtistsAndPaintingsDataSet();
 
-		SelectQuery q = new SelectQuery(Painting.class);
-		q.andQualifier(ExpressionFactory.matchExp("toArtist.artistName", "artist2"));
-		q.orQualifier(ExpressionFactory.matchExp("toArtist.artistName", "artist4"));
-		List<Painting> results = context.performQuery(q);
+		List<Painting> results = ObjectSelect.query(Painting.class)
+				.where(Painting.TO_ARTIST.dot(Artist.ARTIST_NAME).eq("artist2"))
+				.or(Painting.TO_ARTIST.dot(Artist.ARTIST_NAME).eq("artist4"))
+				.select(context);
 
 		assertEquals(2, results.size());
 	}
@@ -286,10 +275,10 @@ public class DataContextIT extends ServerCase {
 	public void testMultiDbRelFetch() throws Exception {
 		createArtistsAndPaintingsDataSet();
 
-		SelectQuery q = new SelectQuery("Painting");
-		q.andQualifier(ExpressionFactory.matchDbExp("toArtist.ARTIST_NAME", "artist2"));
-		q.orQualifier(ExpressionFactory.matchDbExp("toArtist.ARTIST_NAME", "artist4"));
-		List<?> results = context.performQuery(q);
+		List<Painting> results = ObjectSelect.query(Painting.class)
+				.where(ExpressionFactory.matchDbExp("toArtist.ARTIST_NAME", "artist2"))
+				.or(ExpressionFactory.matchDbExp("toArtist.ARTIST_NAME", "artist4"))
+				.select(context);
 
 		assertEquals(2, results.size());
 	}
@@ -298,7 +287,7 @@ public class DataContextIT extends ServerCase {
 	public void testSelectDate() throws Exception {
 		createGalleriesAndExhibitsDataSet();
 
-		List<Exhibit> objects = context.performQuery(new SelectQuery(Exhibit.class));
+		List<Exhibit> objects = ObjectSelect.query(Exhibit.class).select(context);
 		assertFalse(objects.isEmpty());
 
 		Exhibit e1 = objects.get(0);
@@ -317,11 +306,9 @@ public class DataContextIT extends ServerCase {
 		// to the query when query is using DISTINCT...
 		// verify that the result is not messed up
 
-		SelectQuery query = new SelectQuery(Artist.class);
-		query.addOrdering(Artist.ARTIST_NAME.ascInsensitive());
-		query.setDistinct(true);
-
-		List<Artist> objects = context.performQuery(query);
+		List<Artist> objects = ObjectSelect.query(Artist.class)
+				.orderBy(Artist.ARTIST_NAME.ascInsensitive())
+				.select(context);
 		assertEquals(5, objects.size());
 
 		Artist artist = objects.get(0);
@@ -340,8 +327,7 @@ public class DataContextIT extends ServerCase {
 	public void testSelect_DataRows() throws Exception {
 		createArtistsAndPaintingsDataSet();
 
-		SelectQuery<DataRow> query = SelectQuery.dataRowQuery(Artist.class, null);
-		List<DataRow> objects = context.select(query);
+		List<DataRow> objects = ObjectSelect.dataRowQuery(Artist.class, null).select(context);
 
 		assertNotNull(objects);
 		assertEquals(7, objects.size());
@@ -352,8 +338,7 @@ public class DataContextIT extends ServerCase {
 	public void testPerformSelectQuery1() throws Exception {
 		createArtistsAndPaintingsDataSet();
 
-		SelectQuery query = new SelectQuery(Artist.class);
-		List<?> objects = context.performQuery(query);
+		List<Artist> objects = ObjectSelect.query(Artist.class).select(context);
 
 		assertNotNull(objects);
 		assertEquals(7, objects.size());
@@ -365,14 +350,11 @@ public class DataContextIT extends ServerCase {
 		createArtistsAndPaintingsDataSet();
 
 		// do a query with complex qualifier
-		List<Expression> expressions = new ArrayList<Expression>();
-		expressions.add(ExpressionFactory.matchExp("artistName", "artist3"));
-		expressions.add(ExpressionFactory.matchExp("artistName", "artist5"));
-		expressions.add(ExpressionFactory.matchExp("artistName", "artist21"));
-
-		SelectQuery query = new SelectQuery(Artist.class, ExpressionFactory.joinExp(Expression.OR, expressions));
-
-		List<?> objects = context.performQuery(query);
+		List<?> objects = ObjectSelect.query(Artist.class)
+				.where(Artist.ARTIST_NAME.eq("artist3"))
+				.or(Artist.ARTIST_NAME.eq("artist5"))
+				.or(Artist.ARTIST_NAME.eq("artist21"))
+				.select(context);
 
 		assertNotNull(objects);
 		assertEquals(3, objects.size());
@@ -393,15 +375,16 @@ public class DataContextIT extends ServerCase {
 
 		createSingleArtistDataSet();
 
-		SelectQuery select = new SelectQuery(Painting.class, ExpressionFactory.exp("db:PAINTING_ID = 1"));
+		ObjectSelect<Painting> query = ObjectSelect.query(Painting.class, ExpressionFactory.exp("db:PAINTING_ID = 1"));
 
-		assertEquals(0, context.performQuery(select).size());
+		assertEquals(0, query.select(context).size());
 
-		SQLTemplate query = new SQLTemplate(Painting.class,
+		SQLTemplate insert = new SQLTemplate(Painting.class,
 				"INSERT INTO PAINTING (PAINTING_ID, PAINTING_TITLE, ARTIST_ID, ESTIMATED_PRICE) "
 						+ "VALUES (1, 'PX', 33001, 1)");
-		context.performNonSelectingQuery(query);
-		assertEquals(1, context.performQuery(select).size());
+		context.performNonSelectingQuery(insert);
+
+		assertEquals(1, query.select(context).size());
 	}
 
 	@Test
@@ -413,10 +396,10 @@ public class DataContextIT extends ServerCase {
 						+ "VALUES ($pid, '$pt', $aid, $price)");
 
 		Map<String, Object> map = new HashMap<>();
-		map.put("pid", new Integer(1));
+		map.put("pid", 1);
 		map.put("pt", "P1");
-		map.put("aid", new Integer(33002));
-		map.put("price", new Double(1.1));
+		map.put("aid", 33002);
+		map.put("price", 1.1);
 
 		// single batch of parameters
 		query.setParameters(map);
@@ -439,9 +422,9 @@ public class DataContextIT extends ServerCase {
 		Map<String, Object>[] maps = new Map[3];
 		for (int i = 0; i < maps.length; i++) {
 			maps[i] = new HashMap<>();
-			maps[i].put("pid", new Integer(1 + i));
+			maps[i].put("pid", 1 + i);
 			maps[i].put("pt", "P-" + i);
-			maps[i].put("aid", new Integer(33002));
+			maps[i].put("aid", 33002);
 			maps[i].put("price", new BigDecimal("1." + i));
 		}
 
@@ -466,9 +449,7 @@ public class DataContextIT extends ServerCase {
 	public void testPerformPaginatedQuery() throws Exception {
 		createArtistsDataSet();
 
-		SelectQuery<Artist> query = SelectQuery.query(Artist.class);
-		query.setPageSize(5);
-		List<Artist> objects = context.select(query);
+		List<Artist> objects = ObjectSelect.query(Artist.class).pageSize(5).select(context);
 		assertNotNull(objects);
 		assertTrue(objects instanceof IncrementalFaultList<?>);
 		assertTrue(((IncrementalFaultList<Artist>) objects).elements.get(0) instanceof Long);
@@ -496,18 +477,11 @@ public class DataContextIT extends ServerCase {
 	public void testPerformPaginatedQueryBigPage() throws Exception {
 		createArtistsDataSet();
 
-		SelectQuery query = new SelectQuery(Artist.class);
-		query.setPageSize(5);
-		final List<?> objects = context.performQuery(query);
+		final List<?> objects = ObjectSelect.query(Artist.class).pageSize(5).select(context);
 		assertNotNull(objects);
 		assertTrue(objects instanceof IncrementalFaultList<?>);
 
-		queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
-
-			public void execute() {
-				assertEquals(7, objects.size());
-			}
-		});
+		queryInterceptor.runWithQueriesBlocked(() -> assertEquals(7, objects.size()));
 	}
 
 	@Test
@@ -515,9 +489,7 @@ public class DataContextIT extends ServerCase {
 
 		createArtistsDataSet();
 
-		SelectQuery query = new SelectQuery(Artist.class);
-		query.setFetchingDataRows(true);
-		List<?> objects = context.performQuery(query);
+		List<?> objects = ObjectSelect.dataRowQuery(Artist.class).select(context);
 
 		assertNotNull(objects);
 		assertEquals(7, objects.size());
@@ -544,8 +516,7 @@ public class DataContextIT extends ServerCase {
 	public void testCommitChangesRO2() throws Exception {
 		createArtistsDataSet();
 
-		SelectQuery query = new SelectQuery(ROArtist.class, Artist.ARTIST_NAME.eq("artist1"));
-		ROArtist a1 = (ROArtist) context.performQuery(query).get(0);
+		ROArtist a1 = ObjectSelect.query(ROArtist.class, Artist.ARTIST_NAME.eq("artist1")).selectOne(context);
 		a1.writeProperty(ROArtist.ARTIST_NAME.getName(), "abc");
 
 		try {
@@ -562,8 +533,7 @@ public class DataContextIT extends ServerCase {
 
 		createArtistsDataSet();
 
-		SelectQuery query = new SelectQuery(ROArtist.class, Artist.ARTIST_NAME.eq("artist1"));
-		ROArtist a1 = (ROArtist) context.performQuery(query).get(0);
+		ROArtist a1 = ObjectSelect.query(ROArtist.class, Artist.ARTIST_NAME.eq("artist1")).selectOne(context);
 		context.deleteObjects(a1);
 
 		try {
@@ -579,8 +549,7 @@ public class DataContextIT extends ServerCase {
 	public void testCommitChangesRO4() throws Exception {
 		createArtistsDataSet();
 
-		SelectQuery query = new SelectQuery(ROArtist.class, Artist.ARTIST_NAME.eq("artist1"));
-		ROArtist a1 = (ROArtist) context.performQuery(query).get(0);
+		ROArtist a1 = ObjectSelect.query(ROArtist.class, Artist.ARTIST_NAME.eq("artist1")).selectOne(context);
 
 		Painting painting = context.newObject(Painting.class);
 		painting.setPaintingTitle("paint");
@@ -638,7 +607,7 @@ public class DataContextIT extends ServerCase {
 	public void testInvalidateObjects_Vararg() throws Exception {
 
 		DataRow row = new DataRow(10);
-		row.put("ARTIST_ID", new Integer(1));
+		row.put("ARTIST_ID", 1);
 		row.put("ARTIST_NAME", "ArtistXYZ");
 		row.put("DATE_OF_BIRTH", new Date());
 		DataObject object = context.objectFromDataRow(Artist.class, row);
@@ -661,7 +630,7 @@ public class DataContextIT extends ServerCase {
 	public void testInvalidateObjects() throws Exception {
 
 		DataRow row = new DataRow(10);
-		row.put("ARTIST_ID", new Integer(1));
+		row.put("ARTIST_ID", 1);
 		row.put("ARTIST_NAME", "ArtistXYZ");
 		row.put("DATE_OF_BIRTH", new Date());
 		DataObject object = context.objectFromDataRow(Artist.class, row);
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextIteratedQueryIT.java b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextIteratedQueryIT.java
index 720cf5b..8853c8c 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextIteratedQueryIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextIteratedQueryIT.java
@@ -21,9 +21,8 @@ package org.apache.cayenne.access;
 import org.apache.cayenne.DataRow;
 import org.apache.cayenne.ResultBatchIterator;
 import org.apache.cayenne.ResultIterator;
-import org.apache.cayenne.ResultIteratorCallback;
 import org.apache.cayenne.di.Inject;
-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.apache.cayenne.testdo.testmap.Artist;
@@ -98,20 +97,12 @@ public class DataContextIteratedQueryIT extends ServerCase {
 
     @Test
     public void testIterate() throws Exception {
-
         createArtistsDataSet();
 
-        SelectQuery<Artist> q1 = new SelectQuery<Artist>(Artist.class);
-
         final int[] count = new int[1];
-
-        context.iterate(q1, new ResultIteratorCallback<Artist>() {
-
-            @Override
-            public void next(Artist object) {
-                assertNotNull(object.getArtistName());
-                count[0]++;
-            }
+        ObjectSelect.query(Artist.class).iterate(context, object -> {
+            assertNotNull(object.getArtistName());
+            count[0]++;
         });
 
         assertEquals(7, count[0]);
@@ -119,19 +110,12 @@ public class DataContextIteratedQueryIT extends ServerCase {
 
     @Test
     public void testIterateDataRows() throws Exception {
-
         createArtistsDataSet();
 
-        SelectQuery<DataRow> q1 = SelectQuery.dataRowQuery(Artist.class, null);
         final int[] count = new int[1];
-
-        context.iterate(q1, new ResultIteratorCallback<DataRow>() {
-
-            @Override
-            public void next(DataRow object) {
-                assertNotNull(object.get("ARTIST_ID"));
-                count[0]++;
-            }
+        ObjectSelect.dataRowQuery(Artist.class).iterate(context, object -> {
+            assertNotNull(object.get("ARTIST_ID"));
+            count[0]++;
         });
 
         assertEquals(7, count[0]);
@@ -139,12 +123,9 @@ public class DataContextIteratedQueryIT extends ServerCase {
 
     @Test
     public void testIterator() throws Exception {
-
         createArtistsDataSet();
 
-        SelectQuery<Artist> q1 = new SelectQuery<Artist>(Artist.class);
-
-        try (ResultIterator<Artist> it = context.iterator(q1);) {
+        try (ResultIterator<Artist> it = ObjectSelect.query(Artist.class).iterator(context)) {
             int count = 0;
 
             for (Artist a : it) {
@@ -159,9 +140,7 @@ public class DataContextIteratedQueryIT extends ServerCase {
     public void testBatchIterator() throws Exception {
         createLargeArtistsDataSet();
 
-        SelectQuery<Artist> q1 = new SelectQuery<Artist>(Artist.class);
-
-        try (ResultBatchIterator<Artist> it = context.batchIterator(q1, 5);) {
+        try (ResultBatchIterator<Artist> it = ObjectSelect.query(Artist.class).batchIterator(context, 5)) {
             int count = 0;
 
             for (List<Artist> artistList : it) {
@@ -176,12 +155,9 @@ public class DataContextIteratedQueryIT extends ServerCase {
 
     @Test
     public void testPerformIteratedQuery_Count() throws Exception {
-
         createArtistsDataSet();
 
-        SelectQuery<Artist> q1 = new SelectQuery<Artist>(Artist.class);
-
-        try (ResultIterator<?> it = context.performIteratedQuery(q1);) {
+        try (ResultIterator<?> it = context.performIteratedQuery(ObjectSelect.query(Artist.class))) {
             int count = 0;
             while (it.hasNextRow()) {
                 it.nextRow();
@@ -196,7 +172,7 @@ public class DataContextIteratedQueryIT extends ServerCase {
     public void testPerformIteratedQuery_resolve() throws Exception {
         createArtistsAndPaintingsDataSet();
 
-        try (ResultIterator<?> it = context.performIteratedQuery(SelectQuery.query(Artist.class));) {
+        try (ResultIterator<?> it = context.performIteratedQuery(ObjectSelect.query(Artist.class))) {
             while (it.hasNextRow()) {
                 DataRow row = (DataRow) it.nextRow();
 
@@ -215,7 +191,7 @@ public class DataContextIteratedQueryIT extends ServerCase {
 
         assertEquals(7, tPainting.getRowCount());
 
-        try (ResultIterator<?> it = context.performIteratedQuery(SelectQuery.query(Artist.class));) {
+        try (ResultIterator<?> it = context.performIteratedQuery(ObjectSelect.query(Artist.class))) {
             while (it.hasNextRow()) {
                 DataRow row = (DataRow) it.nextRow();
 
@@ -235,7 +211,7 @@ public class DataContextIteratedQueryIT extends ServerCase {
     public void testPerformIteratedQuery_Transaction() throws Exception {
         createArtistsDataSet();
 
-        try (ResultIterator<?> it = context.performIteratedQuery(SelectQuery.query(Artist.class));) {
+        try (ResultIterator<?> it = context.performIteratedQuery(ObjectSelect.query(Artist.class))) {
             assertNull("Iterator transaction was not unbound from thread", BaseTransaction.getThreadTransaction());
         }
 
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextJoinAliasesIT.java b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextJoinAliasesIT.java
index 7eb7a14..50aa8cc 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextJoinAliasesIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextJoinAliasesIT.java
@@ -22,7 +22,7 @@ import org.apache.cayenne.Cayenne;
 import org.apache.cayenne.ObjectContext;
 import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.exp.ExpressionFactory;
-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.apache.cayenne.testdo.testmap.Artist;
@@ -101,10 +101,9 @@ public class DataContextJoinAliasesIT extends ServerCase {
         Artist picasso = Cayenne.objectForPK(context, Artist.class, 1);
         Artist dali = Cayenne.objectForPK(context, Artist.class, 2);
 
-        SelectQuery<Gallery> query = SelectQuery.query(Gallery.class);
-        query.andQualifier(ExpressionFactory.matchAllExp("|exhibitArray.artistExhibitArray.toArtist", picasso, dali));
-
-        List<Gallery> galleries = query.select(context);
+        List<Gallery> galleries = ObjectSelect.query(Gallery.class)
+                .where(ExpressionFactory.matchAllExp("|exhibitArray.artistExhibitArray.toArtist", picasso, dali))
+                .select(context);
 
         assertEquals(1, galleries.size());
         assertEquals("G1", galleries.get(0).getGalleryName());
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextNoPkIT.java b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextNoPkIT.java
index e2ce95d..051c5e9 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextNoPkIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextNoPkIT.java
@@ -23,7 +23,7 @@ import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.DataRow;
 import org.apache.cayenne.ObjectContext;
 import org.apache.cayenne.di.Inject;
-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.apache.cayenne.testdo.no_pk.NoPkTestEntity;
@@ -38,7 +38,6 @@ import java.util.List;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 
 @UseServerRuntime(CayenneProjects.NO_PK_PROJECT)
 public class DataContextNoPkIT extends ServerCase {
@@ -58,24 +57,15 @@ public class DataContextNoPkIT extends ServerCase {
         noPkTestTable.insert(2);
     }
 
-    @Test
-    public void testNoPkFetchObjects() throws Exception {
-        try {
-            List objects = context.performQuery(new SelectQuery<>(NoPkTestEntity.class));
-            fail("Query for entity with no primary key must have failed, instead we got "
-                    + objects.size()
-                    + " rows.");
-        }
-        catch (CayenneRuntimeException ex) {
-            // exception expected
-        }
+    @Test(expected = CayenneRuntimeException.class)
+    public void testNoPkFetchObjects() {
+        ObjectSelect.query(NoPkTestEntity.class).select(context);
     }
 
     @Test
-    public void testNoPkFetchDataRows() throws Exception {
-        SelectQuery<DataRow> query = SelectQuery.dataRowQuery(NoPkTestEntity.class);
+    public void testNoPkFetchDataRows() {
 
-        List<DataRow> rows = query.select(context);
+        List<DataRow> rows = ObjectSelect.dataRowQuery(NoPkTestEntity.class).select(context);
         assertNotNull(rows);
         assertEquals(2, rows.size());
 
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextOuterJoinsIT.java b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextOuterJoinsIT.java
index 7202e38..560ee7e 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextOuterJoinsIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextOuterJoinsIT.java
@@ -21,8 +21,7 @@ package org.apache.cayenne.access;
 import org.apache.cayenne.ObjectContext;
 import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.exp.ExpressionFactory;
-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.testmap.Artist;
@@ -82,11 +81,10 @@ public class DataContextOuterJoinsIT extends ServerCase {
 		artistGroupHelper.insert(1, 33002);
 		artistGroupHelper.insert(1, 33004);
 
-		SelectQuery<Artist> missingToManyQuery = new SelectQuery<>(Artist.class);
-		missingToManyQuery.andQualifier(Artist.GROUP_ARRAY.outer().isNull());
-		missingToManyQuery.addOrdering(Artist.ARTIST_NAME.asc());
-
-		List<Artist> artists = missingToManyQuery.select(context);
+		List<Artist> artists = ObjectSelect.query(Artist.class)
+				.where(Artist.GROUP_ARRAY.outer().isNull())
+				.orderBy(Artist.ARTIST_NAME.asc())
+				.select(context);
 		assertEquals(1, artists.size());
 		assertEquals("BB1", artists.get(0).getArtistName());
 	}
@@ -102,20 +100,18 @@ public class DataContextOuterJoinsIT extends ServerCase {
 		paintingHelper.insert(33001, 33001, "P1");
 		paintingHelper.insert(33002, 33002, "P2");
 
-		SelectQuery<Artist> missingToManyQuery = SelectQuery.query(Artist.class);
-		missingToManyQuery.andQualifier(Artist.PAINTING_ARRAY.outer().isNull());
-		missingToManyQuery.addOrdering(Artist.ARTIST_NAME.asc());
-
-		List<Artist> artists = missingToManyQuery.select(context);
+		List<Artist> artists = ObjectSelect.query(Artist.class)
+				.where(Artist.PAINTING_ARRAY.outer().isNull())
+				.orderBy(Artist.ARTIST_NAME.asc())
+				.select(context);
 		assertEquals(2, artists.size());
 		assertEquals("BB1", artists.get(0).getArtistName());
 
-		SelectQuery<Artist> mixedConditionQuery = SelectQuery.query(Artist.class);
-		mixedConditionQuery.andQualifier(Artist.PAINTING_ARRAY.outer().isNull());
-		mixedConditionQuery.orQualifier(Artist.ARTIST_NAME.eq("AA1"));
-		mixedConditionQuery.addOrdering(Artist.ARTIST_NAME.asc());
-
-		artists = mixedConditionQuery.select(context);
+		artists = ObjectSelect.query(Artist.class)
+				.where(Artist.PAINTING_ARRAY.outer().isNull())
+				.or(Artist.ARTIST_NAME.eq("AA1"))
+				.orderBy(Artist.ARTIST_NAME.asc())
+				.select(context);
 		assertEquals(3, artists.size());
 		assertEquals("AA1", artists.get(0).getArtistName());
 		assertEquals("BB1", artists.get(1).getArtistName());
@@ -133,20 +129,18 @@ public class DataContextOuterJoinsIT extends ServerCase {
 		paintingHelper.insert(33001, 33001, "P1");
 		paintingHelper.insert(33002, 33002, "P2");
 
-		SelectQuery<Artist> missingToManyQuery = new SelectQuery<>(Artist.class);
-		missingToManyQuery.andQualifier(ExpressionFactory.exp("paintingArray+ = null"));
-		missingToManyQuery.addOrdering(Artist.ARTIST_NAME.asc());
-
-		List<Artist> artists = missingToManyQuery.select(context);
+		List<Artist> artists = ObjectSelect.query(Artist.class)
+				.where(ExpressionFactory.exp("paintingArray+ = null"))
+				.orderBy(Artist.ARTIST_NAME.asc())
+				.select(context);
 		assertEquals(2, artists.size());
 		assertEquals("BB1", artists.get(0).getArtistName());
 
-		SelectQuery<Artist> mixedConditionQuery = new SelectQuery<>(Artist.class);
-		mixedConditionQuery.andQualifier(Artist.PAINTING_ARRAY.outer().isNull());
-		mixedConditionQuery.orQualifier(Artist.ARTIST_NAME.eq("AA1"));
-		mixedConditionQuery.addOrdering(Artist.ARTIST_NAME.asc());
-
-		artists = mixedConditionQuery.select(context);
+		artists = ObjectSelect.query(Artist.class)
+				.where(ExpressionFactory.exp("paintingArray+ = null"))
+				.or(Artist.ARTIST_NAME.eq("AA1"))
+				.orderBy(Artist.ARTIST_NAME.asc())
+				.select(context);
 		assertEquals(3, artists.size());
 		assertEquals("AA1", artists.get(0).getArtistName());
 		assertEquals("BB1", artists.get(1).getArtistName());
@@ -163,11 +157,9 @@ public class DataContextOuterJoinsIT extends ServerCase {
 		paintingHelper.insert(33002, 33002, "P2");
 		paintingHelper.insert(33003, null, "P3");
 
-		SelectQuery<Painting> query = new SelectQuery<>(Painting.class);
-
-		query.addOrdering("toArtist+.artistName", SortOrder.DESCENDING);
-
-		List<Painting> paintings = query.select(context);
+		List<Painting> paintings = ObjectSelect.query(Painting.class)
+				.orderBy(Painting.TO_ARTIST.outer().dot(Artist.ARTIST_NAME).desc())
+				.select(context);
 		assertEquals(3, paintings.size());
 	}
 }
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextPrefetchMultistepIT.java b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextPrefetchMultistepIT.java
index afffb4d..465b6c1 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextPrefetchMultistepIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextPrefetchMultistepIT.java
@@ -25,10 +25,7 @@ import org.apache.cayenne.PersistenceState;
 import org.apache.cayenne.Persistent;
 import org.apache.cayenne.ValueHolder;
 import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.exp.Expression;
-import org.apache.cayenne.exp.ExpressionFactory;
-import org.apache.cayenne.query.PrefetchTreeNode;
-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.apache.cayenne.testdo.testmap.ArtistExhibit;
@@ -42,7 +39,6 @@ import org.junit.Before;
 import org.junit.Test;
 
 import java.sql.Timestamp;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -111,7 +107,6 @@ public class DataContextPrefetchMultistepIT extends ServerCase {
 
     @Test
     public void testToManyToManyFirstStepUnresolved() throws Exception {
-
         createTwoArtistsWithExhibitsDataSet();
 
         // since objects for the phantom prefetches are not retained explicitly, they may
@@ -135,11 +130,10 @@ public class DataContextPrefetchMultistepIT extends ServerCase {
         assertNull(context.getGraphManager().getNode(oid1));
         assertNull(context.getGraphManager().getNode(oid2));
 
-        Expression e = ExpressionFactory.exp("galleryName = $name");
-        SelectQuery<Gallery> q = SelectQuery.query(Gallery.class, e.params(Collections.singletonMap("name", "gallery2")));
-        q.addPrefetch("exhibitArray.artistExhibitArray");
-
-        List<Gallery> galleries = context.select(q);
+        List<Gallery> galleries = ObjectSelect.query(Gallery.class)
+                .where(Gallery.GALLERY_NAME.eq("gallery2"))
+                .prefetch(Gallery.EXHIBIT_ARRAY.dot(Exhibit.ARTIST_EXHIBIT_ARRAY).disjoint())
+                .select(context);
         assertEquals(1, galleries.size());
 
         Gallery g2 = galleries.get(0);
@@ -160,16 +154,13 @@ public class DataContextPrefetchMultistepIT extends ServerCase {
 
     @Test
     public void testToManyToManyFirstStepResolved() throws Exception {
-
         createTwoArtistsWithExhibitsDataSet();
 
-        Expression e = ExpressionFactory.exp("galleryName = $name");
-        SelectQuery<Gallery> q = SelectQuery.query(Gallery.class, e.params(Collections
-                .singletonMap("name", "gallery2")));
-        q.addPrefetch("exhibitArray");
-        q.addPrefetch("exhibitArray.artistExhibitArray");
-
-        List<Gallery> galleries = context.select(q);
+        List<Gallery> galleries = ObjectSelect.query(Gallery.class)
+                .where(Gallery.GALLERY_NAME.eq("gallery2"))
+                .prefetch(Gallery.EXHIBIT_ARRAY.disjoint())
+                .prefetch(Gallery.EXHIBIT_ARRAY.dot(Exhibit.ARTIST_EXHIBIT_ARRAY).disjoint())
+                .select(context);
         assertEquals(1, galleries.size());
 
         Gallery g2 = galleries.get(0);
@@ -185,8 +176,7 @@ public class DataContextPrefetchMultistepIT extends ServerCase {
 
         // this to-many must also be resolved
         assertTrue(e1.readPropertyDirectly("artistExhibitArray") instanceof ValueHolder);
-        List<ArtistExhibit> aexhibits = (List<ArtistExhibit>) e1
-                .readPropertyDirectly("artistExhibitArray");
+        List<ArtistExhibit> aexhibits = (List<ArtistExhibit>) e1.readPropertyDirectly("artistExhibitArray");
         assertFalse(((ValueHolder) aexhibits).isFault());
         assertEquals(1, exhibits.size());
 
@@ -196,17 +186,13 @@ public class DataContextPrefetchMultistepIT extends ServerCase {
 
     @Test
     public void testMixedPrefetch1() throws Exception {
-
         createTwoArtistsWithExhibitsDataSet();
 
-        Expression e = ExpressionFactory.exp("galleryName = $name");
-        SelectQuery<Gallery> q = SelectQuery.query(Gallery.class, e.params(Collections
-                .singletonMap("name", "gallery2")));
-        q.addPrefetch("exhibitArray").setSemantics(
-                PrefetchTreeNode.JOINT_PREFETCH_SEMANTICS);
-        q.addPrefetch("exhibitArray.artistExhibitArray");
-
-        List<Gallery> galleries = context.select(q);
+        List<Gallery> galleries = ObjectSelect.query(Gallery.class)
+                .where(Gallery.GALLERY_NAME.eq("gallery2"))
+                .prefetch(Gallery.EXHIBIT_ARRAY.joint())
+                .prefetch(Gallery.EXHIBIT_ARRAY.dot(Exhibit.ARTIST_EXHIBIT_ARRAY).disjoint())
+                .select(context);
         assertEquals(1, galleries.size());
 
         Gallery g2 = galleries.get(0);
@@ -222,8 +208,7 @@ public class DataContextPrefetchMultistepIT extends ServerCase {
 
         // this to-many must also be resolved
         assertTrue(e1.readPropertyDirectly("artistExhibitArray") instanceof ValueHolder);
-        List<ArtistExhibit> aexhibits = (List<ArtistExhibit>) e1
-                .readPropertyDirectly("artistExhibitArray");
+        List<ArtistExhibit> aexhibits = (List<ArtistExhibit>) e1.readPropertyDirectly("artistExhibitArray");
         assertFalse(((ValueHolder) aexhibits).isFault());
         assertEquals(2, aexhibits.size());
 
@@ -233,18 +218,13 @@ public class DataContextPrefetchMultistepIT extends ServerCase {
 
     @Test
     public void testMixedPrefetch2() throws Exception {
-
         createTwoArtistsWithExhibitsDataSet();
 
-        Expression e = ExpressionFactory.exp("galleryName = $name");
-        SelectQuery<Gallery> q = SelectQuery.query(Gallery.class, e.params(Collections
-                .singletonMap("name", "gallery2")));
-
-        // reverse the order of prefetches compared to the previous test
-        q.addPrefetch("exhibitArray");
-        q.addPrefetch("exhibitArray.artistExhibitArray").setSemantics(PrefetchTreeNode.JOINT_PREFETCH_SEMANTICS);
-
-        List<Gallery> galleries = context.select(q);
+        List<Gallery> galleries = ObjectSelect.query(Gallery.class)
+                .where(Gallery.GALLERY_NAME.eq("gallery2"))
+                .prefetch(Gallery.EXHIBIT_ARRAY.disjoint())
+                .prefetch(Gallery.EXHIBIT_ARRAY.dot(Exhibit.ARTIST_EXHIBIT_ARRAY).joint())
+                .select(context);
         assertEquals(1, galleries.size());
 
         Gallery g2 = galleries.get(0);
@@ -260,8 +240,7 @@ public class DataContextPrefetchMultistepIT extends ServerCase {
 
         // this to-many must also be resolved
         assertTrue(e1.readPropertyDirectly("artistExhibitArray") instanceof ValueHolder);
-        List<ArtistExhibit> aexhibits = (List<ArtistExhibit>) e1
-                .readPropertyDirectly("artistExhibitArray");
+        List<ArtistExhibit> aexhibits = (List<ArtistExhibit>) e1.readPropertyDirectly("artistExhibitArray");
         assertFalse(((ValueHolder) aexhibits).isFault());
         assertEquals(2, aexhibits.size());
 
@@ -271,14 +250,13 @@ public class DataContextPrefetchMultistepIT extends ServerCase {
 
     @Test
     public void testToManyToOne_EmptyToMany() throws Exception {
-
         createGalleriesAndArtists();
 
-        SelectQuery<Gallery> q = SelectQuery.query(Gallery.class, Gallery.GALLERY_NAME.eq("gallery2"));
-        q.addPrefetch(Gallery.PAINTING_ARRAY.disjoint());
-        q.addPrefetch(Gallery.PAINTING_ARRAY.dot(Painting.TO_ARTIST).disjoint());
-
-        List<Gallery> galleries = context.select(q);
+        List<Gallery> galleries = ObjectSelect.query(Gallery.class)
+                .where(Gallery.GALLERY_NAME.eq("gallery2"))
+                .prefetch(Gallery.PAINTING_ARRAY.disjoint())
+                .prefetch(Gallery.PAINTING_ARRAY.dot(Painting.TO_ARTIST).disjoint())
+                .select(context);
         assertEquals(1, galleries.size());
 
         Gallery g2 = galleries.get(0);
@@ -292,14 +270,12 @@ public class DataContextPrefetchMultistepIT extends ServerCase {
 
     @Test
     public void testToManyToOne_EmptyToMany_NoRootQualifier() throws Exception {
-
         createGalleriesAndArtists();
 
-        SelectQuery<Gallery> q = SelectQuery.query(Gallery.class);
-        q.addPrefetch(Gallery.PAINTING_ARRAY.disjoint());
-        q.addPrefetch(Gallery.PAINTING_ARRAY.dot(Painting.TO_ARTIST).disjoint());
-
-        List<Gallery> galleries = context.select(q);
+        List<Gallery> galleries = ObjectSelect.query(Gallery.class)
+                .prefetch(Gallery.PAINTING_ARRAY.disjoint())
+                .prefetch(Gallery.PAINTING_ARRAY.dot(Painting.TO_ARTIST).disjoint())
+                .select(context);
         assertEquals(3, galleries.size());
 
         Gallery g = galleries.get(0);
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextQueryCachingIT.java b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextQueryCachingIT.java
index 582d9b8..f61e516 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextQueryCachingIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextQueryCachingIT.java
@@ -24,9 +24,9 @@ import org.apache.cayenne.DataRow;
 import org.apache.cayenne.cache.MapQueryCache;
 import org.apache.cayenne.cache.QueryCache;
 import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.query.ObjectSelect;
 import org.apache.cayenne.query.QueryCacheStrategy;
 import org.apache.cayenne.query.QueryMetadata;
-import org.apache.cayenne.query.SelectQuery;
 import org.apache.cayenne.test.jdbc.DBHelper;
 import org.apache.cayenne.test.jdbc.TableHelper;
 import org.apache.cayenne.testdo.testmap.Artist;
@@ -102,8 +102,7 @@ public class DataContextQueryCachingIT extends ServerCase {
 
     @Test
     public void testLocalCacheDataRowsRefresh() throws Exception {
-        SelectQuery<DataRow> select = SelectQuery.dataRowQuery(Artist.class);
-        select.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
+        ObjectSelect<DataRow> select = ObjectSelect.dataRowQuery(Artist.class).localCache();
 
         MockDataNode engine = MockDataNode.interceptNode(domain, getNode());
 
@@ -141,8 +140,7 @@ public class DataContextQueryCachingIT extends ServerCase {
     @Test
     public void testSharedCacheDataRowsRefresh() throws Exception {
 
-        SelectQuery<DataRow> select = SelectQuery.dataRowQuery(Artist.class);
-        select.setCacheStrategy(QueryCacheStrategy.SHARED_CACHE);
+        ObjectSelect<DataRow> select = ObjectSelect.dataRowQuery(Artist.class).sharedCache();
 
         MockDataNode engine = MockDataNode.interceptNode(domain, getNode());
 
@@ -182,8 +180,7 @@ public class DataContextQueryCachingIT extends ServerCase {
     @Test
     public void testLocalCacheDataObjectsRefresh() throws Exception {
 
-        SelectQuery<Artist> select = new SelectQuery<>(Artist.class);
-        select.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
+        ObjectSelect<Artist> select = ObjectSelect.query(Artist.class).localCache();
 
         MockDataNode engine = MockDataNode.interceptNode(domain, getNode());
 
@@ -223,12 +220,12 @@ public class DataContextQueryCachingIT extends ServerCase {
     public void testLocalCacheRefreshObjectsRefresh() throws Exception {
         createInsertDataSet();
 
-        SelectQuery<Artist> select = new SelectQuery<>(Artist.class);
-        select.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE_REFRESH);
+        ObjectSelect<Artist> query = ObjectSelect.query(Artist.class)
+                .cacheStrategy(QueryCacheStrategy.LOCAL_CACHE_REFRESH);
 
         // no cache yet...
 
-        List<Artist> objects1 = context.performQuery(select);
+        List<Artist> objects1 = query.select(context);
         assertEquals(1, objects1.size());
         Artist a1 = objects1.get(0);
         assertEquals("aaa", a1.getArtistName());
@@ -237,7 +234,7 @@ public class DataContextQueryCachingIT extends ServerCase {
 
         createUpdateDataSet1();
 
-        List<?> objects2 = context.performQuery(select);
+        List<?> objects2 = query.select(context);
         assertEquals(1, objects2.size());
         Artist a2 = (Artist) objects2.get(0);
         assertSame(a1, a2);
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextSelectQuerySplitAliasesIT.java b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextSelectQuerySplitAliasesIT.java
index 71caf7a..51c0d1a 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextSelectQuerySplitAliasesIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextSelectQuerySplitAliasesIT.java
@@ -34,6 +34,10 @@ import java.util.List;
 
 import static org.junit.Assert.assertEquals;
 
+/**
+ * @deprecated as part of deprecation of SelectQuery
+ */
+@Deprecated
 @UseServerRuntime(CayenneProjects.TESTMAP_PROJECT)
 public class DataContextSelectQuerySplitAliasesIT extends ServerCase {
 
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/EmbeddingIT.java b/cayenne-server/src/test/java/org/apache/cayenne/access/EmbeddingIT.java
index 2df551e..87797ad 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/EmbeddingIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/EmbeddingIT.java
@@ -18,15 +18,11 @@
  ****************************************************************/
 package org.apache.cayenne.access;
 
-import org.apache.cayenne.Cayenne;
 import org.apache.cayenne.DataRow;
 import org.apache.cayenne.ObjectContext;
 import org.apache.cayenne.PersistenceState;
 import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.exp.Expression;
-import org.apache.cayenne.exp.ExpressionFactory;
 import org.apache.cayenne.query.ObjectSelect;
-import org.apache.cayenne.query.SelectQuery;
 import org.apache.cayenne.test.jdbc.DBHelper;
 import org.apache.cayenne.test.jdbc.TableHelper;
 import org.apache.cayenne.testdo.embeddable.EmbedEntity1;
@@ -74,13 +70,10 @@ public class EmbeddingIT extends ServerCase {
     public void testSelect() throws Exception {
         createSelectDataSet();
 
-        SelectQuery query = new SelectQuery<>(EmbedEntity1.class);
-        query.addOrdering(EmbedEntity1.NAME.asc());
-
-        List<?> results = context.performQuery(query);
+        List<EmbedEntity1> results = ObjectSelect.query(EmbedEntity1.class).orderBy(EmbedEntity1.NAME.asc()).select(context);
         assertEquals(2, results.size());
 
-        EmbedEntity1 o1 = (EmbedEntity1) results.get(0);
+        EmbedEntity1 o1 = results.get(0);
 
         assertEquals("n1", o1.getName());
         Embeddable1 e11 = o1.getEmbedded1();
@@ -93,7 +86,7 @@ public class EmbeddingIT extends ServerCase {
         assertEquals("e3", e12.getEmbedded10());
         assertEquals("e4", e12.getEmbedded20());
 
-        EmbedEntity1 o2 = (EmbedEntity1) results.get(1);
+        EmbedEntity1 o2 = results.get(1);
 
         assertEquals("n2", o2.getName());
         Embeddable1 e21 = o2.getEmbedded1();
@@ -120,7 +113,7 @@ public class EmbeddingIT extends ServerCase {
     }
 
     @Test
-    public void testInsert() throws Exception {
+    public void testInsert() {
 
         EmbedEntity1 o1 = context.newObject(EmbedEntity1.class);
         o1.setName("NAME");
@@ -141,8 +134,7 @@ public class EmbeddingIT extends ServerCase {
 
         context.commitChanges();
 
-        SelectQuery<DataRow> query = SelectQuery.dataRowQuery(EmbedEntity1.class);
-        DataRow row = query.selectOne(context);
+        DataRow row = ObjectSelect.dataRowQuery(EmbedEntity1.class).selectOne(context);
         assertNotNull(row);
         assertEquals("E11", row.get("EMBEDDED10"));
         assertEquals("E12", row.get("EMBEDDED20"));
@@ -154,11 +146,8 @@ public class EmbeddingIT extends ServerCase {
     public void testUpdateEmbeddedProperties() throws Exception {
         createUpdateDataSet();
 
-        SelectQuery query = new SelectQuery<>(EmbedEntity1.class);
-        query.addOrdering(EmbedEntity1.NAME.asc());
-
-        List<?> results = context.performQuery(query);
-        EmbedEntity1 o1 = (EmbedEntity1) results.get(0);
+        List<EmbedEntity1> results = ObjectSelect.query(EmbedEntity1.class).orderBy(EmbedEntity1.NAME.asc()).select(context);
+        EmbedEntity1 o1 = results.get(0);
 
         Embeddable1 e11 = o1.getEmbedded1();
         e11.setEmbedded10("x1");
@@ -166,8 +155,8 @@ public class EmbeddingIT extends ServerCase {
         assertEquals(PersistenceState.MODIFIED, o1.getPersistenceState());
 
         context.commitChanges();
-        SelectQuery<DataRow> query1 = SelectQuery.dataRowQuery(EmbedEntity1.class);
-        DataRow row = (DataRow) Cayenne.objectForQuery(context, query1);
+
+        DataRow row = ObjectSelect.dataRowQuery(EmbedEntity1.class).selectOne(context);
         assertNotNull(row);
         assertEquals("x1", row.get("EMBEDDED10"));
     }
@@ -176,11 +165,8 @@ public class EmbeddingIT extends ServerCase {
     public void testUpdateEmbedded() throws Exception {
         createUpdateDataSet();
 
-        SelectQuery query = new SelectQuery<>(EmbedEntity1.class);
-        query.addOrdering(EmbedEntity1.NAME.asc());
-
-        List<?> results = context.performQuery(query);
-        EmbedEntity1 o1 = (EmbedEntity1) results.get(0);
+        List<EmbedEntity1> results = ObjectSelect.query(EmbedEntity1.class).orderBy(EmbedEntity1.NAME.asc()).select(context);
+        EmbedEntity1 o1 = results.get(0);
 
         Embeddable1 e11 = new Embeddable1();
         e11.setEmbedded10("x1");
@@ -190,8 +176,8 @@ public class EmbeddingIT extends ServerCase {
         assertEquals(PersistenceState.MODIFIED, o1.getPersistenceState());
 
         context.commitChanges();
-        SelectQuery<DataRow> query1 = SelectQuery.dataRowQuery(EmbedEntity1.class);
-        DataRow row = query1.selectOne(context);
+
+        DataRow row = ObjectSelect.dataRowQuery(EmbedEntity1.class).selectOne(context);
         assertNotNull(row);
         assertEquals("x1", row.get("EMBEDDED10"));
     }
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/JointPrefetchIT.java b/cayenne-server/src/test/java/org/apache/cayenne/access/JointPrefetchIT.java
index a7f9e21..18ad1d8 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/JointPrefetchIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/JointPrefetchIT.java
@@ -26,12 +26,11 @@ import org.apache.cayenne.PersistenceState;
 import org.apache.cayenne.ValueHolder;
 import org.apache.cayenne.configuration.server.ServerRuntime;
 import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.exp.Expression;
 import org.apache.cayenne.map.ObjAttribute;
 import org.apache.cayenne.map.ObjEntity;
+import org.apache.cayenne.query.ObjectSelect;
 import org.apache.cayenne.query.SQLSelect;
 import org.apache.cayenne.query.SQLTemplate;
-import org.apache.cayenne.query.SelectQuery;
 import org.apache.cayenne.query.SortOrder;
 import org.apache.cayenne.test.jdbc.DBHelper;
 import org.apache.cayenne.test.jdbc.TableHelper;
@@ -93,7 +92,7 @@ public class JointPrefetchIT extends ServerCase {
                 "GALLERY_ID");
     }
 
-    protected void createJointPrefetchDataSet() throws Exception {
+    private void createJointPrefetchDataSet() throws Exception {
         tGallery.insert(33001, "G1");
         tGallery.insert(33002, "G2");
         tArtist.insert(33001, "artist1");
@@ -108,13 +107,11 @@ public class JointPrefetchIT extends ServerCase {
     public void testJointPrefetch_ToOne_FetchLimit() throws Exception {
         createJointPrefetchDataSet();
 
-        SelectQuery<Painting> q = new SelectQuery<>(Painting.class);
-        q.setFetchLimit(2);
-        q.setFetchOffset(0);
-        q.addOrdering("db:PAINTING_ID", SortOrder.ASCENDING);
-        q.addPrefetch(Painting.TO_ARTIST.joint());
-
-        final List<Painting> objects = q.select(context);
+        final List<Painting> objects = ObjectSelect.query(Painting.class)
+                .limit(2).offset(0)
+                .orderBy("db:PAINTING_ID", SortOrder.ASCENDING)
+                .prefetch(Painting.TO_ARTIST.joint())
+                .select(context);
 
         queryInterceptor.runWithQueriesBlocked(() -> {
             assertEquals(2, objects.size());
@@ -131,13 +128,11 @@ public class JointPrefetchIT extends ServerCase {
     public void testJointPrefetch_ToMany_FetchLimit() throws Exception {
         createJointPrefetchDataSet();
 
-        SelectQuery<Artist> q = new SelectQuery<>(Artist.class);
-        q.setFetchLimit(2);
-        q.setFetchOffset(0);
-        q.addOrdering("db:ARTIST_ID", SortOrder.ASCENDING);
-        q.addPrefetch(Artist.PAINTING_ARRAY.joint());
-
-        final List<Artist> objects = q.select(context);
+        final List<Artist> objects = ObjectSelect.query(Artist.class)
+                .limit(2).offset(0)
+                .orderBy("db:ARTIST_ID", SortOrder.ASCENDING)
+                .prefetch(Artist.PAINTING_ARRAY.joint())
+                .select(context);
 
         queryInterceptor.runWithQueriesBlocked(() -> {
             // herein lies the limitation of prefetching combined with fetch limit -
@@ -159,11 +154,10 @@ public class JointPrefetchIT extends ServerCase {
         createJointPrefetchDataSet();
 
         // query with to-many joint prefetches
-        SelectQuery<DataRow> q = SelectQuery.dataRowQuery(Painting.class);
-        q.addOrdering("db:PAINTING_ID", SortOrder.ASCENDING);
-        q.addPrefetch(Painting.TO_ARTIST.joint());
-
-        final List<DataRow> rows = q.select(context);
+        final List<DataRow> rows = ObjectSelect.dataRowQuery(Painting.class)
+                .orderBy("db:PAINTING_ID", SortOrder.ASCENDING)
+                .prefetch(Painting.TO_ARTIST.joint())
+                .select(context);
 
         queryInterceptor.runWithQueriesBlocked(() -> {
             assertEquals(3, rows.size());
@@ -235,11 +229,10 @@ public class JointPrefetchIT extends ServerCase {
         createJointPrefetchDataSet();
 
         // query with to-many joint prefetches
-        SelectQuery<Painting> q = new SelectQuery<>(Painting.class);
-        q.addOrdering("db:PAINTING_ID", SortOrder.ASCENDING);
-        q.addPrefetch(Painting.TO_ARTIST.joint());
-
-        final List<Painting> objects = q.select(context);
+        final List<Painting> objects = ObjectSelect.query(Painting.class)
+                .orderBy("db:PAINTING_ID", SortOrder.ASCENDING)
+                .prefetch(Painting.TO_ARTIST.joint())
+                .select(context);
 
         queryInterceptor.runWithQueriesBlocked(() -> {
             assertEquals(3, objects.size());
@@ -273,15 +266,14 @@ public class JointPrefetchIT extends ServerCase {
         context.performNonSelectingQuery(paintingSQL);
 
         // test
-        SelectQuery<Painting> q = new SelectQuery<>(Painting.class);
-        q.addPrefetch(Painting.TO_ARTIST.joint());
-
         ObjEntity artistE = context.getEntityResolver().getObjEntity("Artist");
         ObjAttribute dateOfBirth = artistE.getAttribute("dateOfBirth");
         assertEquals("java.util.Date", dateOfBirth.getType());
         dateOfBirth.setType("java.sql.Date");
         try {
-            final List<Painting> objects = q.select(context);
+            final List<Painting> objects = ObjectSelect.query(Painting.class)
+                    .prefetch(Painting.TO_ARTIST.joint())
+                    .select(context);
 
             queryInterceptor.runWithQueriesBlocked(() -> {
                 assertEquals(1, objects.size());
@@ -302,10 +294,9 @@ public class JointPrefetchIT extends ServerCase {
         createJointPrefetchDataSet();
 
         // query with to-many joint prefetches
-        SelectQuery<Artist> q = new SelectQuery<>(Artist.class);
-        q.addPrefetch(Artist.PAINTING_ARRAY.joint());
-
-        final List<Artist> objects = q.select(context);
+        final List<Artist> objects = ObjectSelect.query(Artist.class)
+                .prefetch(Artist.PAINTING_ARRAY.joint())
+                .select(context);
 
         queryInterceptor.runWithQueriesBlocked(() -> {
             assertEquals(3, objects.size());
@@ -329,13 +320,11 @@ public class JointPrefetchIT extends ServerCase {
     public void testJointPrefetchToManyNonConflictingQualifier() throws Exception {
         createJointPrefetchDataSet();
 
-        // query with to-many joint prefetches and qualifier that doesn't match
-        // prefetch....
-        Expression qualifier = Artist.ARTIST_NAME.eq("artist1");
-        SelectQuery<Artist> q = new SelectQuery<>(Artist.class, qualifier);
-        q.addPrefetch(Artist.PAINTING_ARRAY.joint());
-
-        final List<Artist> objects = q.select(context);
+        // query with to-many joint prefetches and qualifier that doesn't match prefetch....
+        final List<Artist> objects = ObjectSelect.query(Artist.class)
+                .where(Artist.ARTIST_NAME.eq("artist1"))
+                .prefetch(Artist.PAINTING_ARRAY.joint())
+                .select(context);
 
         queryInterceptor.runWithQueriesBlocked(() -> {
             assertEquals(1, objects.size());
@@ -363,10 +352,6 @@ public class JointPrefetchIT extends ServerCase {
     public void testJointPrefetchMultiStep() throws Exception {
         createJointPrefetchDataSet();
 
-        // query with to-many joint prefetches
-        SelectQuery<Artist> q = new SelectQuery<>(Artist.class);
-        q.addPrefetch(Artist.PAINTING_ARRAY.dot(Painting.TO_GALLERY).joint());
-
         final DataContext context = this.context;
 
         // make sure phantomly prefetched objects are not deallocated
@@ -377,7 +362,10 @@ public class JointPrefetchIT extends ServerCase {
                 ObjectId.of("Gallery", Gallery.GALLERY_ID_PK_COLUMN, 33001));
         assertNull(g1);
 
-        final List<Artist> objects = q.select(context);
+        // query with to-many joint prefetches
+        final List<Artist> objects = ObjectSelect.query(Artist.class)
+                .prefetch(Artist.PAINTING_ARRAY.dot(Painting.TO_GALLERY).joint())
+                .select(context);
 
         queryInterceptor.runWithQueriesBlocked(() -> {
             assertEquals(3, objects.size());
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/NestedDataContextReadIT.java b/cayenne-server/src/test/java/org/apache/cayenne/access/NestedDataContextReadIT.java
index 6f3d30c..d8abe16 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/NestedDataContextReadIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/NestedDataContextReadIT.java
@@ -28,7 +28,7 @@ import org.apache.cayenne.PersistenceState;
 import org.apache.cayenne.Persistent;
 import org.apache.cayenne.configuration.server.ServerRuntime;
 import org.apache.cayenne.di.Inject;
-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.apache.cayenne.testdo.testmap.Artist;
@@ -160,7 +160,7 @@ public class NestedDataContextReadIT extends ServerCase {
         assertEquals(PersistenceState.DELETED, deleted.getPersistenceState());
         assertEquals(PersistenceState.NEW, _new.getPersistenceState());
 
-        List<Artist> objects = new SelectQuery<>(Artist.class).select(child);
+        List<Artist> objects = ObjectSelect.query(Artist.class).select(child);
         assertEquals("All but NEW object must have been included", 4, objects.size());
 
         for (Artist next : objects) {
@@ -179,12 +179,11 @@ public class NestedDataContextReadIT extends ServerCase {
         createArtistsDataSet();
         ObjectContext child = runtime.newContext(context);
 
-        SelectQuery<Artist> query = SelectQuery.query(Artist.class);
-        query.addOrdering(Artist.ARTIST_NAME.desc());
-        query.setPageSize(1);
-
         @SuppressWarnings("unchecked")
-        IncrementalFaultList<Artist> records = (IncrementalFaultList) child.performQuery(query);
+        IncrementalFaultList<Artist> records = (IncrementalFaultList) ObjectSelect.query(Artist.class)
+                .orderBy(Artist.ARTIST_NAME.desc())
+                .pageSize(1)
+                .select(child);
 
         assertEquals(4, records.size());
         assertEquals(1, records.getPageSize());
@@ -235,9 +234,9 @@ public class NestedDataContextReadIT extends ServerCase {
         assertEquals(PersistenceState.NEW, newTarget.getPersistenceState());
 
         // run an ordered query, so we can address specific objects directly by index
-        SelectQuery<Painting> q = new SelectQuery<>(Painting.class);
-        q.addOrdering(Painting.PAINTING_TITLE.asc());
-        final List<Painting> childSources = q.select(child);
+        final List<Painting> childSources = ObjectSelect.query(Painting.class)
+                .orderBy(Painting.PAINTING_TITLE.asc())
+                .select(child);
         assertEquals(5, childSources.size());
 
         queryInterceptor.runWithQueriesBlocked(() -> {
@@ -288,11 +287,10 @@ public class NestedDataContextReadIT extends ServerCase {
                 Artist.ARTIST_ID_PK_COLUMN,
                 33001);
 
-        SelectQuery<Painting> q = new SelectQuery<>(Painting.class);
-        q.addOrdering(Painting.PAINTING_TITLE.asc());
-        q.addPrefetch(Painting.TO_ARTIST.disjoint());
-
-        final List<Painting> results = q.select(child);
+        final List<Painting> results = ObjectSelect.query(Painting.class)
+                .orderBy(Painting.PAINTING_TITLE.asc())
+                .prefetch(Painting.TO_ARTIST.disjoint())
+                .select(child);
 
         // blockQueries();
 
@@ -317,11 +315,10 @@ public class NestedDataContextReadIT extends ServerCase {
 
         final ObjectContext child = runtime.newContext(context);
 
-        SelectQuery<Artist> q = new SelectQuery<>(Artist.class);
-        q.addOrdering(Artist.ARTIST_NAME.asc());
-        q.addPrefetch(Artist.PAINTING_ARRAY.disjoint());
-
-        final List<Artist> results = q.select(child);
+        final List<Artist> results = ObjectSelect.query(Artist.class)
+                .orderBy(Artist.ARTIST_NAME.asc())
+                .prefetch(Artist.PAINTING_ARRAY.disjoint())
+                .select(child);
 
         queryInterceptor.runWithQueriesBlocked(() -> {
             Artist o1 = results.get(0);
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/QuotedIdentifiersIT.java b/cayenne-server/src/test/java/org/apache/cayenne/access/QuotedIdentifiersIT.java
index 09d374f..d73d594 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/QuotedIdentifiersIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/QuotedIdentifiersIT.java
@@ -26,8 +26,8 @@ import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.query.EJBQLQuery;
 import org.apache.cayenne.query.ObjectIdQuery;
+import org.apache.cayenne.query.ObjectSelect;
 import org.apache.cayenne.query.RelationshipQuery;
-import org.apache.cayenne.query.SelectQuery;
 import org.apache.cayenne.query.UpdateBatchQuery;
 import org.apache.cayenne.test.jdbc.DBHelper;
 import org.apache.cayenne.testdo.quotemap.QuoteAdress;
@@ -82,12 +82,10 @@ public class QuotedIdentifiersIT extends ServerCase {
 
     @Test
     public void testDataSetup() {
-        SelectQuery<QuoteAdress> q = SelectQuery.query(QuoteAdress.class);
-        List<QuoteAdress> objects = q.select(context);
+        List<QuoteAdress> objects = ObjectSelect.query(QuoteAdress.class).select(context);
         assertEquals(2, objects.size());
 
-        SelectQuery<Quote_Person> qQuote_Person = SelectQuery.query(Quote_Person.class);
-        List<Quote_Person> objects2 = qQuote_Person.select(context);
+        List<Quote_Person> objects2 = ObjectSelect.query(Quote_Person.class).select(context);
         assertEquals(2, objects2.size());
     }
 
@@ -117,12 +115,10 @@ public class QuotedIdentifiersIT extends ServerCase {
 
         context.commitChanges();
 
-        SelectQuery<QuoteAdress> q = SelectQuery.query(QuoteAdress.class);
-        List<QuoteAdress> objects = q.select(context);
+        List<QuoteAdress> objects = ObjectSelect.query(QuoteAdress.class).select(context);
         assertEquals(4, objects.size());
 
-        SelectQuery<Quote_Person> qQuote_Person = SelectQuery.query(Quote_Person.class);
-        List<Quote_Person> objects2 = qQuote_Person.select(context);
+        List<Quote_Person> objects2 = ObjectSelect.query(Quote_Person.class).select(context);
         assertEquals(4, objects2.size());
     }
 
@@ -137,20 +133,16 @@ public class QuotedIdentifiersIT extends ServerCase {
         List objects3 = context.performQuery(updateQuery);
         assertEquals(0, objects3.size());
 
-        SelectQuery<Quote_Person> qQuote_Person2 = SelectQuery.query(Quote_Person.class);
-        List<Quote_Person> objects4 = qQuote_Person2.select(context);
+        List<Quote_Person> objects4 = ObjectSelect.query(Quote_Person.class).select(context);
         assertEquals(2, objects4.size());
 
-        SelectQuery<Quote_Person> qQuote_Person3 = SelectQuery.query(Quote_Person.class, ExpressionFactory.matchExp("salary", 100));
-        List<Quote_Person> objects5 = qQuote_Person3.select(context);
+        List<Quote_Person> objects5 = ObjectSelect.query(Quote_Person.class, Quote_Person.SALARY.eq(100)).select(context);
         assertEquals(1, objects5.size());
 
-        SelectQuery<Quote_Person> qQuote_Person4 = SelectQuery.query(Quote_Person.class, ExpressionFactory.matchExp("group", "107324"));
-        List<Quote_Person> objects6 = qQuote_Person4.select(context);
+        List<Quote_Person> objects6 =ObjectSelect.query(Quote_Person.class, Quote_Person.GROUP.eq("107324")).select(context);
         assertEquals(1, objects6.size());
 
-        SelectQuery<QuoteAdress> quoteAdress1 = SelectQuery.query(QuoteAdress.class, ExpressionFactory.matchExp("group", "324"));
-        List<QuoteAdress> objects7 = quoteAdress1.select(context);
+        List<QuoteAdress> objects7 = ObjectSelect.query(QuoteAdress.class, QuoteAdress.GROUP.eq("324")).select(context);
         assertEquals(1, objects7.size());
 
         ObjectIdQuery queryObjectId = new ObjectIdQuery(ObjectId.of("QuoteAdress", QuoteAdress.GROUP.getName(), "324"));
@@ -162,8 +154,7 @@ public class QuotedIdentifiersIT extends ServerCase {
         List objects9 = context.performQuery(queryObjectId2);
         assertEquals(1, objects9.size());
 
-        SelectQuery<Quote_Person> person2Query = SelectQuery.query(Quote_Person.class, ExpressionFactory.matchExp("name", "Name"));
-        Quote_Person quote_Person2 = person2Query.select(context).get(0);
+        Quote_Person quote_Person2 = ObjectSelect.query(Quote_Person.class, Quote_Person.NAME.eq("Name")).selectOne(context);
 
         RelationshipQuery relationshipQuery = new RelationshipQuery(quote_Person2.getObjectId(), "address_Rel");
         List objects10 = context.performQuery(relationshipQuery);
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/SimpleIdIncrementalFaultListDataRowsIT.java b/cayenne-server/src/test/java/org/apache/cayenne/access/SimpleIdIncrementalFaultListDataRowsIT.java
index 181a1e9..3808fe1 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/SimpleIdIncrementalFaultListDataRowsIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/SimpleIdIncrementalFaultListDataRowsIT.java
@@ -21,9 +21,7 @@ package org.apache.cayenne.access;
 
 import org.apache.cayenne.DataRow;
 import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.exp.Expression;
-import org.apache.cayenne.exp.ExpressionFactory;
-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;
@@ -65,10 +63,8 @@ public class SimpleIdIncrementalFaultListDataRowsIT extends ServerCase {
         tArtist.setColumns("ARTIST_ID", "ARTIST_NAME");
         createArtistsDataSet();
 
-        SelectQuery q = SelectQuery.dataRowQuery(Artist.class);
-        q.setPageSize(6);
-        q.addOrdering("db:ARTIST_ID", SortOrder.ASCENDING);
-
+        ObjectSelect<DataRow> q = ObjectSelect.dataRowQuery(Artist.class)
+                .pageSize(6).orderBy("db:ARTIST_ID", SortOrder.ASCENDING);
         list = new SimpleIdIncrementalFaultList<>(context, q, 10000);
     }
 
@@ -101,7 +97,7 @@ public class SimpleIdIncrementalFaultListDataRowsIT extends ServerCase {
     }
 
     @Test
-    public void testGet1() throws Exception {
+    public void testGet1() {
         assertEquals(1, list.idWidth);
         assertTrue(list.elements.get(0) instanceof Long);
         assertTrue(list.elements.get(19) instanceof Long);
@@ -115,15 +111,12 @@ public class SimpleIdIncrementalFaultListDataRowsIT extends ServerCase {
     }
 
     @Test
-    public void testIndexOf1() throws Exception {
-
-        Expression qual = ExpressionFactory.matchExp("artistName", "artist20");
-        SelectQuery<DataRow> query = SelectQuery.dataRowQuery(Artist.class, qual);
-        List<?> artists = context1.performQuery(query);
+    public void testIndexOf1() {
+        List<DataRow> artists = ObjectSelect.dataRowQuery(Artist.class, Artist.ARTIST_NAME.eq("artist20")).select(context);
 
         assertEquals(1, artists.size());
 
-        DataRow row = (DataRow) artists.get(0);
+        DataRow row = artists.get(0);
         assertEquals(19, list.indexOf(row));
 
         DataRow clone = new DataRow(row);
@@ -134,18 +127,16 @@ public class SimpleIdIncrementalFaultListDataRowsIT extends ServerCase {
     }
 
     @Test
-    public void testIndexOf2() throws Exception {
+    public void testIndexOf2() {
 
         // resolve first page
         list.get(0);
 
-        Expression qual = ExpressionFactory.matchExp("artistName", "artist2");
-        SelectQuery<DataRow> query = SelectQuery.dataRowQuery(Artist.class, qual);
-        List<?> artists = context1.performQuery(query);
+        List<DataRow> artists =  ObjectSelect.dataRowQuery(Artist.class, Artist.ARTIST_NAME.eq("artist2")).select(context);
 
         assertEquals(1, artists.size());
 
-        DataRow row = (DataRow) artists.get(0);
+        DataRow row = artists.get(0);
         assertEquals(1, list.indexOf(row));
 
         row.remove("ARTIST_NAME");
@@ -153,18 +144,16 @@ public class SimpleIdIncrementalFaultListDataRowsIT extends ServerCase {
     }
 
     @Test
-    public void testLastIndexOf1() throws Exception {
+    public void testLastIndexOf1() {
 
         // resolve first page
         list.get(0);
 
-        Expression qual = ExpressionFactory.matchExp("artistName", "artist3");
-        SelectQuery<DataRow> query = SelectQuery.dataRowQuery(Artist.class, qual);
-        List<?> artists = context1.performQuery(query);
+        List<DataRow> artists = ObjectSelect.dataRowQuery(Artist.class, Artist.ARTIST_NAME.eq("artist3")).select(context);
 
         assertEquals(1, artists.size());
 
-        DataRow row = (DataRow) artists.get(0);
+        DataRow row = artists.get(0);
         assertEquals(2, list.lastIndexOf(row));
 
         row.remove("ARTIST_NAME");
@@ -172,15 +161,12 @@ public class SimpleIdIncrementalFaultListDataRowsIT extends ServerCase {
     }
 
     @Test
-    public void testLastIndexOf2() throws Exception {
-
-        Expression qual = ExpressionFactory.matchExp("artistName", "artist20");
-        SelectQuery<DataRow> query = SelectQuery.dataRowQuery(Artist.class, qual);
-        List<?> artists = context1.performQuery(query);
+    public void testLastIndexOf2() {
+        List<DataRow> artists = ObjectSelect.dataRowQuery(Artist.class, Artist.ARTIST_NAME.eq("artist20")).select(context);
 
         assertEquals(1, artists.size());
 
-        DataRow row = (DataRow) artists.get(0);
+        DataRow row = artists.get(0);
         assertEquals(19, list.lastIndexOf(row));
 
         row.remove("ARTIST_ID");
@@ -188,7 +174,7 @@ public class SimpleIdIncrementalFaultListDataRowsIT extends ServerCase {
     }
 
     @Test
-    public void testIterator() throws Exception {
+    public void testIterator() {
         assertEquals(1, list.idWidth);
 
         Iterator<?> it = list.iterator();
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/map/SelectQueryDescriptorTest.java b/cayenne-server/src/test/java/org/apache/cayenne/map/SelectQueryDescriptorTest.java
index 010a9af..a5f1944 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/map/SelectQueryDescriptorTest.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/map/SelectQueryDescriptorTest.java
@@ -29,6 +29,7 @@ import static org.junit.Assert.*;
 
 /**
  */
+@Deprecated
 public class SelectQueryDescriptorTest {
 
     @Test
@@ -48,7 +49,7 @@ public class SelectQueryDescriptorTest {
         builder.setRoot(entity);
 
         assertTrue(builder.buildQuery() instanceof SelectQuery);
-        assertSame(entity, ((SelectQuery) builder.buildQuery()).getRoot());
+        assertSame(entity, builder.buildQuery().getRoot());
     }
 
     @Test
@@ -57,7 +58,7 @@ public class SelectQueryDescriptorTest {
         builder.setRoot("FakeRoot");
         builder.setQualifier(ExpressionFactory.exp("abc = 5"));
 
-        SelectQuery query = (SelectQuery) builder.buildQuery();
+        SelectQuery query = builder.buildQuery();
 
         assertEquals(ExpressionFactory.exp("abc = 5"), query.getQualifier());
     }
@@ -69,11 +70,10 @@ public class SelectQueryDescriptorTest {
         builder.setProperty(QueryMetadata.FETCH_LIMIT_PROPERTY, "5");
         builder.setProperty(QueryMetadata.STATEMENT_FETCH_SIZE_PROPERTY, "6");
 
-        Query query = builder.buildQuery();
+        SelectQuery<?> query = builder.buildQuery();
         assertTrue(query instanceof SelectQuery);
-        assertEquals(5, ((SelectQuery) query).getFetchLimit());
-        
-        assertEquals(6, ((SelectQuery) query).getStatementFetchSize());
+        assertEquals(5, query.getFetchLimit());
+        assertEquals(6, query.getStatementFetchSize());
 
         // TODO: test other properties...
     }
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/query/SelectQueryTest.java b/cayenne-server/src/test/java/org/apache/cayenne/query/SelectQueryTest.java
index 0379aae..8d04906 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/query/SelectQueryTest.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/query/SelectQueryTest.java
@@ -39,6 +39,7 @@ import org.apache.cayenne.testdo.testmap.Artist;
 import org.junit.Before;
 import org.junit.Test;
 
+@Deprecated
 public class SelectQueryTest {
 
 	private SelectQuery<?> query;


Mime
View raw message