svn commit: r880835 [1/2] - in /ofbiz/trunk: ./ framework/ framework/base/src/org/ofbiz/base/util/ framework/entity/ framework/entity/src/org/ofbiz/entity/sql/ framework/sql/ framework/sql/src/ framework/sql/src/org/ framework/sql/src/org/ofbiz/ framew...

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r880835 [1/2] - in /ofbiz/trunk: ./ framework/ framework/base/src/org/ofbiz/base/util/ framework/entity/ framework/entity/src/org/ofbiz/entity/sql/ framework/sql/ framework/sql/src/ framework/sql/src/org/ framework/sql/src/org/ofbiz/ framew...

doogie-3
Author: doogie
Date: Mon Nov 16 16:31:32 2009
New Revision: 880835

URL: http://svn.apache.org/viewvc?rev=880835&view=rev
Log:
Very large update.  SQL parser is fairly generic now.  Can parse sql
that is compatible with features used by ofbiz.  Has support for
DELETE, INSERT, INSERT SELECT, SELECT, UPDATE, and VIEW.

Modified the delegator side of the above to handle the new
interfaces.  Now supports complex alias.  Only SELECT is supported,
and the parseCondition code is disabled for the time being.

The plan(sic) here is to obviously support the other sql statements.
Then, to have a jdbc wrapper around all this, so external tools, that
only know how to talk jdbc, can actually talk directly to the
delegator.

Plus, many more people can understand sql syntax.  This allows them
to do things with ofbiz, that they would find much more difficult if
they had to write <view-entity> definitions.

Added:
    ofbiz/trunk/framework/base/src/org/ofbiz/base/util/Appender.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/EntityDeletePlan.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/EntityInsertPlan.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/EntityPlanner.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/EntitySelectPlan.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/EntityUpdatePlan.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/EntityViewPlan.java
    ofbiz/trunk/framework/sql/   (with props)
    ofbiz/trunk/framework/sql/build.xml
    ofbiz/trunk/framework/sql/ofbiz-component.xml
    ofbiz/trunk/framework/sql/src/
    ofbiz/trunk/framework/sql/src/org/
    ofbiz/trunk/framework/sql/src/org/ofbiz/
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/BooleanCondition.java
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Condition.java
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/ConditionList.java
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/ConstantValue.java
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/DeletePlan.java
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/FieldAll.java
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/FieldDef.java
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/FieldDefFieldValue.java
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/FieldDefValue.java
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/FieldValue.java
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/FunctionCall.java
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/InsertPlan.java
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/InsertRow.java
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/InsertSource.java
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/InsertValues.java
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Joined.java
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Joiner.java
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/KeyMap.java
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/ListValue.java
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Main.java
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/MathValue.java
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/NumberValue.java
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/ParameterValue.java
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Parser.jj
      - copied, changed from r880822, ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/Parser.jj
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Planner.java
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Relation.java
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/SQLDelete.java
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/SQLInsert.java
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/SQLPlan.java
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/SQLSelect.java
      - copied, changed from r880823, ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/SQLSelect.java
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/SQLStatement.java
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/SQLUpdate.java
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/SQLView.java
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/SelectPlan.java
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/SetField.java
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/StaticValue.java
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/StringValue.java
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Table.java
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/TableName.java
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/UpdatePlan.java
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Value.java
    ofbiz/trunk/framework/sql/src/org/ofbiz/sql/ViewPlan.java
Removed:
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/Parser.jj
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/SQLSelect.java
Modified:
    ofbiz/trunk/.gitignore
    ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java
    ofbiz/trunk/framework/component-load.xml
    ofbiz/trunk/framework/entity/build.xml
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/SQLUtil.java
    ofbiz/trunk/framework/webslinger/websites/webslinger/www/TestSQL.groovy

Modified: ofbiz/trunk/.gitignore
URL: http://svn.apache.org/viewvc/ofbiz/trunk/.gitignore?rev=880835&r1=880834&r2=880835&view=diff
==============================================================================
--- ofbiz/trunk/.gitignore (original)
+++ ofbiz/trunk/.gitignore Mon Nov 16 16:31:32 2009
@@ -24,6 +24,7 @@
 framework/minilang/build/
 framework/security/build/
 framework/service/build/
+framework/sql/build/
 framework/start/build/
 framework/testtools/build/
 framework/webapp/build/

Added: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/Appender.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/Appender.java?rev=880835&view=auto
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/Appender.java (added)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/Appender.java Mon Nov 16 16:31:32 2009
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.ofbiz.base.util;
+
+public interface Appender<T> {
+    T appendTo(T target);
+}

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java?rev=880835&r1=880834&r2=880835&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringUtil.java Mon Nov 16 16:31:32 2009
@@ -685,6 +685,28 @@
         return new StringWrapper(theString);
     }
 
