openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwsut...@apache.org
Subject svn commit: r447584 [3/8] - in /incubator/openjpa/sandboxes/OPENJPA-24: ./ openjpa-all/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ openjpa-jdbc/src/main/java/org/apache/openjpa/jd...
Date Mon, 18 Sep 2006 21:58:05 GMT
Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/GetObjectId.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/GetObjectId.java?view=diff&rev=447584&r1=447583&r2=447584
==============================================================================
--- incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/GetObjectId.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/GetObjectId.java Mon Sep 18 14:57:52 2006
@@ -17,12 +17,9 @@
 
 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.Joinable;
 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;
@@ -57,8 +54,11 @@
         _path = path;
     }
 
-    public Column[] getColumns() {
-        return _path.getClassMapping().getPrimaryKeyColumns();
+    /**
+     * Return the oid columns.
+     */
+    public Column[] getColumns(ExpState state) {
+        return _path.getClassMapping(state).getPrimaryKeyColumns();
     }
 
     public ClassMetaData getMetaData() {
@@ -76,26 +76,23 @@
     public void setImplicitType(Class type) {
     }
 
-    public void initialize(Select sel, JDBCStore store, boolean nullTest) {
-        _path.initialize(sel, store, false);
-        _path.joinRelation();
+    public ExpState initialize(Select sel, ExpContext ctx, int flags) {
+        ExpState state = _path.initialize(sel, ctx, JOIN_REL);
 
         // it's difficult to get calls on non-pc fields to always return null
         // without screwing up the SQL, to just don't let users call it on
         // non-pc fields at all
-        if (_path.getClassMapping() == null
-            || _path.getClassMapping().getEmbeddingMapping() != null)
+        ClassMapping cls = _path.getClassMapping(state);
+        if (cls == null || cls.getEmbeddingMapping() != null)
             throw new UserException(_loc.get("bad-getobjectid",
-                _path.getFieldMapping()));
-    }
-
-    public Joins getJoins() {
-        return _path.getJoins();
+                _path.getFieldMapping(state)));
+        return state;
     }
 
-    public Object toDataStoreValue(Object val, JDBCStore store) {
+    public Object toDataStoreValue(Select sel, ExpContext ctx, ExpState state, 
+        Object val) {
         // if datastore identity, try to convert to a long value
-        ClassMapping mapping = _path.getClassMapping();
+        ClassMapping mapping = _path.getClassMapping(state);
         if (mapping.getIdentityType() == mapping.ID_DATASTORE) {
             if (val instanceof Id)
                 return Numbers.valueOf(((Id) val).getId());
@@ -129,48 +126,42 @@
         return ordered;
     }
 
-    public void select(Select sel, JDBCStore store, Object[] params,
-        boolean pks, JDBCFetchConfiguration fetch) {
-        selectColumns(sel, store, params, true, fetch);
+    public void select(Select sel, ExpContext ctx, ExpState state, 
+        boolean pks) {
+        selectColumns(sel, ctx, state, true);
     }
 
-    public void selectColumns(Select sel, JDBCStore store,
-        Object[] params, boolean pks, JDBCFetchConfiguration fetch) {
-        _path.selectColumns(sel, store, params, true, fetch);
+    public void selectColumns(Select sel, ExpContext ctx, ExpState state, 
+        boolean pks) {
+        _path.selectColumns(sel, ctx, state, true);
     }
 
-    public void groupBy(Select sel, JDBCStore store, Object[] params,
-        JDBCFetchConfiguration fetch) {
-        _path.groupBy(sel, store, params, fetch);
+    public void groupBy(Select sel, ExpContext ctx, ExpState state) {
+        _path.groupBy(sel, ctx, state);
     }
 
-    public void orderBy(Select sel, JDBCStore store, Object[] params,
-        boolean asc, JDBCFetchConfiguration fetch) {
-        _path.orderBy(sel, store, params, asc, fetch);
+    public void orderBy(Select sel, ExpContext ctx, ExpState state, 
+        boolean asc) {
+        _path.orderBy(sel, ctx, state, asc);
     }
 
-    public Object load(Result res, JDBCStore store,
-        JDBCFetchConfiguration fetch)
+    public Object load(ExpContext ctx, ExpState state, Result res)
         throws SQLException {
-        return _path.load(res, store, true, fetch);
-    }
-
-    public void calculateValue(Select sel, JDBCStore store,
-        Object[] params, Val other, JDBCFetchConfiguration fetch) {
-        _path.calculateValue(sel, store, params, null, fetch);
+        return _path.load(ctx, state, res, true);
     }
 
-    public void clearParameters() {
-        _path.clearParameters();
+    public void calculateValue(Select sel, ExpContext ctx, ExpState state, 
+        Val other, ExpState otherState) {
+        _path.calculateValue(sel, ctx, state, null, null);
     }
 
-    public int length() {
-        return _path.length();
+    public int length(Select sel, ExpContext ctx, ExpState state) {
+        return _path.length(sel, ctx, state);
     }
 
-    public void appendTo(SQLBuffer sql, int index, Select sel,
-        JDBCStore store, Object[] params, JDBCFetchConfiguration fetch) {
-        _path.appendTo(sql, index, sel, store, params, fetch);
+    public void appendTo(Select sel, ExpContext ctx, ExpState state, 
+        SQLBuffer sql, int index) {
+        _path.appendTo(sel, ctx, state, sql, index);
     }
 
     public void acceptVisit(ExpressionVisitor visitor) {

Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InExpression.java?view=diff&rev=447584&r1=447583&r2=447584
==============================================================================
--- incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InExpression.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InExpression.java Mon Sep 18 14:57:52 2006
@@ -20,8 +20,6 @@
 import java.util.Iterator;
 import java.util.Map;
 
-import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
-import org.apache.openjpa.jdbc.kernel.JDBCStore;
 import org.apache.openjpa.jdbc.schema.Column;
 import org.apache.openjpa.jdbc.sql.Joins;
 import org.apache.openjpa.jdbc.sql.SQLBuffer;
@@ -48,58 +46,79 @@
         _const = constant;
     }
 
-    public Const getConst() {
+    /**
+     * Constant collection.
+     */
+    public Const getConstant() {
         return _const;
     }
 
+    /**
+     * Contained value.
+     */
     public Val getValue() {
         return _val;
     }
 
-    public void initialize(Select sel, JDBCStore store,
-        Object[] params, Map contains) {
-        _val.initialize(sel, store, false);
-        _const.initialize(sel, store, false);
+    public ExpState initialize(Select sel, ExpContext ctx, Map contains) {
+        ExpState valueState = _val.initialize(sel, ctx, 0);
+        ExpState constantState = _const.initialize(sel, ctx, 0);
+        return new InExpState(valueState.joins, constantState, valueState);
+    }
+
+    /**
+     * Expression state.
+     */
+    private static class InExpState
+        extends ExpState {
+
+        public final ExpState constantState;
+        public final ExpState valueState;
+
+        public InExpState(Joins joins, ExpState constantState, 
+            ExpState valueState) {
+            super(joins);
+            this.constantState = constantState;
+            this.valueState = valueState;
+        }
     }
 
-    public void appendTo(SQLBuffer buf, Select sel, JDBCStore store,
-        Object[] params, JDBCFetchConfiguration fetch) {
-        _val.calculateValue(sel, store, params, null, fetch);
-        _const.calculateValue(sel, store, params, null, fetch);
+    public void appendTo(Select sel, ExpContext ctx, ExpState state, 
+        SQLBuffer buf) {
+        InExpState istate = (InExpState) state; 
+        _const.calculateValue(sel, ctx, istate.constantState, null, null);
+        _val.calculateValue(sel, ctx, istate.valueState, null, null);
 
-        Collection coll = getCollection();
+        Collection coll = getCollection(ctx, istate.constantState);
         if (coll != null) {
             Collection ds = new ArrayList(coll.size());
             for (Iterator itr = coll.iterator(); itr.hasNext();)
-                ds.add(_val.toDataStoreValue(itr.next(), store));
+                ds.add(_val.toDataStoreValue(sel, ctx, istate.valueState, 
+                    itr.next()));
             coll = ds;
         }
 
         Column[] cols = null;
         if (_val instanceof PCPath)
-            cols = ((PCPath) _val).getColumns();
+            cols = ((PCPath) _val).getColumns(istate.valueState);
         else if (_val instanceof GetObjectId)
-            cols = ((GetObjectId) _val).getColumns();
+            cols = ((GetObjectId) _val).getColumns(istate.valueState);
 
         if (coll == null || coll.isEmpty())
             buf.append("1 <> 1");
-        else if (_val.length() == 1)
-            inContains(buf, sel, store, params, fetch, coll, cols);
+        else if (_val.length(sel, ctx, istate.valueState) == 1)
+            inContains(sel, ctx, istate.valueState, buf, coll, cols);
         else
-            orContains(buf, sel, store, params, fetch, coll, cols);
-        sel.append(buf, _val.getJoins());
-
-        _val.clearParameters();
-        _const.clearParameters();
+            orContains(sel, ctx, istate.valueState, buf, coll, cols);
+        sel.append(buf, state.joins);
     }
 
     /**
      * Construct an IN clause with the value of the given collection.
      */
-    private void inContains(SQLBuffer buf, Select sel, JDBCStore store,
-        Object[] params, JDBCFetchConfiguration fetch,
-        Collection coll, Column[] cols) {
-        _val.appendTo(buf, 0, sel, store, params, fetch);
+    private void inContains(Select sel, ExpContext ctx, ExpState state, 
+        SQLBuffer buf, Collection coll, Column[] cols) {
+        _val.appendTo(sel, ctx, state, buf, 0);
         buf.append(" IN (");
 
         Column col = (cols != null && cols.length == 1) ? cols[0] : null;
@@ -115,9 +134,8 @@
      * If the value to test is a compound key, we can't use IN,
      * so create a clause like '(a = b AND c = d) OR (e = f AND g = h) ...'
      */
-    private void orContains(SQLBuffer buf, Select sel, JDBCStore store,
-        Object[] params, JDBCFetchConfiguration fetch, Collection coll,
-        Column[] cols) {
+    private void orContains(Select sel, ExpContext ctx, ExpState state, 
+        SQLBuffer buf, Collection coll, Column[] cols) {
         if (coll.size() > 1)
             buf.append("(");
 
@@ -133,7 +151,7 @@
                 if (i > 0)
                     buf.append(" AND ");
 
-                _val.appendTo(buf, i, sel, store, params, fetch);
+                _val.appendTo(sel, ctx, state, buf, i);
                 if (vals[i] == null)
                     buf.append(" IS ");
                 else
@@ -149,21 +167,18 @@
             buf.append(")");
     }
 
-    public void selectColumns(Select sel, JDBCStore store,
-        Object[] params, boolean pks, JDBCFetchConfiguration fetch) {
-        _val.selectColumns(sel, store, params, true, fetch);
-        _const.selectColumns(sel, store, params, pks, fetch);
-    }
-
-    public Joins getJoins() {
-        return _val.getJoins();
+    public void selectColumns(Select sel, ExpContext ctx, ExpState state, 
+        boolean pks) {
+        InExpState istate = (InExpState) state; 
+        _const.selectColumns(sel, ctx, istate.constantState, true);
+        _val.selectColumns(sel, ctx, istate.valueState, true);
     }
 
     /**
      * Return the collection to test for containment with.
      */
-    protected Collection getCollection() {
-        return (Collection) _const.getValue();
+    protected Collection getCollection(ExpContext ctx, ExpState state) {
+        return (Collection) _const.getValue(ctx, state);
     }
 
     public void acceptVisit(ExpressionVisitor visitor) {

Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InKeyExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InKeyExpression.java?view=diff&rev=447584&r1=447583&r2=447584
==============================================================================
--- incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InKeyExpression.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InKeyExpression.java Mon Sep 18 14:57:52 2006
@@ -37,8 +37,8 @@
     /**
      * Return the collection to test for containment with.
      */
-    protected Collection getCollection() {
-        Map map = (Map) getConst().getValue();
+    protected Collection getCollection(ExpContext ctx, ExpState state) {
+        Map map = (Map) getConstant().getValue(ctx, state);
         return (map == null) ? null : map.keySet();
     }
 }

Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InSubQExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InSubQExpression.java?view=diff&rev=447584&r1=447583&r2=447584
==============================================================================
--- incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InSubQExpression.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InSubQExpression.java Mon Sep 18 14:57:52 2006
@@ -17,8 +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;
@@ -43,31 +41,44 @@
         _sub = sub;
     }
 
-    public void initialize(Select sel, JDBCStore store,
-        Object[] params, Map contains) {
-        _val.initialize(sel, store, false);
-        _sub.initialize(sel, store, false);
+    public ExpState initialize(Select sel, ExpContext ctx, Map contains) {
+        ExpState subqState = _sub.initialize(sel, ctx, 0);
+        ExpState valueState = _val.initialize(sel, ctx, 0);
+        return new InSubQExpState(valueState.joins, subqState, valueState);
     }
 
-    public void appendTo(SQLBuffer buf, Select sel, JDBCStore store,
-        Object[] params, JDBCFetchConfiguration fetch) {
-        _val.calculateValue(sel, store, params, null, fetch);
-        _sub.calculateValue(sel, store, params, null, fetch);
-        _val.appendTo(buf, 0, sel, store, params, fetch);
-        buf.append(" IN ");
-        _sub.appendTo(buf, 0, sel, store, params, fetch);
-        _val.clearParameters();
-        _sub.clearParameters();
+    /**
+     * Expression state.
+     */
+    private static class InSubQExpState
+        extends ExpState {
+
+        public final ExpState subqState;
+        public final ExpState valueState;
+
+        public InSubQExpState(Joins joins, ExpState subqState, 
+            ExpState valueState) {
+            super(joins);
+            this.subqState = subqState;
+            this.valueState = valueState;
+        }
     }
 
-    public void selectColumns(Select sel, JDBCStore store,
-        Object[] params, boolean pks, JDBCFetchConfiguration fetch) {
-        _val.selectColumns(sel, store, params, true, fetch);
-        _sub.selectColumns(sel, store, params, pks, fetch);
+    public void appendTo(Select sel, ExpContext ctx, ExpState state, 
+        SQLBuffer buf) {
+        InSubQExpState istate = (InSubQExpState) state;
+        _sub.calculateValue(sel, ctx, istate.subqState, null, null);
+        _val.calculateValue(sel, ctx, istate.valueState, null, null);
+        _val.appendTo(sel, ctx, istate.valueState, buf, 0);
+        buf.append(" IN ");
+        _sub.appendTo(sel, ctx, istate.valueState, buf, 0);
     }
 
-    public Joins getJoins() {
-        return _val.getJoins();
+    public void selectColumns(Select sel, ExpContext ctx, ExpState state, 
+        boolean pks) {
+        InSubQExpState istate = (InSubQExpState) state;
+        _sub.selectColumns(sel, ctx, istate.subqState, pks);
+        _val.selectColumns(sel, ctx, istate.valueState, true);
     }
 
     public void acceptVisit(ExpressionVisitor visitor) {

Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InValueExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InValueExpression.java?view=diff&rev=447584&r1=447583&r2=447584
==============================================================================
--- incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InValueExpression.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InValueExpression.java Mon Sep 18 14:57:52 2006
@@ -37,8 +37,8 @@
     /**
      * Return the collection to test for containment with.
      */
-    protected Collection getCollection() {
-        Map map = (Map) getConst().getValue();
+    protected Collection getCollection(ExpContext ctx, ExpState state) {
+        Map map = (Map) getConstant().getValue(ctx, state);
         return (map == null) ? null : map.values();
     }
 }

Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/IndexOf.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/IndexOf.java?view=diff&rev=447584&r1=447583&r2=447584
==============================================================================
--- incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/IndexOf.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/IndexOf.java Mon Sep 18 14:57:52 2006
@@ -17,10 +17,7 @@
 
 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.Joins;
 import org.apache.openjpa.jdbc.sql.Result;
 import org.apache.openjpa.jdbc.sql.SQLBuffer;
 import org.apache.openjpa.jdbc.sql.Select;
@@ -38,7 +35,6 @@
 
     private final Val _val1;
     private final Val _val2;
-    private Joins _joins = null;
     private ClassMetaData _meta = null;
     private Class _cast = null;
 
@@ -58,10 +54,6 @@
         _meta = meta;
     }
 
-    public boolean isVariable() {
-        return false;
-    }
-
     public Class getType() {
         if (_cast != null)
             return _cast;
@@ -72,87 +64,72 @@
         _cast = 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());
-    }
-
-    public Joins getJoins() {
-        return _joins;
+    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 Object toDataStoreValue(Object val, JDBCStore store) {
-        return val;
+    public void select(Select sel, ExpContext ctx, ExpState state, 
+        boolean pks) {
+        sel.select(newSQLBuffer(sel, ctx, state), this);
     }
 
-    public void select(Select sel, JDBCStore store, Object[] params,
-        boolean pks, JDBCFetchConfiguration fetch) {
-        sel.select(newSQLBuffer(sel, store, params, fetch), this);
+    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 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 groupBy(Select sel, ExpContext ctx, ExpState state) {
+        sel.groupBy(newSQLBuffer(sel, ctx, state));
     }
 
-    public void groupBy(Select sel, JDBCStore store, Object[] params,
-        JDBCFetchConfiguration fetch) {
-        sel.groupBy(newSQLBuffer(sel, store, params, fetch));
+    public void orderBy(Select sel, ExpContext ctx, ExpState state, 
+        boolean asc) {
+        sel.orderBy(newSQLBuffer(sel, ctx, state), asc, false);
     }
 
-    public void orderBy(Select sel, JDBCStore store, Object[] params,
-        boolean asc, JDBCFetchConfiguration fetch) {
-        sel.orderBy(newSQLBuffer(sel, store, params, fetch), 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);
+        return Filters.convert(res.getObject(this, JavaSQLTypes.JDBC_DEFAULT, 
+            null), getType());
     }
 
-    public void clearParameters() {
-        _val1.clearParameters();
-        _val2.clearParameters();
+    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 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) {
-        FilterValue str = new FilterValueImpl(_val1, sel, store, params, fetch);
+    public void appendTo(Select sel, ExpContext ctx, ExpState state, 
+        SQLBuffer sql, int index) {
+        BinaryOpExpState bstate = (BinaryOpExpState) state;
+        FilterValue str = new FilterValueImpl(sel, ctx, bstate.state1, _val1);
         FilterValue search;
         FilterValue start = null;
         if (_val2 instanceof Args) {
-            Val[] args = ((Args) _val2).getVals();
-            search =
-                new FilterValueImpl(args[0], sel, store, params, fetch);
-            start =
-                new FilterValueImpl(args[1], sel, store, params, fetch);
+            FilterValue[] filts = ((Args) _val2).newFilterValues(sel, ctx, 
+                bstate.state2);
+            search = filts[0];
+            start = filts[1];
         } else
-            search = new FilterValueImpl(_val2, sel, store, params, fetch);
+            search = new FilterValueImpl(sel, ctx, bstate.state2, _val2);
 
-        store.getDBDictionary().indexOf(sql, str, search, start);
+        ctx.store.getDBDictionary().indexOf(sql, str, search, start);
     }
 
     public void acceptVisit(ExpressionVisitor visitor) {

Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InstanceofExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InstanceofExpression.java?view=diff&rev=447584&r1=447583&r2=447584
==============================================================================
--- incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InstanceofExpression.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InstanceofExpression.java Mon Sep 18 14:57:52 2006
@@ -17,8 +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.meta.ClassMapping;
 import org.apache.openjpa.jdbc.meta.Discriminator;
 import org.apache.openjpa.jdbc.meta.FieldMapping;
@@ -39,10 +37,6 @@
 
     private final PCPath _path;
     private final Class _cls;
-    private Joins _joins = null;
-    private Discriminator _dsc = null;
-    private Class _relCls = null;
-    private ClassMapping _mapping = null;
 
     /**
      * Constructor. Supply path and class to test for.
@@ -52,96 +46,117 @@
         _cls = cls;
     }
 
-    public void initialize(Select sel, JDBCStore store,
-        Object[] params, Map contains) {
+    public ExpState initialize(Select sel, ExpContext ctx, Map contains) {
         // note that we tell the path to go ahead and join to its related
         // object (if any) in order to access its class indicator
-        _path.initialize(sel, store, false);
-        _path.joinRelation();
-        _joins = _path.getJoins();
+        ExpState pathState = _path.initialize(sel, ctx, Val.JOIN_REL);
 
         // does this path represent a relation?  if not, what class
         // is the field?
-        ClassMapping rel = _path.getClassMapping();
-        if (rel == null) {
-            FieldMapping field = _path.getFieldMapping();
+        ClassMapping relMapping = _path.getClassMapping(pathState);
+        Class rel = null;
+        if (relMapping == null) {
+            FieldMapping field = _path.getFieldMapping(pathState);
             switch (field.getTypeCode()) {
                 case JavaTypes.MAP:
                     if (_path.isKey())
-                        _relCls = field.getKey().getDeclaredType();
+                        rel = field.getKey().getDeclaredType();
                     // no break
                 case JavaTypes.ARRAY:
                 case JavaTypes.COLLECTION:
-                    _relCls = field.getElement().getDeclaredType();
+                    rel = field.getElement().getDeclaredType();
                     break;
                 default:
-                    _relCls = field.getDeclaredType();
+                    rel = field.getDeclaredType();
             }
         } else
-            _relCls = rel.getDescribedType();
+            rel = relMapping.getDescribedType();
 
         // if the path represents a relation, get its class indicator and
         // make sure it's joined down to its base type
-        _dsc = (rel == null || !rel.getDescribedType().isAssignableFrom(_cls))
-            ? null : rel.getDiscriminator();
-        if (_dsc != null) {
+        Discriminator discrim = (relMapping == null 
+            || !relMapping.getDescribedType().isAssignableFrom(_cls)) 
+            ? null : relMapping.getDiscriminator();
+        ClassMapping mapping = null;
+        Joins joins = pathState.joins;
+        if (discrim != null) {
             // cache mapping for cast
-            MappingRepository repos = store.getConfiguration().
+            MappingRepository repos = ctx.store.getConfiguration().
                 getMappingRepositoryInstance();
-            _mapping = repos.getMapping(_cls, store.getContext().
+            mapping = repos.getMapping(_cls, ctx.store.getContext().
                 getClassLoader(), false);
 
             // if not looking for a PC, don't bother with indicator
-            if (_mapping == null)
-                _dsc = null;
+            if (mapping == null)
+                discrim = null;
             else {
-                ClassMapping owner = _dsc.getClassMapping();
+                ClassMapping owner = discrim.getClassMapping();
                 ClassMapping from, to;
-                if (rel.getDescribedType().isAssignableFrom
+                if (relMapping.getDescribedType().isAssignableFrom
                     (owner.getDescribedType())) {
                     from = owner;
-                    to = rel;
+                    to = relMapping;
                 } else {
-                    from = rel;
+                    from = relMapping;
                     to = owner;
                 }
 
                 for (; from != null && from != to;
                     from = from.getJoinablePCSuperclassMapping())
-                    _joins = from.joinSuperclass(_joins, false);
+                    joins = from.joinSuperclass(joins, false);
             }
         }
+        return new InstanceofExpState(joins, pathState, mapping, discrim, rel);
     }
 
-    public void appendTo(SQLBuffer sql, Select sel, JDBCStore store,
-        Object[] params, JDBCFetchConfiguration fetch) {
+    /**
+     * Expression state.
+     */
+    private static class InstanceofExpState
+        extends ExpState {
+
+        public final ExpState pathState;
+        public final ClassMapping mapping;
+        public final Discriminator discrim;
+        public final Class rel;
+
+        public InstanceofExpState(Joins joins, ExpState pathState, 
+            ClassMapping mapping, Discriminator discrim, Class rel) {
+            super(joins);
+            this.pathState = pathState;
+            this.mapping = mapping;
+            this.discrim = discrim;
+            this.rel = rel;
+        }
+    }
+
+    public void appendTo(Select sel, ExpContext ctx, ExpState state, 
+        SQLBuffer sql) {
         // if no class indicator or a final class, just append true or false
         // depending on whether the cast matches the expected type
-        if (_dsc == null) {
-            if (_cls.isAssignableFrom(_relCls))
+        InstanceofExpState istate = (InstanceofExpState) state;
+        if (istate.discrim == null) {
+            if (_cls.isAssignableFrom(istate.rel))
                 sql.append("1 = 1");
             else
                 sql.append("1 <> 1");
         } else {
-            store.loadSubclasses(_dsc.getClassMapping());
-            SQLBuffer buf = _dsc.getClassConditions(sel, _joins, _mapping, 
-                true);
+            ctx.store.loadSubclasses(istate.discrim.getClassMapping());
+            SQLBuffer buf = istate.discrim.getClassConditions(sel,
+                istate.joins, istate.mapping, true);
             if (buf == null)
                 sql.append("1 = 1");
             else
                 sql.append(buf);
         }
-        sel.append(sql, _joins);
-    }
-
-    public void selectColumns(Select sel, JDBCStore store,
-        Object[] params, boolean pks, JDBCFetchConfiguration fetch) {
-        if (_dsc != null)
-            sel.select(_dsc.getColumns(), _joins);
+        sel.append(sql, istate.joins);
     }
 
-    public Joins getJoins() {
-        return _joins;
+    public void selectColumns(Select sel, ExpContext ctx, ExpState state, 
+        boolean pks) {
+        InstanceofExpState istate = (InstanceofExpState) state;
+        if (istate.discrim != null)
+            sel.select(istate.discrim.getColumns(), istate.joins);
     }
 
     public void acceptVisit(ExpressionVisitor visitor) {

Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/IsEmptyExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/IsEmptyExpression.java?view=diff&rev=447584&r1=447583&r2=447584
==============================================================================
--- incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/IsEmptyExpression.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/IsEmptyExpression.java Mon Sep 18 14:57:52 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;
@@ -41,28 +38,22 @@
         _val = val;
     }
 
-    public void initialize(Select sel, JDBCStore store,
-        Object[] params, Map contains) {
-        _val.initialize(sel, store, true);
+    public ExpState initialize(Select sel, ExpContext ctx, Map contains) {
+        return _val.initialize(sel, ctx, Val.NULL_CMP);
     }
 
-    public void appendTo(SQLBuffer buf, Select sel, JDBCStore store,
-        Object[] params, JDBCFetchConfiguration fetch) {
-        _val.calculateValue(sel, store, params, null, fetch);
-        _val.appendIsEmpty(buf, sel, store, params, fetch);
-        sel.append(buf, _val.getJoins());
-        _val.clearParameters();
+    public void appendTo(Select sel, ExpContext ctx, ExpState state, 
+        SQLBuffer buf) {
+        _val.calculateValue(sel, ctx, state, null, null);
+        _val.appendIsEmpty(sel, ctx, state, buf);
+        sel.append(buf, state.joins);
     }
 
-    public void selectColumns(Select sel, JDBCStore store,
-        Object[] params, boolean pks, JDBCFetchConfiguration fetch) {
-        _val.selectColumns(sel, store, params, true, fetch);
+    public void selectColumns(Select sel, ExpContext ctx, ExpState state, 
+        boolean pks) {
+        _val.selectColumns(sel, ctx, state, true);
     }
 
-    public Joins getJoins() {
-        return _val.getJoins();
-    }
-    
     public void acceptVisit(ExpressionVisitor visitor) {
         visitor.enter(this);
         _val.acceptVisit(visitor);

Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/IsNotEmptyExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/IsNotEmptyExpression.java?view=diff&rev=447584&r1=447583&r2=447584
==============================================================================
--- incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/IsNotEmptyExpression.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/IsNotEmptyExpression.java Mon Sep 18 14:57:52 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;
@@ -41,26 +38,20 @@
         _val = val;
     }
 
-    public void initialize(Select sel, JDBCStore store,
-        Object[] params, Map contains) {
-        _val.initialize(sel, store, true);
+    public ExpState initialize(Select sel, ExpContext ctx, Map contains) {
+        return _val.initialize(sel, ctx, Val.NULL_CMP);
     }
 
-    public void appendTo(SQLBuffer buf, Select sel, JDBCStore store,
-        Object[] params, JDBCFetchConfiguration fetch) {
-        _val.calculateValue(sel, store, params, null, fetch);
-        _val.appendIsNotEmpty(buf, sel, store, params, fetch);
-        sel.append(buf, _val.getJoins());
-        _val.clearParameters();
+    public void appendTo(Select sel, ExpContext ctx, ExpState state, 
+        SQLBuffer buf) {
+        _val.calculateValue(sel, ctx, state, null, null);
+        _val.appendIsNotEmpty(sel, ctx, state, buf);
+        sel.append(buf, state.joins);
     }
 
-    public void selectColumns(Select sel, JDBCStore store,
-        Object[] params, boolean pks, JDBCFetchConfiguration fetch) {
-        _val.selectColumns(sel, store, params, true, fetch);
-    }
-
-    public Joins getJoins() {
-        return _val.getJoins();
+    public void selectColumns(Select sel, ExpContext ctx, ExpState state, 
+        boolean pks) {
+        _val.selectColumns(sel, ctx, state, true);
     }
 
     public void acceptVisit(ExpressionVisitor visitor) {

Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCExpressionFactory.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCExpressionFactory.java?view=diff&rev=447584&r1=447583&r2=447584
==============================================================================
--- incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCExpressionFactory.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCExpressionFactory.java Mon Sep 18 14:57:52 2006
@@ -19,6 +19,7 @@
 import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
 import org.apache.openjpa.jdbc.kernel.JDBCStoreQuery;
 import org.apache.openjpa.jdbc.meta.ClassMapping;
+import org.apache.openjpa.jdbc.meta.JavaSQLTypes;
 import org.apache.openjpa.jdbc.sql.DBDictionary;
 import org.apache.openjpa.jdbc.sql.Select;
 import org.apache.openjpa.kernel.exps.AggregateListener;
@@ -34,7 +35,6 @@
 import org.apache.openjpa.kernel.exps.Value;
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.meta.ClassMetaData;
-import org.apache.openjpa.util.ImplHelper;
 import org.apache.openjpa.util.UserException;
 
 /**
@@ -48,12 +48,10 @@
     implements ExpressionFactory {
 
     private static final Val NULL = new Null();
-    private static final Val CURRENT_DATE =
-        new CurrentDate(CurrentDate.DATE);
-    private static final Val CURRENT_TIME =
-        new CurrentDate(CurrentDate.TIME);
+    private static final Val CURRENT_DATE = new CurrentDate(JavaSQLTypes.DATE);
+    private static final Val CURRENT_TIME = new CurrentDate(JavaSQLTypes.TIME);
     private static final Val CURRENT_TIMESTAMP =
-        new CurrentDate(CurrentDate.TIMESTAMP);
+        new CurrentDate(JavaSQLTypes.TIMESTAMP);
 
     private static final Localizer _loc = Localizer.forPackage
         (JDBCExpressionFactory.class);
@@ -69,56 +67,10 @@
     }
 
     /**
-     * Evaluate the expression, returning a SQL select with the proper
-     * conditions. Use {@link #select} to then select the data.
-     * This method returns null if there is no query criteria. It is
-     * synchronized because factories may be cached and used by multiple
-     * queries at the same time.
+     * Use to create SQL select.
      */
-    public synchronized Select evaluate(JDBCStoreQuery q,
-        JDBCFetchConfiguration fetch, QueryExpressions exps, Object[] params) {
-        // figure out proper cache level based on parameters
-        int level = getCacheLevel(q, params);
-        return _cons.evaluate(q.getStore(), null, null, exps, params,
-            level, fetch);
-    }
-
-    /**
-     * Return the cache level for this query. The level depends on whether
-     * the query uses any params, as well as the types and values of those
-     * params.
-     */
-    private int getCacheLevel(JDBCStoreQuery q, Object[] params) {
-        // if there are no parameters, we can cache the full SQL
-        if (params.length == 0)
-            return SelectConstructor.CACHE_FULL;
-
-        // if there is a null PC parameter, we have to cache differently
-        // since it affects joins
-        LinkedMap types = null;
-        Class type;
-        for (int i = 0; i < params.length; i++) {
-            if (params[i] != null)
-                continue;
-
-            if (types == null)
-                types = q.getContext().getParameterTypes();
-
-            type = (Class) types.getValue(i);
-            if (type != null && ImplHelper.isManagedType(type))
-                return SelectConstructor.CACHE_NULL;
-        }
-        return SelectConstructor.CACHE_JOINS;
-    }
-
-    /**
-     * Select the data for this query.
-     */
-    public void select(JDBCStoreQuery q, ClassMapping mapping,
-        boolean subclasses, Select sel, QueryExpressions exps,
-        Object[] params, JDBCFetchConfiguration fetch, int eager) {
-        _cons.select(q.getStore(), mapping, subclasses, sel, exps,
-            params, fetch, eager);
+    public SelectConstructor getSelectConstructor() {
+        return _cons;
     }
 
     public Expression emptyExpression() {

Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Lit.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Lit.java?view=diff&rev=447584&r1=447583&r2=447584
==============================================================================
--- incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Lit.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Lit.java Mon Sep 18 14:57:52 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.Filters;
@@ -33,8 +31,6 @@
 
     private Object _val;
     private int _ptype;
-    private Object _sqlVal = null;
-    private int _otherLen = 0;
 
     /**
      * Constructor. Supply literal value.
@@ -56,7 +52,7 @@
         return _ptype;
     }
 
-    public Object getValue() {
+    public Object getValue() { 
         return _val;
     }
 
@@ -64,24 +60,42 @@
         _val = val;
     }
 
-    public void calculateValue(Select sel, JDBCStore store,
-        Object[] params, Val other, JDBCFetchConfiguration fetch) {
-        super.calculateValue(sel, store, params, other, fetch);
+    public Object getValue(Object[] params) {
+        return getValue();
+    }
+
+    public ExpState initialize(Select sel, ExpContext ctx, int flags) {
+        return new LitExpState();
+    }
+
+    /**
+     * Expression state.
+     */
+    private static class LitExpState
+        extends ConstExpState {
+
+        public Object sqlValue;
+        public int otherLength; 
+    } 
+
+    public void calculateValue(Select sel, ExpContext ctx, ExpState state, 
+        Val other, ExpState otherState) {
+        super.calculateValue(sel, ctx, state, other, otherState);
+        LitExpState lstate = (LitExpState) state;
         if (other != null) {
-            _sqlVal = other.toDataStoreValue(_val, store);
-            _otherLen = other.length();
+            lstate.sqlValue = other.toDataStoreValue(sel, ctx, otherState,_val);
+            lstate.otherLength = other.length(sel, ctx, otherState);
         } else
-            _sqlVal = _val;
+            lstate.sqlValue = _val;
     }
 
-    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) {
+        LitExpState lstate = (LitExpState) state;
+        if (lstate.otherLength > 1)
+            sql.appendValue(((Object[]) lstate.sqlValue)[index], 
+                lstate.getColumn(index));
         else
-            sql.appendValue(_sqlVal, getColumn(index));
-    }
-
-    public void clearParameters() {
+            sql.appendValue(lstate.sqlValue, lstate.getColumn(index));
     }
 }

Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/MatchesExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/MatchesExpression.java?view=diff&rev=447584&r1=447583&r2=447584
==============================================================================
--- incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/MatchesExpression.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/MatchesExpression.java Mon Sep 18 14:57:52 2006
@@ -17,10 +17,7 @@
 
 import java.util.Map;
 
-import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
-import org.apache.openjpa.jdbc.kernel.JDBCStore;
 import org.apache.openjpa.jdbc.schema.Column;
-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;
@@ -39,7 +36,6 @@
     private final String _single;
     private final String _multi;
     private final String _escape;
-    private Joins _joins = null;
 
     /**
      * Constructor. Supply values.
@@ -53,26 +49,26 @@
         _escape = escape;
     }
 
-    public void initialize(Select sel, JDBCStore store,
-        Object[] params, Map contains) {
-        _val.initialize(sel, store, false);
-        _const.initialize(sel, store, false);
-        _joins = sel.and(_val.getJoins(), _const.getJoins());
+    public ExpState initialize(Select sel, ExpContext ctx, Map contains) {
+        ExpState s1 = _val.initialize(sel, ctx, 0);
+        ExpState s2 = _const.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) {
-        _val.calculateValue(sel, store, params, _const, fetch);
-        _const.calculateValue(sel, store, params, _val, fetch);
+    public void appendTo(Select sel, ExpContext ctx, ExpState state, 
+        SQLBuffer buf) {
+        BinaryOpExpState bstate = (BinaryOpExpState) state;
+        _val.calculateValue(sel, ctx, bstate.state1, _const, bstate.state2);
+        _const.calculateValue(sel, ctx, bstate.state2, _val, bstate.state1);
 
         Column col = null;
         if (_val instanceof PCPath) {
-            Column[] cols = ((PCPath) _val).getColumns();
+            Column[] cols = ((PCPath) _val).getColumns(bstate.state1);
             if (cols.length == 1)
                 col = cols[0];
         }
 
-        Object o = _const.getValue();
+        Object o = _const.getValue(ctx, bstate.state2);
         if (o == null)
             buf.append("1 <> 1");
         else {
@@ -92,7 +88,7 @@
             // append target
             if (ignoreCase)
                 buf.append("LOWER(");
-            _val.appendTo(buf, 0, sel, store, params, fetch);
+            _val.appendTo(sel, ctx, bstate.state1, buf, 0);
             if (ignoreCase)
                 buf.append(")");
 
@@ -101,27 +97,20 @@
             // with '%' and '.' with '_'
             str = Strings.replace(str, _multi, "%");
             str = Strings.replace(str, _single, "_");
-
             buf.append(" LIKE ").appendValue(str, col);
 
             // escape out characters by using the database's escape sequence
             if (_escape != null)
                 buf.append(" ESCAPE '").append(_escape).append("'");
         }
-        sel.append(buf, _joins);
-
-        _val.clearParameters();
-        _const.clearParameters();
-    }
-
-    public void selectColumns(Select sel, JDBCStore store,
-        Object[] params, boolean pks, JDBCFetchConfiguration fetch) {
-        _val.selectColumns(sel, store, params, true, fetch);
-        _const.selectColumns(sel, store, params, true, 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;
+        _val.selectColumns(sel, ctx, bstate.state1, true);
+        _const.selectColumns(sel, ctx, bstate.state2, true);
     }
 
     public void acceptVisit(ExpressionVisitor visitor) {

Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Math.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Math.java?view=diff&rev=447584&r1=447583&r2=447584
==============================================================================
--- incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Math.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Math.java Mon Sep 18 14:57:52 2006
@@ -17,10 +17,7 @@
 
 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.Joins;
 import org.apache.openjpa.jdbc.sql.Result;
 import org.apache.openjpa.jdbc.sql.SQLBuffer;
 import org.apache.openjpa.jdbc.sql.Select;
@@ -45,7 +42,6 @@
     private final Val _val1;
     private final Val _val2;
     private final String _op;
-    private Joins _joins = null;
     private ClassMetaData _meta = null;
     private Class _cast = null;
 
@@ -66,10 +62,6 @@
         _meta = meta;
     }
 
-    public boolean isVariable() {
-        return false;
-    }
-
     public Class getType() {
         if (_cast != null)
             return _cast;
@@ -82,78 +74,63 @@
         _cast = 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());
-    }
-
-    public Joins getJoins() {
-        return _joins;
+    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 Object toDataStoreValue(Object val, JDBCStore store) {
-        return val;
+    public void select(Select sel, ExpContext ctx, ExpState state, 
+        boolean pks) {
+        sel.select(newSQLBuffer(sel, ctx, state), this);
     }
 
-    public void select(Select sel, JDBCStore store, Object[] params,
-        boolean pks, JDBCFetchConfiguration fetch) {
-        sel.select(newSQLBuffer(sel, store, params, fetch), this);
+    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 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 groupBy(Select sel, ExpContext ctx, ExpState state) {
+        sel.groupBy(newSQLBuffer(sel, ctx, state));
     }
 
-    public void groupBy(Select sel, JDBCStore store, Object[] params,
-        JDBCFetchConfiguration fetch) {
-        sel.groupBy(newSQLBuffer(sel, store, params, fetch));
+    public void orderBy(Select sel, ExpContext ctx, ExpState state, 
+        boolean asc) {
+        sel.orderBy(newSQLBuffer(sel, ctx, state), asc, false);
     }
 
-    public void orderBy(Select sel, JDBCStore store, Object[] params,
-        boolean asc, JDBCFetchConfiguration fetch) {
-        sel.orderBy(newSQLBuffer(sel, store, params, fetch), 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, _val2, fetch);
-        _val2.calculateValue(sel, store, params, _val1, fetch);
+        return Filters.convert(res.getObject(this, JavaSQLTypes.JDBC_DEFAULT, 
+            null), getType());
     }
 
-    public void clearParameters() {
-        _val1.clearParameters();
-        _val2.clearParameters();
+    public void calculateValue(Select sel, ExpContext ctx, ExpState state, 
+        Val other, ExpState otherState) {
+        BinaryOpExpState bstate = (BinaryOpExpState) state;
+        _val1.calculateValue(sel, ctx, bstate.state1, _val2, bstate.state2);
+        _val2.calculateValue(sel, ctx, bstate.state2, _val1, bstate.state1);
     }
 
-    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) {
-        store.getDBDictionary().mathFunction(sql, _op,
-            new FilterValueImpl(_val1, sel, store, params, fetch),
-            new FilterValueImpl(_val2, sel, store, params, fetch));
+    public void appendTo(Select sel, ExpContext ctx, ExpState state, 
+        SQLBuffer sql, int index) {
+        BinaryOpExpState bstate = (BinaryOpExpState) state;
+        ctx.store.getDBDictionary().mathFunction(sql, _op,
+            new FilterValueImpl(sel, ctx, bstate.state1, _val1),
+            new FilterValueImpl(sel, ctx, bstate.state2, _val2));
     }
 
     public void acceptVisit(ExpressionVisitor visitor) {

Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/NotContainsExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/NotContainsExpression.java?view=diff&rev=447584&r1=447583&r2=447584
==============================================================================
--- incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/NotContainsExpression.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/NotContainsExpression.java Mon Sep 18 14:57:52 2006
@@ -17,10 +17,7 @@
 
 import java.util.Map;
 
-import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
-import org.apache.openjpa.jdbc.kernel.JDBCStore;
 import org.apache.openjpa.jdbc.sql.DBDictionary;
-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;
@@ -35,7 +32,6 @@
     implements Exp {
 
     private final Exp _exp;
-    private Map _contains = null;
 
     /**
      * Constructor. Supply the expression to negate.
@@ -44,37 +40,48 @@
         _exp = exp;
     }
 
-    public void initialize(Select sel, JDBCStore store,
-        Object[] params, Map contains) {
-        _contains = contains;
+    public ExpState initialize(Select sel, ExpContext ctx, Map contains) {
+        return new NotContainsExpState(contains);
     }
 
-    public void appendTo(SQLBuffer buf, Select sel, JDBCStore store,
-        Object[] params, JDBCFetchConfiguration fetch) {
-        DBDictionary dict = store.getDBDictionary();
+    /**
+     * Expression state.
+     */
+    private static class NotContainsExpState
+        extends ExpState {
+        
+        public final Map contains;
+
+        public NotContainsExpState(Map contains) {
+            this.contains = contains;
+        }
+    }
+
+    public void appendTo(Select sel, ExpContext ctx, ExpState state, 
+        SQLBuffer buf) {
+        DBDictionary dict = ctx.store.getDBDictionary();
         dict.assertSupport(dict.supportsSubselect, "SupportsSubselect");
 
-        Select sub = store.getSQLFactory().newSelect();
+        Select sub = ctx.store.getSQLFactory().newSelect();
         sub.setParent(sel, null);
-        _exp.initialize(sub, store, params, _contains);
-        sub.where(sub.and(null, _exp.getJoins()));
+        ExpState estate = _exp.initialize(sub, ctx, ((NotContainsExpState) 
+            state).contains);
+        sub.where(sub.and(null, estate.joins));
 
         SQLBuffer where = new SQLBuffer(dict).append("(");
-        _exp.appendTo(where, sub, store, params, fetch);
+        _exp.appendTo(sub, ctx, estate, where);
         if (where.getSQL().length() > 1)
             sub.where(where.append(")"));
 
         buf.append("0 = ");
-        buf.appendCount(sub, fetch);
-    }
-
-    public void selectColumns(Select sel, JDBCStore store,
-        Object[] params, boolean pks, JDBCFetchConfiguration fetch) {
-        _exp.selectColumns(sel, store, params, true, fetch);
+        buf.appendCount(sub, ctx.fetch);
     }
 
-    public Joins getJoins() {
-        return null;
+    public void selectColumns(Select sel, ExpContext ctx, ExpState state, 
+        boolean pks) {
+        ExpState estate = _exp.initialize(sel, ctx, ((NotContainsExpState) 
+            state).contains);
+        _exp.selectColumns(sel, ctx, estate, true);
     }
 
     public void acceptVisit(ExpressionVisitor visitor) {

Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/NotEqualExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/NotEqualExpression.java?view=diff&rev=447584&r1=447583&r2=447584
==============================================================================
--- incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/NotEqualExpression.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/NotEqualExpression.java Mon Sep 18 14:57:52 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;
 
@@ -35,39 +33,41 @@
         super(val1, val2);
     }
 
-    public void appendTo(SQLBuffer buf, Select sel, JDBCStore store,
-        Object[] params, JDBCFetchConfiguration fetch, boolean val1Null,
-        boolean val2Null) {
+    public void appendTo(Select sel, ExpContext ctx, BinaryOpExpState bstate, 
+        SQLBuffer buf, boolean val1Null, boolean val2Null) {
         if (val1Null && val2Null)
             buf.appendValue(null).append(" IS NOT ").appendValue(null);
         else if (val1Null || val2Null) {
             Val val = (val1Null) ? getValue2() : getValue1();
+            ExpState state = (val1Null) ? bstate.state2 : bstate.state1;
             if (!isDirectComparison()) {
-                int len = val.length();
+                int len = val.length(sel, ctx, state);
                 for (int i = 0; i < len; i++) {
                     if (i > 0)
                         buf.append(" AND ");
-                    val.appendTo(buf, i, sel, store, params, fetch);
+                    val.appendTo(sel, ctx, state, buf, i);
                     buf.append(" IS NOT ").appendValue(null);
                 }
             } else
-                val.appendIsNotNull(buf, sel, store, params, fetch);
+                val.appendIsNotNull(sel, ctx, state, buf);
         } else {
             Val val1 = getValue1();
             Val val2 = getValue2();
-            if (val1.length() == 1 && val2.length() == 1) {
-                store.getDBDictionary().comparison(buf, "<>",
-                    new FilterValueImpl(val1, sel, store, params, fetch),
-                    new FilterValueImpl(val2, sel, store, params, fetch));
+            if (val1.length(sel, ctx, bstate.state1) == 1 
+                && val2.length(sel, ctx, bstate.state2) == 1) {
+                ctx.store.getDBDictionary().comparison(buf, "<>",
+                    new FilterValueImpl(sel, ctx, bstate.state1, val1),
+                    new FilterValueImpl(sel, ctx, bstate.state2, val2));
             } else {
-                int len = java.lang.Math.max(val1.length(), val2.length());
+                int len = java.lang.Math.max(val1.length(sel, ctx, 
+                    bstate.state1), val2.length(sel, ctx, bstate.state2));
                 buf.append("(");
                 for (int i = 0; i < len; i++) {
                     if (i > 0)
                         buf.append(" OR ");
-                    val1.appendTo(buf, i, sel, store, params, fetch);
+                    val1.appendTo(sel, ctx, bstate.state1, buf, i);
                     buf.append(" <> ");
-                    val2.appendTo(buf, i, sel, store, params, fetch);
+                    val2.appendTo(sel, ctx, bstate.state2, buf, i);
                 }
                 buf.append(")");
             }

Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/NotExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/NotExpression.java?view=diff&rev=447584&r1=447583&r2=447584
==============================================================================
--- incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/NotExpression.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/NotExpression.java Mon Sep 18 14:57:52 2006
@@ -17,8 +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;
@@ -33,7 +31,6 @@
     implements Exp {
 
     private final Exp _exp;
-    private Joins _joins = null;
 
     /**
      * Constructor. Supply the expression to negate.
@@ -42,26 +39,35 @@
         _exp = exp;
     }
 
-    public void initialize(Select sel, JDBCStore store,
-        Object[] params, Map contains) {
-        _exp.initialize(sel, store, params, contains);
-        _joins = sel.or(_exp.getJoins(), null);
+    public ExpState initialize(Select sel, ExpContext ctx, Map contains) { 
+        ExpState state = _exp.initialize(sel, ctx, contains);
+        return new NotExpState(sel.or(state.joins, null), state);
     }
 
-    public void appendTo(SQLBuffer buf, Select sel, JDBCStore store,
-        Object[] params, JDBCFetchConfiguration fetch) {
-        buf.append("NOT (");
-        _exp.appendTo(buf, sel, store, params, fetch);
-        buf.append(")");
+    /**
+     * Expression state.
+     */
+    private static class NotExpState 
+        extends ExpState {
+
+        public final ExpState state;
+
+        public NotExpState(Joins joins, ExpState state) {
+            super(joins);
+            this.state = state;
+        }
     }
 
-    public void selectColumns(Select sel, JDBCStore store,
-        Object[] params, boolean pks, JDBCFetchConfiguration fetch) {
-        _exp.selectColumns(sel, store, params, pks, fetch);
+    public void appendTo(Select sel, ExpContext ctx, ExpState state, 
+        SQLBuffer buf) {
+        buf.append("NOT (");
+        _exp.appendTo(sel, ctx, ((NotExpState) state).state, buf);
+        buf.append(")");
     }
 
-    public Joins getJoins() {
-        return _joins;
+    public void selectColumns(Select sel, ExpContext ctx, ExpState state, 
+        boolean pks) {
+        _exp.selectColumns(sel, ctx, ((NotExpState) state).state, pks);
     }
 
     public void acceptVisit(ExpressionVisitor visitor) {

Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Null.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Null.java?view=diff&rev=447584&r1=447583&r2=447584
==============================================================================
--- incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Null.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Null.java Mon Sep 18 14:57:52 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;
 
@@ -35,19 +33,16 @@
     public void setImplicitType(Class type) {
     }
 
-    public Object getValue() {
+    public Object getValue(Object[] params) {
         return null;
     }
 
-    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) {
     }
 
-    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) {
         sql.appendValue(null);
-    }
-
-    public void clearParameters() {
     }
 }

Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/OrExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/OrExpression.java?view=diff&rev=447584&r1=447583&r2=447584
==============================================================================
--- incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/OrExpression.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/OrExpression.java Mon Sep 18 14:57:52 2006
@@ -19,9 +19,6 @@
 import java.util.Iterator;
 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;
@@ -36,7 +33,6 @@
 
     private final Exp _exp1;
     private final Exp _exp2;
-    private Joins _joins = null;
 
     /**
      * Constructor. Supply the expressions to combine.
@@ -46,56 +42,53 @@
         _exp2 = exp2;
     }
 
-    public void initialize(Select sel, JDBCStore store,
-        Object[] params, Map contains) {
+    public ExpState initialize(Select sel, ExpContext ctx, Map contains) {
         // when OR'ing expressions each expression gets its own copy of the
         // contains counts, cause it's OK for each to use the same aliases
         Map contains2 = null;
         if (contains != null)
             contains2 = new HashMap(contains);
 
-        _exp1.initialize(sel, store, params, contains);
-        _exp2.initialize(sel, store, params, contains2);
-        _joins = sel.or(_exp1.getJoins(), _exp2.getJoins());
+        ExpState s1 = _exp1.initialize(sel, ctx, contains);
+        ExpState s2 = _exp2.initialize(sel, ctx, contains2);
+        ExpState ret = new BinaryOpExpState(sel.or(s1.joins, s2.joins), s1, s2);
         if (contains == null)
-            return;
+            return ret;
 
         // combine the contains counts from the copy into the main map
         Map.Entry entry;
         Integer val1, val2;
-        for (Iterator itr = contains2.entrySet().iterator();
-            itr.hasNext();) {
+        for (Iterator itr = contains2.entrySet().iterator(); itr.hasNext();) {
             entry = (Map.Entry) itr.next();
             val2 = (Integer) entry.getValue();
             val1 = (Integer) contains.get(entry.getKey());
             if (val1 == null || val2.intValue() > val1.intValue())
                 contains.put(entry.getKey(), val2);
         }
+        return ret;
     }
 
-    public void appendTo(SQLBuffer buf, Select sel, JDBCStore store,
-        Object[] params, JDBCFetchConfiguration fetch) {
-        boolean paren = _joins != null && !_joins.isEmpty();
+    public void appendTo(Select sel, ExpContext ctx, ExpState state, 
+        SQLBuffer buf) {
+        BinaryOpExpState bstate = (BinaryOpExpState) state;
+        boolean paren = bstate.joins != null && !bstate.joins.isEmpty();
         if (paren)
             buf.append("(");
 
-        _exp1.appendTo(buf, sel, store, params, fetch);
+        _exp1.appendTo(sel, ctx, bstate.state1, buf);
         buf.append(" OR ");
-        _exp2.appendTo(buf, sel, store, params, fetch);
+        _exp2.appendTo(sel, ctx, bstate.state2, buf);
 
         if (paren)
             buf.append(")");
-        sel.append(buf, _joins);
+        sel.append(buf, bstate.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);
-    }
-
-    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) {



Mime
View raw message