openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From awh...@apache.org
Subject svn commit: r441158 [1/5] - 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-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/ openjpa-kernel/s...
Date Thu, 07 Sep 2006 17:51:09 GMT
Author: awhite
Date: Thu Sep  7 10:51:05 2006
New Revision: 441158

URL: http://svn.apache.org/viewvc?view=rev&rev=441158
Log:
Refactor JDBC query expression tree to allow greater concurrency and to handle
parameters in result clauses of projections.


Added:
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/QueryExpressionsState.java
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/ProjectionResultObjectProvider.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/AbstractVal.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Aggregate.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/AndExpression.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Args.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/BindVariableAndExpression.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/BindVariableExpression.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CompareEqualExpression.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CompareExpression.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Concat.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Const.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ConstGetObjectId.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ConstInstanceofExpression.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ConstPath.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ContainsExpression.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ContainsKeyExpression.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Count.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CurrentDate.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Distinct.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/EmptyExpression.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/EndsWithExpression.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/EqualExpression.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Exp.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Extension.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/FilterValueImpl.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/GetMapValue.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/GetObjectId.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InExpression.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InKeyExpression.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InSubQExpression.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InValueExpression.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/IndexOf.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InstanceofExpression.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/IsEmptyExpression.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/IsNotEmptyExpression.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCExpressionFactory.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Lit.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/MatchesExpression.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Math.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/NotContainsExpression.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/NotEqualExpression.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/NotExpression.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Null.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/OrExpression.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/PCPath.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Param.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/SQLEmbed.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/SelectConstructor.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Size.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/StartsWithExpression.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/StringFunction.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/StringLength.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/SubQ.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Substring.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ToLowerCase.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ToUpperCase.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Trim.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/UnaryOp.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Val.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Variable.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerFactory.java
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ExpressionStoreQuery.java
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/JDBCFetchPlan.java
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/JDBCFetchPlanImpl.java
    incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/Extent.java
    incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/ExtentImpl.java
    incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/FetchPlan.java
    incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/FetchPlanImpl.java
    incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/Generator.java
    incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/GeneratorImpl.java
    incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/OpenJPAPersistence.java
    incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderExtension.java
    incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryResultCache.java
    incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryResultCacheImpl.java
    incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/StoreCache.java
    incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/StoreCacheImpl.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?view=diff&rev=441158&r1=441157&r2=441158
==============================================================================
--- 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 Thu Sep  7 10:51:05 2006
@@ -27,10 +27,12 @@
 import java.util.Map;
 
 import org.apache.openjpa.event.LifecycleEventManager;
+import org.apache.openjpa.jdbc.kernel.exps.ExpContext;
 import org.apache.openjpa.jdbc.kernel.exps.GetColumn;
 import org.apache.openjpa.jdbc.kernel.exps.JDBCExpressionFactory;
 import org.apache.openjpa.jdbc.kernel.exps.JDBCStringContains;
 import org.apache.openjpa.jdbc.kernel.exps.JDBCWildcardMatch;
+import org.apache.openjpa.jdbc.kernel.exps.QueryExpressionsState;
 import org.apache.openjpa.jdbc.kernel.exps.SQLEmbed;
 import org.apache.openjpa.jdbc.kernel.exps.SQLExpression;
 import org.apache.openjpa.jdbc.kernel.exps.SQLValue;
@@ -150,14 +152,19 @@
             ? range.start : 0L;
         long end = (dict.supportsSelectEndIndex) ? range.end : Long.MAX_VALUE;
 
+        QueryExpressionsState[] states = new QueryExpressionsState[exps.length];
+        for (int i = 0; i < states.length; i++)
+            states[i] = new QueryExpressionsState();
+        ExpContext ctx = new ExpContext(_store, params, fetch);
+
         // add selects with populate WHERE conditions to list
         List sels = new ArrayList(mappings.length);
         List selMappings = new ArrayList(mappings.length);
         BitSet subclassBits = new BitSet();
         BitSet nextBits = new BitSet();
         boolean unionable = createWhereSelects(sels, mappings, selMappings,
-            subclasses, subclassBits, nextBits, facts, exps, params,
-            fetch, subclassMode)
+            subclasses, subclassBits, nextBits, facts, exps, states, ctx,
+            subclassMode)
             && subclassMode == JDBCFetchConfiguration.EAGER_JOIN
             && start == 0
             && end == Long.MAX_VALUE;
@@ -174,9 +181,9 @@
             Union union = _store.getSQLFactory().newUnion(
                 (Select[]) sels.toArray(new Select[sels.size()]));
             BitSet[] paged = populateUnion(union, mappings, subclasses, facts,
-                exps, params, fetch, lrs, eager, start, end);
+                exps, states, ctx, lrs, eager, start, end);
             union.setLRS(lrs);
-            rop = executeUnion(union, mappings, exps, paged, fetch);
+            rop = executeUnion(union, mappings, exps, states, ctx, paged);
         } else {
             if (sels.size() > 1)
                 rops = new ResultObjectProvider[sels.size()];
@@ -187,10 +194,10 @@
                 sel = (Select) sels.get(i);
                 paged = populateSelect(sel, (ClassMapping) selMappings.get(i),
                     subclassBits.get(i), (JDBCExpressionFactory) facts[idx],
-                    exps[idx], params, fetch, lrs, eager, start, end);
+                    exps[idx], states[idx], ctx, lrs, eager, start, end);
 
                 rop = executeSelect(sel, (ClassMapping) selMappings.get(i),
-                    exps[idx], paged, fetch, start, end);
+                    exps[idx], states[idx], ctx, paged, start, end);
                 if (rops != null)
                     rops[i] = rop;
 
@@ -220,16 +227,16 @@
      */
     private BitSet[] populateUnion(Union union, final ClassMapping[] mappings,
         final boolean subclasses, final ExpressionFactory[] facts,
-        final QueryExpressions[] exps, final Object[] params,
-        final JDBCFetchConfiguration fetch, final boolean lrs, final int eager,
+        final QueryExpressions[] exps, final QueryExpressionsState[] states,
+        final ExpContext ctx, final boolean lrs, final int eager,
         final long start, final long end) {
         final BitSet[] paged = (exps[0].projections.length > 0) ? null
             : new BitSet[mappings.length];
         union.select(new Union.Selector() {
             public void select(Select sel, int idx) {
                 BitSet bits = populateSelect(sel, mappings[idx], subclasses,
-                    (JDBCExpressionFactory) facts[idx], exps[idx], params,
-                    fetch, lrs, eager, start, end);
+                    (JDBCExpressionFactory) facts[idx], exps[idx], states[idx],
+                    ctx,  lrs, eager, start, end);
                 if (paged != null)
                     paged[idx] = bits;
             }
@@ -242,7 +249,7 @@
      */
     private BitSet populateSelect(Select sel, ClassMapping mapping,
         boolean subclasses, JDBCExpressionFactory fact, QueryExpressions exps,
-        Object[] params, JDBCFetchConfiguration fetch, boolean lrs, int eager,
+        QueryExpressionsState state, ExpContext ctx, boolean lrs, int eager,
         long start, long end) {
         sel.setLRS(lrs);
         sel.setRange(start, end);
@@ -250,13 +257,13 @@
         BitSet paged = null;
         if (exps.projections.length == 0) {
             paged = PagingResultObjectProvider.getPagedFields(sel, mapping,
-                _store, fetch, eager, end - start);
+                _store, ctx.fetch, eager, end - start);
             if (paged != null)
                 eager = JDBCFetchConfiguration.EAGER_JOIN;
         }
 
-        fact.select(this, mapping, subclasses, sel, exps, params, fetch,
-            eager);
+        fact.getSelectConstructor().select(sel, ctx, mapping, subclasses, exps,
+            state, eager);
         return paged;
     }
 
@@ -264,34 +271,34 @@
      * Execute the given union.
      */
     private ResultObjectProvider executeUnion(Union union,
-        ClassMapping[] mappings, QueryExpressions[] exps, BitSet[] paged,
-        JDBCFetchConfiguration fetch) {
+        ClassMapping[] mappings, QueryExpressions[] exps, 
+        QueryExpressionsState[] states, ExpContext ctx, BitSet[] paged) {
         if (exps[0].projections.length > 0)
-            return new ProjectionResultObjectProvider(union, _store,
-                fetch, exps);
+            return new ProjectionResultObjectProvider(union, exps, states, ctx);
 
         if (paged != null)
             for (int i = 0; i < paged.length; i++)
                 if (paged[i] != null)
                     return new PagingResultObjectProvider(union, mappings,
-                        _store, fetch, paged, Long.MAX_VALUE);
+                        _store, ctx.fetch, paged, Long.MAX_VALUE);
 
         return new InstanceResultObjectProvider(union, mappings[0], _store,
-            fetch);
+            ctx.fetch);
     }
 
     /**
      * Execute the given select.
      */