+    public static StringBuilder appendTo(StringBuilder sb, Iterable<? extends Appender<StringBuilder>> iterable, String prefix, String suffix, String sep) {
+        Iterator<? extends Appender<StringBuilder>> it = iterable.iterator();
+        while (it.hasNext()) {
+            if (prefix != null) sb.append(prefix);
+            it.next().appendTo(sb);
+            if (suffix != null) sb.append(suffix);
+            if (it.hasNext() && sep != null) sb.append(sep);
+        }
+        return sb;
+    }
+
+    public static StringBuilder append(StringBuilder sb, Iterable<? extends Object> iterable, String prefix, String suffix, String sep) {
+        Iterator<? extends Object> it = iterable.iterator();
+        while (it.hasNext()) {
+            if (prefix != null) sb.append(prefix);
+            sb.append(it.next());
+            if (suffix != null) sb.append(suffix);
+            if (it.hasNext() && sep != null) sb.append(sep);
+        }
+        return sb;
+    }
+
     /**
      * A super-lightweight object to wrap a String object. Mainly used with FTL templates
      * to avoid the general HTML auto-encoding that is now done through the Screen Widget.

Modified: ofbiz/trunk/framework/component-load.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/component-load.xml?rev=880835&r1=880834&r2=880835&view=diff
==============================================================================
--- ofbiz/trunk/framework/component-load.xml (original)
+++ ofbiz/trunk/framework/component-load.xml Mon Nov 16 16:31:32 2009
@@ -21,6 +21,7 @@
 <component-loader xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/component-loader.xsd">
     <load-component component-location="geronimo"/>
+    <load-component component-location="sql"/>
     <load-component component-location="entity"/>
     <load-component component-location="catalina"/>
     <!-- <load-component component-location="jetty"/> -->

Modified: ofbiz/trunk/framework/entity/build.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/build.xml?rev=880835&r1=880834&r2=880835&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/build.xml (original)
+++ ofbiz/trunk/framework/entity/build.xml Mon Nov 16 16:31:32 2009
@@ -37,10 +37,7 @@
         <fileset dir="../base/lib/j2eespecs" includes="*.jar"/>
         <fileset dir="../base/lib/scripting" includes="*.jar"/>
         <fileset dir="../base/build/lib" includes="*.jar"/>
-    </path>
-    <path id="src-path">
-        <pathelement location="build/gen-src/javacc"/>
-        <pathelement location="build/gen-src/jjtree"/>
+        <fileset dir="../sql/build/lib" includes="*.jar"/>
     </path>
 
     <patternset id="src.exc.set">
@@ -52,11 +49,7 @@
     <!-- Compilation of the source files                                                                                                                         -->
     <!-- ================================================================== -->
 
-    <target name="gen-src">
-        <ofbiz-javacc dir="org/ofbiz/entity/sql" file="Parser"/>
-    </target>
-
-    <target name="classes" depends="prepare,gen-src">
+    <target name="classes" depends="prepare">
         <javac15/>
     </target>
 

Added: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/EntityDeletePlan.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/EntityDeletePlan.java?rev=880835&view=auto
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/EntityDeletePlan.java (added)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/EntityDeletePlan.java Mon Nov 16 16:31:32 2009
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.ofbiz.entity.sql;
+
+import org.ofbiz.sql.DeletePlan;
+
+public class EntityDeletePlan extends DeletePlan<EntityDeletePlan> {
+}

Added: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/EntityInsertPlan.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/EntityInsertPlan.java?rev=880835&view=auto
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/EntityInsertPlan.java (added)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/EntityInsertPlan.java Mon Nov 16 16:31:32 2009
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.ofbiz.entity.sql;
+
+import org.ofbiz.sql.InsertPlan;
+
+public class EntityInsertPlan extends InsertPlan<EntityInsertPlan> {
+}

Added: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/EntityPlanner.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/EntityPlanner.java?rev=880835&view=auto
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/EntityPlanner.java (added)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/EntityPlanner.java Mon Nov 16 16:31:32 2009
@@ -0,0 +1,253 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.ofbiz.entity.sql;
+
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import javolution.util.FastList;
+
+import org.ofbiz.entity.GenericValue;
+import org.ofbiz.entity.condition.EntityFieldValue;
+import org.ofbiz.entity.condition.EntityCondition;
+import org.ofbiz.entity.condition.EntityConditionValue;
+import org.ofbiz.entity.condition.EntityOperator;
+import org.ofbiz.entity.model.DynamicViewEntity;
+import org.ofbiz.entity.model.ModelViewEntity.ComplexAlias;
+import org.ofbiz.entity.model.ModelViewEntity.ComplexAliasField;
+import org.ofbiz.entity.model.ModelViewEntity.ComplexAliasMember;
+import org.ofbiz.entity.model.ModelKeyMap;
+
+import org.ofbiz.sql.BooleanCondition;
+import org.ofbiz.sql.Condition;
+import org.ofbiz.sql.ConditionList;
+import org.ofbiz.sql.FieldAll;
+import org.ofbiz.sql.FieldDef;
+import org.ofbiz.sql.FieldDefFieldValue;
+import org.ofbiz.sql.FieldDefValue;
+import org.ofbiz.sql.FieldValue;
+import org.ofbiz.sql.FunctionCall;
+import org.ofbiz.sql.Joined;
+import org.ofbiz.sql.Joiner;
+import org.ofbiz.sql.KeyMap;
+import org.ofbiz.sql.MathValue;
+import org.ofbiz.sql.NumberValue;
+import org.ofbiz.sql.Planner;
+import org.ofbiz.sql.MathValue;
+import org.ofbiz.sql.Relation;
+import org.ofbiz.sql.SQLDelete;
+import org.ofbiz.sql.SQLInsert;
+import org.ofbiz.sql.SQLSelect;
+import org.ofbiz.sql.SQLUpdate;
+import org.ofbiz.sql.SQLView;
+import org.ofbiz.sql.StaticValue;
+import org.ofbiz.sql.StringValue;
+import org.ofbiz.sql.Table;
+import org.ofbiz.sql.TableName;
+import org.ofbiz.sql.Value;
+
+public class EntityPlanner implements Planner<EntityPlanner, EntityDeletePlan, EntityInsertPlan, EntitySelectPlan, EntityUpdatePlan, EntityViewPlan> {
+    public EntityDeletePlan plan(SQLDelete<?> deleteStatement) {
+        return null;
+    }
+
+    public EntityInsertPlan plan(SQLInsert<?> insertStatement) {
+        return null;
+    }
+
+    public EntitySelectPlan plan(SQLSelect<?> selectStatement) {
+        DynamicViewEntity dve = new DynamicViewEntity();
+        Table table = selectStatement.getTable();
+        addMember(dve, table.getTableName());
+        addJoined(dve, table.getTableName().getAlias(), table.getJoined());
+        for (FieldAll fieldAll: selectStatement.getFieldAlls()) {
+            dve.addAliasAll(fieldAll.getAlias(), null);
+        }
+        for (Relation relation: selectStatement.getRelations()) {
+            dve.addRelation(relation.getType(), relation.getTitle(), relation.getEntityName(), buildKeyMaps(relation));
+        }
+        List<String> groupBy = selectStatement.getGroupBy();
+        if (groupBy == null) {
+            groupBy = Collections.emptyList();
+        }
+        for (FieldDef fieldDef: selectStatement.getFieldDefs()) {
+            addFieldDef(dve, groupBy, fieldDef.getAlias(), fieldDef);
+        }
+        return new EntitySelectPlan(dve, buildCondition(selectStatement.getWhereCondition()), buildCondition(selectStatement.getHavingCondition()), selectStatement.getOrderBy());
+    }
+
+    public EntityUpdatePlan plan(SQLUpdate<?> updateStatement) {
+        return null;
+    }
+
+    public EntityViewPlan plan(SQLView<?> viewStatement) {
+        return null;
+    }
+
+    private static void addFieldDef(DynamicViewEntity dve, List<String> groupBy, String alias, FieldDef fieldDef) {
+        if (fieldDef instanceof FieldDefFieldValue) {
+            addFieldDef(dve, groupBy, fieldDef.getAlias(), ((FieldDefFieldValue) fieldDef).getFieldValue(), null);
+        } else if (fieldDef instanceof FieldDefValue) {
+            addFieldDef(dve, groupBy, fieldDef.getAlias(), ((FieldDefValue) fieldDef).getValue());
+        } else {
+            throw new UnsupportedOperationException(alias + "[" + fieldDef + "]:" + fieldDef.getClass());
+        }
+    }
+
+    private static void addFieldDef(DynamicViewEntity dve, List<String> groupBy, String alias, FieldValue fieldValue, String function) {
+        dve.addAlias(fieldValue.getTableName(), alias, fieldValue.getFieldName(), null, null, groupBy.contains(alias), function);
+    }
+
+    private static void addFieldDef(DynamicViewEntity dve, List<String> groupBy, String alias, ComplexAliasMember member) {
+        dve.addAlias(null, alias, null, null, null, groupBy.contains(alias), null, member);
+    }
+
+    private static void addFieldDef(DynamicViewEntity dve, List<String> groupBy, String alias, StaticValue value) {
+        ComplexAliasMember complexMember;
+        if (value instanceof FieldValue) {
+            addFieldDef(dve, groupBy, alias, (FieldValue) value, null);
+            return;
+        } else if (value instanceof FunctionCall) {
+            FunctionCall fc = (FunctionCall) value;
+            String name = fc.getName().toLowerCase();
+            Iterator<Value> it = fc.iterator();
+            if (it.hasNext()) {
+                Value firstValue = it.next();
+                if (!it.hasNext()) {
+                    if (firstValue instanceof FieldValue) {
+                        addFieldDef(dve, groupBy, alias, (FieldValue) firstValue, name);
+                        return;
+                    }
+                }
+            }
+        }
+        addFieldDef(dve, groupBy, alias, buildComplexMember(value));
+    }
+
+    private static ComplexAliasMember buildComplexMember(Value value) {
+        if (value instanceof FieldValue) {
+            FieldValue fv = (FieldValue) value;
+            return new ComplexAliasField(fv.getTableName(), fv.getFieldName(), null, null);
+        } else if (value instanceof FunctionCall) {
+            FunctionCall fc = (FunctionCall) value;
+            String name = fc.getName().toLowerCase();
+            if (fc.getArgCount() == 1) {
+                Value firstValue = fc.iterator().next();
+                if (firstValue instanceof FieldValue) {
+                    FieldValue fv = (FieldValue) firstValue;
+                    return new ComplexAliasField(fv.getTableName(), fv.getFieldName(), null, name);
+                } else if (firstValue instanceof FunctionCall) {
+                    FunctionCall fc2 = (FunctionCall) firstValue;
+                    if (fc2.getName().equalsIgnoreCase("coalesce") && fc2.getArgCount() == 2) {
+                        Iterator<Value> it = fc2.iterator();
+                        Value f1 = it.next(), f2 = it.next();
+                        if (f1 instanceof FieldValue) {
+                            FieldValue fv = (FieldValue) f1;
+                            if (f2 instanceof NumberValue) {
+                                return new ComplexAliasField(fv.getTableName(), fv.getFieldName(), ((NumberValue) f2).getNumber().toString(), name);
+                            } else if (f2 instanceof StringValue) {
+                                return new ComplexAliasField(fv.getTableName(), fv.getFieldName(), "'" + ((StringValue) f2).getString() + "'", name);
+                           }
+                        }
+                    }
+                }
+            } else if (fc.getName().equalsIgnoreCase("coalesce") && fc.getArgCount() == 2) {
+                Iterator<Value> it = fc.iterator();
+                Value f1 = it.next(), f2 = it.next();
+                if (f1 instanceof FieldValue) {
+                    FieldValue fv = (FieldValue) f1;
+                    if (f2 instanceof NumberValue) {
+                        return new ComplexAliasField(fv.getTableName(), fv.getFieldName(), ((NumberValue) f2).getNumber().toString(), null);
+                    } else if (f2 instanceof StringValue) {
+                        return new ComplexAliasField(fv.getTableName(), fv.getFieldName(), "'" + ((StringValue) f2).getString() + "'", null);
+                   }
+                }
+            }
+        } else if (value instanceof MathValue) {
+            MathValue mv = (MathValue) value;
+            List<ComplexAliasMember> members = FastList.newInstance();
+            ComplexAlias complexAlias = new ComplexAlias(mv.getOp());
+            for (StaticValue staticValue: mv) {
+                complexAlias.addComplexAliasMember(buildComplexMember(value));
+            }
+            return complexAlias;
+        }
+        throw new UnsupportedOperationException(value + ":" + value.getClass());
+    }
+
+    private static void addMember(DynamicViewEntity dve, TableName member) {
+        dve.addMemberEntity(member.getAlias(), member.getTableName());
+    }
+
+    private static void addJoined(DynamicViewEntity dve, String leftAlias, Joined joined) {
+        if (joined == null) return;
+        addMember(dve, joined.getTableName());
+        dve.addViewLink(leftAlias, joined.getTableName().getAlias(), joined.isOptional(), buildKeyMaps(joined));
+        addJoined(dve, joined.getTableName().getAlias(), joined.getJoined());
+    }
+
+    private static List<ModelKeyMap> buildKeyMaps(Iterable<KeyMap> keyMaps) {
+        List<ModelKeyMap> entityKeyMaps = FastList.newInstance();
+        for (KeyMap keyMap: keyMaps) {
+            entityKeyMaps.add(new ModelKeyMap(keyMap.getLeftFieldName(), keyMap.getRightFieldName()));
+        }
+        return entityKeyMaps;
+    }
+
+    private static EntityCondition buildCondition(Condition condition) {
+        if (condition == null) return null;
+        if (condition instanceof BooleanCondition) {
+            BooleanCondition bc = (BooleanCondition) condition;
+            return EntityCondition.makeCondition(buildFieldValue(bc.getLeft()), EntityOperator.lookupComparison(bc.getOp()), buildValue(bc.getRight()));
+        } else if (condition instanceof ConditionList) {
+            ConditionList cl = (ConditionList) condition;
+            List<EntityCondition> conditions = FastList.newInstance();
+            for (Condition subCondition: cl) {
+                conditions.add(buildCondition(subCondition));
+            }
+            return EntityCondition.makeCondition(conditions, cl.getJoiner() == Joiner.AND ? EntityOperator.AND : EntityOperator.OR);
+        } else {
+            throw new UnsupportedOperationException(condition.toString());
+        }
+    }
+
+    private static EntityFieldValue buildFieldValue(Value value) {
+        if (value instanceof FieldValue) {
+            FieldValue fv = (FieldValue) value;
+            return EntityFieldValue.makeFieldValue(fv.getFieldName(), fv.getTableName(), null, null);
+        }
+        throw new UnsupportedOperationException(value.toString());
+    }
+
+    private static Object buildValue(Object value) {
+        if (value instanceof NumberValue) {
+            return ((NumberValue) value).getNumber();
+        } else if (value instanceof StringValue) {
+            return ((StringValue) value).getString();
+        } else if (value instanceof List) {
+            List<Object> values = FastList.newInstance();
+            for (Object sqlValue: (List) value) {
+                values.add(buildValue(sqlValue));
+            }
+            return values;
+        }
+        throw new UnsupportedOperationException(value.toString());
+    }
+}

Added: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/EntitySelectPlan.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/EntitySelectPlan.java?rev=880835&view=auto
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/EntitySelectPlan.java (added)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/EntitySelectPlan.java Mon Nov 16 16:31:32 2009
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.ofbiz.entity.sql;
+
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
+
+import javolution.util.FastList;
+import javolution.util.FastMap;
+
+import org.ofbiz.entity.condition.EntityCondition;
+import org.ofbiz.entity.condition.EntityOperator;
+import org.ofbiz.entity.model.DynamicViewEntity;
+
+import org.ofbiz.entity.Delegator;
+import org.ofbiz.entity.GenericEntityException;
+import org.ofbiz.entity.GenericValue;
+import org.ofbiz.entity.condition.EntityCondition;
+import org.ofbiz.entity.model.DynamicViewEntity;
+import org.ofbiz.entity.model.ModelKeyMap;
+import org.ofbiz.entity.util.EntityListIterator;
+
+import org.ofbiz.sql.SelectPlan;
+
+public final class EntitySelectPlan extends SelectPlan<EntitySelectPlan> {
+    private final DynamicViewEntity dve;
+    private final EntityCondition whereCondition;
+    private final EntityCondition havingCondition;
+    private final List<String> orderBy;
+    private final int offset = -1;
+    private final int limit = -1;
+
+    public EntitySelectPlan(DynamicViewEntity dve, EntityCondition whereCondition, EntityCondition havingCondition, List<String> orderBy) {
+        this.dve = dve;
+        this.whereCondition = whereCondition;
+        this.havingCondition = havingCondition;
+        this.orderBy = orderBy;
+        //this.offset = offset;
+        //this.limit = limit;
+    }
+
+    public EntityListIterator getEntityListIterator(Delegator delegator) throws GenericEntityException {
+        return delegator.findListIteratorByCondition(dve, whereCondition, havingCondition, null, orderBy, null);
+    }
+
+    public DynamicViewEntity getDynamicViewEntity() {
+        return dve;
+    }
+
+    public EntityCondition getWhereCondition() {
+        return whereCondition;
+    }
+
+    public EntityCondition getHavingCondition() {
+        return havingCondition;
+    }
+
+    public List<String> getOrderBy() {
+        return orderBy;
+    }
+
+    public int getOffset() {
+        return offset;
+    }
+
+    public int getLimit() {
+        return limit;
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        sb.append("dve=" + dve);
+        if (whereCondition != null) {
+            if (sb.length() > 0) sb.append(", ");
+            sb.append("where=(").append(whereCondition).append(")");
+        }
+        if (havingCondition != null) {
+            if (sb.length() > 0) sb.append(", ");
+            sb.append("having=(").append(havingCondition).append(")");
+        }
+        if (offset != -1) {
+            if (sb.length() > 0) sb.append(", ");
+            sb.append("offset=").append(offset);
+        }
+        if (limit != -1) {
+            if (sb.length() > 0) sb.append(", ");
+            sb.append("limit=").append(limit);
+        }
+        sb.append("]");
+        sb.insert(0, "[").insert(0, super.toString());
+        return sb.toString();
+    }
+}

Added: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/EntityUpdatePlan.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/EntityUpdatePlan.java?rev=880835&view=auto
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/EntityUpdatePlan.java (added)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/EntityUpdatePlan.java Mon Nov 16 16:31:32 2009
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.ofbiz.entity.sql;
+
+import org.ofbiz.sql.UpdatePlan;
+
+public class EntityUpdatePlan extends UpdatePlan<EntityUpdatePlan> {
+}

Added: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/EntityViewPlan.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/EntityViewPlan.java?rev=880835&view=auto
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/EntityViewPlan.java (added)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/EntityViewPlan.java Mon Nov 16 16:31:32 2009
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.ofbiz.entity.sql;
+
+import org.ofbiz.sql.ViewPlan;
+
+public final class EntityViewPlan extends ViewPlan<EntityViewPlan> {
+}

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/SQLUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/SQLUtil.java?rev=880835&r1=880834&r2=880835&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/SQLUtil.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/sql/SQLUtil.java Mon Nov 16 16:31:32 2009
@@ -22,12 +22,18 @@
 
 import org.ofbiz.entity.condition.EntityCondition;
 
+import org.ofbiz.sql.Parser;
+import org.ofbiz.sql.ParseException;
+
 public class SQLUtil {
-    public static SQLSelect parseSelect(String sql) throws ParseException {
-       return new Parser(new StringReader(sql)).Select();
-    }
+    private static final EntityPlanner planner = new EntityPlanner();
 
+    public static EntitySelectPlan parseSelect(String sql) throws ParseException {
+       return planner.plan(new Parser(new StringReader(sql)).SelectStatement());
+    }
+    /*
     public static EntityCondition parseCondition(String condition) throws ParseException {
         return new Parser(new StringReader(condition)).EntityCondition();
     }
+    */
 }

