cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r653853 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/access/ main/java/org/apache/cayenne/access/trans/ main/java/org/apache/cayenne/cache/ main/java/org/apache/cayenne/exp/ main/java/org/a...
Date Tue, 06 May 2008 17:51:59 GMT
Author: aadamchik
Date: Tue May  6 10:51:57 2008
New Revision: 653853

URL: http://svn.apache.org/viewvc?rev=653853&view=rev
Log:
CAY-514  implement a "MATCH ALL VALUES" expression

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainQuery.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ObjectStore.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/QueryAssembler.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/cache/NestedQueryCache.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/Expression.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/ExpressionFactory.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/ASTPath.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/SimpleNode.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/BaseQueryMetadata.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/DefaultQueryMetadata.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/QualifiedQuery.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/QueryMetadata.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/QueryMetadataWrapper.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/main/java/org/apache/cayenne/query/SelectQueryMetadata.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/IncrementalQuery.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/IncrementalSelectQuery.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/RangeQuery.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextJoinAliasesTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/MockQueryMetadata.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainQuery.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainQuery.java?rev=653853&r1=653852&r2=653853&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainQuery.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainQuery.java
Tue May  6 10:51:57 2008
@@ -18,6 +18,8 @@
  ****************************************************************/
 package org.apache.cayenne.access;
 
+import java.util.Map;
+
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.EntityResolver;
@@ -72,6 +74,10 @@
     public String getCacheKey() {
         return null;
     }
