Return-Path: X-Original-To: apmail-cayenne-commits-archive@www.apache.org Delivered-To: apmail-cayenne-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3C224D330 for ; Wed, 26 Dec 2012 14:59:46 +0000 (UTC) Received: (qmail 35151 invoked by uid 500); 26 Dec 2012 14:59:44 -0000 Delivered-To: apmail-cayenne-commits-archive@cayenne.apache.org Received: (qmail 35083 invoked by uid 500); 26 Dec 2012 14:59:43 -0000 Mailing-List: contact commits-help@cayenne.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cayenne.apache.org Delivered-To: mailing list commits@cayenne.apache.org Received: (qmail 35048 invoked by uid 99); 26 Dec 2012 14:59:41 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 26 Dec 2012 14:59:41 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 26 Dec 2012 14:59:38 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id A898223889DA; Wed, 26 Dec 2012 14:59:16 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1425935 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/exp/Property.java main/java/org/apache/cayenne/query/SelectQuery.java test/java/org/apache/cayenne/access/DataContextPrefetchTest.java Date: Wed, 26 Dec 2012 14:59:16 -0000 To: commits@cayenne.apache.org From: aadamchik@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20121226145916.A898223889DA@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: aadamchik Date: Wed Dec 26 14:59:16 2012 New Revision: 1425935 URL: http://svn.apache.org/viewvc?rev=1425935&view=rev Log: CAY-1784 Improving 'Property' class to handle a few extra common cases Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/Property.java cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/SelectQuery.java cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPrefetchTest.java Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/Property.java URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/Property.java?rev=1425935&r1=1425934&r2=1425935&view=diff ============================================================================== --- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/Property.java (original) +++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/Property.java Wed Dec 26 14:59:16 2012 @@ -6,219 +6,255 @@ import java.util.List; import org.apache.cayenne.exp.Expression; import org.apache.cayenne.exp.ExpressionFactory; import org.apache.cayenne.query.Ordering; +import org.apache.cayenne.query.PrefetchTreeNode; import org.apache.cayenne.query.SortOrder; /** - *

A property in a DataObject.

+ *

+ * A property in a DataObject. + *

* - *

Used to construct Expressions quickly and with type-safety, - * and to construct Orderings

+ *

+ * Used to construct Expressions quickly and with type-safety, and to construct + * Orderings + *

* - *

Instances of this class are immutable

+ *

+ * Instances of this class are immutable + *