Propchange: ofbiz/trunk/framework/sql/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Nov 16 16:31:32 2009
@@ -0,0 +1 @@
+build

Added: ofbiz/trunk/framework/sql/build.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/sql/build.xml?rev=880835&view=auto
==============================================================================
--- ofbiz/trunk/framework/sql/build.xml (added)
+++ ofbiz/trunk/framework/sql/build.xml Mon Nov 16 16:31:32 2009
@@ -0,0 +1,68 @@
+<?xml version="1.0"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<project name="OFBiz - SQL" default="jar" basedir=".">
+    <import file="../../common.xml"/>
+
+    <!-- ================================================================== -->
+    <!-- Initialization of all property settings                            -->
+    <!-- ================================================================== -->
+
+    <property name="desc" value="SQL Component"/>
+    <property name="name" value="ofbiz-sql"/>
+    <property name="ofbiz.home.dir" value="../.."/>
+
+    <path id="local.class.path">
+        <fileset dir="../base/lib" includes="*.jar"/>
+        <fileset dir="../base/build/lib" includes="*.jar"/>
+    </path>
+    <path id="src-path">
+        <pathelement location="build/gen-src/javacc"/>
+        <pathelement location="build/gen-src/jjtree"/>
+    </path>
+
+    <!-- ================================================================== -->
+    <!-- Compilation of the source files                                                                                                                         -->
+    <!-- ================================================================== -->
+
+    <target name="gen-src">
+        <ofbiz-javacc dir="org/ofbiz/sql" file="Parser"/>
+    </target>
+
+    <target name="classes" depends="prepare,gen-src">
+        <javac15/>
+    </target>
+
+    <!-- ================================================================== -->
+    <!-- Build JavaDoc                                                      -->
+    <!-- ================================================================== -->
+
+    <target name="docs" depends="prepare-docs">
+        <javadoc packagenames="org.ofbiz.sql.*"
+                 classpathref="local.class.path"
+                 destdir="${build.dir}/javadocs"
+                 Windowtitle="Open for Business - ${desc}">
+            <fileset dir="${src.dir}" defaultexcludes="yes">
+                <patternset refid="src.inc.set"/>
+                <patternset refid="src.exc.set"/>
+            </fileset>
+        </javadoc>
+    </target>
+</project>

