openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwsut...@apache.org
Subject svn commit: r447584 [2/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/CompareEqualExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CompareEqualExpression.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/CompareEqualExpression.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CompareEqualExpression.java Mon Sep 18 14:57:52 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/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CompareExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CompareExpression.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/CompareExpression.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CompareExpression.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.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/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Concat.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Concat.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/Concat.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Concat.java Mon Sep 18 14:57:52 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/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Const.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Const.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/Const.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Const.java Mon Sep 18 14:57:52 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/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ConstGetObjectId.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ConstGetObjectId.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/ConstGetObjectId.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ConstGetObjectId.java Mon Sep 18 14:57:52 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/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ConstInstanceofExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ConstInstanceofExpression.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/ConstInstanceofExpression.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ConstInstanceofExpression.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.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/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ConstPath.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ConstPath.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/ConstPath.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ConstPath.java Mon Sep 18 14:57:52 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;
+        }
     }
 }

Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ContainsExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ContainsExpression.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/ContainsExpression.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ContainsExpression.java Mon Sep 18 14:57:52 2006
@@ -17,7 +17,6 @@
 
 import java.util.Map;
 
-import org.apache.openjpa.jdbc.kernel.JDBCStore;
 import org.apache.openjpa.jdbc.sql.Select;
 import serp.util.Numbers;
 
@@ -36,8 +35,7 @@
         super(val1, val2);
     }
 
