cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject cayenne git commit: CAY-2012 ObjectSelect, SelectById: eiliminating methods that reset query state
Date Mon, 11 May 2015 05:03:24 GMT
Repository: cayenne
Updated Branches:
  refs/heads/master 200ac46e7 -> 6a4d83f63


CAY-2012 ObjectSelect, SelectById: eiliminating methods that reset query state

*    addOrderBy - gone
*    orderBy - append instead of reset

*    addPrefetch - gone
*    prefetch - merge instead of reset

*    where - behave as "and" instead of reset


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

Branch: refs/heads/master
Commit: 6a4d83f63b205e4f64fe90516b5eef9a11e9ca1f
Parents: 200ac46
Author: aadamchik <aadamchik@apache.org>
Authored: Mon May 11 02:00:30 2015 +0200
Committer: aadamchik <aadamchik@apache.org>
Committed: Mon May 11 07:03:05 2015 +0200

----------------------------------------------------------------------
 .../org/apache/cayenne/query/ObjectSelect.java  | 145 +++++--------------
 .../org/apache/cayenne/query/SelectById.java    |  26 +---
 .../apache/cayenne/query/ObjectSelectTest.java  | 127 +++++-----------
 .../apache/cayenne/query/SelectByIdTest.java    |  36 ++---
 docs/doc/src/main/resources/RELEASE-NOTES.txt   |   1 +
 docs/doc/src/main/resources/UPGRADE.txt         |   3 +
 6 files changed, 103 insertions(+), 235 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/6a4d83f6/cayenne-server/src/main/java/org/apache/cayenne/query/ObjectSelect.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/query/ObjectSelect.java b/cayenne-server/src/main/java/org/apache/cayenne/query/ObjectSelect.java
index bf1564a..f4fcb7b 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/query/ObjectSelect.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/query/ObjectSelect.java
@@ -18,6 +18,12 @@
  ****************************************************************/
 package org.apache.cayenne.query;
 
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.DataRow;
 import org.apache.cayenne.ObjectContext;
@@ -30,12 +36,6 @@ import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.EntityResolver;
 import org.apache.cayenne.map.ObjEntity;
 
-import java.sql.Statement;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-
 /**
  * A selecting query providing chainable API. Can be viewed as an alternative to
  * {@link SelectQuery}.
@@ -231,23 +231,25 @@ public class ObjectSelect<T> extends IndirectQuery implements
Select<T> {
 	}
 
 	/**
-	 * Initializes or resets a qualifier expression of this query.
+	 * Appends a qualifier expression of this query. An equivalent to
+	 * {@link #and(Expression...)} that can be used a syntactic sugar.
 	 * 
 	 * @return this object
 	 */
 	public ObjectSelect<T> where(Expression expression) {
-		this.where = expression;
+		and(expression);
 		return this;
 	}
 
 	/**
-	 * Initializes or resets a qualifier expression of this query, using
-	 * provided expression String and an array of position parameters.
+	 * Appends a qualifier expression of this query, using provided expression
+	 * String and an array of position parameters. This is an equivalent to
+	 * calling "and".
 	 * 
 	 * @return this object
 	 */
 	public ObjectSelect<T> where(String expressionString, Object... parameters) {
-		this.where = ExpressionFactory.exp(expressionString, parameters);
+		and(ExpressionFactory.exp(expressionString, parameters));
 		return this;
 	}
 