Added: ofbiz/trunk/framework/sql/ofbiz-component.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/sql/ofbiz-component.xml?rev=880835&view=auto
==============================================================================
--- ofbiz/trunk/framework/sql/ofbiz-component.xml (added)
+++ ofbiz/trunk/framework/sql/ofbiz-component.xml Mon Nov 16 16:31:32 2009
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<ofbiz-component name="sql"
+        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+        xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/ofbiz-component.xsd">
+    <resource-loader name="main" type="component"/>
+    <classpath type="jar" location="build/lib/*"/>
+
+</ofbiz-component>

Added: ofbiz/trunk/framework/sql/src/org/ofbiz/sql/BooleanCondition.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/sql/src/org/ofbiz/sql/BooleanCondition.java?rev=880835&view=auto
==============================================================================
--- ofbiz/trunk/framework/sql/src/org/ofbiz/sql/BooleanCondition.java (added)
+++ ofbiz/trunk/framework/sql/src/org/ofbiz/sql/BooleanCondition.java Mon Nov 16 16:31:32 2009
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.ofbiz.sql;
+
+public final class BooleanCondition implements Condition {
+    private final Value left;
+    private final String op;
+    private final Value right;
+
+    public BooleanCondition(Value left, String op, Value right) {
+        this.left = left;
+        this.op = op;
+        this.right = right;
+    }
+
+    public Value getLeft() {
+        return left;
+    }
+
+    public String getOp() {
+        return op;
+    }
+
+    public Value getRight() {
+        return right;
+    }
+
+    public String toString() {
+        return appendTo(new StringBuilder()).toString();
+    }
+
+    public StringBuilder appendTo(StringBuilder sb) {
+        left.appendTo(sb);
+        sb.append(' ').append(op).append(' ');
+        right.appendTo(sb);
+        return sb;
+    }
+}

