cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
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 GMT
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;
 
 /**
- * <p>A property in a DataObject.</p>
+ * <p>
+ * A property in a DataObject.
+ * </p>
  * 
- * <p>Used to construct Expressions quickly and with type-safety,
- * and to construct Orderings</p>
+ * <p>
+ * Used to construct Expressions quickly and with type-safety, and to construct
+ * Orderings
+ * </p>
  * 
- * <p>Instances of this class are immutable</p>
+ * <p>
+ * Instances of this class are immutable
+ * </p>
  * 
- * @param <E> The type this property returns.
+ * @param <E>
+ *            The type this property returns.
  * @since 3.2
  */
 public class Property<E> {
 
-	/**
-	 * 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<Object> dot(String property) {
-		return new Property<Object>(getName() + "." + property);
-	}
-
-	/**
-	 * @return Constructs a property path by appending the argument to 
-	 * 	       the existing property separated by a dot
-	 */
-	public <T> Property<T> dot(Property<T> property) {
-		return new Property<T>(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<Ordering> ascs() {
-		List<Ordering> result = new ArrayList<Ordering>(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<Ordering> ascInsensitives() {
-		List<Ordering> result = new ArrayList<Ordering>(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<Ordering> descs() {
-		List<Ordering> result = new ArrayList<Ordering>(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<Ordering> descInsensitives() {
-		List<Ordering> result = new ArrayList<Ordering>(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<Object> dot(String property) {
+        return new Property<Object>(getName() + "." + property);
+    }
+
+    /**
+     * @return Constructs a property path by appending the argument to the
+     *         existing property separated by a dot
+     */
+    public <T> Property<T> dot(Property<T> property) {
+        return new Property<T>(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<Ordering> ascs() {
+        List<Ordering> result = new ArrayList<Ordering>(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<Ordering> ascInsensitives() {
+        List<Ordering> result = new ArrayList<Ordering>(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<Ordering> descs() {
+        List<Ordering> result = new ArrayList<Ordering>(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<Ordering> descInsensitives() {
+        List<Ordering> result = new ArrayList<Ordering>(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<T> 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<Artist> q = new SelectQuery<Artist>(Artist.class);
+        q.addPrefetch(Artist.PAINTING_ARRAY_PROPERTY);
+
+        final List<Artist> 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();



Mime
View raw message