-    public void initialize(Select sel, JDBCStore store,
-        Object[] params, Map contains) {
+    public ExpState initialize(Select sel, ExpContext ctx, Map contains) {
         Val val1 = getValue1();
         if (contains != null && val1 instanceof PCPath) {
             PCPath sql = (PCPath) val1;
@@ -53,7 +51,7 @@
 
             sql.setContainsId(count.toString());
         }
-        super.initialize(sel, store, params, contains);
+        return super.initialize(sel, ctx, contains);
     }
 
     protected boolean isDirectComparison() {

Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ContainsKeyExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ContainsKeyExpression.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/ContainsKeyExpression.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ContainsKeyExpression.java Mon Sep 18 14:57:52 2006
@@ -17,7 +17,6 @@
 
 import java.util.Map;
 
-import org.apache.openjpa.jdbc.kernel.JDBCStore;
 import org.apache.openjpa.jdbc.sql.Select;
 
 /**
@@ -35,12 +34,10 @@
         super(val1, val2);
     }
 
-    public void initialize(Select sel, JDBCStore store,
-        Object[] params, Map contains) {
+    public ExpState initialize(Select sel, ExpContext ctx, Map contains) {
         Val val1 = getValue1();
         if (val1 instanceof PCPath)
             ((PCPath) val1).getKey();
-
-        super.initialize(sel, store, params, contains);
+        return super.initialize(sel, ctx, contains);
     }
 }

Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Count.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Count.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/Count.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Count.java Mon Sep 18 14:57:52 2006
@@ -15,7 +15,6 @@
  */
 package org.apache.openjpa.jdbc.kernel.exps;
 
-import org.apache.openjpa.jdbc.kernel.JDBCStore;
 import org.apache.openjpa.jdbc.sql.Select;
 
 /**
@@ -33,11 +32,9 @@
         super(val);
     }
 
-    public void initialize(Select sel, JDBCStore store, boolean nullTest) {
-        super.initialize(sel, store, nullTest);
+    public ExpState initialize(Select sel, ExpContext ctx, int flags) {
         // join into related object if present
-        if (getVal()instanceof PCPath)
-            ((PCPath) getVal()).joinRelation();
+        return initializeValue(sel, ctx, JOIN_REL);
     }
 
     protected Class getType(Class c) {

Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CurrentDate.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CurrentDate.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/CurrentDate.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CurrentDate.java Mon Sep 18 14:57:52 2006
@@ -17,10 +17,10 @@
 
 import java.util.Date;
 
-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.SQLBuffer;
 import org.apache.openjpa.jdbc.sql.Select;
+import org.apache.openjpa.util.InternalException;
 
 /**
  * A literal current DATE/TIME/TIMESTAMP value in a filter.
@@ -30,13 +30,9 @@
 class CurrentDate
     extends Const {
 
-    static final int DATE = 1;
-    static final int TIME = 2;
-    static final int TIMESTAMP = 3;
-
     private final int _type;
 
-    CurrentDate(int type) {
+    public CurrentDate(int type) {
         _type = type;
     }
 
@@ -47,24 +43,25 @@
     public void setImplicitType(Class type) {
     }
 
-    public Object getValue() {
+    public Object getValue(Object[] params) {
         return new Date();
     }
 
-    public void calculateValue(Select sel, JDBCStore store,
-        Object[] params, Val other, JDBCFetchConfiguration fetch) {
-    }
-
-    public void appendTo(SQLBuffer sql, int index, Select sel,
-        JDBCStore store, Object[] params, JDBCFetchConfiguration fetch) {
-        if (_type == DATE)
-            sql.append(store.getDBDictionary().currentDateFunction);
-        else if (_type == TIME)
-            sql.append(store.getDBDictionary().currentTimeFunction);
-        else if (_type == TIMESTAMP)
-            sql.append(store.getDBDictionary().currentTimestampFunction);
-    }
-
-    public void clearParameters() {
+    public void appendTo(Select sel, ExpContext ctx, ExpState state, 
+        SQLBuffer sql, int index) {
+        switch (_type) {
+            case JavaSQLTypes.DATE:
+                sql.append(ctx.store.getDBDictionary().currentDateFunction);
+                break;
+            case JavaSQLTypes.TIME:
+                sql.append(ctx.store.getDBDictionary().currentTimeFunction);
+                break;
+            case JavaSQLTypes.TIMESTAMP:
+                sql.append(ctx.store.getDBDictionary().
+                    currentTimestampFunction);
+                break;
+            default:
+                throw new InternalException();
+        }
     }
 }

Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Distinct.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Distinct.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/Distinct.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Distinct.java Mon Sep 18 14:57:52 2006
@@ -15,7 +15,6 @@
  */
 package org.apache.openjpa.jdbc.kernel.exps;
 
-import org.apache.openjpa.jdbc.kernel.JDBCStore;
 import org.apache.openjpa.jdbc.sql.Select;
 
 /**
@@ -30,16 +29,12 @@
         super(val);
     }
 
-    public void initialize(Select sel, JDBCStore store, boolean nullTest) {
-        super.initialize(sel, store, nullTest);
-
+    public ExpState initialize(Select sel, ExpContext ctx, int flags) {
         // join into related object if present
-        if (getVal()instanceof PCPath)
-            ((PCPath) getVal()).joinRelation();
+        return initializeValue(sel, ctx, JOIN_REL);
     }
 
     protected String getOperator() {
         return "DISTINCT";
     }
 }
-

Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/EmptyExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/EmptyExpression.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/EmptyExpression.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/EmptyExpression.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;
@@ -32,20 +29,16 @@
 class EmptyExpression
     implements Exp {
 
-    public void initialize(Select sel, JDBCStore store,
-        Object[] params, Map contains) {
+    public ExpState initialize(Select sel, ExpContext ctx, Map contains) {
+        return ExpState.NULL;
     }
 
-    public void appendTo(SQLBuffer buf, Select sel, JDBCStore store,
-        Object[] params, JDBCFetchConfiguration fetch) {
+    public void appendTo(Select sel, ExpContext ctx, ExpState state, 
+        SQLBuffer buf) {
     }
 
-    public void selectColumns(Select sel, JDBCStore store,
-        Object[] params, boolean pks, JDBCFetchConfiguration fetch) {
-    }
-
-    public Joins getJoins() {
-        return null;
+    public void selectColumns(Select sel, ExpContext ctx, ExpState state, 
+        boolean pks) {
     }
 
     public void acceptVisit(ExpressionVisitor visitor) {

Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/EndsWithExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/EndsWithExpression.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/EndsWithExpression.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/EndsWithExpression.java Mon Sep 18 14:57:52 2006
@@ -17,14 +17,11 @@
 
 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.FieldMapping;
 import org.apache.openjpa.jdbc.schema.Column;
 import org.apache.openjpa.jdbc.schema.Table;
 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;
@@ -39,9 +36,6 @@
 
     private final Val _val1;
     private final Val _val2;
-    private Joins _joins = null;
-    private String _pre = null;
-    private String _post = null;
 
     /**
      * Constructor. Supply values.
@@ -51,70 +45,67 @@
         _val2 = val2;
     }
 
-    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(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);
 
-        DBDictionary dict = store.getDBDictionary();
+        DBDictionary dict = ctx.store.getDBDictionary();
         String func = dict.stringLengthFunction;
+        String pre = null;
+        String post = null;
         if (func != null) {
             int idx = func.indexOf("{0}");
-            _pre = func.substring(0, idx);
-            _post = func.substring(idx + 3);
+            pre = func.substring(0, idx);
+            post = func.substring(idx + 3);
         }
-    }
 
-    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);
-
-        if (_val1 instanceof Const && ((Const) _val1).getValue() == null)
+        if (_val1 instanceof Const && ((Const) _val1).getValue(ctx, 
+            bstate.state1) == null)
             buf.append("1 <> 1");
         else if (_val2 instanceof Const) {
-            Object o = ((Const) _val2).getValue();
+            Object o = ((Const) _val2).getValue(ctx, bstate.state2);
             if (o == null)
                 buf.append("1 <> 1");
             else {
                 Column col = null;
                 if (_val1 instanceof PCPath) {
-                    Column[] cols = ((PCPath) _val1).getColumns();
+                    Column[] cols = ((PCPath) _val1).getColumns(bstate.state1);
                     if (cols.length == 1)
                         col = cols[0];
                 }
 
-                _val1.appendTo(buf, 0, sel, store, params, fetch);
+                _val1.appendTo(sel, ctx, bstate.state1, buf, 0);
                 buf.append(" LIKE ");
                 buf.appendValue("%" + o.toString(), col);
             }
         } else {
             // if we can't use LIKE, we have to take the substring of the
             // first value and compare it to the second
-            DBDictionary dict = store.getDBDictionary();
-            dict.assertSupport(_pre != null, "StringLengthFunction");
-            dict.substring(buf,
-                new FilterValueImpl(_val1, sel, store, params, fetch),
-                new StringLengthDifferenceFilterValue(sel, store, params,
-                    fetch), null);
+            dict.assertSupport(pre != null, "StringLengthFunction");
+            dict.substring(buf, 
+                new FilterValueImpl(sel, ctx, bstate.state1, _val1),
+                new StringLengthDifferenceFilterValue(sel, ctx, bstate, pre, 
+                    post), null);
             buf.append(" = ");
-            _val2.appendTo(buf, 0, sel, store, params, fetch);
+            _val2.appendTo(sel, ctx, bstate.state2, buf, 0);
         }
 
-        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);
+        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) {
@@ -131,16 +122,18 @@
         implements FilterValue {
 
         private final Select _sel;
-        private final JDBCStore _store;
-        private final Object[] _params;
-        private final JDBCFetchConfiguration _fetch;
+        private final ExpContext _ctx;
+        private final BinaryOpExpState _state;
+        private final String _pre;
+        private final String _post;
 
-        public StringLengthDifferenceFilterValue(Select sel,
-            JDBCStore store, Object[] params, JDBCFetchConfiguration fetch) {
+        public StringLengthDifferenceFilterValue(Select sel, ExpContext ctx, 
+            BinaryOpExpState state, String pre, String post) {
             _sel = sel;
-            _store = store;
-            _params = params;
-            _fetch = fetch;
+            _ctx = ctx;
+            _state = state;
+            _pre = pre;
+            _post = post;
         }
 
         public Class getType() {
@@ -157,18 +150,18 @@
 
         public void appendTo(SQLBuffer buf, int index) {
             buf.append(_pre);
-            _val1.appendTo(buf, index, _sel, _store, _params, _fetch);
+            _val1.appendTo(_sel, _ctx, _state.state1, buf, index);
             buf.append(_post).append(" - ").append(_pre);
-            _val2.appendTo(buf, index, _sel, _store, _params, _fetch);
+            _val2.appendTo(_sel, _ctx, _state.state2, buf, index);
             buf.append(_post);
         }
 
         public String getColumnAlias(Column col) {
-            return _sel.getColumnAlias(col, _joins);
+            return _sel.getColumnAlias(col, _state.joins);
         }
 
         public String getColumnAlias(String col, Table table) {
-            return _sel.getColumnAlias(col, table, _joins);
+            return _sel.getColumnAlias(col, table, _state.joins);
         }
 
         public Object toDataStoreValue(Object val) {

Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/EqualExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/EqualExpression.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/EqualExpression.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/EqualExpression.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 ").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 ").appendValue(null);
                 }
             } else
-                val.appendIsNull(buf, sel, store, params, fetch);
+                val.appendIsNull(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));
                 for (int i = 0; i < len; i++) {
                     if (i > 0)
                         buf.append(" AND ");
 
-                    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);
                 }
             }
         }

Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Exp.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Exp.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/Exp.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Exp.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.Expression;
@@ -35,38 +32,25 @@
 
     /**
      * Initialize the expression. This method should recursively
-     * initialize any sub-expressions or values. It should also cache
-     * the {@link Joins} instance containing the joins for this expression.
+     * initialize any sub-expressions or values.
      *
-     * @param params the parameter values; the initialization process
-     * should not rely on exact values, but may need
-     * to see if parameter values are null
      * @param contains map of relation paths to the number of times
      * the paths appear in a contains() expression;
      * used to ensure paths used for contains() within
      * the same AND expression used different aliases
      */
-    public void initialize(Select sel, JDBCStore store,
-        Object[] params, Map contains);
+    public ExpState initialize(Select sel, ExpContext ctx, Map contains);
 
     /**
      * Append the SQL for this expression to the given buffer. The SQL
      * should optionally include any joins this expression needs.
      */
-    public void appendTo(SQLBuffer buf, Select sel, JDBCStore store,
-        Object[] params, JDBCFetchConfiguration fetch);
+    public void appendTo(Select sel, ExpContext ctx, ExpState state, 
+        SQLBuffer buf);
 
     /**
-     * Select just the columns for this value.
+     * Select just the columns for this expression.
      */
-    public void selectColumns(Select sel, JDBCStore store,
-        Object[] params, boolean pks, JDBCFetchConfiguration fetch);
-
-    /**
-     * Return the joins for this expression. These joins should be created
-     * and cached during the {@link #initialize} method. The parent
-     * expression might modify these joins during its own initialization so
-     * that common joins are moved up the expression tree.
-     */
-    public Joins getJoins();
+    public void selectColumns(Select sel, ExpContext ctx, ExpState state, 
+        boolean pks);
 }

Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Extension.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Extension.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/Extension.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Extension.java Mon Sep 18 14:57:52 2006
@@ -18,8 +18,6 @@
 import java.sql.SQLException;
 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.JavaSQLTypes;
 import org.apache.openjpa.jdbc.sql.Joins;
@@ -43,7 +41,6 @@
     private final Val _target;
     private final Val _arg;
     private final ClassMapping _candidate;
-    private Joins _joins = null;
     private ClassMetaData _meta = null;
     private Class _cast = null;
 
@@ -93,119 +90,108 @@
         _cast = type;
     }
 