Added: ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Condition.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Condition.java?rev=880835&view=auto
==============================================================================
--- ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Condition.java (added)
+++ ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Condition.java Mon Nov 16 16:31:32 2009
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.ofbiz.sql;
+
+import org.ofbiz.base.util.Appender;
+
+public interface Condition extends Appender<StringBuilder> {
+}

Added: ofbiz/trunk/framework/sql/src/org/ofbiz/sql/ConditionList.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/sql/src/org/ofbiz/sql/ConditionList.java?rev=880835&view=auto
==============================================================================
--- ofbiz/trunk/framework/sql/src/org/ofbiz/sql/ConditionList.java (added)
+++ ofbiz/trunk/framework/sql/src/org/ofbiz/sql/ConditionList.java Mon Nov 16 16:31:32 2009
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.ofbiz.sql;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.ofbiz.base.util.StringUtil;
+
+public final class ConditionList implements Condition, Iterable<Condition> {
+    private final Joiner joiner;
+    private final List<Condition> conditions;
+
+    public ConditionList(Joiner joiner, List<Condition> conditions) {
+        this.joiner = joiner;
+        this.conditions = conditions;
+    }
+
+    public void add(Condition condition) {
+        conditions.add(condition);
+    }
+
+    public Joiner getJoiner() {
+        return joiner;
+    }
+
+    public Iterator<Condition> iterator() {
+        return conditions.iterator();
+    }
+
+    public StringBuilder appendTo(StringBuilder sb) {
+        sb.append('(');
+        StringUtil.appendTo(sb, conditions, " ", " ", joiner.toString());
+        sb.append(')');
+        return sb;
+    }
+}

Added: ofbiz/trunk/framework/sql/src/org/ofbiz/sql/ConstantValue.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/sql/src/org/ofbiz/sql/ConstantValue.java?rev=880835&view=auto
==============================================================================
--- ofbiz/trunk/framework/sql/src/org/ofbiz/sql/ConstantValue.java (added)
+++ ofbiz/trunk/framework/sql/src/org/ofbiz/sql/ConstantValue.java Mon Nov 16 16:31:32 2009
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.ofbiz.sql;
+
+public abstract class ConstantValue extends Value {
+}

