openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From awh...@apache.org
Subject svn commit: r433431 - in /incubator/openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ openjpa-kernel/src/mai...
Date Mon, 21 Aug 2006 23:53:49 GMT
Author: awhite
Date: Mon Aug 21 16:53:49 2006
New Revision: 433431

URL: http://svn.apache.org/viewvc?rev=433431&view=rev
Log:
No need for parser to populate separate QueryExpressions.aggregate member now 
that we can visit the projection values to see if they're aggregates.


Modified:
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreQuery.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/SelectConstructor.java
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ExpressionStoreQuery.java
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/InMemoryExpressionFactory.java
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/QueryExpressions.java
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreQuery.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreQuery.java?rev=433431&r1=433430&r2=433431&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreQuery.java
(original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreQuery.java
Mon Aug 21 16:53:49 2006
@@ -131,7 +131,7 @@
         ClassMetaData base, ClassMetaData[] metas, boolean subclasses,
         ExpressionFactory[] facts, QueryExpressions[] exps, Object[] params,
         boolean lrs, long startIdx, long endIdx) {
-        if (metas.length > 1 && exps[0].aggregate)
+        if (metas.length > 1 && exps[0].isAggregate())
             throw new UserException(Localizer.forPackage(JDBCStoreQuery.class)
                 .get("mult-mapping-aggregate", Arrays.asList(metas)));
 

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/SelectConstructor.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/SelectConstructor.java?rev=433431&r1=433430&r2=433431&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/SelectConstructor.java
(original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/SelectConstructor.java
Mon Aug 21 16:53:49 2006
@@ -177,8 +177,8 @@
                 // get unique candidate values) and needed field values and
                 // applies the where conditions; the outer select applies
                 // ordering, grouping, etc
-                if (exps.aggregate || (exps.distinct & exps.DISTINCT_TRUE) == 0)
-                {
+                if (exps.isAggregate() 
+                    || (exps.distinct & exps.DISTINCT_TRUE) == 0) {
                     DBDictionary dict = store.getDBDictionary();
                     dict.assertSupport(dict.supportsSubselect,
                         "SupportsSubselect");
@@ -186,7 +186,7 @@
                     Select inner = sel;
                     sel = store.getSQLFactory().newSelect();
                     sel.setParent(parent, alias);
-                    sel.setDistinct(exps.aggregate
+                    sel.setDistinct(exps.isAggregate()
                         && (exps.distinct & exps.DISTINCT_TRUE) != 0);
                     sel.setFromSelect(inner);
                 }

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ExpressionStoreQuery.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ExpressionStoreQuery.java?rev=433431&r1=433430&r2=433431&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ExpressionStoreQuery.java
(original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ExpressionStoreQuery.java
Mon Aug 21 16:53:49 2006
@@ -349,7 +349,7 @@
         }
 
         public final boolean isAggregate(StoreQuery q) {
-            return assertQueryExpression().aggregate;
+            return assertQueryExpression().isAggregate();
         }
 
         public final boolean hasGrouping(StoreQuery q) {

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/InMemoryExpressionFactory.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/InMemoryExpressionFactory.java?rev=433431&r1=433430&r2=433431&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/InMemoryExpressionFactory.java
(original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/InMemoryExpressionFactory.java
Mon Aug 21 16:53:49 2006
@@ -221,7 +221,7 @@
             return matches;
 
         // if an ungrouped aggregate, evaluate the whole matches list
-        if (exps.grouping.length == 0 && exps.aggregate) {
+        if (exps.grouping.length == 0 && exps.isAggregate()) {
             Object[] projection = project(matches, exps, true, ctx, params);
             return Arrays.asList(new Object[]{ projection });
         }

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/QueryExpressions.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/QueryExpressions.java?rev=433431&r1=433430&r2=433431&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/QueryExpressions.java
(original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/QueryExpressions.java
Mon Aug 21 16:53:49 2006
@@ -37,7 +37,11 @@
     public static final int DISTINCT_FALSE = 2 << 2;
     public static final Value[] EMPTY_VALUES = new Value[0];
 
-    public boolean aggregate = false;
+    /**
+     * Map of {@link FieldMetaData},{@link Value} for update statements.
+     */
+    public Map updates = null;
+
     public int distinct = DISTINCT_AUTO;
     public String alias = null;
     public Value[] projections = EMPTY_VALUES;
@@ -55,9 +59,51 @@
     public int operation = QueryOperations.OP_SELECT;
     public ClassMetaData[] accessPath = StoreQuery.EMPTY_METAS;
     public String[] fetchPaths = StoreQuery.EMPTY_STRINGS;
+    private Boolean _aggregate = null;
+
+    public boolean isAggregate() {
+        if (projections.length == 0)
+            return false; 
+        if (_aggregate == null)
+            _aggregate = (AggregateExpressionVisitor.isAggregate(projections))
+                ? Boolean.TRUE : Boolean.FALSE;
+        return _aggregate.booleanValue();    
+    }
 
     /**
-     * Map of {@link FieldMetaData},{@link Value} for update statements.
+     * Visitor to determine whether our projections are aggregates.
      */
-    public Map updates = null;
+    private static class AggregateExpressionVisitor
+        extends AbstractExpressionVisitor {
+        
+        private Value _sub = null;
+        private boolean _agg = false;
+
+        /**
+         * Return whether the given values include projections.
+         */
+        public static boolean isAggregate(Value[] vals) {
+            if (vals.length == 0)
+                return false;
+            AggregateExpressionVisitor v = new AggregateExpressionVisitor();
+            for (int i = 0; i < vals.length && !v._agg; i++)
+                vals[i].acceptVisit(v);
+            return v._agg;
+        }
+
+        public void enter(Value val) {
+            if (_agg)
+                return;
+            if (_sub == null) {
+                if (val.isAggregate())
+                    _agg = true;
+            } else if (val instanceof Subquery)
+                _sub = val;
+        }
+
+        public void exit(Value val) {
+            if (val == _sub)
+                _sub = null;
+        }
+    }
 }

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java?rev=433431&r1=433430&r2=433431&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java
(original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/JPQLExpressionBuilder.java
Mon Aug 21 16:53:49 2006
@@ -286,7 +286,6 @@
             JPQLNode parent = parametersNode.getChild(i);
             JPQLNode node = onlyChild(parent);
             Value proj = getValue(node);
-            exps.aggregate = exps.aggregate || node.id == JJTAGGREGATE;
             exps.projections[i] = proj;
             exps.projectionAliases[i] = nextAlias();
 



Mime
View raw message