+    
+    public Map<String, String> getPathSplitAliases() {
+        return null;
+    }
 
     /**
      * @deprecated since 3.0 in favor of 'getCacheStrategy'.

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ObjectStore.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ObjectStore.java?rev=653853&r1=653852&r2=653853&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ObjectStore.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ObjectStore.java
Tue May  6 10:51:57 2008
@@ -1215,6 +1215,10 @@
             return null;
         }
 
+        public Map<String, String> getPathSplitAliases() {
+            return null;
+        }
+
         public Procedure getProcedure() {
             return null;
         }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/QueryAssembler.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/QueryAssembler.java?rev=653853&r1=653852&r2=653853&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/QueryAssembler.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/QueryAssembler.java
Tue May  6 10:51:57 2008
@@ -21,7 +21,6 @@
 
 import java.sql.PreparedStatement;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 
@@ -30,7 +29,6 @@
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbRelationship;
 import org.apache.cayenne.map.JoinType;
-import org.apache.cayenne.query.QualifiedQuery;
 
 /**
  * Abstract superclass of Query translators.
@@ -39,7 +37,9 @@
  */
 public abstract class QueryAssembler extends QueryTranslator {
 
-    /** PreparedStatement values. */
+    /**
+     * Holds PreparedStatement values.
+     */
     protected List<Object> values = new ArrayList<Object>();
 
     /**
@@ -53,10 +53,7 @@
      * @since 3.0
      */
     protected Map<String, String> getPathAliases() {
-        if (query instanceof QualifiedQuery) {
-            return ((QualifiedQuery) query).getJoinAliases();
-        }
-        return Collections.emptyMap();
+        return query.getMetaData(getEntityResolver()).getPathSplitAliases();
     }
 
     /**

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/cache/NestedQueryCache.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/cache/NestedQueryCache.java?rev=653853&r1=653852&r2=653853&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/cache/NestedQueryCache.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/cache/NestedQueryCache.java
Tue May  6 10:51:57 2008
@@ -19,6 +19,7 @@
 package org.apache.cayenne.cache;
 
 import java.util.List;
+import java.util.Map;
 
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.DbEntity;
@@ -177,6 +178,10 @@
         public PrefetchTreeNode getPrefetchTree() {
             return mdDelegate.getPrefetchTree();
         }
+        
+        public Map<String, String> getPathSplitAliases() {
+            return mdDelegate.getPathSplitAliases();
+        }
 
         public Procedure getProcedure() {
             return mdDelegate.getProcedure();

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/Expression.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/Expression.java?rev=653853&r1=653852&r2=653853&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/Expression.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/Expression.java
Tue May  6 10:51:57 2008
@@ -145,6 +145,15 @@
     }
 
     /**
+     * Returns a map of path aliases for this expression. It returns a non-empty map only
+     * if this is a path expression and the aliases are known at the expression creation
+     * time. Otherwise an empty map is returned.
+     * 
+     * @since 3.0
+     */
+    public abstract Map<String, String> getPathAliases();
+
+    /**
      * Returns String label for this expression. Used for debugging.
      */
     public String expName() {
@@ -563,7 +572,7 @@
         buffer.flush();
         return buffer.toString();
     }
-    
+
     public String toEJBQL(String rootId) {
         StringWriter buffer = new StringWriter();
         PrintWriter pw = new PrintWriter(buffer);

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/ExpressionFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/ExpressionFactory.java?rev=653853&r1=653852&r2=653853&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/ExpressionFactory.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/ExpressionFactory.java
Tue May  6 10:51:57 2008
@@ -21,8 +21,10 @@
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
 import java.util.Map;
+import java.util.Random;
 
 import org.apache.cayenne.exp.parser.ASTAdd;
 import org.apache.cayenne.exp.parser.ASTAnd;
@@ -49,9 +51,11 @@
 import org.apache.cayenne.exp.parser.ASTNotLikeIgnoreCase;
 import org.apache.cayenne.exp.parser.ASTObjPath;
 import org.apache.cayenne.exp.parser.ASTOr;
+import org.apache.cayenne.exp.parser.ASTPath;
 import org.apache.cayenne.exp.parser.ASTSubtract;
 import org.apache.cayenne.exp.parser.ASTTrue;
 import org.apache.cayenne.exp.parser.SimpleNode;
+import org.apache.cayenne.map.Entity;
 
 /**
  * Helper class to build expressions. Alternatively expressions can be built using
@@ -61,9 +65,21 @@
  */
 public class ExpressionFactory {
 
+    /**
+     * A "split" character, "|", that is understood by some of the ExpressionFactory
+     * methods that require splitting joins in the middle of the path.
+     * 
+     * @since 3.0
+     */
+    public static final char SPLIT_SEPARATOR = '|';
+
     private static Class<?>[] typeLookup;
+    private static final Random random;
 
     static {
+
+        random = new Random(System.currentTimeMillis());
+
         // make sure all types are small integers, then we can use
         // them as indexes in lookup array
         int[] allTypes = new int[] {
@@ -237,6 +253,86 @@
     }
 
     /**
+     * Creates an expression to match a collection of values against a single path
+     * expression.
+     * <h3>Splits</h3>
+     * <p>
+     * Note that "path" argument here can use a split character (a pipe symbol - '|')
+     * instead of dot to indicate that relationship following a path should be split into
+     * a separate set of joins. There can only be one split at most. Split must always
+     * precede a relationship. E.g. "|exhibits.paintings", "exhibits|paintings", etc.
+     * 
+     * @param path
+     * @param values
+     * @since 3.0
+     */
+    @SuppressWarnings("unchecked")
+    public static Expression matchAllExp(String path, Collection values) {
+
+        if (values == null) {
+            throw new NullPointerException("Null values collection");
+        }
+
+        if (values.size() == 0) {
+            return new ASTTrue();
+        }
+
+        return matchAllExp(path, values.toArray());
+    }
+
+    /**
+     * @since 3.0
+     */
+    public static Expression matchAllExp(String path, Object... values) {
+
+        if (values == null) {
+            throw new NullPointerException("Null values collection");
+        }
+
+        if (values.length == 0) {
+            return new ASTTrue();
+        }
+
+        int split = path.indexOf(SPLIT_SEPARATOR);
+
+        List<Expression> matches = new ArrayList<Expression>(values.length);
+
+        if (split >= 0 && split < path.length() - 1) {
+
+            int splitEnd = path.indexOf(Entity.PATH_SEPARATOR, split + 1);
+
+            String beforeSplit = split > 0 ? path.substring(0, split) + "." : "";
+            String afterSplit = splitEnd > 0 ? "." + path.substring(splitEnd + 1) : "";
+            String aliasBase = "split" + random.nextInt(Integer.MAX_VALUE) + "_";
+            String splitChunk = splitEnd > 0 ? path.substring(split + 1, splitEnd) : path
+                    .substring(split + 1);
+
+            // fix the path - replace split with dot if it's in the middle, or strip it if
+            // it's in the beginning
+            path = split == 0 ? path.substring(1) : path.replace(SPLIT_SEPARATOR, '.');
+
+            int i = 0;
+            for (Object value : values) {
+
+                String alias = aliasBase + i;
+                String aliasedPath = beforeSplit + alias + afterSplit;
+                i++;
+
+                ASTPath pathExp = new ASTObjPath(aliasedPath);
+                pathExp.setPathAliases(Collections.singletonMap(alias, splitChunk));
+                matches.add(new ASTEqual(pathExp, value));
+            }
+        }
+        else {
+            for (Object value : values) {
+                matches.add(new ASTEqual(new ASTObjPath(path), value));
+            }
+        }
+
+        return joinExp(Expression.AND, matches);
+    }
+
+    /**
      * Creates an expression that matches all key-values pairs in <code>map</code>.
      * <p>
      * For each pair <code>pairType</code> operator is used to build a binary

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/ASTPath.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/ASTPath.java?rev=653853&r1=653852&r2=653853&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/ASTPath.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/ASTPath.java
Tue May  6 10:51:57 2008
@@ -20,6 +20,7 @@
 package org.apache.cayenne.exp.parser;
 
 import java.util.Iterator;
+import java.util.Map;
 
 import org.apache.cayenne.map.Entity;
 import org.apache.cayenne.util.CayenneMapEntry;
@@ -31,7 +32,9 @@
  * @since 1.1
  */
 public abstract class ASTPath extends SimpleNode {
+
     protected String path;
+    protected Map<String, String> pathAliases;
 
     ASTPath(int i) {
         super(i);
@@ -67,7 +70,21 @@
     protected String getPath() {
         return path;
     }
+
+    /**
+     * @since 3.0
+     */
+    @Override
+    public Map<String, String> getPathAliases() {
+        return pathAliases != null ? pathAliases : super.getPathAliases();
+    }
     
+    /**
+     * @since 3.0
+     */
+    public void setPathAliases(Map<String, String> pathAliases) {
+        this.pathAliases = pathAliases;
+    }
 
     /**
      * Helper method to evaluate path expression with Cayenne Entity.
@@ -84,7 +101,8 @@
 
     @Override
     protected String getExpressionOperator(int index) {
-        throw new UnsupportedOperationException(
-            "No operator for '" + ExpressionParserTreeConstants.jjtNodeName[id] + "'");
+        throw new UnsupportedOperationException("No operator for '"
+                + ExpressionParserTreeConstants.jjtNodeName[id]
+                + "'");
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/SimpleNode.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/SimpleNode.java?rev=653853&r1=653852&r2=653853&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/SimpleNode.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/SimpleNode.java
Tue May  6 10:51:57 2008
@@ -22,6 +22,8 @@
 package org.apache.cayenne.exp.parser;
 
 import java.io.PrintWriter;
+import java.util.Collections;
+import java.util.Map;
 
 import org.apache.cayenne.ObjectId;
 import org.apache.cayenne.Persistent;
@@ -48,7 +50,10 @@
     /**
      * Utility method that encodes an object that is not an expression Node to String.
      */
-    protected static void encodeScalarAsString(PrintWriter pw, Object scalar, char quoteChar)
{
+    protected static void encodeScalarAsString(
+            PrintWriter pw,
+            Object scalar,
+            char quoteChar) {
         boolean quote = scalar instanceof String;
 
         if (quote) {
@@ -114,6 +119,16 @@
         id = i;
     }
 
+    /**
+     * Always returns empty map.
+     * 
+     * @since 3.0
+     */
+    @Override
+    public Map<String, String> getPathAliases() {
+        return Collections.<String, String> emptyMap();
+    }
+
     protected abstract String getExpressionOperator(int index);
 
     @Override

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/BaseQueryMetadata.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/BaseQueryMetadata.java?rev=653853&r1=653852&r2=653853&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/BaseQueryMetadata.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/BaseQueryMetadata.java
Tue May  6 10:51:57 2008
@@ -277,6 +277,13 @@
     }
 
     /**
+     * @since 3.0
+     */
+    public Map<String, String> getPathSplitAliases() {
+        return Collections.<String, String> emptyMap();
+    }
+
+    /**
      * @since 1.2
      */
     public DbEntity getDbEntity() {

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/DefaultQueryMetadata.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/DefaultQueryMetadata.java?rev=653853&r1=653852&r2=653853&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/DefaultQueryMetadata.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/DefaultQueryMetadata.java
Tue May  6 10:51:57 2008
@@ -19,6 +19,9 @@
 
 package org.apache.cayenne.query;
 
+import java.util.Collections;
+import java.util.Map;
+
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.ObjEntity;
@@ -134,4 +137,8 @@
     public PrefetchTreeNode getPrefetchTree() {
         return null;
     }
+
+    public Map<String, String> getPathSplitAliases() {
+        return Collections.<String, String> emptyMap();
+    }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/QualifiedQuery.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/QualifiedQuery.java?rev=653853&r1=653852&r2=653853&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/QualifiedQuery.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/QualifiedQuery.java
Tue May  6 10:51:57 2008
@@ -19,10 +19,6 @@
 
 package org.apache.cayenne.query;
 
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
 import org.apache.cayenne.exp.Expression;
 
 /**
@@ -33,32 +29,6 @@
 public abstract class QualifiedQuery extends AbstractQuery {
 
     protected Expression qualifier;
-    protected Map<String, String> joinAliases;
-
-    /**
-     * Returns a map of join aliases.
-     * 
-     * @since 3.0
-     */
-    public Map<String, String> getJoinAliases() {
-        return joinAliases != null ? joinAliases : Collections
-                .<String, String> emptyMap();
-    }
-
-    /**
-     * Creates a named alias that would resolve into a separate chain of joins when
-     * translated to SQL. I.e. if the same path has more than one alias, the joins will be
-     * duplicated.
-     * 
-     * @since 3.0
-     */
-    public void aliasJoin(String alias, String expressionPath) {
-        if (joinAliases == null) {
-            joinAliases = new HashMap<String, String>();
-        }
-
-        joinAliases.put(alias, expressionPath);
-    }
 
     /**
      * Sets new query qualifier.

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/QueryMetadata.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/QueryMetadata.java?rev=653853&r1=653852&r2=653853&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/QueryMetadata.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/QueryMetadata.java
Tue May  6 10:51:57 2008
@@ -19,6 +19,8 @@
 
 package org.apache.cayenne.query;
 
+import java.util.Map;
+
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.ObjEntity;
@@ -107,7 +109,7 @@
      * @deprecated since 3.0 use {@value #CACHE_STRATEGY_PROPERTY}
      */
     public static final String CACHE_POLICY_PROPERTY = "cayenne.GenericSelectQuery.cachePolicy";
-    
+
     /**
      * @since 3.0
      */
@@ -159,6 +161,7 @@
 
     /**
      * Returns a caching strategy for this query.
+     * 
      * @since 3.0
      */
     QueryCacheStrategy getCacheStrategy();
@@ -244,6 +247,13 @@
     PrefetchTreeNode getPrefetchTree();
 
     /**
+     * Returns a map of aliases vs. expression subpaths that is used to build split joins.
+     * 
+     * @since 3.0
+     */
+    Map<String, String> getPathSplitAliases();
+
+    /**
      * Returns a mapping of the result set data rows. Can be null. If not null overrides
      * prefetching and data row settings.
      * 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/QueryMetadataWrapper.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/QueryMetadataWrapper.java?rev=653853&r1=653852&r2=653853&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/QueryMetadataWrapper.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/QueryMetadataWrapper.java
Tue May  6 10:51:57 2008
@@ -76,6 +76,13 @@
     public Procedure getProcedure() {
         return info.getProcedure();
     }
+    
+    /**
+     * @since 3.0
+     */
+    public Map<String, String> getPathSplitAliases() {
+        return info.getPathSplitAliases();
+    }
 
     public DbEntity getDbEntity() {
         return info.getDbEntity();

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=653853&r1=653852&r2=653853&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
Tue May  6 10:51:57 2008
@@ -410,6 +410,15 @@
     }
 
     /**
+     * Adds one or more aliases for the qualifier expression path.
+     * 
+     * @since 3.0
+     */
+    public void addPathSplitAliases(String path, String... aliases) {
+        metaData.addPathSplitAliases(path, aliases);
+    }
+
+    /**
      * Returns a list of attributes that will be included in the results of this query.
      */
     public List<String> getCustomDbAttributes() {

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/SelectQueryMetadata.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/SelectQueryMetadata.java?rev=653853&r1=653852&r2=653853&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/SelectQueryMetadata.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/SelectQueryMetadata.java
Tue May  6 10:51:57 2008
@@ -18,6 +18,11 @@
  ****************************************************************/
 package org.apache.cayenne.query;
 
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.cayenne.exp.Expression;
 import org.apache.cayenne.map.EntityResolver;
 import org.apache.cayenne.map.ObjEntity;
 
@@ -27,6 +32,14 @@
  */
 class SelectQueryMetadata extends BaseQueryMetadata {
 
+    Map<String, String> pathSplitAliases;
+
+    @Override
+    void copyFromInfo(QueryMetadata info) {
+        super.copyFromInfo(info);
+        this.pathSplitAliases = new HashMap<String, String>(info.getPathSplitAliases());
+    }
+
     boolean resolve(Object root, EntityResolver resolver, SelectQuery query) {
 
         if (super.resolve(root, resolver, null)) {
@@ -76,9 +89,64 @@
                 this.cacheKey = key.toString();
             }
 
+            resolveAutoAliases(query);
+
             return true;
         }
 
         return false;
     }
+
+    private void resolveAutoAliases(SelectQuery query) {
+        Expression qualifier = query.getQualifier();
+        if (qualifier != null) {
+            resolveAutoAliases(qualifier);
+        }
+
+        // TODO: include aliases in prefetches? flattened attributes?
+    }
+
+    private void resolveAutoAliases(Expression expression) {
+        Map<String, String> aliases = expression.getPathAliases();
+        if (!aliases.isEmpty()) {
+            if (pathSplitAliases == null) {
+                pathSplitAliases = new HashMap<String, String>();
+            }
+
+            pathSplitAliases.putAll(aliases);
+        }
+
+        int len = expression.getOperandCount();
+        for (int i = 0; i < len; i++) {
+            Object operand = expression.getOperand(i);
+            if (operand instanceof Expression) {
+                resolveAutoAliases((Expression) operand);
+            }
+        }
+    }
+
+    /**
+     * @since 3.0
+     */
+    public Map<String, String> getPathSplitAliases() {
+        return pathSplitAliases != null ? pathSplitAliases : Collections
+                .<String, String> emptyMap();
+    }
+
+    /**
+     * @since 3.0
+     */
+    public void addPathSplitAliases(String path, String... aliases) {
+        if (aliases == null) {
+            throw new NullPointerException("Null aliases");
+        }
+
+        if (aliases.length == 0) {
+            throw new IllegalArgumentException("No aliases specified");
+        }
+
+        if (pathSplitAliases == null) {
+            pathSplitAliases = new HashMap<String, String>();
+        }
+    }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/IncrementalQuery.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/IncrementalQuery.java?rev=653853&r1=653852&r2=653853&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/IncrementalQuery.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/IncrementalQuery.java
Tue May  6 10:51:57 2008
@@ -19,6 +19,8 @@
 
 package org.apache.cayenne.remote;
 
+import java.util.Map;
+
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.EntityResolver;
@@ -128,6 +130,10 @@
                 return metadata.getProcedure();
             }
 
+            public Map<String, String> getPathSplitAliases() {
+                return metadata.getPathSplitAliases();
+            }
+
             public boolean isFetchingDataRows() {
                 return metadata.isFetchingDataRows();
             }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/IncrementalSelectQuery.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/IncrementalSelectQuery.java?rev=653853&r1=653852&r2=653853&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/IncrementalSelectQuery.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/IncrementalSelectQuery.java
Tue May  6 10:51:57 2008
@@ -135,6 +135,10 @@
                 return metadata.getProcedure();
             }
 
+            public Map<String, String> getPathSplitAliases() {
+                return metadata.getPathSplitAliases();
+            }
+
             public boolean isFetchingDataRows() {
                 return metadata.isFetchingDataRows();
             }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/RangeQuery.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/RangeQuery.java?rev=653853&r1=653852&r2=653853&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/RangeQuery.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/RangeQuery.java
Tue May  6 10:51:57 2008
@@ -19,6 +19,8 @@
 
 package org.apache.cayenne.remote;
 
+import java.util.Map;
+
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.EntityResolver;
@@ -140,6 +142,10 @@
             public Procedure getProcedure() {
                 throw new UnsupportedOperationException();
             }
+            
+            public Map<String, String> getPathSplitAliases() {
+                throw new UnsupportedOperationException();
+            }
 
             public boolean isRefreshingObjects() {
                 throw new UnsupportedOperationException();

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextJoinAliasesTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextJoinAliasesTest.java?rev=653853&r1=653852&r2=653853&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextJoinAliasesTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextJoinAliasesTest.java
Tue May  6 10:51:57 2008
@@ -54,12 +54,10 @@
         Artist dali = DataObjectUtils.objectForPK(context, Artist.class, 2);
 
         SelectQuery query = new SelectQuery(Gallery.class);
-        String path = "exhibitArray.artistExhibitArray";
-        query.aliasJoin("p", path);
-        query.aliasJoin("d", path);
-
-        query.andQualifier(ExpressionFactory.matchExp("p.toArtist", picasso));
-        query.andQualifier(ExpressionFactory.matchExp("d.toArtist", dali));
+        query.andQualifier(ExpressionFactory.matchAllExp(
+                "|exhibitArray.artistExhibitArray.toArtist",
+                picasso,
+                dali));
 
         List<Gallery> galleries = context.performQuery(query);
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/MockQueryMetadata.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/MockQueryMetadata.java?rev=653853&r1=653852&r2=653853&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/MockQueryMetadata.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/MockQueryMetadata.java
Tue May  6 10:51:57 2008
@@ -19,6 +19,8 @@
 
 package org.apache.cayenne.query;
 
+import java.util.Map;
+
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.ObjEntity;
@@ -42,6 +44,10 @@
     public Procedure getProcedure() {
         return null;
     }
+    
+    public Map<String, String> getPathSplitAliases() {
+        return null;
+    }
 
     public DataMap getDataMap() {
         return null;



Mime
View raw message