-    public void initialize(Select sel, JDBCStore store, boolean nullTest) {
+    public ExpState initialize(Select sel, ExpContext ctx, int flags) {
         // 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
-        Joins j1 = null;
-        Joins j2 = null;
-        if (_target != null) {
-            _target.initialize(sel, store, false);
-            if (_target instanceof PCPath)
-                ((PCPath) _target).joinRelation();
-            j1 = _target.getJoins();
-        }
-        if (_arg != null) {
-            _arg.initialize(sel, store, false);
-            if (_arg instanceof PCPath)
-                ((PCPath) _arg).joinRelation();
-            j2 = _arg.getJoins();
-        }
-        _joins = sel.and(j1, j2);
+        ExpState targetState = null;
+        ExpState argState = null;
+        if (_target != null)
+            targetState = _target.initialize(sel, ctx, JOIN_REL);
+        if (_arg != null)
+            argState = _arg.initialize(sel, ctx, JOIN_REL);
+        Joins j1 = (targetState == null) ? null : targetState.joins;
+        Joins j2 = (argState == null) ? null : argState.joins;
+        return new ExtensionExpState(sel.and(j1, j2), targetState, 
+            argState);
     }
 
-    public Joins getJoins() {
-        return _joins;
-    }
+    /**
+     * Expression state.
+     */
+    private static class ExtensionExpState
+        extends ExpState {
+
+        public final ExpState targetState;
+        public final ExpState argState;
 
-    public Object toDataStoreValue(Object val, JDBCStore store) {
-        return val;
+        public ExtensionExpState(Joins joins, ExpState targetState,
+            ExpState argState) {
+            super(joins);
+            this.targetState = targetState;
+            this.argState = argState;
+        }
     }
 
-    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) {
+    public void selectColumns(Select sel, ExpContext ctx, ExpState state, 
+        boolean pks) {
+        ExtensionExpState estate = (ExtensionExpState) state;
         if (_target != null)
-            _target.selectColumns(sel, store, params, true, fetch);
+            _target.selectColumns(sel, ctx, estate.targetState, true);
         if (_arg != null)
-            _arg.selectColumns(sel, store, params, true, fetch);
+            _arg.selectColumns(sel, ctx, estate.argState, 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) {
+    public void calculateValue(Select sel, ExpContext ctx, ExpState state, 
+        Val other, ExpState otherState) {
+        ExtensionExpState estate = (ExtensionExpState) state;
         if (_target != null)
-            _target.calculateValue(sel, store, params, null, fetch);
+            _target.calculateValue(sel, ctx, estate.targetState, null, null);
         if (_arg != null)
-            _arg.calculateValue(sel, store, params, null, fetch);
+            _arg.calculateValue(sel, ctx, estate.argState, null, null);
     }
 
-    public void clearParameters() {
-        if (_target != null)
-            _target.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) {
+    public void appendTo(Select sel, ExpContext ctx, ExpState state, 
+        SQLBuffer sql, int index) {
+        ExtensionExpState estate = (ExtensionExpState) state;
         FilterValue target = (_target == null) ? null
-            : new FilterValueImpl(_target, sel, store, params, fetch);
-        _listener.appendTo(sql, target, getArgs(sel, store, params, fetch), 
-            _candidate, store);
-        sel.append(sql, _joins);
+            : new FilterValueImpl(sel, ctx, estate.targetState, _target);
+        _listener.appendTo(sql, target, getArgs(sel, ctx, estate.argState),
+            _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;
-        }
-        return new FilterValue[]{
-            new FilterValueImpl(_arg, sel, store, params, fetch)
+        if (_arg instanceof Args)
+            return ((Args) _arg).newFilterValues(sel, ctx, state);
+        return new FilterValue[] {
+            new FilterValueImpl(sel, ctx, state, _arg)
         };
     }
 
@@ -222,16 +208,14 @@
     // Exp implementation
     //////////////////////
 
-    public void initialize(Select sel, JDBCStore store,
-        Object[] params, Map contains) {
-        initialize(sel, store, false);
+    public ExpState initialize(Select sel, ExpContext ctx, Map contains) {
+        return initialize(sel, ctx, 0);
     }
 
-    public void appendTo(SQLBuffer sql, Select sel, JDBCStore store,
-        Object[] params, JDBCFetchConfiguration fetch) {
-        calculateValue(sel, store, params, null, fetch);
-        appendTo(sql, 0, sel, store, params, fetch);
-        sel.append(sql, getJoins());
-        clearParameters();
+    public void appendTo(Select sel, ExpContext ctx, ExpState state, 
+        SQLBuffer sql) {
+        calculateValue(sel, ctx, state, null, null);
+        appendTo(sel, ctx, state, sql, 0);
+        sel.append(sql, state.joins);
     }
 }

Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/FilterValueImpl.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/FilterValueImpl.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/FilterValueImpl.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/FilterValueImpl.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.meta.ClassMapping;
 import org.apache.openjpa.jdbc.meta.FieldMapping;
 import org.apache.openjpa.jdbc.schema.Column;
@@ -32,19 +30,17 @@
 class FilterValueImpl
     implements FilterValue {
 
-    private final Val _val;
     private final Select _sel;
-    private final JDBCStore _store;
-    private final Object[] _params;
-    private final JDBCFetchConfiguration _fetch;
+    private final ExpContext _ctx;
+    private final ExpState _state;
+    private final Val _val;
 
-    public FilterValueImpl(Val val, Select sel, JDBCStore store,
-        Object[] params, JDBCFetchConfiguration fetch) {
-        _val = val;
+    public FilterValueImpl(Select sel, ExpContext ctx, ExpState state, 
+        Val val) {
         _sel = sel;
-        _store = store;
-        _params = params;
-        _fetch = fetch;
+        _ctx = ctx;
+        _state = state;
+        _val = val;
     }
 
     public Class getType() {
@@ -52,7 +48,7 @@
     }
 
     public int length() {
-        return _val.length();
+        return _val.length(_sel, _ctx, _state);
     }
 
     public void appendTo(SQLBuffer buf) {
@@ -60,19 +56,19 @@
     }
 
     public void appendTo(SQLBuffer buf, int index) {
-        _val.appendTo(buf, index, _sel, _store, _params, _fetch);
+        _val.appendTo(_sel, _ctx, _state, buf, index);
     }
 
     public String getColumnAlias(Column col) {
-        return _sel.getColumnAlias(col, _val.getJoins());
+        return _sel.getColumnAlias(col, _state.joins);
     }
 
     public String getColumnAlias(String col, Table table) {
-        return _sel.getColumnAlias(col, table, _val.getJoins());
+        return _sel.getColumnAlias(col, table, _state.joins);
     }
 
     public Object toDataStoreValue(Object val) {
-        return _val.toDataStoreValue(val, _store);
+        return _val.toDataStoreValue(_sel, _ctx, _state, val);
     }
 
     public boolean isConstant() {
@@ -80,11 +76,12 @@
     }
 
     public Object getValue() {
-        return (isConstant()) ? ((Const) _val).getValue() : null;
+        return (isConstant()) ? ((Const) _val).getValue(_ctx.params) : null;
     }
 
     public Object getSQLValue() {
-        return (isConstant()) ? ((Const) _val).getSQLValue() : null;
+        return (isConstant()) ? ((Const) _val).getSQLValue(_sel, _ctx, _state) 
+            : null;
     }
 
     public boolean isPath() {
@@ -92,10 +89,10 @@
     }
 
     public ClassMapping getClassMapping() {
-        return (isPath()) ? ((PCPath) _val).getClassMapping() : null;
+        return (isPath()) ? ((PCPath) _val).getClassMapping(_state) : null;
     }
 
     public FieldMapping getFieldMapping() {
-        return (isPath()) ? ((PCPath) _val).getFieldMapping() : null;
+        return (isPath()) ? ((PCPath) _val).getFieldMapping(_state) : null;
     }
 }

Modified: incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/GetMapValue.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/GetMapValue.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/GetMapValue.java (original)
+++ incubator/openjpa/sandboxes/OPENJPA-24/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/GetMapValue.java Mon Sep 18 14:57:52 2006
@@ -17,8 +17,6 @@
 
 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.FieldMapping;
 import org.apache.openjpa.jdbc.meta.JavaSQLTypes;
@@ -27,7 +25,6 @@
 import org.apache.openjpa.jdbc.meta.strats.RelationStrategies;
 import org.apache.openjpa.jdbc.schema.Column;
 import org.apache.openjpa.jdbc.schema.ForeignKey;
-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;
@@ -42,9 +39,9 @@
  */
 class GetMapValue
     extends AbstractVal {
+
     private final Val _map;
     private final Val _key;
-    private Joins _joins = null;
     private ClassMetaData _meta = null;
     private Class _cast = null;
 
@@ -71,7 +68,6 @@
     public Class getType() {
         if (_cast != null)
             return _cast;
-
         return _map.getType();
     }
 
@@ -79,135 +75,133 @@
         _cast = type;
     }
 
-    public void initialize(Select sel, JDBCStore store, boolean nullTest) {
-        _map.initialize(sel, store, false);
-        _key.initialize(sel, store, false);
-        _joins = sel.and(_map.getJoins(), _key.getJoins());
+    public ExpState initialize(Select sel, ExpContext ctx, int flags) {
+        ExpState mapState = _map.initialize(sel, ctx, 0);
+        ExpState keyState = _key.initialize(sel, ctx, 0);
+        return new GetMapValueExpState(sel.and(mapState.joins, keyState.joins),
+            mapState, keyState);
     }
 
-    public Joins getJoins() {
-        return _joins;
+    /**
+     * Expression state.
+     */
+    private static class GetMapValueExpState
+        extends ExpState {
+
+        public final ExpState mapState;
+        public final ExpState keyState;
+
+        public GetMapValueExpState(Joins joins, ExpState mapState, 
+            ExpState keyState) {
+            super(joins);
+            this.mapState = mapState;
+            this.keyState = keyState;
+        }
     }
 
-    public Object toDataStoreValue(Object val, JDBCStore store) {
-        return _map.toDataStoreValue(val, store);
+    public Object toDataStoreValue(Select sel, ExpContext ctx, ExpState state, 
+        Object val) {
+        GetMapValueExpState gstate = (GetMapValueExpState) state;
+        return _map.toDataStoreValue(sel, ctx, gstate.mapState, val);
     }
 
 
-    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) {
-        _map.selectColumns(sel, store, params, true, fetch);
-        _key.selectColumns(sel, store, params, true, fetch);
+    public void selectColumns(Select sel, ExpContext ctx, ExpState state,
+        boolean pks) {
+        GetMapValueExpState gstate = (GetMapValueExpState) state;
+        _map.selectColumns(sel, ctx, gstate.mapState, true);
+        _key.selectColumns(sel, ctx, gstate.keyState, 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) {
-        _map.calculateValue(sel, store, params, null, fetch);
-        _key.calculateValue(sel, store, params, null, fetch);
-    }
-
-    public void clearParameters() {
-        _map.clearParameters();
-        _key.clearParameters();
+    public void calculateValue(Select sel, ExpContext ctx, ExpState state, 
+        Val other, ExpState otherState) {
+        GetMapValueExpState gstate = (GetMapValueExpState) state;
+        _map.calculateValue(sel, ctx, gstate.mapState, null, null);
+        _key.calculateValue(sel, ctx, gstate.keyState, 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) {
+    public void appendTo(Select sel, ExpContext ctx, ExpState state, 
+        SQLBuffer sql, int index) {
         if (!(_map instanceof PCPath))
             throw new UnsupportedOperationException();
-
         if (!(_key instanceof Const))
             throw new UnsupportedOperationException();
 
+        GetMapValueExpState gstate = (GetMapValueExpState) state;
         PCPath map = (PCPath) _map;
-        Object key = ((Const) _key).getValue();
-
-        FieldMapping field = map.getFieldMapping();
-
+        Object key = ((Const) _key).getValue(ctx, gstate.keyState);
+        FieldMapping field = map.getFieldMapping(gstate.mapState);
         if (!(field.getStrategy() instanceof LRSMapFieldStrategy))
             throw new UnsupportedOperationException();
 
         LRSMapFieldStrategy strat = (LRSMapFieldStrategy) field.getStrategy();
-
         ClassMapping[] clss = strat.getIndependentValueMappings(true);
         if (clss != null && clss.length > 1)
             throw RelationStrategies.unjoinable(field);
 
         ClassMapping cls = (clss.length == 0) ? null : clss[0];
         ForeignKey fk = strat.getJoinForeignKey(cls);
-        DBDictionary dict = store.getDBDictionary();
-        SQLBuffer sub = new SQLBuffer(dict);
 
         // manually create a subselect for the Map's value
-        sub.append("(SELECT ");
+        sql.append("(SELECT ");
         Column[] values = field.getElementMapping().getColumns();
         for (int i = 0; i < values.length; i++) {
             if (i > 0)
-                sub.append(", ");
-            sub.append(values[i].getFullName());
+                sql.append(", ");
+            sql.append(values[i].getFullName());
         }
-
-        sub.append(" FROM ").append(values[0].getTable().getFullName()).
+        sql.append(" FROM ").append(values[0].getTable().getFullName()).
             append(" WHERE ");
 
         // add in the joins
-        ContainerFieldStrategy.appendUnaliasedJoin(sub, sel, null,
-            dict, field, fk);
+        ContainerFieldStrategy.appendUnaliasedJoin(sql, sel, null, 
+            ctx.store.getDBDictionary(), field, fk);
+        sql.append(" AND ");
 
-        sub.append(" AND ");
-
-        key = strat.toKeyDataStoreValue(key, store);
+        key = strat.toKeyDataStoreValue(key, ctx.store);
         Column[] cols = strat.getKeyColumns(cls);
         Object[] vals = (cols.length == 1) ? null : (Object[]) key;
 
         for (int i = 0; i < cols.length; i++) {
-            sub.append(cols[i].getFullName());
-
+            sql.append(cols[i].getFullName());
             if (vals == null)
-                sub.append((key == null) ? " IS " : " = ").
+                sql.append((key == null) ? " IS " : " = ").
                     appendValue(key, cols[i]);
             else
-                sub.append((vals[i] == null) ? " IS " : " = ").
+                sql.append((vals[i] == null) ? " IS " : " = ").
                     appendValue(vals[i], cols[i]);
         }
-
-        sub.append(")");
-
-        sql.append(sub);
+        sql.append(")");
     }
 }



Mime
View raw message