openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From awh...@apache.org
Subject svn commit: r441158 [2/5] - in /incubator/openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/ openjpa-kernel/s...
Date Thu, 07 Sep 2006 17:51:09 GMT
Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ContainsExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ContainsExpression.java?view=diff&rev=441158&r1=441157&r2=441158
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ContainsExpression.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ContainsExpression.java Thu Sep  7 10:51:05 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/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ContainsKeyExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ContainsKeyExpression.java?view=diff&rev=441158&r1=441157&r2=441158
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ContainsKeyExpression.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ContainsKeyExpression.java Thu Sep  7 10:51:05 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/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Count.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Count.java?view=diff&rev=441158&r1=441157&r2=441158
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Count.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Count.java Thu Sep  7 10:51:05 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/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CurrentDate.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CurrentDate.java?view=diff&rev=441158&r1=441157&r2=441158
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CurrentDate.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CurrentDate.java Thu Sep  7 10:51:05 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/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Distinct.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Distinct.java?view=diff&rev=441158&r1=441157&r2=441158
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Distinct.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Distinct.java Thu Sep  7 10:51:05 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/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/EmptyExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/EmptyExpression.java?view=diff&rev=441158&r1=441157&r2=441158
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/EmptyExpression.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/EmptyExpression.java Thu Sep  7 10:51:05 2006
@@ -17,9 +17,6 @@
 
 import java.util.Map;
 
-import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
-import org.apache.openjpa.jdbc.kernel.JDBCStore;
-import org.apache.openjpa.jdbc.sql.Joins;
 import org.apache.openjpa.jdbc.sql.SQLBuffer;
 import org.apache.openjpa.jdbc.sql.Select;
 import org.apache.openjpa.kernel.exps.ExpressionVisitor;
@@ -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/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/EndsWithExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/EndsWithExpression.java?view=diff&rev=441158&r1=441157&r2=441158
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/EndsWithExpression.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/EndsWithExpression.java Thu Sep  7 10:51:05 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/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/EqualExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/EqualExpression.java?view=diff&rev=441158&r1=441157&r2=441158
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/EqualExpression.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/EqualExpression.java Thu Sep  7 10:51:05 2006
@@ -15,8 +15,6 @@
  */
 package org.apache.openjpa.jdbc.kernel.exps;
 
-import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
-import org.apache.openjpa.jdbc.kernel.JDBCStore;
 import org.apache.openjpa.jdbc.sql.SQLBuffer;
 import org.apache.openjpa.jdbc.sql.Select;
 
@@ -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/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Exp.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Exp.java?view=diff&rev=441158&r1=441157&r2=441158
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Exp.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Exp.java Thu Sep  7 10:51:05 2006
@@ -17,9 +17,6 @@
 
 import java.util.Map;
 
-import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
-import org.apache.openjpa.jdbc.kernel.JDBCStore;
-import org.apache.openjpa.jdbc.sql.Joins;
 import org.apache.openjpa.jdbc.sql.SQLBuffer;
 import org.apache.openjpa.jdbc.sql.Select;
 import org.apache.openjpa.kernel.exps.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/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Extension.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Extension.java?view=diff&rev=441158&r1=441157&r2=441158
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Extension.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/Extension.java Thu Sep  7 10:51:05 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/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/FilterValueImpl.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/FilterValueImpl.java?view=diff&rev=441158&r1=441157&r2=441158
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/FilterValueImpl.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/FilterValueImpl.java Thu Sep  7 10:51:05 2006
@@ -15,8 +15,6 @@
  */
 package org.apache.openjpa.jdbc.kernel.exps;
 
-import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
-import org.apache.openjpa.jdbc.kernel.JDBCStore;
 import org.apache.openjpa.jdbc.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/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/GetMapValue.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/GetMapValue.java?view=diff&rev=441158&r1=441157&r2=441158
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/GetMapValue.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/GetMapValue.java Thu Sep  7 10:51:05 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(")");
     }
 }

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/GetObjectId.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/GetObjectId.java?view=diff&rev=441158&r1=441157&r2=441158
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/GetObjectId.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/GetObjectId.java Thu Sep  7 10:51:05 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/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InExpression.java?view=diff&rev=441158&r1=441157&r2=441158
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InExpression.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InExpression.java Thu Sep  7 10:51:05 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/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InKeyExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InKeyExpression.java?view=diff&rev=441158&r1=441157&r2=441158
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InKeyExpression.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InKeyExpression.java Thu Sep  7 10:51:05 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/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InSubQExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InSubQExpression.java?view=diff&rev=441158&r1=441157&r2=441158
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InSubQExpression.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InSubQExpression.java Thu Sep  7 10:51:05 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/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InValueExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InValueExpression.java?view=diff&rev=441158&r1=441157&r2=441158
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InValueExpression.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InValueExpression.java Thu Sep  7 10:51:05 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/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/IndexOf.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/IndexOf.java?view=diff&rev=441158&r1=441157&r2=441158
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/IndexOf.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/IndexOf.java Thu Sep  7 10:51:05 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/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InstanceofExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InstanceofExpression.java?view=diff&rev=441158&r1=441157&r2=441158
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InstanceofExpression.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InstanceofExpression.java Thu Sep  7 10:51:05 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/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/IsEmptyExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/IsEmptyExpression.java?view=diff&rev=441158&r1=441157&r2=441158
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/IsEmptyExpression.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/IsEmptyExpression.java Thu Sep  7 10:51:05 2006
@@ -17,9 +17,6 @@
 
 import java.util.Map;
 
-import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
-import org.apache.openjpa.jdbc.kernel.JDBCStore;
-import org.apache.openjpa.jdbc.sql.Joins;
 import org.apache.openjpa.jdbc.sql.SQLBuffer;
 import org.apache.openjpa.jdbc.sql.Select;
 import org.apache.openjpa.kernel.exps.ExpressionVisitor;
@@ -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/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/IsNotEmptyExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/IsNotEmptyExpression.java?view=diff&rev=441158&r1=441157&r2=441158
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/IsNotEmptyExpression.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/IsNotEmptyExpression.java Thu Sep  7 10:51:05 2006
@@ -17,9 +17,6 @@
 
 import java.util.Map;
 
-import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
-import org.apache.openjpa.jdbc.kernel.JDBCStore;
-import org.apache.openjpa.jdbc.sql.Joins;
 import org.apache.openjpa.jdbc.sql.SQLBuffer;
 import org.apache.openjpa.jdbc.sql.Select;
 import org.apache.openjpa.kernel.exps.ExpressionVisitor;
@@ -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/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCExpressionFactory.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCExpressionFactory.java?view=diff&rev=441158&r1=441157&r2=441158
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCExpressionFactory.java (original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/JDBCExpressionFactory.java Thu Sep  7 10:51:05 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() {



Mime
View raw message