@@ -347,60 +349,12 @@ public class ObjectSelect<T> extends IndirectQuery implements
Select<T> {
 	}
 
 	/**
-	 * Initializes or resets a list of orderings of this query.
+	 * Adds a list of orderings of this query.
 	 * 
 	 * @return this object
 	 */
 	public ObjectSelect<T> orderBy(Ordering... orderings) {
 
-		if (this.orderings != null) {
-			this.orderings.clear();
-		}
-
-		return addOrderBy(orderings);
-	}
-
-	/**
-	 * Initializes or resets a list of orderings of this query.
-	 * 
-	 * @return this object
-	 */
-	public ObjectSelect<T> orderBy(Collection<Ordering> orderings) {
-
-		if (this.orderings != null) {
-			this.orderings.clear();
-		}
-
-		return addOrderBy(orderings);
-	}
-
-	/**
-	 * Adds a single ascending ordering on a given property to the existing
-	 * ordering clause of this query.
-	 * 
-	 * @return this object
-	 */
-	public ObjectSelect<T> addOrderBy(String property) {
-		return addOrderBy(new Ordering(property));
-	}
-
-	/**
-	 * Adds a single ordering on a given property to the existing ordering
-	 * clause of this query.
-	 * 
-	 * @return this object
-	 */
-	public ObjectSelect<T> addOrderBy(String property, SortOrder sortOrder) {
-		return addOrderBy(new Ordering(property, sortOrder));
-	}
-
-	/**
-	 * Adds new orderings to the list of the existing orderings.
-	 * 
-	 * @return this object
-	 */
-	public ObjectSelect<T> addOrderBy(Ordering... orderings) {
-
 		if (orderings == null || orderings == null) {
 			return this;
 		}
@@ -417,11 +371,11 @@ public class ObjectSelect<T> extends IndirectQuery implements
Select<T> {
 	}
 
 	/**
-	 * Adds new orderings to the list of orderings.
+	 * Adds a list of orderings of this query.
 	 * 
 	 * @return this object
 	 */
-	public ObjectSelect<T> addOrderBy(Collection<Ordering> orderings) {
+	public ObjectSelect<T> orderBy(Collection<Ordering> orderings) {
 
 		if (orderings == null || orderings == null) {
 			return this;
@@ -437,32 +391,11 @@ public class ObjectSelect<T> extends IndirectQuery implements
Select<T> {
 	}
 
 	/**
-	 * Resets internal prefetches to the new value, which is a single prefetch
-	 * with specified semantics.
-	 * 
-	 * @return this object
-	 */
-	public ObjectSelect<T> prefetch(String path, int semantics) {
-		this.prefetches = PrefetchTreeNode.withPath(path, semantics);
-		return this;
-	}
-
-	/**
-	 * Resets internal prefetches to the new value.
-	 * 
-	 * @return this object
-	 */
-	public ObjectSelect<T> prefetch(PrefetchTreeNode prefetch) {
-		this.prefetches = prefetch;
-		return this;
-	}
-
-	/**
 	 * Merges prefetch into the query prefetch tree.
 	 * 
 	 * @return this object
 	 */
-	public ObjectSelect<T> addPrefetch(PrefetchTreeNode prefetch) {
+	public ObjectSelect<T> prefetch(PrefetchTreeNode prefetch) {
 
 		if (prefetch == null) {
 			return this;
@@ -482,7 +415,7 @@ public class ObjectSelect<T> extends IndirectQuery implements Select<T>
{
 	 * 
 	 * @return this object
 	 */
-	public ObjectSelect<T> addPrefetch(String path, int semantics) {
+	public ObjectSelect<T> prefetch(String path, int semantics) {
 
 		if (path == null) {
 			return this;
@@ -600,7 +533,7 @@ public class ObjectSelect<T> extends IndirectQuery implements Select<T>
{
 		return cacheStrategy(QueryCacheStrategy.SHARED_CACHE, cacheGroups);
 	}
 
-    public String[] getCacheGroups() {
+	public String[] getCacheGroups() {
 		return cacheGroups;
 	}
 
@@ -655,33 +588,33 @@ public class ObjectSelect<T> extends IndirectQuery implements
Select<T> {
 		return prefetches;
 	}
 
-    @Override
-    public List<T> select(ObjectContext context) {
+	@Override
+	public List<T> select(ObjectContext context) {
 		return context.select(this);
 	}
 
-    @Override
-    public T selectOne(ObjectContext context) {
+	@Override
+	public T selectOne(ObjectContext context) {
 		return context.selectOne(this);
 	}
 
-    @Override
-    public T selectFirst(ObjectContext context) {
-        return context.selectFirst(limit(1));
-    }
+	@Override
+	public T selectFirst(ObjectContext context) {
+		return context.selectFirst(limit(1));
+	}
 
-    @Override
-    public void iterate(ObjectContext context, ResultIteratorCallback<T> callback)
{
-        context.iterate((Select<T>) this, callback);
-    }
+	@Override
+	public void iterate(ObjectContext context, ResultIteratorCallback<T> callback) {
+		context.iterate((Select<T>) this, callback);
+	}
 
-    @Override
-    public ResultIterator<T> iterator(ObjectContext context) {
-        return context.iterator(this);
-    }
+	@Override
+	public ResultIterator<T> iterator(ObjectContext context) {
+		return context.iterator(this);
+	}
 
-    @Override
-    public ResultBatchIterator<T> batchIterator(ObjectContext context, int size) {
-        return context.batchIterator(this, size);
-    }
+	@Override
+	public ResultBatchIterator<T> batchIterator(ObjectContext context, int size) {
+		return context.batchIterator(this, size);
+	}
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/6a4d83f6/cayenne-server/src/main/java/org/apache/cayenne/query/SelectById.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/query/SelectById.java b/cayenne-server/src/main/java/org/apache/cayenne/query/SelectById.java
index 489537c..f9e8209 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/query/SelectById.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/query/SelectById.java
@@ -255,32 +255,11 @@ public class SelectById<T> extends IndirectQuery implements Select<T>
{
 	}
 
 	/**
-	 * Resets internal prefetches to the new value, which is a single prefetch
-	 * with specified semantics.
-	 * 
-	 * @return this object
-	 */
-	public SelectById<T> prefetch(String path, int semantics) {
-		this.prefetches = PrefetchTreeNode.withPath(path, semantics);
-		return this;
-	}
-
-	/**
-	 * Resets internal prefetches to the new value.
-	 * 
-	 * @return this object
-	 */
-	public SelectById<T> prefetch(PrefetchTreeNode prefetch) {
-		this.prefetches = prefetch;
-		return this;
-	}
-
-	/**
 	 * Merges prefetch into the query prefetch tree.
 	 * 
 	 * @return this object
 	 */
-	public SelectById<T> addPrefetch(PrefetchTreeNode prefetch) {
+	public SelectById<T> prefetch(PrefetchTreeNode prefetch) {
 
 		if (prefetch == null) {
 			return this;
@@ -300,7 +279,7 @@ public class SelectById<T> extends IndirectQuery implements Select<T>
{
 	 * 
 	 * @return this object
 	 */
-	public SelectById<T> addPrefetch(String path, int semantics) {
+	public SelectById<T> prefetch(String path, int semantics) {
 
 		if (path == null) {
 			return this;
@@ -318,6 +297,7 @@ public class SelectById<T> extends IndirectQuery implements Select<T>
{
 		return prefetches;
 	}
 
+	@SuppressWarnings("deprecation")
 	@Override
 	protected Query createReplacementQuery(EntityResolver resolver) {
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/6a4d83f6/cayenne-server/src/test/java/org/apache/cayenne/query/ObjectSelectTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/query/ObjectSelectTest.java b/cayenne-server/src/test/java/org/apache/cayenne/query/ObjectSelectTest.java
index 9a3056e..cb86ceb 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/query/ObjectSelectTest.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/query/ObjectSelectTest.java
@@ -18,25 +18,24 @@
  ****************************************************************/
 package org.apache.cayenne.query;
 
-import org.apache.cayenne.DataRow;
-import org.apache.cayenne.exp.Expression;
-import org.apache.cayenne.exp.ExpressionFactory;
-import org.apache.cayenne.testdo.testmap.Artist;
-import org.junit.Test;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNotSame;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
 
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+
+import org.apache.cayenne.DataRow;
+import org.apache.cayenne.exp.Expression;
+import org.apache.cayenne.exp.ExpressionFactory;
+import org.apache.cayenne.testdo.testmap.Artist;
+import org.junit.Test;
+
 public class ObjectSelectTest {
 
 	@Test
@@ -105,7 +104,7 @@ public class ObjectSelectTest {
 		assertEquals("a = 3", q.getWhere().toString());
 
 		q.where(ExpressionFactory.matchExp("b", 4));
-		assertEquals("b = 4", q.getWhere().toString());
+		assertEquals("(a = 3) and (b = 4)", q.getWhere().toString());
 	}
 
 	@Test
@@ -214,26 +213,6 @@ public class ObjectSelectTest {
 		q.orderBy(o2);
 
 		Object[] result2 = q.getOrderings().toArray();
-		assertEquals(1, result2.length);
-		assertSame(o2, result2[0]);
-	}
-
-	@Test
-	public void testAddOrderBy_Array() {
-
-		ObjectSelect<Artist> q = ObjectSelect.query(Artist.class);
-
-		Ordering o1 = new Ordering("x");
-		q.orderBy(o1);
-
-		Object[] result1 = q.getOrderings().toArray();
-		assertEquals(1, result1.length);
-		assertSame(o1, result1[0]);
-
-		Ordering o2 = new Ordering("y");
-		q.addOrderBy(o2);
-
-		Object[] result2 = q.getOrderings().toArray();
 		assertEquals(2, result2.length);
 		assertSame(o1, result2[0]);
 		assertSame(o2, result2[1]);
@@ -255,50 +234,12 @@ public class ObjectSelectTest {
 		q.orderBy(Collections.singletonList(o2));
 
 		Object[] result2 = q.getOrderings().toArray();
-		assertEquals(1, result2.length);
-		assertSame(o2, result2[0]);
-	}
-
-	@Test
-	public void testAddOrderBy_Collection() {
-
-		ObjectSelect<Artist> q = ObjectSelect.query(Artist.class);
-
-		Ordering o1 = new Ordering("x");
-		q.orderBy(Collections.singletonList(o1));
-
-		Object[] result1 = q.getOrderings().toArray();
-		assertEquals(1, result1.length);
-		assertSame(o1, result1[0]);
-
-		Ordering o2 = new Ordering("y");
-		q.addOrderBy(Collections.singletonList(o2));
-
-		Object[] result2 = q.getOrderings().toArray();
 		assertEquals(2, result2.length);
 		assertSame(o1, result2[0]);
 		assertSame(o2, result2[1]);
 	}
 
 	@Test
-	public void testOrderBy_Property() {
-
-		ObjectSelect<Artist> q = ObjectSelect.query(Artist.class);
-
-		q.orderBy("x");
-
-		Object[] result1 = q.getOrderings().toArray();
-		assertEquals(1, result1.length);
-		assertEquals(new Ordering("x", SortOrder.ASCENDING), result1[0]);
-
-		q.orderBy("y");
-
-		Object[] result2 = q.getOrderings().toArray();
-		assertEquals(1, result2.length);
-		assertEquals(new Ordering("y", SortOrder.ASCENDING), result2[0]);
-	}
-
-	@Test
 	public void testOrderBy_PropertyStrategy() {
 
 		ObjectSelect<Artist> q = ObjectSelect.query(Artist.class);
@@ -312,22 +253,22 @@ public class ObjectSelectTest {
 		q.orderBy("y", SortOrder.DESCENDING);
 
 		Object[] result2 = q.getOrderings().toArray();
-		assertEquals(1, result2.length);
-		assertEquals(new Ordering("y", SortOrder.DESCENDING), result2[0]);
+		assertEquals(2, result2.length);
+		assertEquals(new Ordering("y", SortOrder.DESCENDING), result2[1]);
 	}
 
 	@Test
-	public void testAddOrderBy_Property() {
+	public void testOrderBy_Property() {
 
 		ObjectSelect<Artist> q = ObjectSelect.query(Artist.class);
 
-		q.addOrderBy("x");
+		q.orderBy("x");
 
 		Object[] result1 = q.getOrderings().toArray();
 		assertEquals(1, result1.length);
 		assertEquals(new Ordering("x", SortOrder.ASCENDING), result1[0]);
 
-		q.addOrderBy("y");
+		q.orderBy("y");
 
 		Object[] result2 = q.getOrderings().toArray();
 		assertEquals(2, result2.length);
@@ -343,7 +284,10 @@ public class ObjectSelectTest {
 		ObjectSelect<Artist> q = ObjectSelect.query(Artist.class);
 		q.prefetch(root);
 
-		assertSame(root, q.getPrefetches());
+		PrefetchTreeNode root1 = q.getPrefetches();
+		assertNotNull(root1);
+		assertNotNull(root1.getNode("a.b"));
+		assertEquals(PrefetchTreeNode.JOINT_PREFETCH_SEMANTICS, root1.getNode("a.b").getSemantics());
 	}
 
 	@Test
@@ -361,26 +305,32 @@ public class ObjectSelectTest {
 
 		assertNotNull(root2);
 		assertNotNull(root2.getNode("a.c"));
-		assertNull(root2.getNode("a.b"));
-		assertNotSame(root1, root2);
+		assertNotNull(root2.getNode("a.b"));
 	}
 
 	@Test
-	public void testAddPrefetch() {
+	public void testPrefetch_Merge() {
 
 		PrefetchTreeNode root = PrefetchTreeNode.withPath("a.b", PrefetchTreeNode.JOINT_PREFETCH_SEMANTICS);
 
 		ObjectSelect<Artist> q = ObjectSelect.query(Artist.class);
 		q.prefetch(root);
 
-		assertSame(root, q.getPrefetches());
+		PrefetchTreeNode root1 = q.getPrefetches();
+		assertNotNull(root1);
+		assertNotNull(root1.getNode("a.b"));
+		assertEquals(PrefetchTreeNode.JOINT_PREFETCH_SEMANTICS, root1.getNode("a.b").getSemantics());
 
 		PrefetchTreeNode subRoot = PrefetchTreeNode.withPath("a.b.c", PrefetchTreeNode.JOINT_PREFETCH_SEMANTICS);
-		q.addPrefetch(subRoot);
+		q.prefetch(subRoot);
 
-		assertSame(root, q.getPrefetches());
+		root1 = q.getPrefetches();
+		assertNotNull(root1);
+		assertNotNull(root1.getNode("a.b"));
+		assertEquals(PrefetchTreeNode.JOINT_PREFETCH_SEMANTICS, root1.getNode("a.b").getSemantics());
 
-		assertNotNull(root.getNode("a.b.c"));
+		assertNotNull(root1.getNode("a.b.c"));
+		assertEquals(PrefetchTreeNode.JOINT_PREFETCH_SEMANTICS, root1.getNode("a.b.c").getSemantics());
 	}
 
 	@Test
@@ -394,7 +344,7 @@ public class ObjectSelectTest {
 		q.limit(3).limit(5);
 		assertEquals(5, q.getLimit());
 	}
-	
+
 	@Test
 	public void testOffset() {
 		ObjectSelect<Artist> q = ObjectSelect.query(Artist.class);
@@ -406,7 +356,7 @@ public class ObjectSelectTest {
 		q.offset(3).offset(5);
 		assertEquals(5, q.getOffset());
 	}
-	
+
 	@Test
 	public void testStatementFetchSize() {
 		ObjectSelect<Artist> q = ObjectSelect.query(Artist.class);
@@ -418,8 +368,7 @@ public class ObjectSelectTest {
 		q.statementFetchSize(3).statementFetchSize(5);
 		assertEquals(5, q.getStatementFetchSize());
 	}
-	
-	
+
 	@Test
 	public void testCacheGroups_Collection() {
 		ObjectSelect<DataRow> q = ObjectSelect.dataRowQuery(Artist.class);
@@ -447,7 +396,7 @@ public class ObjectSelectTest {
 		assertSame(QueryCacheStrategy.SHARED_CACHE, q.getCacheStrategy());
 		assertNull(q.getCacheGroups());
 	}
-	
+
 	@Test
 	public void testLocalCache() {
 		ObjectSelect<DataRow> q = ObjectSelect.dataRowQuery(Artist.class);
@@ -463,7 +412,7 @@ public class ObjectSelectTest {
 		assertSame(QueryCacheStrategy.LOCAL_CACHE, q.getCacheStrategy());
 		assertNull(q.getCacheGroups());
 	}
-	
+
 	@Test
 	public void testSharedCache() {
 		ObjectSelect<DataRow> q = ObjectSelect.dataRowQuery(Artist.class);

http://git-wip-us.apache.org/repos/asf/cayenne/blob/6a4d83f6/cayenne-server/src/test/java/org/apache/cayenne/query/SelectByIdTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/query/SelectByIdTest.java b/cayenne-server/src/test/java/org/apache/cayenne/query/SelectByIdTest.java
index 4dca1c8..668c8d9 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/query/SelectByIdTest.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/query/SelectByIdTest.java
@@ -19,9 +19,6 @@
 package org.apache.cayenne.query;
 
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
 
 import org.apache.cayenne.testdo.testmap.Artist;
 import org.junit.Test;
@@ -36,7 +33,10 @@ public class SelectByIdTest {
 		SelectById<Artist> q = SelectById.query(Artist.class, 6);
 		q.prefetch(root);
 
-		assertSame(root, q.getPrefetches());
+		PrefetchTreeNode prefetch = q.getPrefetches();
+
+		assertNotNull(prefetch);
+		assertNotNull(prefetch.getNode("a.b"));
 	}
 
 	@Test
@@ -44,35 +44,37 @@ public class SelectByIdTest {
 
 		SelectById<Artist> q = SelectById.query(Artist.class, 7);
 		q.prefetch("a.b", PrefetchTreeNode.DISJOINT_PREFETCH_SEMANTICS);
-		PrefetchTreeNode root1 = q.getPrefetches();
+		PrefetchTreeNode prefetch = q.getPrefetches();
 
-		assertNotNull(root1);
-		assertNotNull(root1.getNode("a.b"));
+		assertNotNull(prefetch);
+		assertNotNull(prefetch.getNode("a.b"));
 
 		q.prefetch("a.c", PrefetchTreeNode.DISJOINT_PREFETCH_SEMANTICS);
-		PrefetchTreeNode root2 = q.getPrefetches();
+		prefetch = q.getPrefetches();
 
-		assertNotNull(root2);
-		assertNotNull(root2.getNode("a.c"));
-		assertNull(root2.getNode("a.b"));
-		assertNotSame(root1, root2);
+		assertNotNull(prefetch);
+		assertNotNull(prefetch.getNode("a.c"));
+		assertNotNull(prefetch.getNode("a.b"));
 	}
 
 	@Test
-	public void testAddPrefetch() {
+	public void testPrefetch_Subroot() {
 
 		PrefetchTreeNode root = PrefetchTreeNode.withPath("a.b", PrefetchTreeNode.JOINT_PREFETCH_SEMANTICS);
 
 		SelectById<Artist> q = SelectById.query(Artist.class, 8);
 		q.prefetch(root);
 
-		assertSame(root, q.getPrefetches());
+		PrefetchTreeNode prefetch = q.getPrefetches();
+
+		assertNotNull(prefetch.getNode("a.b"));
 
 		PrefetchTreeNode subRoot = PrefetchTreeNode.withPath("a.b.c", PrefetchTreeNode.JOINT_PREFETCH_SEMANTICS);
-		q.addPrefetch(subRoot);
+		q.prefetch(subRoot);
 
-		assertSame(root, q.getPrefetches());
+		prefetch = q.getPrefetches();
 
-		assertNotNull(root.getNode("a.b.c"));
+		assertNotNull(prefetch.getNode("a.b"));
+		assertNotNull(prefetch.getNode("a.b.c"));
 	}
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/6a4d83f6/docs/doc/src/main/resources/RELEASE-NOTES.txt
----------------------------------------------------------------------
diff --git a/docs/doc/src/main/resources/RELEASE-NOTES.txt b/docs/doc/src/main/resources/RELEASE-NOTES.txt
index 35c97e0..a47eaec 100644
--- a/docs/doc/src/main/resources/RELEASE-NOTES.txt
+++ b/docs/doc/src/main/resources/RELEASE-NOTES.txt
@@ -25,6 +25,7 @@ CAY-2008 Connection pool refactoring and validation query support in Cayenne
Dat
 CAY-2009 Non-blocking connection pool
 CAY-2010 Splitting DataSourceBuilder from ServerRuntimeBuilder
 CAY-2011 Support for Java 8 date and time types
+CAY-2012 ObjectSelect, SelectById: eliminating methods that reset query state
 
 Bug Fixes:
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/6a4d83f6/docs/doc/src/main/resources/UPGRADE.txt
----------------------------------------------------------------------
diff --git a/docs/doc/src/main/resources/UPGRADE.txt b/docs/doc/src/main/resources/UPGRADE.txt
index c29320d..c980f1d 100644
--- a/docs/doc/src/main/resources/UPGRADE.txt
+++ b/docs/doc/src/main/resources/UPGRADE.txt
@@ -22,6 +22,9 @@ UPGRADING TO 4.0.M3
   pooling DataSource. A replacement is non-blocking DataSource under org.apache.cayenne.datasource
(PoolingDataSource, ManagedPoolingDataSource),
   best assembled using org.apache.cayenne.datasource.DataSourceBuilder.
 
+* Per CAY-2012 API for ObjectSelect and SelectById queries were changed to remove "reset"
functionality. Methods like 'where', 'prefetch',
+  'orderBy' that would previously reset the corresponding option state now work as "append".
Methods that would previously append to the
+  option state were removed as redundant. Please revisit your code if you previously relied
on the reset behavior.
 
 UPGRADING TO 4.0.M2
 


Mime
View raw message