Added: ofbiz/trunk/framework/sql/src/org/ofbiz/sql/DeletePlan.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/sql/src/org/ofbiz/sql/DeletePlan.java?rev=880835&view=auto
==============================================================================
--- ofbiz/trunk/framework/sql/src/org/ofbiz/sql/DeletePlan.java (added)
+++ ofbiz/trunk/framework/sql/src/org/ofbiz/sql/DeletePlan.java Mon Nov 16 16:31:32 2009
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.ofbiz.sql;
+
+public abstract class DeletePlan<P extends DeletePlan<P>> extends SQLPlan<P> {
+}

Added: ofbiz/trunk/framework/sql/src/org/ofbiz/sql/FieldAll.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/sql/src/org/ofbiz/sql/FieldAll.java?rev=880835&view=auto
==============================================================================
--- ofbiz/trunk/framework/sql/src/org/ofbiz/sql/FieldAll.java (added)
+++ ofbiz/trunk/framework/sql/src/org/ofbiz/sql/FieldAll.java Mon Nov 16 16:31:32 2009
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.ofbiz.sql;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.ofbiz.base.util.Appender;
+import org.ofbiz.base.util.StringUtil;
+
+public final class FieldAll implements Appender<StringBuilder>, Iterable<String> {
+    private final String alias;
+    private final List<String> exclude;
+
+    public FieldAll(String alias, List<String> exclude) {
+        this.alias = alias;
+        this.exclude = exclude;
+    }
+
+    public String getAlias() {
+        return alias;
+    }
+
+    public Iterator<String> iterator() {
+        return exclude.iterator();
+    }
+
+    public StringBuilder appendTo(StringBuilder sb) {
+        sb.append(alias).append(".*");
+        if (!exclude.isEmpty()) {
+            sb.append(" EXCLUDE (");
+            StringUtil.append(sb, exclude, null, null, ", ");
+            sb.append(')');
+        }
+        return sb;
+    }
+}

Added: ofbiz/trunk/framework/sql/src/org/ofbiz/sql/FieldDef.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/sql/src/org/ofbiz/sql/FieldDef.java?rev=880835&view=auto
==============================================================================
--- ofbiz/trunk/framework/sql/src/org/ofbiz/sql/FieldDef.java (added)
+++ ofbiz/trunk/framework/sql/src/org/ofbiz/sql/FieldDef.java Mon Nov 16 16:31:32 2009
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.ofbiz.sql;
+
+import org.ofbiz.base.util.Appender;
+
+public abstract class FieldDef implements Appender<StringBuilder> {
+    protected final String alias;
+
+    protected FieldDef(String alias) {
+        this.alias = alias;
+    }
+
+    public final String getAlias() {
+        return alias;
+    }
+
+    public String toString() {
+        return appendTo(new StringBuilder()).toString();
+    }
+}

Added: ofbiz/trunk/framework/sql/src/org/ofbiz/sql/FieldDefFieldValue.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/sql/src/org/ofbiz/sql/FieldDefFieldValue.java?rev=880835&view=auto
==============================================================================
--- ofbiz/trunk/framework/sql/src/org/ofbiz/sql/FieldDefFieldValue.java (added)
+++ ofbiz/trunk/framework/sql/src/org/ofbiz/sql/FieldDefFieldValue.java Mon Nov 16 16:31:32 2009
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.ofbiz.sql;
+
+public final class FieldDefFieldValue extends FieldDef {
+    private final FieldValue value;
+
+    public FieldDefFieldValue(FieldValue value, String alias) {
+        super(alias == null ? value.getFieldName() : alias);
+        this.value = value;
+    }
+
+    public FieldValue getFieldValue() {
+        return value;
+    }
+
+    public StringBuilder appendTo(StringBuilder sb) {
+        value.appendTo(sb);
+        if (!value.getFieldName().equals(alias)) {
+            sb.append(" AS ").append(alias);
+        }
+        return sb;
+    }
+}

Added: ofbiz/trunk/framework/sql/src/org/ofbiz/sql/FieldDefValue.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/sql/src/org/ofbiz/sql/FieldDefValue.java?rev=880835&view=auto
==============================================================================
--- ofbiz/trunk/framework/sql/src/org/ofbiz/sql/FieldDefValue.java (added)
+++ ofbiz/trunk/framework/sql/src/org/ofbiz/sql/FieldDefValue.java Mon Nov 16 16:31:32 2009
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.ofbiz.sql;
+
+public final class FieldDefValue extends FieldDef {
+    private final StaticValue value;
+
+    public FieldDefValue(StaticValue value, String alias) {
+        super(alias == null ? value.getDefaultName() : alias);
+        this.value = value;
+    }
+
+    public StaticValue getValue() {
+        return value;
+    }
+
+    public StringBuilder appendTo(StringBuilder sb) {
+        value.appendTo(sb);
+        sb.append(" AS ").append(alias);
+        return sb;
+    }
+}

Added: ofbiz/trunk/framework/sql/src/org/ofbiz/sql/FieldValue.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/sql/src/org/ofbiz/sql/FieldValue.java?rev=880835&view=auto
==============================================================================
--- ofbiz/trunk/framework/sql/src/org/ofbiz/sql/FieldValue.java (added)
+++ ofbiz/trunk/framework/sql/src/org/ofbiz/sql/FieldValue.java Mon Nov 16 16:31:32 2009
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.ofbiz.sql;
+
+public final class FieldValue extends StaticValue {
+    private final String fieldName;
+    private final String tableName;
+
+    public FieldValue(String fieldName) {
+        this(null, fieldName);
+    }
+
+    public FieldValue(String tableName, String fieldName) {
+        this.tableName = tableName;
+        this.fieldName = fieldName;
+    }
+
+    public final String getTableName() {
+        return tableName;
+    }
+
+    public final String getFieldName() {
+        return fieldName;
+    }
+
+    public String getDefaultName() {
+        return fieldName;
+    }
+
+    public StringBuilder appendTo(StringBuilder sb) {
+        if (tableName != null) {
+            sb.append(tableName).append('.');
+        }
+        sb.append(fieldName);
+        return sb;
+    }
+}