* - * @param The type this property returns. + * @param + * The type this property returns. * @since 3.2 */ public class Property { - /** - * Name of the property in the object - */ - private final String name; - - /** - * Constructs a new property with the given name. - */ - public Property(String name) { - this.name = name; - } - - /** - * @return Name of the property in the object. - */ - public String getName() { - return name; - } - - /** - * @return Constructs a property path by appending the argument to - * the existing property separated by a dot - */ - public Property dot(String property) { - return new Property(getName() + "." + property); - } - - /** - * @return Constructs a property path by appending the argument to - * the existing property separated by a dot - */ - public Property dot(Property property) { - return new Property(getName() + "." + property.getName()); - } - - /** - * @return An expression representing null. - */ - public Expression isNull() { - return ExpressionFactory.matchExp(getName(), null); - } - - /** - * @return An expression representing a non-null value. - */ - public Expression isNotNull() { - return ExpressionFactory.matchExp(getName(), null).notExp(); - } - - /** - * @return An expression representing equality to TRUE. - */ - public Expression isTrue() { - return ExpressionFactory.matchExp(getName(), Boolean.TRUE); - } - - /** - * @return An expression representing equality to FALSE. - */ - public Expression isFalse() { - return ExpressionFactory.matchExp(getName(), Boolean.FALSE); - } - - /** - * @return An expression representing equality to a value. - */ - public Expression eq(E value) { - return ExpressionFactory.matchExp(getName(), value); - } - - /** - * @return An expression representing inequality to a value. - */ - public Expression ne(E value) { - return ExpressionFactory.noMatchExp(getName(), value); - } - - /** - * @return An expression for a Database "Like" query. - */ - public Expression like(E value) { - return ExpressionFactory.likeExp(getName(), value); - } - - /** - * @return An expression for a case insensitive "Like" query. - */ - public Expression likeInsensitive(E value) { - return ExpressionFactory.likeIgnoreCaseExp(getName(), value); - } - - /** - * @return An expression checking for objects between a lower and upper bound inclusive - * - * @param lower The lower bound. - * @param upper The upper bound. - */ - public Expression between(E lower, E upper) { - return ExpressionFactory.betweenExp(getName(), lower, upper); - } - - /** - * @return An expression for finding objects with values in the given set. - */ - public Expression in(E... values) { - return ExpressionFactory.inExp(getName(), values); - } - - /** - * @return A greater than Expression. - */ - public Expression gt(E value) { - return ExpressionFactory.greaterExp(getName(), value); - } - - /** - * @return A greater than or equal to Expression. - */ - public Expression gte(E value) { - return ExpressionFactory.greaterOrEqualExp(getName(), value); - } - - /** - * @return A less than Expression. - */ - public Expression lt(E value) { - return ExpressionFactory.lessExp(getName(), value); - } - - /** - * @return A less than or equal to Expression. - */ - public Expression lte(E value) { - return ExpressionFactory.lessOrEqualExp(getName(), value); - } - - /** - * @return Ascending sort orderings on this property. - */ - public Ordering asc() { - return new Ordering(getName(), SortOrder.ASCENDING); - } - - /** - * @return Ascending sort orderings on this property. - */ - public List ascs() { - List result = new ArrayList(1); - result.add(asc()); - return result; - } - - /** - * @return Ascending case insensitive sort orderings on this property. - */ - public Ordering ascInsensitive() { - return new Ordering(getName(), SortOrder.ASCENDING_INSENSITIVE); - } - - /** - * @return Ascending case insensitive sort orderings on this property. - */ - public List ascInsensitives() { - List result = new ArrayList(1); - result.add(ascInsensitive()); - return result; - } - - /** - * @return Descending sort orderings on this property. - */ - public Ordering desc() { - return new Ordering(getName(), SortOrder.DESCENDING); - } - - /** - * @return Descending sort orderings on this property. - */ - public List descs() { - List result = new ArrayList(1); - result.add(desc()); - return result; - } - - /** - * @return Descending case insensitive sort orderings on this property. - */ - public Ordering descInsensitive() { - return new Ordering(getName(), SortOrder.DESCENDING_INSENSITIVE); - } - - /** - * @return Descending case insensitive sort orderings on this property. - */ - public List descInsensitives() { - List result = new ArrayList(1); - result.add(descInsensitive()); - return result; - } + /** + * Name of the property in the object + */ + private final String name; + + /** + * Constructs a new property with the given name. + */ + public Property(String name) { + this.name = name; + } + + /** + * @return Name of the property in the object. + */ + public String getName() { + return name; + } + + /** + * @return Constructs a property path by appending the argument to the + * existing property separated by a dot + */ + public Property dot(String property) { + return new Property(getName() + "." + property); + } + + /** + * @return Constructs a property path by appending the argument to the + * existing property separated by a dot + */ + public Property dot(Property property) { + return new Property(getName() + "." + property.getName()); + } + + /** + * @return An expression representing null. + */ + public Expression isNull() { + return ExpressionFactory.matchExp(getName(), null); + } + + /** + * @return An expression representing a non-null value. + */ + public Expression isNotNull() { + return ExpressionFactory.matchExp(getName(), null).notExp(); + } + + /** + * @return An expression representing equality to TRUE. + */ + public Expression isTrue() { + return ExpressionFactory.matchExp(getName(), Boolean.TRUE); + } + + /** + * @return An expression representing equality to FALSE. + */ + public Expression isFalse() { + return ExpressionFactory.matchExp(getName(), Boolean.FALSE); + } + + /** + * @return An expression representing equality to a value. + */ + public Expression eq(E value) { + return ExpressionFactory.matchExp(getName(), value); + } + + /** + * @return An expression representing inequality to a value. + */ + public Expression ne(E value) { + return ExpressionFactory.noMatchExp(getName(), value); + } + + /** + * @return An expression for a Database "Like" query. + */ + public Expression like(E value) { + return ExpressionFactory.likeExp(getName(), value); + } + + /** + * @return An expression for a case insensitive "Like" query. + */ + public Expression likeInsensitive(E value) { + return ExpressionFactory.likeIgnoreCaseExp(getName(), value); + } + + /** + * @return An expression checking for objects between a lower and upper + * bound inclusive + * + * @param lower + * The lower bound. + * @param upper + * The upper bound. + */ + public Expression between(E lower, E upper) { + return ExpressionFactory.betweenExp(getName(), lower, upper); + } + + /** + * @return An expression for finding objects with values in the given set. + */ + public Expression in(E... values) { + return ExpressionFactory.inExp(getName(), values); + } + + /** + * @return A greater than Expression. + */ + public Expression gt(E value) { + return ExpressionFactory.greaterExp(getName(), value); + } + + /** + * @return A greater than or equal to Expression. + */ + public Expression gte(E value) { + return ExpressionFactory.greaterOrEqualExp(getName(), value); + } + + /** + * @return A less than Expression. + */ + public Expression lt(E value) { + return ExpressionFactory.lessExp(getName(), value); + } + + /** + * @return A less than or equal to Expression. + */ + public Expression lte(E value) { + return ExpressionFactory.lessOrEqualExp(getName(), value); + } + + /** + * @return Ascending sort orderings on this property. + */ + public Ordering asc() { + return new Ordering(getName(), SortOrder.ASCENDING); + } + + /** + * @return Ascending sort orderings on this property. + */ + public List ascs() { + List result = new ArrayList(1); + result.add(asc()); + return result; + } + + /** + * @return Ascending case insensitive sort orderings on this property. + */ + public Ordering ascInsensitive() { + return new Ordering(getName(), SortOrder.ASCENDING_INSENSITIVE); + } + + /** + * @return Ascending case insensitive sort orderings on this property. + */ + public List ascInsensitives() { + List result = new ArrayList(1); + result.add(ascInsensitive()); + return result; + } + + /** + * @return Descending sort orderings on this property. + */ + public Ordering desc() { + return new Ordering(getName(), SortOrder.DESCENDING); + } + + /** + * @return Descending sort orderings on this property. + */ + public List descs() { + List result = new ArrayList(1); + result.add(desc()); + return result; + } + + /** + * @return Descending case insensitive sort orderings on this property. + */ + public Ordering descInsensitive() { + return new Ordering(getName(), SortOrder.DESCENDING_INSENSITIVE); + } + + /** + * @return Descending case insensitive sort orderings on this property. + */ + public List descInsensitives() { + List result = new ArrayList(1); + result.add(descInsensitive()); + return result; + } + + public PrefetchTreeNode joint() { + PrefetchTreeNode node = prefetch(); + node.setSemantics(PrefetchTreeNode.JOINT_PREFETCH_SEMANTICS); + return node; + } + + public PrefetchTreeNode disjoint() { + PrefetchTreeNode node = prefetch(); + node.setSemantics(PrefetchTreeNode.DISJOINT_PREFETCH_SEMANTICS); + return node; + } + + public PrefetchTreeNode disjointById() { + PrefetchTreeNode node = prefetch(); + node.setSemantics(PrefetchTreeNode.DISJOINT_BY_ID_PREFETCH_SEMANTICS); + return node; + } + + PrefetchTreeNode prefetch() { + PrefetchTreeNode root = new PrefetchTreeNode(); + PrefetchTreeNode node = root.addPath(name); + node.setPhantom(false); + return node; + } } \ No newline at end of file Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/SelectQuery.java URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/SelectQuery.java?rev=1425935&r1=1425934&r2=1425935&view=diff ============================================================================== --- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/SelectQuery.java (original) +++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/SelectQuery.java Wed Dec 26 14:59:16 2012 @@ -515,6 +515,18 @@ public class SelectQuery extends Qual /** * Adds a prefetch with specified relationship path to the query. * + * @since 3.2 + */ + public PrefetchTreeNode addPrefetch(PrefetchTreeNode prefetchElement) { + String path = prefetchElement.getPath(); + int semantics = prefetchElement.getSemantics(); + + return metaData.addPrefetch(path, semantics); + } + + /** + * Adds a prefetch with specified relationship path to the query. + * * @since 1.2 signature changed to return created PrefetchTreeNode. */ public PrefetchTreeNode addPrefetch(String prefetchPath) { Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPrefetchTest.java URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPrefetchTest.java?rev=1425935&r1=1425934&r2=1425935&view=diff ============================================================================== --- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPrefetchTest.java (original) +++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextPrefetchTest.java Wed Dec 26 14:59:16 2012 @@ -143,6 +143,35 @@ public class DataContextPrefetchTest ext tArtistExhibit.insert(101, 3); tArtistExhibit.insert(101, 4); } + + public void testPrefetchToMany_ViaProperty() throws Exception { + createTwoArtistsAndTwoPaintingsDataSet(); + + SelectQuery q = new SelectQuery(Artist.class); + q.addPrefetch(Artist.PAINTING_ARRAY_PROPERTY); + + final List artists = context.select(q); + + queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() { + + public void execute() { + + assertEquals(2, artists.size()); + + for (int i = 0; i < 2; i++) { + Artist a = artists.get(i); + List toMany = (List) a.readPropertyDirectly("paintingArray"); + assertNotNull(toMany); + assertFalse(((ValueHolder) toMany).isFault()); + assertEquals(1, toMany.size()); + + Painting p = (Painting) toMany.get(0); + assertEquals("Invalid prefetched painting:" + p, "p_" + + a.getArtistName(), p.getPaintingTitle()); + } + } + }); + } public void testPrefetchToMany_WithQualfier() throws Exception { createTwoArtistsAndTwoPaintingsDataSet();