-    private ResultObjectProvider executeSelect(Select sel,
-        ClassMapping mapping, QueryExpressions exps, BitSet paged,
-        JDBCFetchConfiguration fetch, long start, long end) {
+    private ResultObjectProvider executeSelect(Select sel, ClassMapping mapping,
+        QueryExpressions exps, QueryExpressionsState state, ExpContext ctx, 
+        BitSet paged, long start, long end) {
         if (exps.projections.length > 0)
-            return new ProjectionResultObjectProvider(sel, _store, fetch, exps);
+            return new ProjectionResultObjectProvider(sel, exps, state, ctx);
         if (paged != null)
-            return new PagingResultObjectProvider(sel, mapping, _store, fetch, 
-                paged, end - start);
-        return new InstanceResultObjectProvider(sel, mapping, _store, fetch);
+            return new PagingResultObjectProvider(sel, mapping, _store, 
+                ctx.fetch, paged, end - start);
+        return new InstanceResultObjectProvider(sel, mapping, _store, 
+            ctx.fetch);
     }
 
     /**
@@ -301,10 +308,10 @@
     private boolean createWhereSelects(List sels, ClassMapping[] mappings,
         List selMappings, boolean subclasses, BitSet subclassBits,
         BitSet nextBits, ExpressionFactory[] facts, QueryExpressions[] exps,
-        Object[] params, JDBCFetchConfiguration fetch, int subclassMode) {
-        Select sel;
+        QueryExpressionsState[] states, ExpContext ctx, int subclassMode) {
         ClassMapping[] verts;
         boolean unionable = true;
+        Select sel;
         for (int i = 0; i < mappings.length; i++) {
             // determine vertical mappings to select separately
             verts = getVerticalMappings(mappings[i], subclasses, exps[i],
@@ -313,8 +320,8 @@
                 subclassBits.set(sels.size());
 
             // create criteria select and clone for each vert mapping
-            sel = ((JDBCExpressionFactory) facts[i]).evaluate(this, fetch,
-                exps[i], params);
+            sel = ((JDBCExpressionFactory) facts[i]).getSelectConstructor().
+                evaluate(ctx, null, null, exps[i], states[i]);
             for (int j = 0; j < verts.length; j++) {
                 selMappings.add(verts[j]);
                 if (j == verts.length - 1) {
@@ -437,16 +444,22 @@
 
         JDBCFetchConfiguration fetch = (JDBCFetchConfiguration) 
             ctx.getFetchConfiguration();
+        ExpContext ctx = new ExpContext(_store, params, fetch);
         DBDictionary dict = _store.getDBDictionary();
+        QueryExpressionsState[] state = new QueryExpressionsState[exps.length];
+        for (int i = 0; i < state.length; i++)
+            state[i] = new QueryExpressionsState();
 
         SQLBuffer[] sql = new SQLBuffer[mappings.length];
         JDBCExpressionFactory jdbcFactory;
         Select sel;
         for (int i = 0; i < mappings.length; i++) {
             jdbcFactory = (JDBCExpressionFactory) facts[i];
-            sel = jdbcFactory.evaluate(this, fetch, exps[i], params);
-            jdbcFactory.select(this, mappings[i], subclasses, sel, exps[i],
-                params, fetch, JDBCFetchConfiguration.EAGER_NONE);
+            sel = jdbcFactory.getSelectConstructor().evaluate(ctx, null, null,
+                exps[i], state[i]);
+            jdbcFactory.getSelectConstructor().select(sel, ctx, mappings[i], 
+                subclasses, exps[i], state[i], 
+                JDBCFetchConfiguration.EAGER_NONE);
 
             // specification of the "udpates" map indicates that this is
             // an update query; otherwise, this is a delete statement
@@ -465,7 +478,7 @@
         }
 
         // we need to make sure we have an active store connection
-        ctx.getStoreContext().beginStore();
+        _store.getContext().beginStore();
 
         Connection conn = _store.getConnection();
         long count = 0;
@@ -582,13 +595,18 @@
             ? range.start : 0L;
         long end = (dict.supportsSelectEndIndex) ? range.end : Long.MAX_VALUE;
 
+        QueryExpressionsState[] states = new QueryExpressionsState[exps.length];
+        for (int i = 0; i < states.length; i++)
+            states[i] = new QueryExpressionsState();
+        ExpContext ctx = new ExpContext(_store, params, fetch);
+
         // add selects with populate WHERE conditions to list
         List sels = new ArrayList(mappings.length);
         List selMappings = new ArrayList(mappings.length);
         BitSet subclassBits = new BitSet();
         BitSet nextBits = new BitSet();
         boolean unionable = createWhereSelects(sels, mappings, selMappings,
-            subclasses, subclassBits, nextBits, facts, exps, params, fetch, 
+            subclasses, subclassBits, nextBits, facts, exps, states, ctx, 
             subclassMode) && subclassMode == JDBCFetchConfiguration.EAGER_JOIN;
         if (sels.size() > 1)
             start = 0L;
@@ -596,8 +614,8 @@
         if (unionable) {
             Union union = _store.getSQLFactory().newUnion(
                 (Select[]) sels.toArray(new Select[sels.size()]));
-            populateUnion(union, mappings, subclasses, facts, exps, params,
-                fetch, false, eager, start, end);
+            populateUnion(union, mappings, subclasses, facts, exps, states, ctx,
+                false, eager, start, end);
             if (union.isUnion())
                 return new String[] {union.toSelect(false, fetch).getSQL(true)};
             sels = Arrays.asList(union.getSelects());
@@ -607,7 +625,7 @@
                 sel = (Select) sels.get(i);
                 populateSelect(sel, (ClassMapping) selMappings.get(i),
                     subclassBits.get(i), (JDBCExpressionFactory) facts[idx],
-                    exps[idx], params, fetch, false, eager, start, end);
+                    exps[idx], states[idx], ctx, false, eager, start, end);
                 if (nextBits.get(i))
                     idx++;
             }

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ProjectionResultObjectProvider.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ProjectionResultObjectProvider.java?view=diff&rev=441158&r1=441157&r2=441158
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ProjectionResultObjectProvider.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ProjectionResultObjectProvider.java Thu Sep  7 10:51:05 2006
@@ -15,6 +15,8 @@
  */
 package org.apache.openjpa.jdbc.kernel;
 
+import org.apache.openjpa.jdbc.kernel.exps.ExpContext;
+import org.apache.openjpa.jdbc.kernel.exps.QueryExpressionsState;
 import org.apache.openjpa.jdbc.kernel.exps.Val;
 import org.apache.openjpa.jdbc.sql.Result;
 import org.apache.openjpa.jdbc.sql.SelectExecutor;
@@ -29,32 +31,37 @@
     extends SelectResultObjectProvider {
 
     private final QueryExpressions[] _exps;
+    private final QueryExpressionsState[] _state;
+    private final ExpContext _ctx;
 
     /**
      * Constructor.
      *
      * @param sel the select to execute
-     * @param store the store manager to delegate loading to
-     * @param fetch the fetch configuration
      * @param exps the query expressions
+     * @param states the query expression states
+     * @param ctx the query execution context
      */
-    public ProjectionResultObjectProvider(SelectExecutor sel, JDBCStore store,
-        JDBCFetchConfiguration fetch, QueryExpressions exps) {
-        this(sel, store, fetch, new QueryExpressions[]{ exps });
+    public ProjectionResultObjectProvider(SelectExecutor sel, 
+        QueryExpressions exps, QueryExpressionsState state, ExpContext ctx) {
+        this(sel, new QueryExpressions[]{ exps }, 
+            new QueryExpressionsState[]{ state }, ctx);
     }
 
     /**
      * Constructor.
      *
      * @param sel the select to execute
-     * @param store the store manager to delegate loading to
-     * @param fetch the fetch configuration
      * @param exps the query expressions
+     * @param states the query expression states
+     * @param ctx the query execution context
      */
-    public ProjectionResultObjectProvider(SelectExecutor sel, JDBCStore store,
-        JDBCFetchConfiguration fetch, QueryExpressions[] exps) {
-        super(sel, store, fetch);
+    public ProjectionResultObjectProvider(SelectExecutor sel, 
+        QueryExpressions[] exps, QueryExpressionsState[] state, ExpContext ctx){
+        super(sel, ctx.store, ctx.fetch);
         _exps = exps;
+        _state = state;
+        _ctx = ctx;
     }
 
     public Object getResultObject()
@@ -63,8 +70,8 @@
         int idx = res.indexOf();
         Object[] arr = new Object[_exps[idx].projections.length];
         for (int i = 0; i < _exps[idx].projections.length; i++)
-            arr[i] = ((Val) _exps[idx].projections[i]).load(res, getStore(),
-                getFetchConfiguration());
+            arr[i] = ((Val) _exps[idx].projections[i]).load(_ctx, 
+                _state[idx].projections[i], res);
         return arr;
     }
 }

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/AbstractVal.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/AbstractVal.java?view=diff&rev=441158&r1=441157&r2=441158
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/AbstractVal.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/AbstractVal.java Thu Sep  7 10:51:05 2006
@@ -15,8 +15,6 @@
  */
 package org.apache.openjpa.jdbc.kernel.exps;
 
-import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
-import org.apache.openjpa.jdbc.kernel.JDBCStore;
 import org.apache.openjpa.jdbc.sql.SQLBuffer;
 import org.apache.openjpa.jdbc.sql.Select;
 import org.apache.openjpa.kernel.exps.ExpressionVisitor;
@@ -40,30 +38,35 @@
         return false;
     }
 
-    public void appendIsEmpty(SQLBuffer sql, Select sel, JDBCStore store,
-        Object[] params, JDBCFetchConfiguration fetch) {
+    public Object toDataStoreValue(Select sel, ExpContext ctx, ExpState state, 
+        Object val) {
+        return val;
+    }
+
+    public void appendIsEmpty(Select sel, ExpContext ctx, ExpState state, 
+        SQLBuffer sql) {
         sql.append(FALSE);
     }
 
-    public void appendIsNotEmpty(SQLBuffer sql, Select sel, JDBCStore store,
-        Object[] params, JDBCFetchConfiguration fetch) {
+    public void appendIsNotEmpty(Select sel, ExpContext ctx, ExpState state, 
+        SQLBuffer sql){
         sql.append(TRUE);
     }
 
-    public void appendIsNull(SQLBuffer sql, Select sel,
-        JDBCStore store, Object[] params, JDBCFetchConfiguration fetch) {
-        appendTo(sql, 0, sel, store, params, fetch);
+    public void appendIsNull(Select sel, ExpContext ctx, ExpState state, 
+        SQLBuffer sql) {
+        appendTo(sel, ctx, state, sql, 0);
         sql.append(" IS ").appendValue(null);
     }
 
-    public void appendIsNotNull(SQLBuffer sql, Select sel,
-        JDBCStore store, Object[] params, JDBCFetchConfiguration fetch) {
-        appendTo(sql, 0, sel, store, params, fetch);
+    public void appendIsNotNull(Select sel, ExpContext ctx, ExpState state, 
+        SQLBuffer sql) {
+        appendTo(sel, ctx, state, sql, 0);
         sql.append(" IS NOT ").appendValue(null);
     }
 
-    public void appendSize(SQLBuffer sql, Select sel, JDBCStore store,
-        Object[] params, JDBCFetchConfiguration fetch) {
+    public void appendSize(Select sel, ExpContext ctx, ExpState state, 
+        SQLBuffer sql) {
         sql.append("1");
     }
 

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Aggregate.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Aggregate.java?view=diff&rev=441158&r1=441157&r2=441158
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Aggregate.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Aggregate.java Thu Sep  7 10:51:05 2006
@@ -17,11 +17,8 @@
 
 import java.sql.SQLException;
 
-import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
-import org.apache.openjpa.jdbc.kernel.JDBCStore;
 import org.apache.openjpa.jdbc.meta.ClassMapping;
 import org.apache.openjpa.jdbc.meta.JavaSQLTypes;
-import org.apache.openjpa.jdbc.sql.Joins;
 import org.apache.openjpa.jdbc.sql.Result;
 import org.apache.openjpa.jdbc.sql.SQLBuffer;
 import org.apache.openjpa.jdbc.sql.Select;
@@ -40,7 +37,6 @@
     private final JDBCAggregateListener _listener;
     private final Val _arg;
     private final ClassMapping _candidate;
-    private Joins _joins = null;
     private ClassMetaData _meta = null;
     private Class _cast = null;
 
@@ -84,103 +80,77 @@
         _cast = type;
     }
 
-    public void initialize(Select sel, JDBCStore store, boolean nullTest) {
+    public ExpState initialize(Select sel, ExpContext ctx, int flags) {
+        if (_arg == null)
+            return ExpState.NULL;
+
         // note that we tell targets and args to extensions that are sql
         // paths to go ahead and join to their related object (if any),
         // because we assume that, unlike most operations, if a relation
         // field like a 1-1 is given as the target of an extension, then
         // the extension probably acts on some field or column in the
         // related object, not the 1-1 field itself
-        if (_arg != null) {
-            _arg.initialize(sel, store, false);
-            if (_arg instanceof PCPath)
-                ((PCPath) _arg).joinRelation();
-            _joins = _arg.getJoins();
-        }
-    }
-
-    public Joins getJoins() {
-        return _joins;
-    }
-
-    public Object toDataStoreValue(Object val, JDBCStore store) {
-        return val;
+        return _arg.initialize(sel, ctx, JOIN_REL);
     }
 
-    public void select(Select sel, JDBCStore store, Object[] params,
-        boolean pks, JDBCFetchConfiguration fetch) {
-        sel.select(newSQLBuffer(sel, store, params, fetch), this);
+    public void select(Select sel, ExpContext ctx, ExpState state, 
+        boolean pks) {
+        sel.select(newSQLBuffer(sel, ctx, state), this);
         sel.setAggregate(true);
     }
 
-    public void selectColumns(Select sel, JDBCStore store, Object[] params,
-        boolean pks, JDBCFetchConfiguration fetch) {
+    public void selectColumns(Select sel, ExpContext ctx, ExpState state, 
+        boolean pks) {
         if (_arg != null)
-            _arg.selectColumns(sel, store, params, true, fetch);
+            _arg.selectColumns(sel, ctx, state, true);
     }
 
-    public void groupBy(Select sel, JDBCStore store, Object[] params,
-        JDBCFetchConfiguration fetch) {
-        sel.groupBy(newSQLBuffer(sel, store, params, fetch));
+    public void groupBy(Select sel, ExpContext ctx, ExpState state) {
+        sel.groupBy(newSQLBuffer(sel, ctx, state));
     }
 
-    public void orderBy(Select sel, JDBCStore store, Object[] params,
-        boolean asc, JDBCFetchConfiguration fetch) {
-        sel.orderBy(newSQLBuffer(sel, store, params, fetch), asc, false);
+    public void orderBy(Select sel, ExpContext ctx, ExpState state, 
+        boolean asc) {
+        sel.orderBy(newSQLBuffer(sel, ctx, state), asc, false);
     }
 
-    private SQLBuffer newSQLBuffer(Select sel, JDBCStore store,
-        Object[] params, JDBCFetchConfiguration fetch) {
-        calculateValue(sel, store, params, null, fetch);
-        SQLBuffer buf = new SQLBuffer(store.getDBDictionary());
-        appendTo(buf, 0, sel, store, params, fetch);
-        clearParameters();
+    private SQLBuffer newSQLBuffer(Select sel, ExpContext ctx, ExpState state) {
+        calculateValue(sel, ctx, state, null, null);
+        SQLBuffer buf = new SQLBuffer(ctx.store.getDBDictionary());
+        appendTo(sel, ctx, state, buf, 0);
         return buf;
     }
 
-    public Object load(Result res, JDBCStore store,
-        JDBCFetchConfiguration fetch)
+    public Object load(ExpContext ctx, ExpState state, Result res)
         throws SQLException {
-        return Filters.convert(res.getObject(this,
-            JavaSQLTypes.JDBC_DEFAULT, null), getType());
+        return Filters.convert(res.getObject(this, JavaSQLTypes.JDBC_DEFAULT, 
+            null), getType());
     }
 
-    public void calculateValue(Select sel, JDBCStore store,
-        Object[] params, Val other, JDBCFetchConfiguration fetch) {
+    public void calculateValue(Select sel, ExpContext ctx, ExpState state, 
+        Val other, ExpState otherState) {
         if (_arg != null)
-            _arg.calculateValue(sel, store, params, null, fetch);
+            _arg.calculateValue(sel, ctx, state, null, null);
     }
 
-    public void clearParameters() {
-        if (_arg != null)
-            _arg.clearParameters();
-    }
-
-    public int length() {
+    public int length(Select sel, ExpContext ctx, ExpState state) {
         return 1;
     }
 
-    public void appendTo(SQLBuffer sql, int index, Select sel, JDBCStore store,
-        Object[] params, JDBCFetchConfiguration fetch) {
-        _listener.appendTo(sql, getArgs(sel, store, params, fetch),
-            _candidate, store);
-        sel.append(sql, _joins);
+    public void appendTo(Select sel, ExpContext ctx, ExpState state, 
+        SQLBuffer sql, int index) {
+        _listener.appendTo(sql, getArgs(sel, ctx, state), _candidate, 
+            ctx.store);
+        sel.append(sql, state.joins);
     }
 
-    private FilterValue[] getArgs(Select sel, JDBCStore store,
-        Object[] params, JDBCFetchConfiguration fetch) {
+    private FilterValue[] getArgs(Select sel, ExpContext ctx, ExpState state) {
         if (_arg == null)
             return null;
-        if (_arg instanceof Args) {
-            Val[] vals = ((Args) _arg).getVals();
-            FilterValue[] filts = new FilterValue[vals.length];
-            for (int i = 0; i < vals.length; i++)
-                filts[i] = new FilterValueImpl(vals[i], sel, store, params,
-                    fetch);
-            return filts;
-        }
+        if (_arg instanceof Args)
+            return ((Args) _arg).newFilterValues(sel, ctx, state);
         return new FilterValue[]{
-            new FilterValueImpl(_arg, sel, store, params, fetch)
+            new FilterValueImpl(sel, ctx, state, _arg)
         };
     }
 

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/AndExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/AndExpression.java?view=diff&rev=441158&r1=441157&r2=441158
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/AndExpression.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/AndExpression.java Thu Sep  7 10:51:05 2006
@@ -17,9 +17,6 @@
 
 import java.util.Map;
 
-import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
-import org.apache.openjpa.jdbc.kernel.JDBCStore;
-import org.apache.openjpa.jdbc.sql.Joins;
 import org.apache.openjpa.jdbc.sql.SQLBuffer;
 import org.apache.openjpa.jdbc.sql.Select;
 import org.apache.openjpa.kernel.exps.ExpressionVisitor;
@@ -34,9 +31,6 @@
 
     private final Exp _exp1;
     private final Exp _exp2;
-    private Joins _joins = null;
-    private boolean _paren1 = false;
-    private boolean _paren2 = false;
 
     /**
      * Constructor. Supply the expressions to combine.
@@ -46,40 +40,36 @@
         _exp2 = exp2;
     }
 
-    public void initialize(Select sel, JDBCStore store,
-        Object[] params, Map contains) {
-        _exp1.initialize(sel, store, params, contains);
-        _exp2.initialize(sel, store, params, contains);
-        _joins = sel.and(_exp1.getJoins(), _exp2.getJoins());
-
-        _paren1 = _exp1 instanceof OrExpression;
-        _paren2 = _exp2 instanceof OrExpression;
+    public ExpState initialize(Select sel, ExpContext ctx, Map contains) {
+        ExpState s1 = _exp1.initialize(sel, ctx, contains);
+        ExpState s2 = _exp2.initialize(sel, ctx, contains);
+        return new BinaryOpExpState(sel.and(s1.joins, s2.joins), s1, s2);
     }
 
-    public void appendTo(SQLBuffer buf, Select sel, JDBCStore store,
-        Object[] params, JDBCFetchConfiguration fetch) {
-        if (_paren1)
+    public void appendTo(Select sel, ExpContext ctx, ExpState state, 
+        SQLBuffer buf) {
+        BinaryOpExpState bstate = (BinaryOpExpState) state;
+        boolean paren1 = _exp1 instanceof OrExpression;
+        boolean paren2 = _exp2 instanceof OrExpression;
+        if (paren1)
             buf.append("(");
-        _exp1.appendTo(buf, sel, store, params, fetch);
-        if (_paren1)
+        _exp1.appendTo(sel, ctx, bstate.state1, buf);
+        if (paren1)
             buf.append(")");
         buf.append(" AND ");
-        if (_paren2)
+        if (paren2)
             buf.append("(");
-        _exp2.appendTo(buf, sel, store, params, fetch);
-        if (_paren2)
+        _exp2.appendTo(sel, ctx, bstate.state2, buf);
+        if (paren2)
             buf.append(")");
-        sel.append(buf, _joins);
-    }
-
-    public void selectColumns(Select sel, JDBCStore store,
-        Object[] params, boolean pks, JDBCFetchConfiguration fetch) {
-        _exp1.selectColumns(sel, store, params, pks, fetch);
-        _exp2.selectColumns(sel, store, params, pks, fetch);
+        sel.append(buf, state.joins);
     }
 
-    public Joins getJoins() {
-        return _joins;
+    public void selectColumns(Select sel, ExpContext ctx, ExpState state, 
+        boolean pks) {
+        BinaryOpExpState bstate = (BinaryOpExpState) state;
+        _exp1.selectColumns(sel, ctx, bstate.state1, pks);
+        _exp2.selectColumns(sel, ctx, bstate.state2, pks);
     }
 
     public void acceptVisit(ExpressionVisitor visitor) {

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Args.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Args.java?view=diff&rev=441158&r1=441157&r2=441158
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Args.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Args.java Thu Sep  7 10:51:05 2006
@@ -15,8 +15,6 @@
  */
 package org.apache.openjpa.jdbc.kernel.exps;
 
-import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
-import org.apache.openjpa.jdbc.kernel.JDBCStore;
 import org.apache.openjpa.jdbc.sql.Joins;
 import org.apache.openjpa.jdbc.sql.Result;
 import org.apache.openjpa.jdbc.sql.SQLBuffer;
@@ -36,7 +34,6 @@
     implements Arguments {
 
     private final Val[] _args;
-    private Joins _joins = null;
     private ClassMetaData _meta = null;
 
     /**
@@ -57,6 +54,19 @@
             _args[len1] = val2;
     }
 
+    /**
+     * Return a filter value for each argument.
+     */
+    public FilterValue[] newFilterValues(Select sel, ExpContext ctx, 
+        ExpState state) {
+        ArgsExpState astate = (ArgsExpState) state; 
+        FilterValue[] filts = new FilterValue[_args.length];
+        for (int i = 0; i < _args.length; i++)
+            filts[i] = new FilterValueImpl(sel, ctx, astate.states[i], 
+                _args[i]); 
+        return filts;
+    }
+
     public Value[] getValues() {
         return _args;
     }
@@ -91,84 +101,88 @@
     public void setImplicitType(Class type) {
     }
 
-    public void initialize(Select sel, JDBCStore store, boolean nullTest) {
+    public ExpState initialize(Select sel, ExpContext ctx, int flags) {
+        ExpState[] states = new ExpState[_args.length];
+        Joins joins = null;
         for (int i = 0; i < _args.length; i++) {
-            _args[i].initialize(sel, store, nullTest);
-            if (_joins == null)
-                _joins = _args[i].getJoins();
+            states[i] = _args[i].initialize(sel, ctx, flags);
+            if (joins == null)
+                joins = states[i].joins;
             else
-                _joins = sel.and(_joins, _args[i].getJoins());
+                joins = sel.and(joins, states[i].joins);
         }
+        return new ArgsExpState(joins, states);
     }
 
-    public Joins getJoins() {
-        return _joins;
-    }
-
-    public Object toDataStoreValue(Object val, JDBCStore store) {
-        return val;
+    /**
+     * Expression state.
+     */
+    private static class ArgsExpState
+        extends ExpState {
+        
+        public ExpState[] states;
+
+        public ArgsExpState(Joins joins, ExpState[] states) {
+            super(joins);
+            this.states = states;
+        }
     }
 
-    public void select(Select sel, JDBCStore store, Object[] params,
-        boolean pks, JDBCFetchConfiguration fetch) {
+    public void select(Select sel, ExpContext ctx, ExpState state, 
+        boolean pks) {
     }
 
-    public void selectColumns(Select sel, JDBCStore store,
-        Object[] params, boolean pks, JDBCFetchConfiguration fetch) {
+    public void selectColumns(Select sel, ExpContext ctx, ExpState state, 
+        boolean pks) {
+        ArgsExpState astate = (ArgsExpState) state;
         for (int i = 0; i < _args.length; i++)
-            _args[i].selectColumns(sel, store, params, pks, fetch);
+            _args[i].selectColumns(sel, ctx, astate.states[i], pks);
     }
 
-    public void groupBy(Select sel, JDBCStore store, Object[] params,
-        JDBCFetchConfiguration fetch) {
+    public void groupBy(Select sel, ExpContext ctx, ExpState state) {
     }
 
-    public void orderBy(Select sel, JDBCStore store, Object[] params,
-        boolean asc, JDBCFetchConfiguration fetch) {
+    public void orderBy(Select sel, ExpContext ctx, ExpState state, 
+        boolean asc) {
     }
 
-    public Object load(Result res, JDBCStore store,
-        JDBCFetchConfiguration fetch) {
+    public Object load(ExpContext ctx, ExpState state, Result res) {
         return null;
     }
 
-    public void calculateValue(Select sel, JDBCStore store,
-        Object[] params, Val other, JDBCFetchConfiguration fetch) {
-        for (int i = 0; i < _args.length; i++)
-            _args[i].calculateValue(sel, store, params, null, fetch);
-    }
-
-    public void clearParameters() {
+    public void calculateValue(Select sel, ExpContext ctx, ExpState state, 
+        Val other, ExpState otherState) {
+        ArgsExpState astate = (ArgsExpState) state;
         for (int i = 0; i < _args.length; i++)
-            _args[i].clearParameters();
+            _args[i].calculateValue(sel, ctx, astate.states[i], null, null);
     }
 
-    public int length() {
+    public int length(Select sel, ExpContext ctx, ExpState state) {
         return 0;
     }
 
-    public void appendTo(SQLBuffer sql, int index, Select sel,
-        JDBCStore store, Object[] params, JDBCFetchConfiguration fetch) {
+    public void appendTo(Select sel, ExpContext ctx, ExpState state, 
+        SQLBuffer sql, int index) {
     }
 
-    public void appendIsEmpty(SQLBuffer sql, Select sel,
-        JDBCStore store, Object[] params, JDBCFetchConfiguration fetch) {
+    public void appendIsEmpty(Select sel, ExpContext ctx, ExpState state, 
+        SQLBuffer sql) {
     }
 
-    public void appendIsNotEmpty(SQLBuffer sql, Select sel,
-        JDBCStore store, Object[] params, JDBCFetchConfiguration fetch) {
+    public void appendIsNotEmpty(Select sel, ExpContext ctx, ExpState state, 
+        SQLBuffer sql){
     }
 
-    public void appendSize(SQLBuffer sql, Select sel, JDBCStore store,
-        Object[] params, JDBCFetchConfiguration fetch) {
+    public void appendSize(Select sel, ExpContext ctx, ExpState state, 
+        SQLBuffer sql) {
     }
 
-    public void appendIsNull(SQLBuffer sql, Select sel,
-        JDBCStore store, Object[] params, JDBCFetchConfiguration fetch) {
+    public void appendIsNull(Select sel, ExpContext ctx, ExpState state, 
+        SQLBuffer sql) {
     }
 
-    public void appendIsNotNull(SQLBuffer sql, Select sel,
-        JDBCStore store, Object[] params, JDBCFetchConfiguration fetch) {
+    public void appendIsNotNull(Select sel, ExpContext ctx, ExpState state, 
+        SQLBuffer sql) {
     }
 
     public void acceptVisit(ExpressionVisitor visitor) {

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/BindVariableAndExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/BindVariableAndExpression.java?view=diff&rev=441158&r1=441157&r2=441158
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/BindVariableAndExpression.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/BindVariableAndExpression.java Thu Sep  7 10:51:05 2006
@@ -17,9 +17,6 @@
 
 import java.util.Map;
 
-import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
-import org.apache.openjpa.jdbc.kernel.JDBCStore;
-import org.apache.openjpa.jdbc.sql.Joins;
 import org.apache.openjpa.jdbc.sql.SQLBuffer;
 import org.apache.openjpa.jdbc.sql.Select;
 import org.apache.openjpa.kernel.exps.ExpressionVisitor;
@@ -34,7 +31,6 @@
 
     private final BindVariableExpression _bind;
     private final Exp _exp;
-    private Joins _joins = null;
 
     /**
      * Constructor. Supply the two combined expressions.
@@ -44,30 +40,25 @@
         _exp = exp;
     }
 
-    public void initialize(Select sel, JDBCStore store,
-        Object[] params, Map contains) {
-        _bind.initialize(sel, store, params, contains);
-        _exp.initialize(sel, store, params, contains);
-        _joins = sel.and(_bind.getJoins(), _exp.getJoins());
+    public ExpState initialize(Select sel, ExpContext ctx, Map contains) {
+        ExpState s1 = _bind.initialize(sel, ctx, contains);
+        ExpState s2 = _exp.initialize(sel, ctx, contains);
+        return new BinaryOpExpState(sel.and(s1.joins, s2.joins), s1, s2);
     }
 
-    public void appendTo(SQLBuffer buf, Select sel, JDBCStore store,
-        Object[] params, JDBCFetchConfiguration fetch) {
+    public void appendTo(Select sel, ExpContext ctx, ExpState state, 
+        SQLBuffer buf) {
         boolean or = _exp instanceof OrExpression;
         if (or)
             buf.append("(");
-        _exp.appendTo(buf, sel, store, params, fetch);
+        _exp.appendTo(sel, ctx, ((BinaryOpExpState) state).state2, buf);
         if (or)
             buf.append(")");
     }
 
-    public void selectColumns(Select sel, JDBCStore store,
-        Object[] params, boolean pks, JDBCFetchConfiguration fetch) {
-        _exp.selectColumns(sel, store, params, pks, fetch);
-    }
-
-    public Joins getJoins() {
-        return _joins;
+    public void selectColumns(Select sel, ExpContext ctx, ExpState state, 
+        boolean pks) {
+        _exp.selectColumns(sel, ctx, ((BinaryOpExpState) state).state2, pks);
     }
 
     public void acceptVisit(ExpressionVisitor visitor) {

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/BindVariableExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/BindVariableExpression.java?view=diff&rev=441158&r1=441157&r2=441158
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/BindVariableExpression.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/BindVariableExpression.java Thu Sep  7 10:51:05 2006
@@ -17,9 +17,6 @@
 
 import java.util.Map;
 
-import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
-import org.apache.openjpa.jdbc.kernel.JDBCStore;
-import org.apache.openjpa.jdbc.sql.Joins;
 import org.apache.openjpa.jdbc.sql.SQLBuffer;
 import org.apache.openjpa.jdbc.sql.Select;
 import org.apache.openjpa.kernel.exps.ExpressionVisitor;
@@ -54,22 +51,17 @@
         return _var;
     }
 
-    public void initialize(Select sel, JDBCStore store,
-        Object[] params, Map contains) {
-        _var.initialize(sel, store, false);
+    public ExpState initialize(Select sel, ExpContext ctx, Map contains) {
+        return _var.initialize(sel, ctx, 0);
     }
 
-    public void appendTo(SQLBuffer buf, Select sel, JDBCStore store,
-        Object[] params, JDBCFetchConfiguration fetch) {
+    public void appendTo(Select sel, ExpContext ctx, ExpState state, 
+        SQLBuffer buf) {
         buf.append("1 = 1");
     }
 
-    public void selectColumns(Select sel, JDBCStore store,
-        Object[] params, boolean pks, JDBCFetchConfiguration fetch) {
-    }
-
-    public Joins getJoins() {
-        return _var.getJoins();
+    public void selectColumns(Select sel, ExpContext ctx, ExpState state, 
+        boolean pks) {
     }
 
     public void acceptVisit(ExpressionVisitor visitor) {

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CompareEqualExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CompareEqualExpression.java?view=diff&rev=441158&r1=441157&r2=441158
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CompareEqualExpression.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CompareEqualExpression.java Thu Sep  7 10:51:05 2006
@@ -17,12 +17,10 @@
 
 import java.util.Map;
 
-import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
-import org.apache.openjpa.jdbc.kernel.JDBCStore;
-import org.apache.openjpa.jdbc.sql.Joins;
 import org.apache.openjpa.jdbc.sql.SQLBuffer;
 import org.apache.openjpa.jdbc.sql.Select;
 import org.apache.openjpa.kernel.Filters;
+import org.apache.openjpa.kernel.exps.Constant;
 import org.apache.openjpa.kernel.exps.ExpressionVisitor;
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.util.UserException;
@@ -40,7 +38,6 @@
 
     private final Val _val1;
     private final Val _val2;
-    private Joins _joins = null;
 
     /**
      * Constructor. Supply values to compare.
@@ -58,63 +55,61 @@
         return _val2;
     }
 
-    public void initialize(Select sel, JDBCStore store,
-        Object[] params, Map contains) {
+    public ExpState initialize(Select sel, ExpContext ctx, Map contains) {
         boolean direct = isDirectComparison();
-        _val1.initialize(sel, store, direct && isNull(_val2, params));
-        _val2.initialize(sel, store, direct && isNull(_val1, params));
-        _joins = sel.and(_val1.getJoins(), _val2.getJoins());
-    }
-
-    /**
-     * Return whether the given value is null.
-     */
-    private boolean isNull(Val val, Object[] params) {
-        if (val instanceof Null)
-            return true;
-        if (!(val instanceof Param))
-            return false;
-
-        Param param = (Param) val;
-        return params[param.getIndex()] == null;
-    }
-
-    public void appendTo(SQLBuffer buf, Select sel, JDBCStore store,
-        Object[] params, JDBCFetchConfiguration fetch) {
-        _val1.calculateValue(sel, store, params, _val2, fetch);
-        _val2.calculateValue(sel, store, params, _val1, fetch);
+        int flags1 = 0;
+        int flags2 = 0;
+        ExpState s1 = null;
+        ExpState s2 = null;
+        if (_val1 instanceof Const) {
+            s1 = _val1.initialize(sel, ctx, 0);
+            if (direct && ((Const) _val1).getValue(ctx, s1) == null)
+                flags2 = Val.NULL_CMP;
+        }
+        if (_val2 instanceof Const) {
+            s2 = _val2.initialize(sel, ctx, 0);
+            if (direct && ((Const) _val2).getValue(ctx, s2) == null)
+                flags1 = Val.NULL_CMP;
+        }
+        
+        if (s1 == null)
+            s1 = _val1.initialize(sel, ctx, flags1);
+        if (s2 == null)
+            s2 = _val2.initialize(sel, ctx, flags2);
+        return new BinaryOpExpState(sel.and(s1.joins, s2.joins), s1, s2);
+    }
+
+    public void appendTo(Select sel, ExpContext ctx, ExpState state, 
+        SQLBuffer buf) {
+        BinaryOpExpState bstate = (BinaryOpExpState) state;
+        _val1.calculateValue(sel, ctx, bstate.state1, _val2, bstate.state2);
+        _val2.calculateValue(sel, ctx, bstate.state2, _val1, bstate.state1);
         if (!Filters.canConvert(_val1.getType(), _val2.getType(), false)
             && !Filters.canConvert(_val2.getType(), _val1.getType(), false))
             throw new UserException(_loc.get("cant-convert", _val1.getType(),
                 _val2.getType()));
 
         boolean val1Null = _val1 instanceof Const
-            && ((Const) _val1).isSQLValueNull();
+            && ((Const) _val1).isSQLValueNull(sel, ctx, bstate.state1);
         boolean val2Null = _val2 instanceof Const
-            && ((Const) _val2).isSQLValueNull();
-        appendTo(buf, sel, store, params, fetch, val1Null, val2Null);
-        sel.append(buf, _joins);
-
-        _val1.clearParameters();
-        _val2.clearParameters();
-    }
-
-    public void selectColumns(Select sel, JDBCStore store,
-        Object[] params, boolean pks, JDBCFetchConfiguration fetch) {
-        _val1.selectColumns(sel, store, params, true, fetch);
-        _val2.selectColumns(sel, store, params, true, fetch);
+            && ((Const) _val2).isSQLValueNull(sel, ctx, bstate.state2);
+        appendTo(sel, ctx, bstate, buf, val1Null, val2Null);
+        sel.append(buf, state.joins);
     }
 
-    public Joins getJoins() {
-        return _joins;
+    public void selectColumns(Select sel, ExpContext ctx, ExpState state, 
+        boolean pks) {
+        BinaryOpExpState bstate = (BinaryOpExpState) state;
+        _val1.selectColumns(sel, ctx, bstate.state1, true);
+        _val2.selectColumns(sel, ctx, bstate.state2, true);
     }
 
     /**
      * Append the SQL for the comparison.
      */
-    protected abstract void appendTo(SQLBuffer buf, Select sel,
-        JDBCStore store, Object[] params, JDBCFetchConfiguration fetch,
-        boolean val1Null, boolean val2Null);
+    protected abstract void appendTo(Select sel, ExpContext ctx, 
+        BinaryOpExpState state, SQLBuffer buf, boolean val1Null, 
+        boolean val2Null);
 
     /**
      * Subclasses can override this method if, when they compare to another,

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CompareExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CompareExpression.java?view=diff&rev=441158&r1=441157&r2=441158
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CompareExpression.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CompareExpression.java Thu Sep  7 10:51:05 2006
@@ -17,9 +17,6 @@
 
 import java.util.Map;
 
-import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
-import org.apache.openjpa.jdbc.kernel.JDBCStore;
-import org.apache.openjpa.jdbc.sql.Joins;
 import org.apache.openjpa.jdbc.sql.SQLBuffer;
 import org.apache.openjpa.jdbc.sql.Select;
 import org.apache.openjpa.kernel.Filters;
@@ -46,7 +43,6 @@
     private final Val _val1;
     private final Val _val2;
     private final String _op;
-    private Joins _joins = null;
 
     /**
      * Constructor. Supply values and operator.
@@ -57,39 +53,33 @@
         _op = op;
     }
 
-    public void initialize(Select sel, JDBCStore store,
-        Object[] params, Map contains) {
-        _val1.initialize(sel, store, false);
-        _val2.initialize(sel, store, false);
-        _joins = sel.and(_val1.getJoins(), _val2.getJoins());
+    public ExpState initialize(Select sel, ExpContext ctx, Map contains) {
+        ExpState s1 = _val1.initialize(sel, ctx, 0);
+        ExpState s2 = _val2.initialize(sel, ctx, 0);
+        return new BinaryOpExpState(sel.and(s1.joins, s2.joins), s1, s2);
     }
 
-    public void appendTo(SQLBuffer buf, Select sel, JDBCStore store,
-        Object[] params, JDBCFetchConfiguration fetch) {
-        _val1.calculateValue(sel, store, params, _val2, fetch);
-        _val2.calculateValue(sel, store, params, _val1, fetch);
+    public void appendTo(Select sel, ExpContext ctx, ExpState state, 
+        SQLBuffer buf) {
+        BinaryOpExpState bstate = (BinaryOpExpState) state;
+        _val1.calculateValue(sel, ctx, bstate.state1, _val2, bstate.state2);
+        _val2.calculateValue(sel, ctx, bstate.state2, _val1, bstate.state1);
         if (!Filters.canConvert(_val1.getType(), _val2.getType(), false)
             && !Filters.canConvert(_val2.getType(), _val1.getType(), false))
             throw new UserException(_loc.get("cant-convert", _val1.getType(),
                 _val2.getType()));
 
-        store.getDBDictionary().comparison(buf, _op,
-            new FilterValueImpl(_val1, sel, store, params, fetch),
-            new FilterValueImpl(_val2, sel, store, params, fetch));
-        sel.append(buf, _joins);
-
-        _val1.clearParameters();
-        _val2.clearParameters();
-    }
-
-    public void selectColumns(Select sel, JDBCStore store,
-        Object[] params, boolean pks, JDBCFetchConfiguration fetch) {
-        _val1.selectColumns(sel, store, params, true, fetch);
-        _val2.selectColumns(sel, store, params, true, fetch);
+        ctx.store.getDBDictionary().comparison(buf, _op,
+            new FilterValueImpl(sel, ctx, bstate.state1, _val1),
+            new FilterValueImpl(sel, ctx, bstate.state2, _val2));
+        sel.append(buf, state.joins);
     }
 
-    public Joins getJoins() {
-        return _joins;
+    public void selectColumns(Select sel, ExpContext ctx, ExpState state, 
+        boolean pks) {
+        BinaryOpExpState bstate = (BinaryOpExpState) state;
+        _val1.selectColumns(sel, ctx, bstate.state1, true);
+        _val2.selectColumns(sel, ctx, bstate.state2, true);
     }
 
     public void acceptVisit(ExpressionVisitor visitor) {

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Concat.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Concat.java?view=diff&rev=441158&r1=441157&r2=441158
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Concat.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Concat.java Thu Sep  7 10:51:05 2006
@@ -18,11 +18,8 @@
 import java.lang.Math;
 import java.sql.SQLException;
 
-import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
-import org.apache.openjpa.jdbc.kernel.JDBCStore;
 import org.apache.openjpa.jdbc.meta.JavaSQLTypes;
 import org.apache.openjpa.jdbc.sql.DBDictionary;
-import org.apache.openjpa.jdbc.sql.Joins;
 import org.apache.openjpa.jdbc.sql.Result;
 import org.apache.openjpa.jdbc.sql.SQLBuffer;
 import org.apache.openjpa.jdbc.sql.Select;
@@ -40,11 +37,7 @@
 
     private final Val _val1;
     private final Val _val2;
-    private Joins _joins = null;
     private ClassMetaData _meta = null;
-    private String _part1;
-    private String _part2;
-    private String _part3;
 
     /**
      * Constructor. Provide the strings to operate on.
@@ -62,10 +55,6 @@
         _meta = meta;
     }
 
-    public boolean isVariable() {
-        return false;
-    }
-
     public Class getType() {
         return String.class;
     }
@@ -73,95 +62,78 @@
     public void setImplicitType(Class type) {
     }
 
-    public void initialize(Select sel, JDBCStore store, boolean nullTest) {
-        _val1.initialize(sel, store, false);
-        _val2.initialize(sel, store, false);
-        _joins = sel.and(_val1.getJoins(), _val2.getJoins());
-
-        DBDictionary dict = store.getDBDictionary();
-        String func = dict.concatenateFunction;
-
-        dict.assertSupport(func != null, "ConcatenateFunction");
-
-        int part1idx = func.indexOf("{0}");
-        int part2idx = func.indexOf("{1}");
-
-        _part1 = func.substring(0, Math.min(part1idx, part2idx));
-        _part2 = func.substring(Math.min(part1idx, part2idx) + 3,
-            Math.max(part1idx, part2idx));
-        _part3 = func.substring(Math.max(part1idx, part2idx) + 3);
-    }
-
-    public Joins getJoins() {
-        return _joins;
-    }
-
-    public Object toDataStoreValue(Object val, JDBCStore store) {
-        return val;
+    public ExpState initialize(Select sel, ExpContext ctx, int flags) {
+        ExpState s1 = _val1.initialize(sel, ctx, 0);
+        ExpState s2 = _val2.initialize(sel, ctx, 0);
+        return new BinaryOpExpState(sel.and(s1.joins, s2.joins), s1, s2);
     }
 
-    public void select(Select sel, JDBCStore store, Object[] params,
-        boolean pks, JDBCFetchConfiguration fetch) {
-        sel.select(newSQLBuffer(sel, store, params, fetch), this);
+    public void select(Select sel, ExpContext ctx, ExpState state, 
+        boolean pks) {
+        sel.select(newSQLBuffer(sel, ctx, state), this);
     }
 
-    public void selectColumns(Select sel, JDBCStore store,
-        Object[] params, boolean pks, JDBCFetchConfiguration fetch) {
-        _val1.selectColumns(sel, store, params, true, fetch);
-        _val2.selectColumns(sel, store, params, true, fetch);
+    public void selectColumns(Select sel, ExpContext ctx, ExpState state, 
+        boolean pks) {
+        BinaryOpExpState bstate = (BinaryOpExpState) state;
+        _val1.selectColumns(sel, ctx, bstate.state1, true);
+        _val2.selectColumns(sel, ctx, bstate.state2, true);
     }
 
-    public void groupBy(Select sel, JDBCStore store, Object[] params,
-        JDBCFetchConfiguration fetch) {
-        sel.groupBy(newSQLBuffer(sel, store, params, fetch));
+    public void groupBy(Select sel, ExpContext ctx, ExpState state) {
+        sel.groupBy(newSQLBuffer(sel, ctx, state));
     }
 
-    public void orderBy(Select sel, JDBCStore store, Object[] params,
-        boolean asc, JDBCFetchConfiguration fetch) {
-        sel.orderBy(newSQLBuffer(sel, store, params, fetch), asc, false);
+    public void orderBy(Select sel, ExpContext ctx, ExpState state, 
+        boolean asc) {
+        sel.orderBy(newSQLBuffer(sel, ctx, state), asc, false);
     }
 
-    private SQLBuffer newSQLBuffer(Select sel, JDBCStore store,
-        Object[] params, JDBCFetchConfiguration fetch) {
-        calculateValue(sel, store, params, null, fetch);
-        SQLBuffer buf = new SQLBuffer(store.getDBDictionary());
-        appendTo(buf, 0, sel, store, params, fetch);
-        clearParameters();
+    private SQLBuffer newSQLBuffer(Select sel, ExpContext ctx, ExpState state) {
+        calculateValue(sel, ctx, state, null, null);
+        SQLBuffer buf = new SQLBuffer(ctx.store.getDBDictionary());
+        appendTo(sel, ctx, state, buf, 0);
         return buf;
     }
 
-    public Object load(Result res, JDBCStore store, 
-        JDBCFetchConfiguration fetch)
+    public Object load(ExpContext ctx, ExpState state, Result res) 
         throws SQLException {
         return Filters.convert(res.getObject(this,
             JavaSQLTypes.JDBC_DEFAULT, null), getType());
     }
 
-    public void calculateValue(Select sel, JDBCStore store,
-        Object[] params, Val other, JDBCFetchConfiguration fetch) {
-        _val1.calculateValue(sel, store, params, null, fetch);
-        _val2.calculateValue(sel, store, params, null, fetch);
+    public void calculateValue(Select sel, ExpContext ctx, ExpState state, 
+        Val other, ExpState otherState) {
+        BinaryOpExpState bstate = (BinaryOpExpState) state;
+        _val1.calculateValue(sel, ctx, bstate.state1, null, null);
+        _val2.calculateValue(sel, ctx, bstate.state2, null, null);
     }
 
-    public void clearParameters() {
-        _val1.clearParameters();
-        _val2.clearParameters();
-    }
-
-    public int length() {
+    public int length(Select sel, ExpContext ctx, ExpState state) {
         return 1;
     }
 
-    public void appendTo(SQLBuffer sql, int index, Select sel,
-        JDBCStore store, Object[] params, JDBCFetchConfiguration fetch) {
-        _val1.calculateValue(sel, store, params, _val2, fetch);
-        _val2.calculateValue(sel, store, params, _val1, fetch);
-
-        sql.append(_part1);
-        _val1.appendTo(sql, 0, sel, store, params, fetch);
-        sql.append(_part2);
-        _val2.appendTo(sql, 0, sel, store, params, fetch);
-        sql.append(_part3);
+    public void appendTo(Select sel, ExpContext ctx, ExpState state, 
+        SQLBuffer sql, int index) {
+        BinaryOpExpState bstate = (BinaryOpExpState) state;
+        _val1.calculateValue(sel, ctx, bstate.state1, null, null);
+        _val2.calculateValue(sel, ctx, bstate.state2, null, null);
+
+        DBDictionary dict = ctx.store.getDBDictionary();
+        String func = dict.concatenateFunction;
+        dict.assertSupport(func != null, "ConcatenateFunction");
+        int part1idx = func.indexOf("{0}");
+        int part2idx = func.indexOf("{1}");
+        String part1 = func.substring(0, Math.min(part1idx, part2idx));
+        String part2 = func.substring(Math.min(part1idx, part2idx) + 3,
+            Math.max(part1idx, part2idx));
+        String part3 = func.substring(Math.max(part1idx, part2idx) + 3);
+
+        sql.append(part1);
+        _val1.appendTo(sel, ctx, bstate.state1, sql, 0);
+        sql.append(part2);
+        _val2.appendTo(sel, ctx, bstate.state2, sql, 0);
+        sql.append(part3);
     }
 
     public void acceptVisit(ExpressionVisitor visitor) {

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Const.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Const.java?view=diff&rev=441158&r1=441157&r2=441158
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Const.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Const.java Thu Sep  7 10:51:05 2006
@@ -19,11 +19,8 @@
 import java.util.Collection;
 import java.util.Map;
 
-import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
-import org.apache.openjpa.jdbc.kernel.JDBCStore;
 import org.apache.openjpa.jdbc.meta.JavaSQLTypes;
 import org.apache.openjpa.jdbc.schema.Column;
-import org.apache.openjpa.jdbc.sql.Joins;
 import org.apache.openjpa.jdbc.sql.Result;
 import org.apache.openjpa.jdbc.sql.SQLBuffer;
 import org.apache.openjpa.jdbc.sql.Select;
@@ -42,7 +39,6 @@
     implements Constant {
 
     private ClassMetaData _meta = null;
-    private Column[] _cols = null;
 
     public ClassMetaData getMetaData() {
         return _meta;
@@ -53,33 +49,17 @@
     }
 
     /**
-     * Return the column for the value at the specified index, or null.
-     */
-    public Column getColumn(int index) {
-        return (_cols != null && _cols.length > index) ? _cols[index] : null;
-    }
-
-    /**
-     * Return the value of this constant.
-     */
-    public abstract Object getValue();
-
-    public Object getValue(Object[] parameters) {
-        return getValue();
-    }
-
-    /**
      * Return the SQL value of this constant.
      */
-    public Object getSQLValue() {
-        return getValue();
+    public Object getSQLValue(Select sel, ExpContext ctx, ExpState state) {
+        return getValue(ctx, state);
     }
 
     /**
      * Return true if this constant's SQL value is equivalent to NULL.
      */
-    public boolean isSQLValueNull() {
-        Object val = getSQLValue();
+    public boolean isSQLValueNull(Select sel, ExpContext ctx, ExpState state) {
+        Object val = getSQLValue(sel, ctx, state);
         if (val == null)
             return true;
         if (!(val instanceof Object[]))
@@ -93,69 +73,78 @@
         return true;
     }
 
-    public void initialize(Select sel, JDBCStore store, boolean nullTest) {
+    /**
+     * Return the value of this constant.  May be more robust than the
+     * parameters-only form.
+     */
+    public Object getValue(ExpContext ctx, ExpState state) {
+        return getValue(ctx.params);
     }
 
-    public Joins getJoins() {
-        return null;
+    public ExpState initialize(Select sel, ExpContext ctx, int flags) {
+        return new ConstExpState();
     }
 
-    public void calculateValue(Select sel, JDBCStore store,
-        Object[] params, Val other, JDBCFetchConfiguration fetch) {
-        if (other instanceof PCPath)
-            _cols = ((PCPath) other).getColumns();
-        else
-            _cols = null;
+    /**
+     * Constant expression state.
+     */
+    protected static class ConstExpState
+        extends ExpState {
+
+        public Column[] cols = null;
+
+        /**
+         * Return the column for the value at the specified index, or null.
+         */
+        public Column getColumn(int index) {
+            return (cols != null && cols.length > index) ? cols[index] : null;
+        }
     }
 
-    public Object toDataStoreValue(Object val, JDBCStore store) {
-        return val;
+    public void calculateValue(Select sel, ExpContext ctx, ExpState state, 
+        Val other, ExpState otherState) {
+        if (other instanceof PCPath)
+            ((ConstExpState) state).cols = ((PCPath) other).
+                getColumns(otherState);
     }
 
-    public void select(Select sel, JDBCStore store, Object[] params,
-        boolean pks, JDBCFetchConfiguration fetch) {
-        sel.select(newSQLBuffer(sel, store, params, fetch), this);
+    public void select(Select sel, ExpContext ctx, ExpState state, 
+        boolean pks) {
+        sel.select(newSQLBuffer(sel, ctx, state), this);
     }
 
-    private SQLBuffer newSQLBuffer(Select sel, JDBCStore store,
-        Object[] params, JDBCFetchConfiguration fetch) {
-        calculateValue(sel, store, params, null, fetch);
-        SQLBuffer buf = new SQLBuffer(store.getDBDictionary());
-        appendTo(buf, 0, sel, store, params, fetch);
-        clearParameters();
+    private SQLBuffer newSQLBuffer(Select sel, ExpContext ctx, ExpState state) {
+        calculateValue(sel, ctx, state, null, null);
+        SQLBuffer buf = new SQLBuffer(ctx.store.getDBDictionary());
+        appendTo(sel, ctx, state, buf, 0);
         return buf;
     }
 
-    public void selectColumns(Select sel, JDBCStore store,
-        Object[] params, boolean pks, JDBCFetchConfiguration fetch) {
+    public void selectColumns(Select sel, ExpContext ctx, ExpState state, 
+        boolean pks) {
     }
 
-    public void groupBy(Select sel, JDBCStore store, Object[] params,
-        JDBCFetchConfiguration fetch) {
-        sel.groupBy(newSQLBuffer(sel, store, params, fetch));
+    public void groupBy(Select sel, ExpContext ctx, ExpState state) {
+        sel.groupBy(newSQLBuffer(sel, ctx, state));
     }
 
-    public void orderBy(Select sel, JDBCStore store, Object[] params,
-        boolean asc, JDBCFetchConfiguration fetch) {
-        sel.orderBy(newSQLBuffer(sel, store, params, fetch), asc, false);
+    public void orderBy(Select sel, ExpContext ctx, ExpState state, 
+        boolean asc) {
+        sel.orderBy(newSQLBuffer(sel, ctx, state), asc, false);
     }
 
-    public Object load(Result res, JDBCStore store,
-        JDBCFetchConfiguration fetch)
+    public Object load(ExpContext ctx, ExpState state, Result res)
         throws SQLException {
-        int code = JavaTypes.getTypeCode(getType());
-        if (code == JavaTypes.OBJECT)
-            code = JavaSQLTypes.JDBC_DEFAULT;
-        return Filters.convert(res.getObject(this, code, null), getType());
+        return getValue(ctx, state);
     }
 
-    public int length() {
+    public int length(Select sel, ExpContext ctx, ExpState state) {
         return 1;
     }
 
-    public void appendIsEmpty(SQLBuffer sql, Select sel,
-        JDBCStore store, Object[] params, JDBCFetchConfiguration fetch) {
-        Object obj = getValue();
+    public void appendIsEmpty(Select sel, ExpContext ctx, ExpState state, 
+        SQLBuffer sql) {
+        Object obj = getValue(ctx, state);
         if (obj instanceof Collection && ((Collection) obj).isEmpty())
             sql.append(TRUE);
         else if (obj instanceof Map && ((Map) obj).isEmpty())
@@ -164,9 +153,9 @@
             sql.append(FALSE);
     }
 
-    public void appendIsNotEmpty(SQLBuffer sql, Select sel,
-        JDBCStore store, Object[] params, JDBCFetchConfiguration fetch) {
-        Object obj = getValue();
+    public void appendIsNotEmpty(Select sel, ExpContext ctx, ExpState state, 
+        SQLBuffer sql){
+        Object obj = getValue(ctx, state);
         if (obj instanceof Collection && ((Collection) obj).isEmpty())
             sql.append(FALSE);
         else if (obj instanceof Map && ((Map) obj).isEmpty())
@@ -175,9 +164,9 @@
             sql.append(TRUE);
     }
 
-    public void appendSize(SQLBuffer sql, Select sel, JDBCStore store,
-        Object[] params, JDBCFetchConfiguration fetch) {
-        Object obj = getValue();
+    public void appendSize(Select sel, ExpContext ctx, ExpState state, 
+        SQLBuffer sql) {
+        Object obj = getValue(ctx, state);
         if (obj instanceof Collection)
             sql.appendValue(((Collection) obj).size());
         else if (obj instanceof Map)
@@ -186,17 +175,17 @@
             sql.append("1");
     }
 
-    public void appendIsNull(SQLBuffer sql, Select sel,
-        JDBCStore store, Object[] params, JDBCFetchConfiguration fetch) {
-        if (getSQLValue() == null)
+    public void appendIsNull(Select sel, ExpContext ctx, ExpState state, 
+        SQLBuffer sql) {
+        if (isSQLValueNull(sel, ctx, state))
             sql.append(TRUE);
         else
             sql.append(FALSE);
     }
 
-    public void appendIsNotNull(SQLBuffer sql, Select sel,
-        JDBCStore store, Object[] params, JDBCFetchConfiguration fetch) {
-        if (getSQLValue() != null)
+    public void appendIsNotNull(Select sel, ExpContext ctx, ExpState state, 
+        SQLBuffer sql) {
+        if (!isSQLValueNull(sel, ctx, state))
             sql.append(TRUE);
         else
             sql.append(FALSE);

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ConstGetObjectId.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ConstGetObjectId.java?view=diff&rev=441158&r1=441157&r2=441158
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ConstGetObjectId.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ConstGetObjectId.java Thu Sep  7 10:51:05 2006
@@ -15,8 +15,8 @@
  */
 package org.apache.openjpa.jdbc.kernel.exps;
 
-import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
-import org.apache.openjpa.jdbc.kernel.JDBCStore;
+import org.apache.openjpa.enhance.PersistenceCapable;
+import org.apache.openjpa.jdbc.schema.Column;
 import org.apache.openjpa.jdbc.sql.SQLBuffer;
 import org.apache.openjpa.jdbc.sql.Select;
 
@@ -29,9 +29,6 @@
     extends Const {
 
     private final Const _constant;
-    private Object _val = null;
-    private Object _sqlVal = null;
-    private int _otherLen = 0;
 
     /**
      * Constructor. Supply constant to traverse.
@@ -47,37 +44,62 @@
     public void setImplicitType(Class type) {
     }
 
-    public Object getValue() {
-        return _val;
+    public Object getValue(Object[] params) {
+        Object o = _constant.getValue(params);
+        if (!(o instanceof PersistenceCapable))
+            return null;
+        return ((PersistenceCapable) o).pcFetchObjectId();
     }
 
-    public Object getSQLValue() {
-        return _sqlVal;
+    public Object getValue(ExpContext ctx, ExpState state) {
+        return ctx.store.getContext().getObjectId(_constant.getValue(ctx, 
+            ((ConstGetObjectIdExpState) state).constantState));
     }
 
-    public void calculateValue(Select sel, JDBCStore store,
-        Object[] params, Val other, JDBCFetchConfiguration fetch) {
-        super.calculateValue(sel, store, params, other, fetch);
-        _constant.calculateValue(sel, store, params, null, fetch);
-        _val = store.getContext().getObjectId(_constant.getValue());
+    public ExpState initialize(Select sel, ExpContext ctx, int flags) {
+        return new ConstGetObjectIdExpState(_constant.initialize(sel, ctx, 0));
+    }
+
+    public Object getSQLValue(Select sel, ExpContext ctx, ExpState state) {
+        return ((ConstGetObjectIdExpState) state).sqlValue;
+    }
+
+    public void calculateValue(Select sel, ExpContext ctx, ExpState state, 
+        Val other, ExpState otherState) {
+        super.calculateValue(sel, ctx, state, other, otherState);
+        ConstGetObjectIdExpState cstate = (ConstGetObjectIdExpState) state;
+        _constant.calculateValue(sel, ctx, cstate.constantState, null, null);
+        Object oid = ctx.store.getContext().getObjectId(_constant.getValue(ctx, 
+            cstate.constantState));
         if (other != null) {
-            _sqlVal = other.toDataStoreValue(_val, store);
-            _otherLen = other.length();
+            cstate.sqlValue = other.toDataStoreValue(sel, ctx, otherState, oid);
+            cstate.otherLength = other.length(sel, ctx, otherState);
         } else
-            _sqlVal = _val;
+            cstate.sqlValue = oid;
     }
 
-    public void appendTo(SQLBuffer sql, int index, Select sel,
-        JDBCStore store, Object[] params, JDBCFetchConfiguration fetch) {
-        if (_otherLen > 1)
-            sql.appendValue(((Object[]) _sqlVal)[index], getColumn(index));
+    public void appendTo(Select sel, ExpContext ctx, ExpState state, 
+        SQLBuffer sql, int index) {
+        ConstGetObjectIdExpState cstate = (ConstGetObjectIdExpState) state;
+        if (cstate.otherLength > 1)
+            sql.appendValue(((Object[]) cstate.sqlValue)[index], 
+                cstate.getColumn(index));
         else
-            sql.appendValue(_sqlVal, getColumn(index));
+            sql.appendValue(cstate.sqlValue, cstate.getColumn(index));
     }
 
-    public void clearParameters() {
-        _constant.clearParameters();
-        _val = null;
-        _sqlVal = null;
+    /**
+     * Expression state.
+     */
+    private static class ConstGetObjectIdExpState 
+        extends ConstExpState {
+
+        public final ExpState constantState;
+        public Object sqlValue = null;
+        public int otherLength = 0;
+
+        public ConstGetObjectIdExpState(ExpState constantState) {
+            this.constantState = constantState;
+        }
     }
 }

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ConstInstanceofExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ConstInstanceofExpression.java?view=diff&rev=441158&r1=441157&r2=441158
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ConstInstanceofExpression.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ConstInstanceofExpression.java Thu Sep  7 10:51:05 2006
@@ -17,9 +17,6 @@
 
 import java.util.Map;
 
-import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
-import org.apache.openjpa.jdbc.kernel.JDBCStore;
-import org.apache.openjpa.jdbc.sql.Joins;
 import org.apache.openjpa.jdbc.sql.SQLBuffer;
 import org.apache.openjpa.jdbc.sql.Select;
 import org.apache.openjpa.kernel.Filters;
@@ -44,28 +41,22 @@
         _cls = Filters.wrap(cls);
     }
 
-    public void initialize(Select sel, JDBCStore store,
-        Object[] params, Map contains) {
-        _const.initialize(sel, store, false);
+    public ExpState initialize(Select sel, ExpContext ctx, Map contains) {
+        return _const.initialize(sel, ctx, 0);
     }
 
-    public void appendTo(SQLBuffer buf, Select sel, JDBCStore store,
-        Object[] params, JDBCFetchConfiguration fetch) {
-        _const.calculateValue(sel, store, params, null, fetch);
-        if (_cls.isInstance(_const.getValue()))
+    public void appendTo(Select sel, ExpContext ctx, ExpState state, 
+        SQLBuffer buf) {
+        _const.calculateValue(sel, ctx, state, null, null);
+        if (_cls.isInstance(_const.getValue(ctx, state)))
             buf.append("1 = 1");
         else
             buf.append("1 <> 1");
-        _const.clearParameters();
     }
 
-    public void selectColumns(Select sel, JDBCStore store,
-        Object[] params, boolean pks, JDBCFetchConfiguration fetch) {
-        _const.selectColumns(sel, store, params, pks, fetch);
-    }
-
-    public Joins getJoins() {
-        return _const.getJoins();
+    public void selectColumns(Select sel, ExpContext ctx, ExpState state, 
+        boolean pks) {
+        _const.selectColumns(sel, ctx, state, pks);
     }
 
     public void acceptVisit(ExpressionVisitor visitor) {

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ConstPath.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ConstPath.java?view=diff&rev=441158&r1=441157&r2=441158
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ConstPath.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ConstPath.java Thu Sep  7 10:51:05 2006
@@ -20,8 +20,6 @@
 import java.util.ListIterator;
 
 import org.apache.openjpa.enhance.PersistenceCapable;
-import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
-import org.apache.openjpa.jdbc.kernel.JDBCStore;
 import org.apache.openjpa.jdbc.sql.SQLBuffer;
 import org.apache.openjpa.jdbc.sql.Select;
 import org.apache.openjpa.kernel.Broker;
@@ -30,6 +28,7 @@
 import org.apache.openjpa.kernel.exps.ExpressionVisitor;
 import org.apache.openjpa.meta.ClassMetaData;
 import org.apache.openjpa.meta.FieldMetaData;
+import org.apache.openjpa.util.InternalException;
 
 /**
  * A field traversal starting with a constant filter parameter.
@@ -42,9 +41,6 @@
 
     private final Const _constant;
     private final LinkedList _actions = new LinkedList();
-    private Object _val = null;
-    private Object _sqlVal = null;
-    private int _otherLen = 0;
 
     /**
      * Constructor. Supply constant to traverse.
@@ -90,19 +86,28 @@
         return null;
     }
 
-    public Object getValue() {
-        return _val;
+    public Object getValue(Object[] params) {
+        throw new InternalException();
     }
 
-    public Object getSQLValue() {
-        return _sqlVal;
+    public Object getValue(ExpContext ctx, ExpState state) {
+        return ((ConstPathExpState) state).value;
     }
 
-    public void calculateValue(Select sel, JDBCStore store,
-        Object[] params, Val other, JDBCFetchConfiguration fetch) {
-        super.calculateValue(sel, store, params, other, fetch);
-        _constant.calculateValue(sel, store, params, null, fetch);
-        _val = _constant.getValue();
+    public Object getSQLValue(Select sel, ExpContext ctx, ExpState state) {
+        return ((ConstPathExpState) state).sqlValue;
+    }
+
+    public ExpState initialize(Select sel, ExpContext ctx, int flags) {
+        return new ConstPathExpState(_constant.initialize(sel, ctx, 0));
+    }
+
+    public void calculateValue(Select sel, ExpContext ctx, ExpState state, 
+        Val other, ExpState otherState) {
+        super.calculateValue(sel, ctx, state, other, otherState);
+        ConstPathExpState cstate = (ConstPathExpState) state;
+        _constant.calculateValue(sel, ctx, cstate.constantState, null, null);
+        cstate.value = _constant.getValue(ctx, cstate.constantState);
         boolean failed = false;
 
         // copied from org.apache.openjpa.query.InMemoryPath
@@ -111,7 +116,7 @@
         Broker tmpBroker = null;
         for (Iterator itr = _actions.iterator(); itr.hasNext();) {
             // fail on null value
-            if (_val == null) {
+            if (cstate.value == null) {
                 failed = true;
                 break;
             }
@@ -119,7 +124,7 @@
             action = itr.next();
             if (action instanceof Class) {
                 try {
-                    _val = Filters.convert(_val, (Class) action);
+                    cstate.value = Filters.convert(cstate.value, (Class)action);
                     continue;
                 } catch (ClassCastException cce) {
                     failed = true;
@@ -131,19 +136,19 @@
             // be proxyable
             sm = null;
             tmpBroker = null;
-            if (_val instanceof PersistenceCapable)
-                sm = (OpenJPAStateManager) ((PersistenceCapable) _val).
+            if (cstate.value instanceof PersistenceCapable)
+                sm = (OpenJPAStateManager) ((PersistenceCapable) cstate.value).
                     pcGetStateManager();
             if (sm == null) {
-                tmpBroker = store.getContext().getBroker();
-                tmpBroker.transactional(_val, false, null);
-                sm = tmpBroker.getStateManager(_val);
+                tmpBroker = ctx.store.getContext().getBroker();
+                tmpBroker.transactional(cstate.value, false, null);
+                sm = tmpBroker.getStateManager(cstate.value);
             }
 
             try {
                 // get the specified field value and switch candidate
-                _val = sm.fetchField(((FieldMetaData) action).getIndex(),
-                    true);
+                cstate.value = sm.fetchField(((FieldMetaData) action).
+                    getIndex(), true);
             } finally {
                 // setTransactional does not clear the state, which is
                 // important since tmpVal might be also managed by
@@ -154,32 +159,45 @@
         }
 
         if (failed)
-            _val = null;
+            cstate.value = null;
 
         if (other != null) {
-            _sqlVal = other.toDataStoreValue(_val, store);
-            _otherLen = other.length();
+            cstate.sqlValue = other.toDataStoreValue(sel, ctx, otherState, 
+                cstate.value);
+            cstate.otherLength = other.length(sel, ctx, otherState);
         } else
-            _sqlVal = _val;
+            cstate.sqlValue = cstate.value;
     }
 
-    public void appendTo(SQLBuffer sql, int index, Select sel,
-        JDBCStore store, Object[] params, JDBCFetchConfiguration fetch) {
-        if (_otherLen > 1)
-            sql.appendValue(((Object[]) _sqlVal)[index], getColumn(index));
+    public void appendTo(Select sel, ExpContext ctx, ExpState state, 
+        SQLBuffer sql, int index) {
+        ConstPathExpState cstate = (ConstPathExpState) state;
+        if (cstate.otherLength > 1)
+            sql.appendValue(((Object[]) cstate.sqlValue)[index], 
+                cstate.getColumn(index));
         else
-            sql.appendValue(_sqlVal, getColumn(index));
-    }
-
-    public void clearParameters() {
-        _constant.clearParameters();
-        _val = null;
-        _sqlVal = null;
+            sql.appendValue(cstate.sqlValue, cstate.getColumn(index));
     }
 
     public void acceptVisit(ExpressionVisitor visitor) {
         visitor.enter(this);
         _constant.acceptVisit(visitor);
         visitor.exit(this);
+    }
+
+    /**
+     * Expression state.
+     */
+    private static class ConstPathExpState 
+        extends ConstExpState {
+
+        public final ExpState constantState;
+        public Object value = null;
+        public Object sqlValue = null;
+        public int otherLength = 0;
+
+        public ConstPathExpState(ExpState constantState) {
+            this.constantState = constantState;
+        }
     }
 }



Mime
View raw message