Added: ofbiz/trunk/framework/sql/src/org/ofbiz/sql/FunctionCall.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/sql/src/org/ofbiz/sql/FunctionCall.java?rev=880835&view=auto
==============================================================================
--- ofbiz/trunk/framework/sql/src/org/ofbiz/sql/FunctionCall.java (added)
+++ ofbiz/trunk/framework/sql/src/org/ofbiz/sql/FunctionCall.java Mon Nov 16 16:31:32 2009
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.ofbiz.sql;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.ofbiz.base.util.StringUtil;
+
+public final class FunctionCall extends StaticValue implements Iterable<Value> {
+    private final String name;
+    private final List<Value> values;
+
+    public FunctionCall(String name, List<Value> values) {
+        this.name = name;
+        this.values = values;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public String getDefaultName() {
+        return name;
+    }
+
+    public int getArgCount() {
+        return values.size();
+    }
+
+    public Iterator<Value> iterator() {
+        return values.iterator();
+    }
+
+    public StringBuilder appendTo(StringBuilder sb) {
+        sb.append(name).append('(');
+        StringUtil.appendTo(sb, values, null, null, ", ");
+        sb.append(')');
+        return sb;
+    }
+}

Added: ofbiz/trunk/framework/sql/src/org/ofbiz/sql/InsertPlan.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/sql/src/org/ofbiz/sql/InsertPlan.java?rev=880835&view=auto
==============================================================================
--- ofbiz/trunk/framework/sql/src/org/ofbiz/sql/InsertPlan.java (added)
+++ ofbiz/trunk/framework/sql/src/org/ofbiz/sql/InsertPlan.java Mon Nov 16 16:31:32 2009
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.ofbiz.sql;
+
+public abstract class InsertPlan<P extends InsertPlan<P>> extends SQLPlan<P> {
+}

Added: ofbiz/trunk/framework/sql/src/org/ofbiz/sql/InsertRow.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/sql/src/org/ofbiz/sql/InsertRow.java?rev=880835&view=auto
==============================================================================
--- ofbiz/trunk/framework/sql/src/org/ofbiz/sql/InsertRow.java (added)
+++ ofbiz/trunk/framework/sql/src/org/ofbiz/sql/InsertRow.java Mon Nov 16 16:31:32 2009
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.ofbiz.sql;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.ofbiz.base.util.Appender;
+import org.ofbiz.base.util.StringUtil;
+
+public class InsertRow implements Appender<StringBuilder>, Iterable<Value> {
+    private final List<Value> values;
+
+    public InsertRow(List<Value> values) {
+        this.values = values;
+    }
+
+    public Iterator<Value> iterator() {
+        return values.iterator();
+    }
+
+    public StringBuilder appendTo(StringBuilder sb) {
+        sb.append('(');
+        StringUtil.appendTo(sb, values, null, null, ", ");
+        sb.append(')');
+        return sb;
+    }
+}

Added: ofbiz/trunk/framework/sql/src/org/ofbiz/sql/InsertSource.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/sql/src/org/ofbiz/sql/InsertSource.java?rev=880835&view=auto
==============================================================================
--- ofbiz/trunk/framework/sql/src/org/ofbiz/sql/InsertSource.java (added)
+++ ofbiz/trunk/framework/sql/src/org/ofbiz/sql/InsertSource.java Mon Nov 16 16:31:32 2009
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.ofbiz.sql;
+
+import org.ofbiz.base.util.Appender;
+
+public interface InsertSource extends Appender<StringBuilder> {
+}

Added: ofbiz/trunk/framework/sql/src/org/ofbiz/sql/InsertValues.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/sql/src/org/ofbiz/sql/InsertValues.java?rev=880835&view=auto
==============================================================================
--- ofbiz/trunk/framework/sql/src/org/ofbiz/sql/InsertValues.java (added)
+++ ofbiz/trunk/framework/sql/src/org/ofbiz/sql/InsertValues.java Mon Nov 16 16:31:32 2009
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.ofbiz.sql;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.ofbiz.base.util.StringUtil;
+
+public class InsertValues implements InsertSource, Iterable<InsertRow> {
+    private final List<InsertRow> rows;
+
+    public InsertValues(List<InsertRow> rows) {
+        this.rows = rows;
+    }
+
+    public Iterator<InsertRow> iterator() {
+        return rows.iterator();
+    }
+
+    public StringBuilder appendTo(StringBuilder sb) {
+        sb.append("VALUES ");
+        StringUtil.appendTo(sb, rows, null, null, ", ");
+        return sb;
+    }
+}

Added: ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Joined.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Joined.java?rev=880835&view=auto
==============================================================================
--- ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Joined.java (added)
+++ ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Joined.java Mon Nov 16 16:31:32 2009
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.ofbiz.sql;
+
+import java.util.Iterator;
+import java.util.List;
+
+public final class Joined implements Iterable<KeyMap> {
+    private final boolean isOptional;
+    private final TableName tableName;
+    private final List<KeyMap> keyMaps;
+    private final Joined joined;
+
+    public Joined(boolean isOptional, TableName tableName, List<KeyMap> keyMaps) {
+        this(isOptional, tableName, keyMaps, null);
+    }
+
+    public Joined(boolean isOptional, TableName tableName, List<KeyMap> keyMaps, Joined joined) {
+        this.isOptional = isOptional;
+        this.tableName = tableName;
+        this.keyMaps = keyMaps;
+        this.joined = joined;
+    }
+
+    public boolean isOptional() {
+        return isOptional;
+    }
+
+    public TableName getTableName() {
+        return tableName;
+    }
+
+    public Iterator<KeyMap> iterator() {
+        return keyMaps.iterator();
+    }
+
+    public Joined getJoined() {
+        return joined;
+    }
+
+    public StringBuilder appendTo(String leftAlias, StringBuilder sb) {
+        sb.append(isOptional ? " LEFT JOIN " : " JOIN ");
+        return appendToRest(leftAlias, sb);
+    }
+
+    public StringBuilder appendToRest(String leftAlias, StringBuilder sb) {
+        tableName.appendTo(sb);
+        sb.append(" ON ");
+        for (int i = 0; i < keyMaps.size(); i++) {
+            if (i != 0) sb.append(" AND ");
+            keyMaps.get(i).appendTo(leftAlias, tableName.getAlias(), sb);
+        }
+        if (joined != null) {
+            joined.appendTo(tableName.getAlias(), sb);
+        }
+        return sb;
+    }
+}

Added: ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Joiner.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Joiner.java?rev=880835&view=auto
==============================================================================
--- ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Joiner.java (added)
+++ ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Joiner.java Mon Nov 16 16:31:32 2009
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.ofbiz.sql;
+
+public enum Joiner {
+    AND, OR
+}

Added: ofbiz/trunk/framework/sql/src/org/ofbiz/sql/KeyMap.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/sql/src/org/ofbiz/sql/KeyMap.java?rev=880835&view=auto
==============================================================================
--- ofbiz/trunk/framework/sql/src/org/ofbiz/sql/KeyMap.java (added)
+++ ofbiz/trunk/framework/sql/src/org/ofbiz/sql/KeyMap.java Mon Nov 16 16:31:32 2009
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.ofbiz.sql;
+
+public final class KeyMap {
+    private final String leftFieldName;
+    private final String rightFieldName;
+
+    public KeyMap(String leftFieldName, String rightFieldName) {
+        this.leftFieldName = leftFieldName;
+        this.rightFieldName = rightFieldName;
+    }
+
+    public String getLeftFieldName() {
+        return leftFieldName;
+    }
+
+    public String getRightFieldName() {
+        return rightFieldName;
+    }
+
+    public StringBuilder appendTo(String leftAlias, String rightAlias, StringBuilder sb) {
+        sb.append(leftAlias).append('.').append(leftFieldName);
+        sb.append(" = ");
+        sb.append(rightAlias).append('.').append(rightFieldName);
+        return sb;
+    }
+}

Added: ofbiz/trunk/framework/sql/src/org/ofbiz/sql/ListValue.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/sql/src/org/ofbiz/sql/ListValue.java?rev=880835&view=auto
==============================================================================
--- ofbiz/trunk/framework/sql/src/org/ofbiz/sql/ListValue.java (added)
+++ ofbiz/trunk/framework/sql/src/org/ofbiz/sql/ListValue.java Mon Nov 16 16:31:32 2009
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.ofbiz.sql;
+
+import java.util.List;
+
+import org.ofbiz.base.util.StringUtil;
+
+public final class ListValue extends Value {
+    private final List<Value> values;
+
+    public ListValue(List<Value> values) {
+        this.values = values;
+    }
+
+    public StringBuilder appendTo(StringBuilder sb) {
+        sb.append('(');
+        StringUtil.appendTo(sb, values, null, null, ", ");
+        sb.append(')');
+        return sb;
+    }
+}

Added: ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Main.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Main.java?rev=880835&view=auto
==============================================================================
--- ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Main.java (added)
+++ ofbiz/trunk/framework/sql/src/org/ofbiz/sql/Main.java Mon Nov 16 16:31:32 2009
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.ofbiz.sql;
+
+import java.util.List;
+
+public final class Main {
+ public static void main(String[] args) throws Exception {
+        Planner<?, ?, ?, ?, ?, ?> planner = new DebugPlanner();
+ List<SQLStatement<?, ?>> statements = new Parser(System.in).SQLFile();
+        for (SQLStatement<?, ?> statement: statements) {
+            run(statement, planner);
+        }
+ }
+
+    private static final void run(SQLStatement statement, Planner planner) {
+        System.err.println(statement);
+        SQLPlan plan = statement.plan(planner);
+        System.err.println("\tplan=" + plan);
+    }
+
+    private final static class DebugPlanner implements Planner {
+        public SQLPlan plan(SQLStatement statement) {
+            return null;
+        }
+
+        public DeletePlan plan(SQLDelete deleteStatement) {
+            return null;
+        }
+
+        public InsertPlan plan(SQLInsert insertStatement) {
+            return null;
+        }
+
+        public SelectPlan plan(SQLSelect selectStatement) {
+            return null;
+        }
+
+        public UpdatePlan plan(SQLUpdate updateStatement) {
+            return null;
+        }
+
+        public ViewPlan plan(SQLView viewStatement) {
+            return null;
+        }
+    }
+}

Added: ofbiz/trunk/framework/sql/src/org/ofbiz/sql/MathValue.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/sql/src/org/ofbiz/sql/MathValue.java?rev=880835&view=auto
==============================================================================
--- ofbiz/trunk/framework/sql/src/org/ofbiz/sql/MathValue.java (added)
+++ ofbiz/trunk/framework/sql/src/org/ofbiz/sql/MathValue.java Mon Nov 16 16:31:32 2009
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.ofbiz.sql;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.ofbiz.base.util.StringUtil;
+
+public final class MathValue extends StaticValue implements Iterable<StaticValue> {
+    private final String op;
+    private final List<StaticValue> values;
+
+    public MathValue(String op, List<StaticValue> values) {
+        this.op = op;
+        this.values = values;
+    }
+
+    public String getOp() {
+        return op;
+    }
+
+    public String getDefaultName() {
+        return null;
+    }
+
+    public Iterator<StaticValue> iterator() {
+        return values.iterator();
+    }
+
+    public StringBuilder appendTo(StringBuilder sb) {
+        sb.append('(');
+        StringUtil.appendTo(sb, values, " ", null, op);
+        sb.append(')');
+        return sb;
+    }
+}

Added: ofbiz/trunk/framework/sql/src/org/ofbiz/sql/NumberValue.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/sql/src/org/ofbiz/sql/NumberValue.java?rev=880835&view=auto
==============================================================================
--- ofbiz/trunk/framework/sql/src/org/ofbiz/sql/NumberValue.java (added)
+++ ofbiz/trunk/framework/sql/src/org/ofbiz/sql/NumberValue.java Mon Nov 16 16:31:32 2009
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.ofbiz.sql;
+
+public final class NumberValue<N extends Number> extends ConstantValue {
+    private final N number;
+
+    public NumberValue(N number) {
+        this.number = number;
+    }
+
+    public N getNumber() {
+        return number;
+    }
+
+    public StringBuilder appendTo(StringBuilder sb) {
+        sb.append(number);
+        return sb;
+    }
+}

Added: ofbiz/trunk/framework/sql/src/org/ofbiz/sql/ParameterValue.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/sql/src/org/ofbiz/sql/ParameterValue.java?rev=880835&view=auto
==============================================================================
--- ofbiz/trunk/framework/sql/src/org/ofbiz/sql/ParameterValue.java (added)
+++ ofbiz/trunk/framework/sql/src/org/ofbiz/sql/ParameterValue.java Mon Nov 16 16:31:32 2009
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.ofbiz.sql;
+
+public final class ParameterValue extends Value {
+    private final String name;
+
+    public ParameterValue(String name) {
+        this.name = name;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public StringBuilder appendTo(StringBuilder sb) {
+        sb.append('?').append(name);
+        return sb;
+    }
+}