From ee209c08f6cfdf46caeefd959ae02fa9c63409ee Mon Sep 17 00:00:00 2001 From: Jacopo Cappellato Date: Wed, 10 Dec 2014 16:24:48 +0000 Subject: [PATCH] Moved to the Attic the framework/sql component. The framework/sql was an attempt to create a specialized SQL parser for the OFBiz entity engine. The idea was to use a standardized SQL string that the parser would convert to entity conditions and Delegator calls. So, you could use the same SQL string on any database. The component was never finished. git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@1644469 13f79535-47bb-0310-9956-ffa450edef68 --- build.xml | 4 +- framework/build.xml | 4 +- framework/component-load.xml | 1 - framework/entity/build.xml | 1 - .../entity/sql/EntityConditionPlanner.java | 90 ------- .../ofbiz/entity/sql/EntityDeletePlan.java | 29 --- .../ofbiz/entity/sql/EntityInsertPlan.java | 24 -- .../org/ofbiz/entity/sql/EntityPlanner.java | 240 ------------------ .../ofbiz/entity/sql/EntitySelectPlan.java | 121 --------- .../ofbiz/entity/sql/EntityUpdatePlan.java | 29 --- .../org/ofbiz/entity/sql/EntityViewPlan.java | 24 -- framework/sql/build.xml | 74 ------ framework/sql/ofbiz-component.xml | 27 -- .../src/org/ofbiz/sql/AggregateFunction.java | 78 ------ framework/sql/src/org/ofbiz/sql/Atom.java | 45 ---- .../src/org/ofbiz/sql/BetweenCondition.java | 70 ----- .../src/org/ofbiz/sql/BooleanCondition.java | 68 ----- .../sql/src/org/ofbiz/sql/Condition.java | 44 ---- .../sql/src/org/ofbiz/sql/ConditionList.java | 70 ----- .../sql/src/org/ofbiz/sql/ConditionPlan.java | 52 ---- .../src/org/ofbiz/sql/ConditionPlanner.java | 25 -- .../sql/src/org/ofbiz/sql/ConstantValue.java | 22 -- .../src/org/ofbiz/sql/CountAllFunction.java | 63 ----- .../sql/src/org/ofbiz/sql/DeletePlan.java | 31 --- framework/sql/src/org/ofbiz/sql/FieldAll.java | 64 ----- framework/sql/src/org/ofbiz/sql/FieldDef.java | 62 ----- .../sql/src/org/ofbiz/sql/FieldValue.java | 72 ------ .../sql/src/org/ofbiz/sql/FunctionCall.java | 75 ------ .../sql/src/org/ofbiz/sql/InsertPlan.java | 22 -- .../sql/src/org/ofbiz/sql/InsertRow.java | 53 ---- .../sql/src/org/ofbiz/sql/InsertSource.java | 24 -- .../sql/src/org/ofbiz/sql/InsertValues.java | 52 ---- framework/sql/src/org/ofbiz/sql/Joined.java | 90 ------- framework/sql/src/org/ofbiz/sql/Joiner.java | 23 -- framework/sql/src/org/ofbiz/sql/KeyMap.java | 47 ---- .../sql/src/org/ofbiz/sql/ListCondition.java | 71 ------ .../sql/src/org/ofbiz/sql/MathValue.java | 71 ------ .../sql/src/org/ofbiz/sql/NumberValue.java | 62 ----- .../sql/src/org/ofbiz/sql/OrderByItem.java | 80 ------ .../sql/src/org/ofbiz/sql/ParameterValue.java | 54 ---- .../sql/ParameterizedConditionException.java | 40 --- framework/sql/src/org/ofbiz/sql/Planner.java | 54 ---- framework/sql/src/org/ofbiz/sql/Relation.java | 87 ------- .../sql/src/org/ofbiz/sql/SQLDelete.java | 67 ----- framework/sql/src/org/ofbiz/sql/SQLIndex.java | 93 ------- .../sql/src/org/ofbiz/sql/SQLInsert.java | 77 ------ framework/sql/src/org/ofbiz/sql/SQLPlan.java | 25 -- .../sql/src/org/ofbiz/sql/SQLSelect.java | 113 --------- .../sql/src/org/ofbiz/sql/SQLStatement.java | 52 ---- .../sql/src/org/ofbiz/sql/SQLUpdate.java | 106 -------- framework/sql/src/org/ofbiz/sql/SQLView.java | 58 ----- .../sql/src/org/ofbiz/sql/SelectGroup.java | 121 --------- .../sql/src/org/ofbiz/sql/SelectPlan.java | 37 --- framework/sql/src/org/ofbiz/sql/SetField.java | 53 ---- .../sql/src/org/ofbiz/sql/StaticValue.java | 23 -- .../sql/src/org/ofbiz/sql/StringValue.java | 54 ---- framework/sql/src/org/ofbiz/sql/Table.java | 59 ----- .../sql/src/org/ofbiz/sql/TableName.java | 55 ---- framework/sql/src/org/ofbiz/sql/Unioned.java | 64 ----- .../sql/src/org/ofbiz/sql/UpdatePlan.java | 31 --- framework/sql/src/org/ofbiz/sql/Value.java | 79 ------ framework/sql/src/org/ofbiz/sql/ViewPlan.java | 22 -- .../org/ofbiz/sql/test/ConditionsTest.java | 162 ------------ .../src/org/ofbiz/sql/test/GoodParseAll.sql | 74 ------ .../sql/src/org/ofbiz/sql/test/Recorder.java | 36 --- .../src/org/ofbiz/sql/test/SelectTest.java | 116 --------- .../sql/src/org/ofbiz/sql/test/TestSelect.sql | 44 ---- .../src/org/ofbiz/sql/test/ValuesTest.java | 239 ----------------- 68 files changed, 4 insertions(+), 4195 deletions(-) delete mode 100644 framework/entity/src/org/ofbiz/entity/sql/EntityConditionPlanner.java delete mode 100644 framework/entity/src/org/ofbiz/entity/sql/EntityDeletePlan.java delete mode 100644 framework/entity/src/org/ofbiz/entity/sql/EntityInsertPlan.java delete mode 100644 framework/entity/src/org/ofbiz/entity/sql/EntityPlanner.java delete mode 100644 framework/entity/src/org/ofbiz/entity/sql/EntitySelectPlan.java delete mode 100644 framework/entity/src/org/ofbiz/entity/sql/EntityUpdatePlan.java delete mode 100644 framework/entity/src/org/ofbiz/entity/sql/EntityViewPlan.java delete mode 100644 framework/sql/build.xml delete mode 100644 framework/sql/ofbiz-component.xml delete mode 100644 framework/sql/src/org/ofbiz/sql/AggregateFunction.java delete mode 100644 framework/sql/src/org/ofbiz/sql/Atom.java delete mode 100644 framework/sql/src/org/ofbiz/sql/BetweenCondition.java delete mode 100644 framework/sql/src/org/ofbiz/sql/BooleanCondition.java delete mode 100644 framework/sql/src/org/ofbiz/sql/Condition.java delete mode 100644 framework/sql/src/org/ofbiz/sql/ConditionList.java delete mode 100644 framework/sql/src/org/ofbiz/sql/ConditionPlan.java delete mode 100644 framework/sql/src/org/ofbiz/sql/ConditionPlanner.java delete mode 100644 framework/sql/src/org/ofbiz/sql/ConstantValue.java delete mode 100644 framework/sql/src/org/ofbiz/sql/CountAllFunction.java delete mode 100644 framework/sql/src/org/ofbiz/sql/DeletePlan.java delete mode 100644 framework/sql/src/org/ofbiz/sql/FieldAll.java delete mode 100644 framework/sql/src/org/ofbiz/sql/FieldDef.java delete mode 100644 framework/sql/src/org/ofbiz/sql/FieldValue.java delete mode 100644 framework/sql/src/org/ofbiz/sql/FunctionCall.java delete mode 100644 framework/sql/src/org/ofbiz/sql/InsertPlan.java delete mode 100644 framework/sql/src/org/ofbiz/sql/InsertRow.java delete mode 100644 framework/sql/src/org/ofbiz/sql/InsertSource.java delete mode 100644 framework/sql/src/org/ofbiz/sql/InsertValues.java delete mode 100644 framework/sql/src/org/ofbiz/sql/Joined.java delete mode 100644 framework/sql/src/org/ofbiz/sql/Joiner.java delete mode 100644 framework/sql/src/org/ofbiz/sql/KeyMap.java delete mode 100644 framework/sql/src/org/ofbiz/sql/ListCondition.java delete mode 100644 framework/sql/src/org/ofbiz/sql/MathValue.java delete mode 100644 framework/sql/src/org/ofbiz/sql/NumberValue.java delete mode 100644 framework/sql/src/org/ofbiz/sql/OrderByItem.java delete mode 100644 framework/sql/src/org/ofbiz/sql/ParameterValue.java delete mode 100644 framework/sql/src/org/ofbiz/sql/ParameterizedConditionException.java delete mode 100644 framework/sql/src/org/ofbiz/sql/Planner.java delete mode 100644 framework/sql/src/org/ofbiz/sql/Relation.java delete mode 100644 framework/sql/src/org/ofbiz/sql/SQLDelete.java delete mode 100644 framework/sql/src/org/ofbiz/sql/SQLIndex.java delete mode 100644 framework/sql/src/org/ofbiz/sql/SQLInsert.java delete mode 100644 framework/sql/src/org/ofbiz/sql/SQLPlan.java delete mode 100644 framework/sql/src/org/ofbiz/sql/SQLSelect.java delete mode 100644 framework/sql/src/org/ofbiz/sql/SQLStatement.java delete mode 100644 framework/sql/src/org/ofbiz/sql/SQLUpdate.java delete mode 100644 framework/sql/src/org/ofbiz/sql/SQLView.java delete mode 100644 framework/sql/src/org/ofbiz/sql/SelectGroup.java delete mode 100644 framework/sql/src/org/ofbiz/sql/SelectPlan.java delete mode 100644 framework/sql/src/org/ofbiz/sql/SetField.java delete mode 100644 framework/sql/src/org/ofbiz/sql/StaticValue.java delete mode 100644 framework/sql/src/org/ofbiz/sql/StringValue.java delete mode 100644 framework/sql/src/org/ofbiz/sql/Table.java delete mode 100644 framework/sql/src/org/ofbiz/sql/TableName.java delete mode 100644 framework/sql/src/org/ofbiz/sql/Unioned.java delete mode 100644 framework/sql/src/org/ofbiz/sql/UpdatePlan.java delete mode 100644 framework/sql/src/org/ofbiz/sql/Value.java delete mode 100644 framework/sql/src/org/ofbiz/sql/ViewPlan.java delete mode 100644 framework/sql/src/org/ofbiz/sql/test/ConditionsTest.java delete mode 100644 framework/sql/src/org/ofbiz/sql/test/GoodParseAll.sql delete mode 100644 framework/sql/src/org/ofbiz/sql/test/Recorder.java delete mode 100644 framework/sql/src/org/ofbiz/sql/test/SelectTest.java delete mode 100644 framework/sql/src/org/ofbiz/sql/test/TestSelect.sql delete mode 100644 framework/sql/src/org/ofbiz/sql/test/ValuesTest.java diff --git a/build.xml b/build.xml index 82ec6136f9..afa636173b 100644 --- a/build.xml +++ b/build.xml @@ -1312,7 +1312,7 @@ under the License. diff --git a/framework/build.xml b/framework/build.xml index d91cec8d2c..4568603669 100644 --- a/framework/build.xml +++ b/framework/build.xml @@ -20,7 +20,7 @@ under the License. - + diff --git a/framework/component-load.xml b/framework/component-load.xml index 95f167d36d..4009ec1af5 100644 --- a/framework/component-load.xml +++ b/framework/component-load.xml @@ -22,7 +22,6 @@ under the License. xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/component-loader.xsd"> - diff --git a/framework/entity/build.xml b/framework/entity/build.xml index 8fce494a8f..1ef70694f7 100644 --- a/framework/entity/build.xml +++ b/framework/entity/build.xml @@ -37,7 +37,6 @@ under the License. - diff --git a/framework/entity/src/org/ofbiz/entity/sql/EntityConditionPlanner.java b/framework/entity/src/org/ofbiz/entity/sql/EntityConditionPlanner.java deleted file mode 100644 index 8dd607d3a1..0000000000 --- a/framework/entity/src/org/ofbiz/entity/sql/EntityConditionPlanner.java +++ /dev/null @@ -1,90 +0,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. - */ -package org.ofbiz.entity.sql; - -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -import org.ofbiz.entity.condition.EntityCondition; -import org.ofbiz.entity.condition.EntityFieldValue; -import org.ofbiz.entity.condition.EntityOperator; -import org.ofbiz.sql.BooleanCondition; -import org.ofbiz.sql.Condition; -import org.ofbiz.sql.ConditionList; -import org.ofbiz.sql.ConditionPlanner; -import org.ofbiz.sql.FieldValue; -import org.ofbiz.sql.Joiner; -import org.ofbiz.sql.NumberValue; -import org.ofbiz.sql.ParameterValue; -import org.ofbiz.sql.ParameterizedConditionException; -import org.ofbiz.sql.StringValue; -import org.ofbiz.sql.Value; - -public class EntityConditionPlanner implements ConditionPlanner { - public EntityCondition parse(Condition condition, Map params) throws ParameterizedConditionException { - 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(), params)); - } else if (condition instanceof ConditionList) { - ConditionList cl = (ConditionList) condition; - List conditions = new LinkedList(); - for (Condition subCondition: cl) { - conditions.add(parse(subCondition, params)); - } - 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, Map params) throws ParameterizedConditionException { - if (value instanceof NumberValue) { - return ((NumberValue) value).getNumber(); - } else if (value instanceof StringValue) { - return ((StringValue) value).getString(); - } else if (value instanceof FieldValue) { - FieldValue fv = (FieldValue) value; - return EntityFieldValue.makeFieldValue(fv.getFieldName(), fv.getTableName(), null, null); - } else if (value instanceof List) { - List values = new LinkedList(); - for (Object sqlValue: (List) value) { - values.add(buildValue(sqlValue, params)); - } - return values; - } else if (value == Value.NULL) { - return null; - } else if (value instanceof ParameterValue) { - if (params == null) { - throw new ParameterizedConditionException(); - } - return params.get(((ParameterValue) value).getName()); - } - throw new UnsupportedOperationException(value.getClass().getName() + ":" + value.toString()); - } -} diff --git a/framework/entity/src/org/ofbiz/entity/sql/EntityDeletePlan.java b/framework/entity/src/org/ofbiz/entity/sql/EntityDeletePlan.java deleted file mode 100644 index 1dbe389efc..0000000000 --- a/framework/entity/src/org/ofbiz/entity/sql/EntityDeletePlan.java +++ /dev/null @@ -1,29 +0,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. - */ -package org.ofbiz.entity.sql; - -import org.ofbiz.entity.condition.EntityCondition; -import org.ofbiz.sql.ConditionPlan; -import org.ofbiz.sql.DeletePlan; - -public class EntityDeletePlan extends DeletePlan { - public EntityDeletePlan(ConditionPlan wherePlan) { - super(wherePlan); - } -} diff --git a/framework/entity/src/org/ofbiz/entity/sql/EntityInsertPlan.java b/framework/entity/src/org/ofbiz/entity/sql/EntityInsertPlan.java deleted file mode 100644 index 431acd3221..0000000000 --- a/framework/entity/src/org/ofbiz/entity/sql/EntityInsertPlan.java +++ /dev/null @@ -1,24 +0,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. - */ -package org.ofbiz.entity.sql; - -import org.ofbiz.sql.InsertPlan; - -public class EntityInsertPlan extends InsertPlan { -} diff --git a/framework/entity/src/org/ofbiz/entity/sql/EntityPlanner.java b/framework/entity/src/org/ofbiz/entity/sql/EntityPlanner.java deleted file mode 100644 index 2832e9189f..0000000000 --- a/framework/entity/src/org/ofbiz/entity/sql/EntityPlanner.java +++ /dev/null @@ -1,240 +0,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. - */ -package org.ofbiz.entity.sql; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - -import org.ofbiz.entity.condition.EntityCondition; -import org.ofbiz.entity.model.DynamicViewEntity; -import org.ofbiz.entity.model.ModelKeyMap; -import org.ofbiz.entity.model.ModelViewEntity.ComplexAlias; -import org.ofbiz.entity.model.ModelViewEntity.ComplexAliasField; -import org.ofbiz.entity.model.ModelViewEntity.ComplexAliasMember; -import org.ofbiz.sql.ConstantValue; -import org.ofbiz.sql.FieldAll; -import org.ofbiz.sql.FieldDef; -import org.ofbiz.sql.FieldValue; -import org.ofbiz.sql.FunctionCall; -import org.ofbiz.sql.Joined; -import org.ofbiz.sql.KeyMap; -import org.ofbiz.sql.MathValue; -import org.ofbiz.sql.NumberValue; -import org.ofbiz.sql.OrderByItem; -import org.ofbiz.sql.Planner; -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.SelectGroup; -import org.ofbiz.sql.StaticValue; -import org.ofbiz.sql.StringValue; -import org.ofbiz.sql.Table; -import org.ofbiz.sql.TableName; -import org.ofbiz.sql.Unioned; -import org.ofbiz.sql.Value; - -public class EntityPlanner extends Planner { - public EntityPlanner() { - super(new EntityConditionPlanner()); - } - - @Override - public EntityDeletePlan planDelete(SQLDelete deleteStatement) { - return null; - } - - @Override - public EntityInsertPlan planInsert(SQLInsert insertStatement) { - return null; - } - - @Override - public EntitySelectPlan planSelect(SQLSelect selectStatement) { - DynamicViewEntity dve = new DynamicViewEntity(); - Unioned unioned = selectStatement.getUnioned(); - if (unioned != null) { - throw new IllegalArgumentException("union views not yet supported"); - } - SelectGroup selectGroup = unioned.getGroup(); - Table table = selectGroup.getTable(); - addMember(dve, table.getTableName()); - addJoined(dve, table.getTableName().getAlias(), table.getJoined()); - if (selectGroup.getFieldAlls() != null) { - for (FieldAll fieldAll: selectGroup.getFieldAlls()) { - List excludes = new LinkedList(); - for (String exclude: fieldAll) { - excludes.add(exclude); - } - if (excludes.isEmpty()) { - excludes = null; - } - dve.addAliasAll(fieldAll.getAlias(), null, excludes); - } - } - if (selectStatement.getRelations() != null) { - for (Relation relation: selectStatement.getRelations().values()) { - dve.addRelation(relation.getType(), relation.getTitle(), relation.getEntityName(), buildKeyMaps(relation)); - } - } - List groupBy = selectGroup.getGroupBy(); - if (groupBy == null) { - groupBy = Collections.emptyList(); - } - if (selectGroup.getFieldDefs() != null) { - for (FieldDef fieldDef: selectGroup.getFieldDefs()) { - addFieldDef(dve, groupBy, fieldDef.getAlias(), fieldDef); - } - } - List orderBy; - if (selectStatement.getOrderBy() == null) { - orderBy = null; - } else { - orderBy = new LinkedList(); - for (OrderByItem orderByItem: selectStatement.getOrderBy()) { - orderBy.add(orderByItem.toString()); - } - } - return new EntitySelectPlan(dve, plan(selectGroup.getWhereCondition()), plan(selectGroup.getHavingCondition()), orderBy); - } - - @Override - public EntityUpdatePlan planUpdate(SQLUpdate updateStatement) { - return null; - } - - @Override - public EntityViewPlan planView(SQLView viewStatement) { - return null; - } - - private static void addFieldDef(DynamicViewEntity dve, List groupBy, String alias, FieldDef fieldDef) { - StaticValue value = fieldDef.getValue(); - if (value instanceof FieldValue) { - addFieldDef(dve, groupBy, fieldDef.getAlias(), (FieldValue) value, null); - } else if (value instanceof ConstantValue) { - addFieldDef(dve, groupBy, fieldDef.getAlias(), value); - } else { - throw new UnsupportedOperationException(alias + "[" + fieldDef + "]:" + fieldDef.getClass()); - } - } - - private static void addFieldDef(DynamicViewEntity dve, List 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 groupBy, String alias, ComplexAliasMember member) { - dve.addAlias(null, alias, null, null, null, groupBy.contains(alias), null, member); - } - - private static void addFieldDef(DynamicViewEntity dve, List groupBy, String alias, ConstantValue value) { - 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 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 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 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; - ComplexAlias complexAlias = new ComplexAlias(mv.getOp()); - for (ConstantValue constantValue: mv) { - complexAlias.addComplexAliasMember(buildComplexMember(constantValue)); - } - 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 buildKeyMaps(Iterable keyMaps) { - List entityKeyMaps = new ArrayList(); - for (KeyMap keyMap: keyMaps) { - entityKeyMaps.add(new ModelKeyMap(keyMap.getLeftFieldName(), keyMap.getRightFieldName())); - } - return entityKeyMaps; - } -} diff --git a/framework/entity/src/org/ofbiz/entity/sql/EntitySelectPlan.java b/framework/entity/src/org/ofbiz/entity/sql/EntitySelectPlan.java deleted file mode 100644 index 6bd6d7c25a..0000000000 --- a/framework/entity/src/org/ofbiz/entity/sql/EntitySelectPlan.java +++ /dev/null @@ -1,121 +0,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. - */ -package org.ofbiz.entity.sql; - -import java.util.List; -import java.util.Map; -import java.util.concurrent.Callable; - -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.transaction.TransactionUtil; -import org.ofbiz.entity.util.EntityListIterator; -import org.ofbiz.sql.ConditionPlan; -import org.ofbiz.sql.ParameterizedConditionException; -import org.ofbiz.sql.SelectPlan; - -public final class EntitySelectPlan extends SelectPlan { - private final DynamicViewEntity dve; - private final List orderBy; - private final int offset = -1; - private final int limit = -1; - - public EntitySelectPlan(DynamicViewEntity dve, ConditionPlan wherePlan, ConditionPlan havingPlan, List orderBy) { - super(wherePlan, havingPlan); - this.dve = dve; - this.orderBy = orderBy; - //this.offset = offset; - //this.limit = limit; - } - - public EntityListIterator getEntityListIterator(Delegator delegator, Map params) throws GenericEntityException { - EntityCondition whereCondition; - EntityCondition havingCondition; - try { - whereCondition = getWherePlan().getCondition(params); - havingCondition = getHavingPlan().getCondition(params); - } catch (ParameterizedConditionException e) { - throw (GenericEntityException) new GenericEntityException(e.getMessage()).initCause(e); - } - return delegator.findListIteratorByCondition(dve, whereCondition, havingCondition, null, orderBy, null); - } - - public List getAll(final Delegator delegator, final Map params) throws GenericEntityException { - return TransactionUtil.doTransaction(new Callable>() { - public List call() throws Exception { - EntityListIterator it = null; - try { - it = getEntityListIterator(delegator, params); - return it.getCompleteList(); - } finally { - if (it != null) it.close(); - } - } - }, "sql select", 0, true); - } - - public DynamicViewEntity getDynamicViewEntity() { - return dve; - } - - public List getOrderBy() { - return orderBy; - } - - public int getOffset() { - return offset; - } - - public int getLimit() { - return limit; - } - - @Override - public StringBuilder appendTo(StringBuilder sb) { - sb.append("dve=").append(dve); - if (getWherePlan() != null) { - if (sb.length() > 0) sb.append(", "); - sb.append("where=("); - getWherePlan().appendTo(sb); - sb.append(")"); - } - if (getHavingPlan() != null) { - if (sb.length() > 0) sb.append(", "); - sb.append("having=("); - getHavingPlan().appendTo(sb); - sb.append(")"); - } - /*TODO death code can be removed ? - 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, "["); - return sb; - } -} diff --git a/framework/entity/src/org/ofbiz/entity/sql/EntityUpdatePlan.java b/framework/entity/src/org/ofbiz/entity/sql/EntityUpdatePlan.java deleted file mode 100644 index 45e8ffbfa5..0000000000 --- a/framework/entity/src/org/ofbiz/entity/sql/EntityUpdatePlan.java +++ /dev/null @@ -1,29 +0,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. - */ -package org.ofbiz.entity.sql; - -import org.ofbiz.entity.condition.EntityCondition; -import org.ofbiz.sql.ConditionPlan; -import org.ofbiz.sql.UpdatePlan; - -public class EntityUpdatePlan extends UpdatePlan { - public EntityUpdatePlan(ConditionPlan wherePlan) { - super(wherePlan); - } -} diff --git a/framework/entity/src/org/ofbiz/entity/sql/EntityViewPlan.java b/framework/entity/src/org/ofbiz/entity/sql/EntityViewPlan.java deleted file mode 100644 index 57ded02763..0000000000 --- a/framework/entity/src/org/ofbiz/entity/sql/EntityViewPlan.java +++ /dev/null @@ -1,24 +0,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. - */ -package org.ofbiz.entity.sql; - -import org.ofbiz.sql.ViewPlan; - -public final class EntityViewPlan extends ViewPlan { -} diff --git a/framework/sql/build.xml b/framework/sql/build.xml deleted file mode 100644 index baa8300f79..0000000000 --- a/framework/sql/build.xml +++ /dev/null @@ -1,74 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/framework/sql/ofbiz-component.xml b/framework/sql/ofbiz-component.xml deleted file mode 100644 index 5b828f5b91..0000000000 --- a/framework/sql/ofbiz-component.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - diff --git a/framework/sql/src/org/ofbiz/sql/AggregateFunction.java b/framework/sql/src/org/ofbiz/sql/AggregateFunction.java deleted file mode 100644 index d9c0efc386..0000000000 --- a/framework/sql/src/org/ofbiz/sql/AggregateFunction.java +++ /dev/null @@ -1,78 +0,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. - */ -package org.ofbiz.sql; - -import org.ofbiz.base.lang.SourceMonitored; - -@SourceMonitored -public final class AggregateFunction extends StaticValue { - public static final String module = AggregateFunction.class.getName(); - - private final String name; - private final boolean isDistinct; - private final StaticValue value; - - public AggregateFunction(String name, boolean isDistinct, StaticValue value) { - this.name = name; - this.isDistinct = isDistinct; - this.value = value; - } - - @Override - public void accept(Visitor visitor) { - visitor.visit(this); - } - - public String getName() { - return name; - } - - public boolean isDistinct() { - return isDistinct; - } - - @Override - public String getDefaultName() { - return name; - } - - public StaticValue getValue() { - return value; - } - - @Override - public boolean equals(Object o) { - if (o instanceof AggregateFunction) { - AggregateFunction other = (AggregateFunction) o; - return name.equals(other.name) && isDistinct == other.isDistinct && value.equals(other.value); - } else { - return false; - } - } - - public StringBuilder appendTo(StringBuilder sb) { - sb.append(name).append('('); - if (isDistinct) { - sb.append("DISTINCT "); - } - value.appendTo(sb); - sb.append(')'); - return sb; - } -} diff --git a/framework/sql/src/org/ofbiz/sql/Atom.java b/framework/sql/src/org/ofbiz/sql/Atom.java deleted file mode 100644 index 9c31561c05..0000000000 --- a/framework/sql/src/org/ofbiz/sql/Atom.java +++ /dev/null @@ -1,45 +0,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. - */ -package org.ofbiz.sql; - -import java.util.Collection; -import java.util.Map; - -import org.ofbiz.base.lang.Appender; -import org.ofbiz.base.util.UtilObject; -import org.ofbiz.base.util.UtilValidate; - -public abstract class Atom implements Appender { - public static boolean equalsHelper(Object l, Object r) { - return UtilObject.equalsHelper(l, r); - } - - public static , I> T checkEmpty(T col) { - return UtilValidate.isEmpty(col) ? null : col; - } - - public static , K, V> T checkEmpty(T map) { - return UtilValidate.isEmpty(map) ? null : map; - } - - @Override - public String toString() { - return appendTo(new StringBuilder()).toString(); - } -} diff --git a/framework/sql/src/org/ofbiz/sql/BetweenCondition.java b/framework/sql/src/org/ofbiz/sql/BetweenCondition.java deleted file mode 100644 index 3eb1dfc725..0000000000 --- a/framework/sql/src/org/ofbiz/sql/BetweenCondition.java +++ /dev/null @@ -1,70 +0,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. - */ -package org.ofbiz.sql; - -import org.ofbiz.base.lang.SourceMonitored; - -@SourceMonitored -public final class BetweenCondition extends Condition { - private final Value left; - private final Value r1; - private final Value r2; - - public BetweenCondition(Value left, Value r1, Value r2) { - this.left = left; - this.r1 = r1; - this.r2 = r2; - } - - @Override - public void accept(Visitor visitor) { - visitor.visit(this); - } - - public Value getLeft() { - return left; - } - - public Value getR1() { - return r1; - } - - public Value getR2() { - return r2; - } - - @Override - public boolean equals(Object o) { - if (o instanceof BetweenCondition) { - BetweenCondition other = (BetweenCondition) o; - return left.equals(other.left) && r1.equals(other.r1) && r2.equals(other.r2); - } else { - return false; - } - } - - public StringBuilder appendTo(StringBuilder sb) { - left.appendTo(sb); - sb.append(" BETWEEN "); - r1.appendTo(sb); - sb.append(" AND "); - r2.appendTo(sb); - return sb; - } -} diff --git a/framework/sql/src/org/ofbiz/sql/BooleanCondition.java b/framework/sql/src/org/ofbiz/sql/BooleanCondition.java deleted file mode 100644 index 4bf01f2aa3..0000000000 --- a/framework/sql/src/org/ofbiz/sql/BooleanCondition.java +++ /dev/null @@ -1,68 +0,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. - */ -package org.ofbiz.sql; - -import org.ofbiz.base.lang.SourceMonitored; - -@SourceMonitored -public final class BooleanCondition extends 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.toLowerCase(); - this.right = right; - } - - @Override - public void accept(Visitor visitor) { - visitor.visit(this); - } - - public Value getLeft() { - return left; - } - - public String getOp() { - return op; - } - - public Value getRight() { - return right; - } - - @Override - public boolean equals(Object o) { - if (o instanceof BooleanCondition) { - BooleanCondition other = (BooleanCondition) o; - return left.equals(other.left) & op.equals(other.op) && right.equals(other.right); - } else { - return false; - } - } - - public StringBuilder appendTo(StringBuilder sb) { - left.appendTo(sb); - sb.append(' ').append(op).append(' '); - right.appendTo(sb); - return sb; - } -} diff --git a/framework/sql/src/org/ofbiz/sql/Condition.java b/framework/sql/src/org/ofbiz/sql/Condition.java deleted file mode 100644 index e76e2042d7..0000000000 --- a/framework/sql/src/org/ofbiz/sql/Condition.java +++ /dev/null @@ -1,44 +0,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. - */ -package org.ofbiz.sql; - -public abstract class Condition extends Atom { - public interface Visitor { - void visit(BetweenCondition condition); - void visit(BooleanCondition condition); - void visit(ConditionList condition); - void visit(ListCondition condition); - } - - public static class BaseVisitor implements Visitor { - public void visit(BetweenCondition condition) { - } - - public void visit(BooleanCondition condition) { - } - - public void visit(ConditionList condition) { - } - - public void visit(ListCondition condition) { - } - } - - public abstract void accept(Visitor visitor); -} diff --git a/framework/sql/src/org/ofbiz/sql/ConditionList.java b/framework/sql/src/org/ofbiz/sql/ConditionList.java deleted file mode 100644 index 5ec0c56d28..0000000000 --- a/framework/sql/src/org/ofbiz/sql/ConditionList.java +++ /dev/null @@ -1,70 +0,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. - */ -package org.ofbiz.sql; - -import java.util.Iterator; -import java.util.List; - -import org.ofbiz.base.lang.SourceMonitored; -import org.ofbiz.base.util.StringUtil; - -@SourceMonitored -public final class ConditionList extends Condition implements Iterable { - private final Joiner joiner; - private final List conditions; - - public ConditionList(Joiner joiner, List conditions) { - this.joiner = joiner; - this.conditions = conditions; - } - - @Override - public void accept(Visitor visitor) { - visitor.visit(this); - } - - public void add(Condition condition) { - conditions.add(condition); - } - - public Joiner getJoiner() { - return joiner; - } - - public Iterator iterator() { - return conditions.iterator(); - } - - @Override - public boolean equals(Object o) { - if (o instanceof ConditionList) { - ConditionList other = (ConditionList) o; - return joiner.equals(other.joiner) && conditions.equals(other.conditions); - } else { - return false; - } - } - - public StringBuilder appendTo(StringBuilder sb) { - sb.append('('); - StringUtil.appendTo(sb, conditions, " ", " ", joiner.toString()); - sb.append(')'); - return sb; - } -} diff --git a/framework/sql/src/org/ofbiz/sql/ConditionPlan.java b/framework/sql/src/org/ofbiz/sql/ConditionPlan.java deleted file mode 100644 index e8310e1920..0000000000 --- a/framework/sql/src/org/ofbiz/sql/ConditionPlan.java +++ /dev/null @@ -1,52 +0,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. - */ -package org.ofbiz.sql; - -import java.util.Map; - -public final class ConditionPlan extends SQLPlan> { - private final ConditionPlanner planner; - private final Condition originalCondition; - private final C condition; - - public ConditionPlan(ConditionPlanner planner, Condition originalCondition, C condition) { - this.planner = planner; - this.originalCondition = originalCondition; - this.condition = condition; - } - - public C getCondition(Map params) throws ParameterizedConditionException { - if (originalCondition != null) { - return planner.parse(originalCondition, params); - } else { - return condition; - } - } - - @Override - public StringBuilder appendTo(StringBuilder sb) { - sb.append("ConditionPlan["); - if (originalCondition != null) { - sb.append("original=" + originalCondition); - } else { - sb.append("condition=" + condition); - } - return sb.append("]"); - } -} diff --git a/framework/sql/src/org/ofbiz/sql/ConditionPlanner.java b/framework/sql/src/org/ofbiz/sql/ConditionPlanner.java deleted file mode 100644 index 8cca39e19c..0000000000 --- a/framework/sql/src/org/ofbiz/sql/ConditionPlanner.java +++ /dev/null @@ -1,25 +0,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. - */ -package org.ofbiz.sql; - -import java.util.Map; - -public interface ConditionPlanner { - C parse(Condition originalCondition, Map params) throws ParameterizedConditionException; -} diff --git a/framework/sql/src/org/ofbiz/sql/ConstantValue.java b/framework/sql/src/org/ofbiz/sql/ConstantValue.java deleted file mode 100644 index 2fdbd253ff..0000000000 --- a/framework/sql/src/org/ofbiz/sql/ConstantValue.java +++ /dev/null @@ -1,22 +0,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. - */ -package org.ofbiz.sql; - -public abstract class ConstantValue extends Value { -} diff --git a/framework/sql/src/org/ofbiz/sql/CountAllFunction.java b/framework/sql/src/org/ofbiz/sql/CountAllFunction.java deleted file mode 100644 index 527ef40c54..0000000000 --- a/framework/sql/src/org/ofbiz/sql/CountAllFunction.java +++ /dev/null @@ -1,63 +0,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. - */ -package org.ofbiz.sql; - -import org.ofbiz.base.lang.SourceMonitored; - -@SourceMonitored -public final class CountAllFunction extends StaticValue { - private final String tableName; - - public CountAllFunction(String tableName) { - this.tableName = tableName; - } - - @Override - public void accept(Visitor visitor) { - visitor.visit(this); - } - - @Override - public String getDefaultName() { - return "COUNT"; - } - - public String getTableName() { - return tableName; - } - - @Override - public boolean equals(Object o) { - if (o instanceof CountAllFunction) { - CountAllFunction other = (CountAllFunction) o; - return equalsHelper(tableName, other.tableName); - } else { - return false; - } - } - - public StringBuilder appendTo(StringBuilder sb) { - sb.append("COUNT("); - if (tableName != null) { - sb.append(tableName).append('.'); - } - sb.append("*)"); - return sb; - } -} diff --git a/framework/sql/src/org/ofbiz/sql/DeletePlan.java b/framework/sql/src/org/ofbiz/sql/DeletePlan.java deleted file mode 100644 index 51e90e0c9b..0000000000 --- a/framework/sql/src/org/ofbiz/sql/DeletePlan.java +++ /dev/null @@ -1,31 +0,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. - */ -package org.ofbiz.sql; - -public abstract class DeletePlan

, C> extends SQLPlan

{ - private final ConditionPlan wherePlan; - - protected DeletePlan(ConditionPlan wherePlan) { - this.wherePlan = wherePlan; - } - - public ConditionPlan getWherePlan() { - return wherePlan; - } -} diff --git a/framework/sql/src/org/ofbiz/sql/FieldAll.java b/framework/sql/src/org/ofbiz/sql/FieldAll.java deleted file mode 100644 index f0a366fcf5..0000000000 --- a/framework/sql/src/org/ofbiz/sql/FieldAll.java +++ /dev/null @@ -1,64 +0,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. - */ -package org.ofbiz.sql; - -import java.util.Iterator; -import java.util.Set; - -import org.ofbiz.base.lang.SourceMonitored; -import org.ofbiz.base.util.StringUtil; - -@SourceMonitored -public final class FieldAll extends Atom implements Iterable { - private final String alias; - private final Set exclude; - - public FieldAll(String alias, Set exclude) { - this.alias = alias; - this.exclude = exclude; - } - - public String getAlias() { - return alias; - } - - public Iterator iterator() { - return exclude.iterator(); - } - - @Override - public boolean equals(Object o) { - if (o instanceof FieldAll) { - FieldAll other = (FieldAll) o; - return alias.equals(other.alias) && exclude.equals(other.exclude); - } else { - return false; - } - } - - 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; - } -} diff --git a/framework/sql/src/org/ofbiz/sql/FieldDef.java b/framework/sql/src/org/ofbiz/sql/FieldDef.java deleted file mode 100644 index 4570a96775..0000000000 --- a/framework/sql/src/org/ofbiz/sql/FieldDef.java +++ /dev/null @@ -1,62 +0,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. - */ -package org.ofbiz.sql; - -import org.ofbiz.base.lang.SourceMonitored; - -@SourceMonitored -public final class FieldDef extends Atom { - private final String alias; - private final StaticValue value; - - public FieldDef(StaticValue value, String alias) { - this.alias = alias; - this.value = value; - } - - public final String getAlias() { - return alias; - } - - public String getDefaultName() { - return alias == null ? value.getDefaultName() : alias; - } - - public StaticValue getValue() { - return value; - } - - @Override - public boolean equals(Object o) { - if (o instanceof FieldDef) { - FieldDef other = (FieldDef) o; - return equalsHelper(alias, other.alias) && value.equals(other.value); - } else { - return false; - } - } - - public StringBuilder appendTo(StringBuilder sb) { - value.appendTo(sb); - if (alias != null) { - sb.append(" AS ").append(alias); - } - return sb; - } -} diff --git a/framework/sql/src/org/ofbiz/sql/FieldValue.java b/framework/sql/src/org/ofbiz/sql/FieldValue.java deleted file mode 100644 index 532cc72f96..0000000000 --- a/framework/sql/src/org/ofbiz/sql/FieldValue.java +++ /dev/null @@ -1,72 +0,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. - */ -package org.ofbiz.sql; - -import org.ofbiz.base.lang.SourceMonitored; - -@SourceMonitored -public final class FieldValue extends StaticValue { - private final String fieldName; - private final String tableName; - - public FieldValue(String fieldName) { - this(null, fieldName); - } - - @Override - public void accept(Visitor visitor) { - visitor.visit(this); - } - - public FieldValue(String tableName, String fieldName) { - this.tableName = tableName; - this.fieldName = fieldName; - } - - public final String getTableName() { - return tableName; - } - - public final String getFieldName() { - return fieldName; - } - - @Override - public String getDefaultName() { - return fieldName; - } - - @Override - public boolean equals(Object o) { - if (o instanceof FieldValue) { - FieldValue other = (FieldValue) o; - return fieldName.equals(other.fieldName) && equalsHelper(tableName, other.tableName); - } else { - return false; - } - } - - public StringBuilder appendTo(StringBuilder sb) { - if (tableName != null) { - sb.append(tableName).append('.'); - } - sb.append(fieldName); - return sb; - } -} diff --git a/framework/sql/src/org/ofbiz/sql/FunctionCall.java b/framework/sql/src/org/ofbiz/sql/FunctionCall.java deleted file mode 100644 index 417df91475..0000000000 --- a/framework/sql/src/org/ofbiz/sql/FunctionCall.java +++ /dev/null @@ -1,75 +0,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. - */ -package org.ofbiz.sql; - -import java.util.Iterator; -import java.util.List; - -import org.ofbiz.base.lang.SourceMonitored; -import org.ofbiz.base.util.StringUtil; - -@SourceMonitored -public final class FunctionCall extends StaticValue implements Iterable { - private final String name; - private final List values; - - public FunctionCall(String name, List values) { - this.name = name; - this.values = values; - } - - @Override - public void accept(Visitor visitor) { - visitor.visit(this); - } - - public String getName() { - return name; - } - - @Override - public String getDefaultName() { - return name; - } - - public int getArgCount() { - return values.size(); - } - - public Iterator iterator() { - return values.iterator(); - } - - @Override - public boolean equals(Object o) { - if (o instanceof FunctionCall) { - FunctionCall other = (FunctionCall) o; - return name.equals(other.name) && values.equals(other.values); - } else { - return false; - } - } - - public StringBuilder appendTo(StringBuilder sb) { - sb.append(name).append('('); - StringUtil.appendTo(sb, values, null, null, ", "); - sb.append(')'); - return sb; - } -} diff --git a/framework/sql/src/org/ofbiz/sql/InsertPlan.java b/framework/sql/src/org/ofbiz/sql/InsertPlan.java deleted file mode 100644 index eb7fa85225..0000000000 --- a/framework/sql/src/org/ofbiz/sql/InsertPlan.java +++ /dev/null @@ -1,22 +0,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. - */ -package org.ofbiz.sql; - -public abstract class InsertPlan

> extends SQLPlan

{ -} diff --git a/framework/sql/src/org/ofbiz/sql/InsertRow.java b/framework/sql/src/org/ofbiz/sql/InsertRow.java deleted file mode 100644 index 57f8387d98..0000000000 --- a/framework/sql/src/org/ofbiz/sql/InsertRow.java +++ /dev/null @@ -1,53 +0,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. - */ -package org.ofbiz.sql; - -import java.util.Iterator; -import java.util.List; - -import org.ofbiz.base.util.StringUtil; - -public final class InsertRow extends Atom implements Iterable { - private final List values; - - public InsertRow(List values) { - this.values = values; - } - - public Iterator iterator() { - return values.iterator(); - } - - @Override - public boolean equals(Object o) { - if (o instanceof InsertRow) { - InsertRow other = (InsertRow) o; - return values.equals(other.values); - } else { - return false; - } - } - - public StringBuilder appendTo(StringBuilder sb) { - sb.append('('); - StringUtil.appendTo(sb, values, null, null, ", "); - sb.append(')'); - return sb; - } -} diff --git a/framework/sql/src/org/ofbiz/sql/InsertSource.java b/framework/sql/src/org/ofbiz/sql/InsertSource.java deleted file mode 100644 index 700b18caff..0000000000 --- a/framework/sql/src/org/ofbiz/sql/InsertSource.java +++ /dev/null @@ -1,24 +0,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. - */ -package org.ofbiz.sql; - -import org.ofbiz.base.lang.Appender; - -public interface InsertSource extends Appender { -} diff --git a/framework/sql/src/org/ofbiz/sql/InsertValues.java b/framework/sql/src/org/ofbiz/sql/InsertValues.java deleted file mode 100644 index ad080792ac..0000000000 --- a/framework/sql/src/org/ofbiz/sql/InsertValues.java +++ /dev/null @@ -1,52 +0,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. - */ -package org.ofbiz.sql; - -import java.util.Iterator; -import java.util.List; - -import org.ofbiz.base.util.StringUtil; - -public final class InsertValues extends Atom implements InsertSource, Iterable { - private final List rows; - - public InsertValues(List rows) { - this.rows = rows; - } - - public Iterator iterator() { - return rows.iterator(); - } - - @Override - public boolean equals(Object o) { - if (o instanceof InsertValues) { - InsertValues other = (InsertValues) o; - return rows.equals(other.rows); - } else { - return false; - } - } - - public StringBuilder appendTo(StringBuilder sb) { - sb.append("VALUES "); - StringUtil.appendTo(sb, rows, null, null, ", "); - return sb; - } -} diff --git a/framework/sql/src/org/ofbiz/sql/Joined.java b/framework/sql/src/org/ofbiz/sql/Joined.java deleted file mode 100644 index dc9e1c12f1..0000000000 --- a/framework/sql/src/org/ofbiz/sql/Joined.java +++ /dev/null @@ -1,90 +0,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. - */ -package org.ofbiz.sql; - -import java.util.Iterator; -import java.util.List; - -public final class Joined extends Atom implements Iterable { - private final boolean isOptional; - private final TableName tableName; - private final List keyMaps; - private final Joined joined; - - public Joined(boolean isOptional, TableName tableName, List keyMaps) { - this(isOptional, tableName, keyMaps, null); - } - - public Joined(boolean isOptional, TableName tableName, List 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 iterator() { - return keyMaps.iterator(); - } - - public Joined getJoined() { - return joined; - } - - @Override - public boolean equals(Object o) { - if (o instanceof Joined) { - Joined other = (Joined) o; - return tableName.equals(other.tableName) && keyMaps.equals(other.keyMaps) && equalsHelper(joined, other.joined); - } else { - return false; - } - } - - public StringBuilder appendTo(StringBuilder sb) { - return appendTo("left", sb); - } - - 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++) { - KeyMap keyMap = keyMaps.get(i); - if (i != 0) sb.append(" AND "); - sb.append(' ').append(leftAlias).append('.').append(keyMap.getLeftFieldName()); - sb.append(" = ").append(tableName.getAlias()).append('.').append(keyMap.getRightFieldName()); - } - if (joined != null) { - joined.appendTo(tableName.getAlias(), sb); - } - return sb; - } -} diff --git a/framework/sql/src/org/ofbiz/sql/Joiner.java b/framework/sql/src/org/ofbiz/sql/Joiner.java deleted file mode 100644 index f63dcda001..0000000000 --- a/framework/sql/src/org/ofbiz/sql/Joiner.java +++ /dev/null @@ -1,23 +0,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. - */ -package org.ofbiz.sql; - -public enum Joiner { - AND, OR -} diff --git a/framework/sql/src/org/ofbiz/sql/KeyMap.java b/framework/sql/src/org/ofbiz/sql/KeyMap.java deleted file mode 100644 index 12c0a6651f..0000000000 --- a/framework/sql/src/org/ofbiz/sql/KeyMap.java +++ /dev/null @@ -1,47 +0,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. - */ -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; - } - - @Override - public boolean equals(Object o) { - if (o instanceof KeyMap) { - KeyMap other = (KeyMap) o; - return leftFieldName.equals(other.leftFieldName) && rightFieldName.equals(other.rightFieldName); - } else { - return false; - } - } -} diff --git a/framework/sql/src/org/ofbiz/sql/ListCondition.java b/framework/sql/src/org/ofbiz/sql/ListCondition.java deleted file mode 100644 index 112492d56e..0000000000 --- a/framework/sql/src/org/ofbiz/sql/ListCondition.java +++ /dev/null @@ -1,71 +0,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. - */ -package org.ofbiz.sql; - -import java.util.List; - -import org.ofbiz.base.lang.SourceMonitored; -import org.ofbiz.base.util.StringUtil; - -@SourceMonitored -public final class ListCondition extends Condition { - private final Value left; - private final String op; - private final List values; - - public ListCondition(Value left, String op, List values) { - this.left = left; - this.op = op.toLowerCase(); - this.values = values; - } - - @Override - public void accept(Visitor visitor) { - visitor.visit(this); - } - - public Value getLeft() { - return left; - } - - public String getOp() { - return op; - } - - public List getValues() { - return values; - } - - @Override - public boolean equals(Object o) { - if (o instanceof ListCondition) { - ListCondition other = (ListCondition) o; - return left.equals(other.left) && op.equals(other.op) && values.equals(other.values); - } else { - return false; - } - } - - public StringBuilder appendTo(StringBuilder sb) { - left.appendTo(sb); - sb.append(' ').append(op).append(" ("); - StringUtil.appendTo(sb, values, null, null, ", "); - return sb.append(')'); - } -} diff --git a/framework/sql/src/org/ofbiz/sql/MathValue.java b/framework/sql/src/org/ofbiz/sql/MathValue.java deleted file mode 100644 index 486777ee75..0000000000 --- a/framework/sql/src/org/ofbiz/sql/MathValue.java +++ /dev/null @@ -1,71 +0,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. - */ -package org.ofbiz.sql; - -import java.util.Iterator; -import java.util.List; - -import org.ofbiz.base.lang.SourceMonitored; -import org.ofbiz.base.util.StringUtil; - -@SourceMonitored -public final class MathValue extends StaticValue implements Iterable { - private final String op; - private final List values; - - public MathValue(String op, List values) { - this.op = op.toLowerCase(); - this.values = values; - } - - @Override - public void accept(Visitor visitor) { - visitor.visit(this); - } - - public String getOp() { - return op; - } - - @Override - public String getDefaultName() { - return null; - } - - public Iterator iterator() { - return values.iterator(); - } - - @Override - public boolean equals(Object o) { - if (o instanceof MathValue) { - MathValue other = (MathValue) o; - return op.equals(other.op) && values.equals(other.values); - } else { - return false; - } - } - - public StringBuilder appendTo(StringBuilder sb) { - sb.append('('); - StringUtil.appendTo(sb, values, null, null, " ", op, " "); - sb.append(')'); - return sb; - } -} diff --git a/framework/sql/src/org/ofbiz/sql/NumberValue.java b/framework/sql/src/org/ofbiz/sql/NumberValue.java deleted file mode 100644 index 90ee4b22f4..0000000000 --- a/framework/sql/src/org/ofbiz/sql/NumberValue.java +++ /dev/null @@ -1,62 +0,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. - */ -package org.ofbiz.sql; - -import org.ofbiz.base.lang.SourceMonitored; - -@SourceMonitored -public final class NumberValue extends ConstantValue { - private final N number; - - public static NumberValue valueOf(long v) { - return new NumberValue(v); - } - - public static NumberValue valueOf(double v) { - return new NumberValue(v); - } - - public NumberValue(N number) { - this.number = number; - } - - @Override - public void accept(Visitor visitor) { - visitor.visit(this); - } - - public N getNumber() { - return number; - } - - @Override - public boolean equals(Object o) { - if (o instanceof NumberValue) { - NumberValue other = (NumberValue) o; - return number.equals(other.number); - } else { - return false; - } - } - - public StringBuilder appendTo(StringBuilder sb) { - sb.append(number); - return sb; - } -} diff --git a/framework/sql/src/org/ofbiz/sql/OrderByItem.java b/framework/sql/src/org/ofbiz/sql/OrderByItem.java deleted file mode 100644 index 184597923d..0000000000 --- a/framework/sql/src/org/ofbiz/sql/OrderByItem.java +++ /dev/null @@ -1,80 +0,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. - */ -package org.ofbiz.sql; - -import org.ofbiz.base.lang.SourceMonitored; - -@SourceMonitored -public final class OrderByItem extends Atom { - public enum Order { DEFAULT, ASCENDING, DESCENDING } - public enum Nulls { DEFAULT, FIRST, LAST } - - private final Order order; - private final Nulls nulls; - private final ConstantValue value; - - public OrderByItem(Order order, Nulls nulls, ConstantValue value) { - this.order = order; - this.nulls = nulls; - this.value = value; - } - - public final Order getOrder() { - return order; - } - - public final Nulls getNulls() { - return nulls; - } - - public final ConstantValue getValue() { - return value; - } - - @Override - public boolean equals(Object o) { - if (o instanceof OrderByItem) { - OrderByItem other = (OrderByItem) o; - return order.equals(other.order) && nulls.equals(other.nulls) && value.equals(other.value); - } else { - return false; - } - } - - public StringBuilder appendTo(StringBuilder sb) { - value.appendTo(sb); - switch (order) { - case ASCENDING: - sb.append(" ASC"); - break; - case DESCENDING: - sb.append(" DESC"); - break; - } - switch (nulls) { - case FIRST: - sb.append(" NULLS FIRST"); - break; - case LAST: - sb.append(" NULLS LAST"); - break; - } - return sb; - } -} diff --git a/framework/sql/src/org/ofbiz/sql/ParameterValue.java b/framework/sql/src/org/ofbiz/sql/ParameterValue.java deleted file mode 100644 index 4a9b66ab2a..0000000000 --- a/framework/sql/src/org/ofbiz/sql/ParameterValue.java +++ /dev/null @@ -1,54 +0,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. - */ -package org.ofbiz.sql; - -import org.ofbiz.base.lang.SourceMonitored; - -@SourceMonitored -public final class ParameterValue extends Value { - private final String name; - - public ParameterValue(String name) { - this.name = name; - } - - @Override - public void accept(Visitor visitor) { - visitor.visit(this); - } - - public String getName() { - return name; - } - - @Override - public boolean equals(Object o) { - if (o instanceof ParameterValue) { - ParameterValue other = (ParameterValue) o; - return name.equals(other.name); - } else { - return false; - } - } - - public StringBuilder appendTo(StringBuilder sb) { - sb.append('?').append(name); - return sb; - } -} diff --git a/framework/sql/src/org/ofbiz/sql/ParameterizedConditionException.java b/framework/sql/src/org/ofbiz/sql/ParameterizedConditionException.java deleted file mode 100644 index 23c0f33d7a..0000000000 --- a/framework/sql/src/org/ofbiz/sql/ParameterizedConditionException.java +++ /dev/null @@ -1,40 +0,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. - */ -package org.ofbiz.sql; - -import org.ofbiz.base.util.GeneralException; - -@SuppressWarnings("serial") -public final class ParameterizedConditionException extends GeneralException { - public ParameterizedConditionException() { - super(); - } - - public ParameterizedConditionException(String msg) { - super(msg); - } - - public ParameterizedConditionException(String msg, Throwable nested) { - super(msg, nested); - } - - public ParameterizedConditionException(Throwable nested) { - super(nested); - } -} diff --git a/framework/sql/src/org/ofbiz/sql/Planner.java b/framework/sql/src/org/ofbiz/sql/Planner.java deleted file mode 100644 index 939c31279b..0000000000 --- a/framework/sql/src/org/ofbiz/sql/Planner.java +++ /dev/null @@ -1,54 +0,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. - */ -package org.ofbiz.sql; - -public abstract class Planner

, C, D extends DeletePlan, I extends InsertPlan, S extends SelectPlan, U extends UpdatePlan, V extends ViewPlan> { - private final ConditionPlanner conditionPlanner; - - protected Planner(ConditionPlanner conditionPlanner) { - this.conditionPlanner = conditionPlanner; - } - - public ConditionPlanner getConditionPlanner() { - return conditionPlanner; - } - - public ConditionPlan plan(Condition condition) { - try { - return new ConditionPlan(conditionPlanner, null, conditionPlanner.parse(condition, null)); - } catch (ParameterizedConditionException e) { - return new ConditionPlan(conditionPlanner, condition, null); - } - } - - public > SQLPlan plan(STMNT statement) { - if (statement instanceof SQLDelete) return planDelete((SQLDelete) statement); - if (statement instanceof SQLInsert) return planInsert((SQLInsert) statement); - if (statement instanceof SQLSelect) return planSelect((SQLSelect) statement); - if (statement instanceof SQLUpdate) return planUpdate((SQLUpdate) statement); - if (statement instanceof SQLView) return planView((SQLView) statement); - return null; - } - - public abstract D planDelete(SQLDelete deleteStatement); - public abstract I planInsert(SQLInsert insertStatement); - public abstract S planSelect(SQLSelect selectStatement); - public abstract U planUpdate(SQLUpdate updateStatement); - public abstract V planView(SQLView viewStatement); -} diff --git a/framework/sql/src/org/ofbiz/sql/Relation.java b/framework/sql/src/org/ofbiz/sql/Relation.java deleted file mode 100644 index 82b75dbef4..0000000000 --- a/framework/sql/src/org/ofbiz/sql/Relation.java +++ /dev/null @@ -1,87 +0,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. - */ -package org.ofbiz.sql; - -import java.util.Iterator; -import java.util.List; - -public final class Relation extends Atom implements Iterable { - private final String name; - private final String type; - private final String title; - private final String entityName; - private final List keyMaps; - - public Relation(String type, String title, String entityName, List keyMaps) { - this.type = type; - this.title = title; - this.entityName = entityName; - this.keyMaps = keyMaps; - this.name = title == null ? entityName : title + entityName; - } - - public String getName() { - return name; - } - - public String getType() { - return type; - } - - public String getTitle() { - return title; - } - - public String getEntityName() { - return entityName; - } - - public Iterator iterator() { - return keyMaps.iterator(); - } - - @Override - public boolean equals(Object o) { - if (o instanceof Relation) { - Relation other = (Relation) o; - return equalsHelper(type, other.type) && equalsHelper(title, other.title) && entityName.equals(other.entityName) && keyMaps.equals(other.keyMaps); - } else { - return false; - } - } - - public StringBuilder appendTo(StringBuilder sb) { - sb.append("RELATION"); - if (type != null) { - sb.append(" TYPE ").append(type); - } - if (title != null) { - sb.append(" TITLE ").append(title); - } - sb.append(' ').append(entityName); - sb.append(" MAP"); - for (int i = 0; i < keyMaps.size(); i++) { - KeyMap keyMap = keyMaps.get(i); - if (i != 0) sb.append(" AND "); - sb.append(' ').append(keyMap.getLeftFieldName()); - sb.append(" = ").append(keyMap.getRightFieldName()); - } - return sb; - } -} diff --git a/framework/sql/src/org/ofbiz/sql/SQLDelete.java b/framework/sql/src/org/ofbiz/sql/SQLDelete.java deleted file mode 100644 index 8718086a1d..0000000000 --- a/framework/sql/src/org/ofbiz/sql/SQLDelete.java +++ /dev/null @@ -1,67 +0,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. - */ -package org.ofbiz.sql; - -public final class SQLDelete extends SQLStatement { - private final Table table; - private final Condition whereCondition; - - public SQLDelete(Table table, Condition whereCondition) { - this.table = table; - this.whereCondition = whereCondition; - } - - @Override - public void accept(Visitor visitor) { - visitor.visit(this); - } - - public Table getTable() { - return table; - } - - public Condition getWhereCondition() { - return whereCondition; - } - - @Override - public boolean equals(Object o) { - if (o instanceof SQLDelete) { - SQLDelete other = (SQLDelete) o; - return table.equals(other.table) && equalsHelper(whereCondition, other.whereCondition); - } else { - return false; - } - } - - public StringBuilder appendTo(StringBuilder sb) { - sb.append("DELETE FROM "); - table.getTableName().appendTo(sb); - if (table.getJoined() != null) { - sb.append(" USING"); - table.getJoined().appendToRest(table.getTableName().getAlias(), sb); - } - if (whereCondition != null) { - sb.append(" WHERE "); - whereCondition.appendTo(sb); - } - sb.append(';'); - return sb; - } -} diff --git a/framework/sql/src/org/ofbiz/sql/SQLIndex.java b/framework/sql/src/org/ofbiz/sql/SQLIndex.java deleted file mode 100644 index 6db3468c10..0000000000 --- a/framework/sql/src/org/ofbiz/sql/SQLIndex.java +++ /dev/null @@ -1,93 +0,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. - */ -package org.ofbiz.sql; - -import java.util.List; - -import org.ofbiz.base.util.StringUtil; - -public final class SQLIndex extends SQLStatement { - private final boolean isUnique; - private final String name; - private final String table; - private final String using; - private final List values; - - public SQLIndex(boolean isUnique, String name, String table, String using, List values) { - this.isUnique = isUnique; - this.name = name; - this.table = table; - this.using = using; - this.values = values; - } - - @Override - public void accept(Visitor visitor) { - visitor.visit(this); - } - - public boolean getIsUnique() { - return isUnique; - } - - public String getName() { - return name; - } - - public String getTable() { - return table; - } - - public String getUsing() { - return using; - } - - public List getValues() { - return values; - } - - @Override - public boolean equals(Object o) { - if (o instanceof SQLIndex) { - SQLIndex other = (SQLIndex) o; - return isUnique == other.isUnique && name.equals(other.name) && table.equals(other.table) && equalsHelper(using, other.using) && values.equals(other.values); - } else { - return false; - } - } - - public StringBuilder appendTo(StringBuilder sb) { - sb.append("CREATE"); - if (isUnique) { - sb.append(" UNIQUE"); - } - sb.append(" INDEX "); - sb.append(name); - sb.append(" ON "); - sb.append(table); - if (using != null) { - sb.append(" USING ").append(using); - } - sb.append(" ("); - StringUtil.append(sb, values, null, null, ", "); - sb.append(')'); - sb.append(';'); - return sb; - } -} diff --git a/framework/sql/src/org/ofbiz/sql/SQLInsert.java b/framework/sql/src/org/ofbiz/sql/SQLInsert.java deleted file mode 100644 index afa18d1947..0000000000 --- a/framework/sql/src/org/ofbiz/sql/SQLInsert.java +++ /dev/null @@ -1,77 +0,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. - */ -package org.ofbiz.sql; - -import java.util.Iterator; -import java.util.List; - -import org.ofbiz.base.util.StringUtil; -import org.ofbiz.base.util.UtilValidate; - -public final class SQLInsert extends SQLStatement { - private final TableName tableName; - private final InsertSource source; - private final List columns; - - public SQLInsert(TableName tableName, InsertSource source, List columns) { - this.tableName = tableName; - this.source = source; - this.columns = columns; - } - - @Override - public void accept(Visitor visitor) { - visitor.visit(this); - } - - public TableName getTableName() { - return tableName; - } - - public InsertSource getSource() { - return source; - } - - public Iterator iterator() { - return columns.iterator(); - } - - @Override - public boolean equals(Object o) { - if (o instanceof SQLInsert) { - SQLInsert other = (SQLInsert) o; - return tableName.equals(other.tableName) && equalsHelper(columns, other.columns) && source.equals(other.source); - } else { - return false; - } - } - - public StringBuilder appendTo(StringBuilder sb) { - sb.append("INSERT INTO "); - tableName.appendTo(sb); - if (UtilValidate.isNotEmpty(columns)) { - sb.append(" ("); - StringUtil.append(sb, columns, null, null, ", "); - sb.append(')'); - } - sb.append(' '); - source.appendTo(sb); - return sb; - } -} diff --git a/framework/sql/src/org/ofbiz/sql/SQLPlan.java b/framework/sql/src/org/ofbiz/sql/SQLPlan.java deleted file mode 100644 index 517019f7bf..0000000000 --- a/framework/sql/src/org/ofbiz/sql/SQLPlan.java +++ /dev/null @@ -1,25 +0,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. - */ -package org.ofbiz.sql; - -public abstract class SQLPlan

> extends Atom { - public StringBuilder appendTo(StringBuilder sb) { - return sb.append("SQLPlan[").append(getClass().getName()).append("]"); - } -} diff --git a/framework/sql/src/org/ofbiz/sql/SQLSelect.java b/framework/sql/src/org/ofbiz/sql/SQLSelect.java deleted file mode 100644 index f32ea0ae05..0000000000 --- a/framework/sql/src/org/ofbiz/sql/SQLSelect.java +++ /dev/null @@ -1,113 +0,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. - */ -package org.ofbiz.sql; - -import java.util.List; -import java.util.Map; - -import org.ofbiz.base.util.StringUtil; - -public final class SQLSelect extends SQLStatement implements InsertSource { - private final SelectGroup selectGroup; - private final Unioned unioned; - private final Map relations; - private final int offset; - private final int limit; - private final List orderBy; - - public SQLSelect(boolean isDistinct, List fieldAlls, Map fieldDefs, Table table, Map relations, Condition whereCondition, Condition havingCondition, List groupBy, List orderBy, int offset, int limit) { - this(new SelectGroup(isDistinct, fieldAlls, fieldDefs, table, whereCondition, havingCondition, groupBy), null, relations, orderBy, offset, limit); - } - - public SQLSelect(SelectGroup selectGroup, Unioned unioned, Map relations, List orderBy, int offset, int limit) { - this.selectGroup = selectGroup; - this.unioned = unioned; - this.relations = checkEmpty(relations); - this.orderBy = orderBy; - this.offset = offset; - this.limit = limit; - } - - @Override - public void accept(Visitor visitor) { - visitor.visit(this); - } - - public SelectGroup getSelectGroup() { - return selectGroup; - } - - public Unioned getUnioned() { - return unioned; - } - - public Map getRelations() { - return relations; - } - - public List getOrderBy() { - return orderBy; - } - - public int getOffset() { - return offset; - } - - public int getLimit() { - return limit; - } - - @Override - public boolean equals(Object o) { - if (!(o instanceof SQLSelect)) { - return false; - } - - SQLSelect other = (SQLSelect) o; - return selectGroup.equals(other.selectGroup) - && equalsHelper(unioned, other.unioned) - && equalsHelper(relations, other.relations) - && offset == other.offset - && limit == other.limit - && equalsHelper(orderBy, other.orderBy) - ; - } - - public StringBuilder appendTo(StringBuilder sb) { - selectGroup.appendTo(sb); - if (unioned != null) { - unioned.appendTo(sb); - } - if (relations != null) { - StringUtil.appendTo(sb, relations.values(), " ", null, null); - } - if (orderBy != null) { - sb.append(" ORDER BY "); - StringUtil.append(sb, orderBy, null, null, ", "); - } - if (offset != -1) { - sb.append(" OFFSET ").append(offset); - } - if (limit != -1) { - sb.append(" LIMIT ").append(limit); - } - sb.append(';'); - return sb; - } -} diff --git a/framework/sql/src/org/ofbiz/sql/SQLStatement.java b/framework/sql/src/org/ofbiz/sql/SQLStatement.java deleted file mode 100644 index acc5e26c73..0000000000 --- a/framework/sql/src/org/ofbiz/sql/SQLStatement.java +++ /dev/null @@ -1,52 +0,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. - */ -package org.ofbiz.sql; - -public abstract class SQLStatement> extends Atom { - public interface Visitor { - void visit(SQLDelete statement); - void visit(SQLIndex statement); - void visit(SQLInsert statement); - void visit(SQLSelect statement); - void visit(SQLUpdate statement); - void visit(SQLView statement); - } - - public static class BaseVisitor implements Visitor { - public void visit(SQLDelete statement) { - } - - public void visit(SQLIndex statement) { - } - - public void visit(SQLInsert statement) { - } - - public void visit(SQLSelect statement) { - } - - public void visit(SQLUpdate statement) { - } - - public void visit(SQLView statement) { - } - } - - public abstract void accept(Visitor visitor); -} diff --git a/framework/sql/src/org/ofbiz/sql/SQLUpdate.java b/framework/sql/src/org/ofbiz/sql/SQLUpdate.java deleted file mode 100644 index f9958384ec..0000000000 --- a/framework/sql/src/org/ofbiz/sql/SQLUpdate.java +++ /dev/null @@ -1,106 +0,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. - */ -package org.ofbiz.sql; - -import java.util.Iterator; -import java.util.List; - -import org.ofbiz.base.util.StringUtil; - -public final class SQLUpdate extends SQLStatement implements Iterable { - private final Table table; - private final List setFields; - private final Condition whereCondition; - - public SQLUpdate(Table table, List setFields, Condition whereCondition) { - this.table = table; - this.setFields = setFields; - this.whereCondition = whereCondition; - } - - @Override - public void accept(Visitor visitor) { - visitor.visit(this); - } - - public Table getTable() { - return table; - } - - public Iterator iterator() { - return setFields.iterator(); - } - - public Condition getWhereCondition() { - return whereCondition; - } - - @Override - public boolean equals(Object o) { - if (o instanceof SQLUpdate) { - SQLUpdate other = (SQLUpdate) o; - return table.equals(other.table) && setFields.equals(other.setFields) && equalsHelper(whereCondition, other.whereCondition); - } else { - return false; - } - } - - public StringBuilder appendTo(StringBuilder sb) { - sb.append("UPDATE "); - table.getTableName().appendTo(sb); - // n=4;1+(n-1)*2+3+(n-1)*2+1;3*n+(n-1)*2 - // 17 - // 18 - sb.append(" SET "); - if (setFields.size() <= 3) { - StringUtil.appendTo(sb, setFields, null, null, ", "); - } else { - Iterator it = setFields.iterator(); - sb.append('('); - while (it.hasNext()) { - SetField setField = it.next(); - sb.append(setField.getName()); - if (it.hasNext()) { - sb.append(", "); - } - } - sb.append(") = ("); - it = setFields.iterator(); - while (it.hasNext()) { - SetField setField = it.next(); - setField.getValue().appendTo(sb); - if (it.hasNext()) { - sb.append(", "); - } - } - sb.append(')'); - it = setFields.iterator(); - } - if (table.getJoined() != null) { - sb.append(" FROM "); - table.getJoined().appendToRest(table.getTableName().getAlias(), sb); - } - if (whereCondition != null) { - sb.append(" WHERE "); - whereCondition.appendTo(sb); - } - sb.append(';'); - return sb; - } -} diff --git a/framework/sql/src/org/ofbiz/sql/SQLView.java b/framework/sql/src/org/ofbiz/sql/SQLView.java deleted file mode 100644 index 3e69bb7aa8..0000000000 --- a/framework/sql/src/org/ofbiz/sql/SQLView.java +++ /dev/null @@ -1,58 +0,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. - */ -package org.ofbiz.sql; - -public final class SQLView extends SQLStatement { - private final String name; - private final SQLSelect sqlSelect; - - public SQLView(String name, SQLSelect sqlSelect) { - this.name = name; - this.sqlSelect = sqlSelect; - } - - @Override - public void accept(Visitor visitor) { - visitor.visit(this); - } - - public String getName() { - return name; - } - - public SQLSelect getSelect() { - return sqlSelect; - } - - @Override - public boolean equals(Object o) { - if (o instanceof SQLView) { - SQLView other = (SQLView) o; - return name.equals(other.name) && sqlSelect.equals(other.sqlSelect); - } else { - return false; - } - } - - public StringBuilder appendTo(StringBuilder sb) { - sb.append("CREATE VIEW ").append(name).append(" AS "); - sqlSelect.appendTo(sb); - return sb; - } -} diff --git a/framework/sql/src/org/ofbiz/sql/SelectGroup.java b/framework/sql/src/org/ofbiz/sql/SelectGroup.java deleted file mode 100644 index c8cee3702a..0000000000 --- a/framework/sql/src/org/ofbiz/sql/SelectGroup.java +++ /dev/null @@ -1,121 +0,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. - */ -package org.ofbiz.sql; - -import java.util.Collection; -import java.util.List; -import java.util.Map; - -import org.ofbiz.base.util.StringUtil; - -public final class SelectGroup extends Atom { - private final boolean isDistinct; - private final List fieldAlls; - private final Map fieldDefs; - private final Table table; - private final Condition whereCondition; - private final Condition havingCondition; - private final List groupBy; - - public SelectGroup(boolean isDistinct, List fieldAlls, Map fieldDefs, Table table, Condition whereCondition, Condition havingCondition, List groupBy) { - this.isDistinct = isDistinct; - this.fieldAlls = checkEmpty(fieldAlls); - this.fieldDefs = checkEmpty(fieldDefs); - this.table = table; - this.whereCondition = whereCondition; - this.havingCondition = havingCondition; - this.groupBy = groupBy; - } - - public boolean getIsDistinct() { - return isDistinct; - } - - public Collection getFieldAlls() { - return fieldAlls; - } - - public Collection getFieldDefs() { - return fieldDefs != null ? fieldDefs.values() : null; - } - - public Table getTable() { - return table; - } - - public Condition getWhereCondition() { - return whereCondition; - } - - public Condition getHavingCondition() { - return havingCondition; - } - - public List getGroupBy() { - return groupBy; - } - - @Override - public boolean equals(Object o) { - if (!(o instanceof SelectGroup)) { - return false; - } - - SelectGroup other = (SelectGroup) o; - return isDistinct == other.isDistinct - && equalsHelper(fieldAlls, other.fieldAlls) - && equalsHelper(fieldDefs, other.fieldDefs) - && table.equals(other.table) - && equalsHelper(whereCondition, other.whereCondition) - && equalsHelper(havingCondition, other.havingCondition) - && equalsHelper(groupBy, other.groupBy) - ; - } - - public StringBuilder appendTo(StringBuilder sb) { - sb.append("SELECT"); - if (isDistinct) { - sb.append(" DISTINCT"); - } - if (fieldAlls != null) { - StringUtil.appendTo(sb, fieldAlls, " ", null, ","); - } - if (fieldAlls != null && fieldDefs != null) { - sb.append(','); - } - if (fieldDefs != null) { - StringUtil.appendTo(sb, fieldDefs.values(), " ", null, ","); - } - sb.append(" FROM "); - table.appendTo(sb); - if (whereCondition != null) { - sb.append(" WHERE "); - whereCondition.appendTo(sb); - } - if (havingCondition != null) { - sb.append(" HAVING "); - havingCondition.appendTo(sb); - } - if (groupBy != null) { - sb.append(" GROUP BY "); - StringUtil.append(sb, groupBy, null, null, ", "); - } - return sb; - } -} diff --git a/framework/sql/src/org/ofbiz/sql/SelectPlan.java b/framework/sql/src/org/ofbiz/sql/SelectPlan.java deleted file mode 100644 index bd1747b8f0..0000000000 --- a/framework/sql/src/org/ofbiz/sql/SelectPlan.java +++ /dev/null @@ -1,37 +0,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. - */ -package org.ofbiz.sql; - -public abstract class SelectPlan

, C> extends SQLPlan

{ - private final ConditionPlan wherePlan; - private final ConditionPlan havingPlan; - - protected SelectPlan(ConditionPlan wherePlan, ConditionPlan havingPlan) { - this.wherePlan = wherePlan; - this.havingPlan = havingPlan; - } - - public ConditionPlan getWherePlan() { - return wherePlan; - } - - public ConditionPlan getHavingPlan() { - return havingPlan; - } -} diff --git a/framework/sql/src/org/ofbiz/sql/SetField.java b/framework/sql/src/org/ofbiz/sql/SetField.java deleted file mode 100644 index 34c571c0b9..0000000000 --- a/framework/sql/src/org/ofbiz/sql/SetField.java +++ /dev/null @@ -1,53 +0,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. - */ -package org.ofbiz.sql; - -public final class SetField extends Atom { - private final String name; - private final Value value; - - public SetField(String name, Value value) { - this.name = name; - this.value = value; - } - - public String getName() { - return name; - } - - public Value getValue() { - return value; - } - - @Override - public boolean equals(Object o) { - if (o instanceof SetField) { - SetField other = (SetField) o; - return name.equals(other.name) && value.equals(other.value); - } else { - return false; - } - } - - public StringBuilder appendTo(StringBuilder sb) { - sb.append(name).append(" = "); - value.appendTo(sb); - return sb; - } -} diff --git a/framework/sql/src/org/ofbiz/sql/StaticValue.java b/framework/sql/src/org/ofbiz/sql/StaticValue.java deleted file mode 100644 index f1babf9361..0000000000 --- a/framework/sql/src/org/ofbiz/sql/StaticValue.java +++ /dev/null @@ -1,23 +0,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. - */ -package org.ofbiz.sql; - -public abstract class StaticValue extends ConstantValue { - public abstract String getDefaultName(); -} diff --git a/framework/sql/src/org/ofbiz/sql/StringValue.java b/framework/sql/src/org/ofbiz/sql/StringValue.java deleted file mode 100644 index 0612f9a5ed..0000000000 --- a/framework/sql/src/org/ofbiz/sql/StringValue.java +++ /dev/null @@ -1,54 +0,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. - */ -package org.ofbiz.sql; - -import org.ofbiz.base.lang.SourceMonitored; - -@SourceMonitored -public final class StringValue extends ConstantValue { - private final String str; - - public StringValue(String str) { - this.str = str; - } - - @Override - public void accept(Visitor visitor) { - visitor.visit(this); - } - - public String getString() { - return str; - } - - @Override - public boolean equals(Object o) { - if (o instanceof StringValue) { - StringValue other = (StringValue) o; - return str.equals(other.str); - } else { - return false; - } - } - - public StringBuilder appendTo(StringBuilder sb) { - sb.append('\'').append(str.replaceAll("'", "''")).append('\''); - return sb; - } -} diff --git a/framework/sql/src/org/ofbiz/sql/Table.java b/framework/sql/src/org/ofbiz/sql/Table.java deleted file mode 100644 index 47961b45ef..0000000000 --- a/framework/sql/src/org/ofbiz/sql/Table.java +++ /dev/null @@ -1,59 +0,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. - */ -package org.ofbiz.sql; - -public final class Table extends Atom { - private final TableName tableName; - private final Joined joined; - - public Table(TableName tableName) { - this(tableName, null); - } - - public Table(TableName tableName, Joined joined) { - this.tableName = tableName; - this.joined = joined; - } - - public TableName getTableName() { - return tableName; - } - - public Joined getJoined() { - return joined; - } - - @Override - public boolean equals(Object o) { - if (o instanceof Table) { - Table other = (Table) o; - return tableName.equals(other.tableName) && equalsHelper(joined, other.joined); - } else { - return false; - } - } - - public StringBuilder appendTo(StringBuilder sb) { - tableName.appendTo(sb); - if (joined != null) { - joined.appendTo(tableName.getAlias(), sb); - } - return sb; - } -} diff --git a/framework/sql/src/org/ofbiz/sql/TableName.java b/framework/sql/src/org/ofbiz/sql/TableName.java deleted file mode 100644 index 140363371d..0000000000 --- a/framework/sql/src/org/ofbiz/sql/TableName.java +++ /dev/null @@ -1,55 +0,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. - */ -package org.ofbiz.sql; - -public final class TableName extends Atom { - private final String tableName; - private final String alias; - - public TableName(String tableName, String alias) { - this.tableName = tableName; - this.alias = alias != null ? alias : tableName; - } - - public final String getTableName() { - return tableName; - } - - public final String getAlias() { - return alias; - } - - @Override - public boolean equals(Object o) { - if (o instanceof TableName) { - TableName other = (TableName) o; - return tableName.equals(other.tableName) && alias.equals(other.alias); - } else { - return false; - } - } - - public StringBuilder appendTo(StringBuilder sb) { - sb.append(tableName); - if (!alias.equals(tableName)) { - sb.append(' ').append(alias); - } - return sb; - } -} diff --git a/framework/sql/src/org/ofbiz/sql/Unioned.java b/framework/sql/src/org/ofbiz/sql/Unioned.java deleted file mode 100644 index 5a33e1f370..0000000000 --- a/framework/sql/src/org/ofbiz/sql/Unioned.java +++ /dev/null @@ -1,64 +0,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. - */ -package org.ofbiz.sql; - -public final class Unioned extends Atom { - public enum Operator { UNION, UNION_ALL, INTERSECT, INTERSECT_ALL, EXCEPT, EXCEPT_ALL } - - private final Operator operator; - private final SelectGroup group; - private final Unioned next; - - public Unioned(Operator operator, SelectGroup group, Unioned next) { - this.operator = operator; - this.group = group; - this.next = next; - } - - public Operator getOperator() { - return operator; - } - - public SelectGroup getGroup() { - return group; - } - - public Unioned getNext() { - return next; - } - - @Override - public boolean equals(Object o) { - if (o instanceof Unioned) { - Unioned other = (Unioned) o; - return operator.equals(other.operator) && group.equals(other.group) && equalsHelper(next, other.next); - } else { - return false; - } - } - - public StringBuilder appendTo(StringBuilder sb) { - sb.append(' ').append(operator.toString().replace('_', ' ')).append(' '); - group.appendTo(sb); - if (next != null) { - next.appendTo(sb); - } - return sb; - } -} diff --git a/framework/sql/src/org/ofbiz/sql/UpdatePlan.java b/framework/sql/src/org/ofbiz/sql/UpdatePlan.java deleted file mode 100644 index 7f6ba706a9..0000000000 --- a/framework/sql/src/org/ofbiz/sql/UpdatePlan.java +++ /dev/null @@ -1,31 +0,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. - */ -package org.ofbiz.sql; - -public abstract class UpdatePlan

, C> extends SQLPlan

{ - private final ConditionPlan wherePlan; - - protected UpdatePlan(ConditionPlan wherePlan) { - this.wherePlan = wherePlan; - } - - public ConditionPlan getWherePlan() { - return wherePlan; - } -} diff --git a/framework/sql/src/org/ofbiz/sql/Value.java b/framework/sql/src/org/ofbiz/sql/Value.java deleted file mode 100644 index 7e33549f3d..0000000000 --- a/framework/sql/src/org/ofbiz/sql/Value.java +++ /dev/null @@ -1,79 +0,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. - */ -package org.ofbiz.sql; - -public abstract class Value extends Atom { - public static final class Null extends Value { - private Null() { - } - @Override - public void accept(Visitor visitor) { - visitor.visit(this); - } - - public StringBuilder appendTo(StringBuilder sb) { - return sb.append("NULL"); - } - } - - public static final Null NULL = new Null(); - - public interface Visitor { - void visit(AggregateFunction value); - void visit(FieldValue value); - void visit(FunctionCall value); - void visit(MathValue value); - void visit(Null value); - void visit(NumberValue value); - void visit(ParameterValue value); - void visit(StringValue value); - void visit(CountAllFunction value); - } - - public static class BaseVisitor implements Visitor { - public void visit(AggregateFunction value) { - } - - public void visit(FieldValue value) { - } - - public void visit(FunctionCall value) { - } - - public void visit(MathValue value) { - } - - public void visit(Null value) { - } - - public void visit(NumberValue value) { - } - - public void visit(ParameterValue value) { - } - - public void visit(StringValue value) { - } - - public void visit(CountAllFunction value) { - } - } - - public abstract void accept(Visitor visitor); -} diff --git a/framework/sql/src/org/ofbiz/sql/ViewPlan.java b/framework/sql/src/org/ofbiz/sql/ViewPlan.java deleted file mode 100644 index cd6793bd2e..0000000000 --- a/framework/sql/src/org/ofbiz/sql/ViewPlan.java +++ /dev/null @@ -1,22 +0,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. - */ -package org.ofbiz.sql; - -public abstract class ViewPlan

> extends SQLPlan

{ -} diff --git a/framework/sql/src/org/ofbiz/sql/test/ConditionsTest.java b/framework/sql/src/org/ofbiz/sql/test/ConditionsTest.java deleted file mode 100644 index 7b03c48df4..0000000000 --- a/framework/sql/src/org/ofbiz/sql/test/ConditionsTest.java +++ /dev/null @@ -1,162 +0,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. - */ -package org.ofbiz.sql.test; - -import java.util.Collections; -import java.util.List; - -import org.ofbiz.sql.BetweenCondition; -import org.ofbiz.sql.BooleanCondition; -import org.ofbiz.sql.Condition; -import org.ofbiz.sql.ConditionList; -import org.ofbiz.sql.Joiner; -import org.ofbiz.sql.ListCondition; -import org.ofbiz.sql.NumberValue; -import org.ofbiz.sql.Value; - -import org.ofbiz.base.lang.SourceMonitored; -import org.ofbiz.base.test.GenericTestCaseBase; - -@SourceMonitored -public class ConditionsTest extends GenericTestCaseBase { - private static final NumberValue l1 = NumberValue.valueOf(1); - private static final NumberValue l2 = NumberValue.valueOf(5); - private static final NumberValue l3 = NumberValue.valueOf(10); - - public ConditionsTest(String name) { - super(name); - } - - private static void basicTest(String label, Class clz, C c, String s, C o, boolean matches) { - assertEquals(label + ":toString", s, c.toString()); - assertNotEquals(label + ":not-equals-this", c, ConditionsTest.class); - if (o != null) { - if (matches) { - assertEquals(label + ":equals", o, c); - } else { - assertNotEquals(label + ":not-equals", o, c); - } - } - ConditionVisitorRecorder visitor = new ConditionVisitorRecorder(); - c.accept(visitor); - c.accept(visitor); - assertEquals(label + ":visited", 2, visitor.counts.remove(clz).intValue()); - assertTrue(label + ":nothing-else-visited", visitor.counts.isEmpty()); - } - - private static void betweenConditionTest(String label, BetweenCondition c, Value left, Value r1, Value r2, String s, BetweenCondition o, boolean matches) { - assertEquals(label + ":left", left, c.getLeft()); - assertEquals(label + ":r1", r1, c.getR1()); - assertEquals(label + ":r2", r2, c.getR2()); - basicTest(label, BetweenCondition.class, c, s, o, matches); - } - - public void testBetweenCondition() { - BetweenCondition c1 = new BetweenCondition(l1, l2, l3); - betweenConditionTest("c1", c1, l1, l2, l3, "1 BETWEEN 5 AND 10", null, false); - BetweenCondition c2 = new BetweenCondition(l3, l1, l2); - betweenConditionTest("c2", c2, l3, l1, l2, "10 BETWEEN 1 AND 5", c1, false); - BetweenCondition c3 = new BetweenCondition(l1, l2, l3); - betweenConditionTest("c3", c3, l1, l2, l3, "1 BETWEEN 5 AND 10", c1, true); - BetweenCondition c4 = new BetweenCondition(l1, l3, l2); - betweenConditionTest("c4", c4, l1, l3, l2, "1 BETWEEN 10 AND 5", c1, false); - BetweenCondition c5 = new BetweenCondition(l1, l2, l1); - betweenConditionTest("c5", c5, l1, l2, l1, "1 BETWEEN 5 AND 1", c1, false); - } - - private static void booleanConditionTest(String label, BooleanCondition c, Value left, String op, Value right, String s, BooleanCondition o, boolean matches) { - assertEquals(label + ":left", left, c.getLeft()); - assertEquals(label + ":op", op, c.getOp()); - assertEquals(label + ":right", right, c.getRight()); - basicTest(label, BooleanCondition.class, c, s, o, matches); - } - - public void testBooleanCondition() { - BooleanCondition c1 = new BooleanCondition(l1, "=", l2); - booleanConditionTest("c1", c1, l1, "=", l2, "1 = 5", null, false); - BooleanCondition c2 = new BooleanCondition(l1, "=", l3); - booleanConditionTest("c2", c2, l1, "=", l3, "1 = 10", c1, false); - BooleanCondition c3 = new BooleanCondition(l1, "<", l2); - booleanConditionTest("c3", c3, l1, "<", l2, "1 < 5", c1, false); - BooleanCondition c4 = new BooleanCondition(l2, ">", l3); - booleanConditionTest("c4", c4, l2, ">", l3, "5 > 10", c1, false); - BooleanCondition c5 = new BooleanCondition(l1, "=", l2); - booleanConditionTest("c5", c5, l1, "=", l2, "1 = 5", c1, true); - } - - private static void conditionListTest(String label, ConditionList c, Joiner joiner, List conditions, String s, ConditionList o, boolean matches) { - assertEquals(label + ":joiner", joiner, c.getJoiner()); - basicTest(label, ConditionList.class, c, s, o, matches); - BooleanCondition b = new BooleanCondition(l1, "=", l3); - c.add(b); - assertEqualsIterable(label + ":iterable", conditions, Collections.emptyList(), false, c, list(b), true); - } - - public void testConditionList() { - BooleanCondition b1 = new BooleanCondition(l1, "=", l2); - BooleanCondition b2 = new BooleanCondition(l2, "=", l3); - ConditionList c1 = new ConditionList(Joiner.AND, GenericTestCaseBase.list(b1)); - conditionListTest("c1", c1, Joiner.AND, list(b1), "( 1 = 5 )", null, false); - ConditionList c2 = new ConditionList(Joiner.AND, GenericTestCaseBase.list(b1, b2)); - conditionListTest("c2", c2, Joiner.AND, list(b1, b2), "( 1 = 5 AND 5 = 10 )", c1, false); - ConditionList c3 = new ConditionList(Joiner.OR, GenericTestCaseBase.list(b2, b1)); - conditionListTest("c3", c3, Joiner.OR, list(b2, b1), "( 5 = 10 OR 1 = 5 )", c1, false); - ConditionList c4 = new ConditionList(Joiner.AND, GenericTestCaseBase.list(b1)); - conditionListTest("c4", c4, Joiner.AND, list(b1), "( 1 = 5 )", c1, true); - } - - private static void listConditionTest(String label, ListCondition c, Value left, String op, List values, String s, ListCondition o, boolean matches) { - assertEquals(label + ":left", left, c.getLeft()); - assertEquals(label + ":op", op, c.getOp()); - assertEquals(label + ":right", values, c.getValues()); - basicTest(label, ListCondition.class, c, s, o, matches); - } - - @SuppressWarnings("unchecked") - public void testListCondition() { - ListCondition c1 = new ListCondition(l1, "IN", GenericTestCaseBase.list(l2)); - listConditionTest("c1", c1, l1, "in", list(l2), "1 in (5)", null, false); - ListCondition c2 = new ListCondition(l1, "NOT IN", GenericTestCaseBase.list(l2)); - listConditionTest("c2", c2, l1, "not in", list(l2), "1 not in (5)", c1, false); - ListCondition c3 = new ListCondition(l2, "IN", GenericTestCaseBase.list(l3)); - listConditionTest("c3", c3, l2, "in", list(l3), "5 in (10)", c1, false); - ListCondition c4 = new ListCondition(l1, "IN", GenericTestCaseBase.list(l2, l3)); - listConditionTest("c4", c4, l1, "in", list(l2, l3), "1 in (5, 10)", c1, false); - ListCondition c5 = new ListCondition(l1, "IN", GenericTestCaseBase.list(l2)); - listConditionTest("c5", c5, l1, "in", list(l2), "1 in (5)", c1, true); - } - - public static class ConditionVisitorRecorder extends Recorder> implements Condition.Visitor { - public void visit(BetweenCondition condition) { - record(BetweenCondition.class); - } - - public void visit(BooleanCondition condition) { - record(BooleanCondition.class); - } - - public void visit(ConditionList condition) { - record(ConditionList.class); - } - - public void visit(ListCondition condition) { - record(ListCondition.class); - } - } -} diff --git a/framework/sql/src/org/ofbiz/sql/test/GoodParseAll.sql b/framework/sql/src/org/ofbiz/sql/test/GoodParseAll.sql deleted file mode 100644 index 1379255afd..0000000000 --- a/framework/sql/src/org/ofbiz/sql/test/GoodParseAll.sql +++ /dev/null @@ -1,74 +0,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. - */ - -SELECT - a.*, - b.* EXCLUDE (partyId, partyId), - c.* EXCLUDE (partyId), - d.roleTypeId, - d.description AS roleDescription, - SUM(a.partyId), - FOO(a.partyId, 1) AS baz, - (a.partyId || '-' || a.partyTypeId) AS one, - COUNT(a.partyId) AS cnt1, - COUNT(partyId) AS cnt2, - COUNT(DISTINCT a.partyId) AS cnt3 -FROM - Party a LEFT JOIN Person b USING partyId - LEFT JOIN PartyGroup c ON b.partyId = c.partyId - JOIN PartyRole d ON c.partyId = d.partyId AND c.partyId = d.partyId -WHERE - a.partyTypeId = 'PERSON' - AND - b.lastName LIKE ?lastName - AND - b.birthDate BETWEEN '1974-12-01' AND '1974-12-31' - OR - ( - b.partyId IN ('1', '2', '3', '4') - AND - b.gender = 'M' - ) - -HAVING - b.firstName LIKE '%foo%' -RELATION TYPE one TITLE MainA Person MAP partyId -RELATION TITLE MainB Person MAP partyId -RELATION TYPE one Person MAP partyId -RELATION PartyGroup MAP partyId -ORDER BY - LOWER(lastName), firstName, -birthDate -OFFSET 5 -LIMIT 10 -; - -INSERT INTO Party (partyId, partyTypeId, statusId) VALUES - ('a', 'PERSON', 'PARTY_DISABLED'), - (5, 'PARTY_GROUP', ?name); -INSERT INTO Person (partyId, firstName) SELECT partyId, (partyId || '-auto') AS firstName FROM Party WHERE partyId IN ('a', 'b'); -UPDATE Person SET (lastName) = (('auto-' || partyId)) WHERE partyId IN ('a', 'b'); -UPDATE Person SET (lastName, height, width) = (('auto-' || partyId), 5, 7) WHERE partyId IN ('a', 'b'); -UPDATE Person SET lastName = ('auto-' || partyId), height = 6, width = 5, nickname = 'a' WHERE partyId IN ('a', 'b'); -DELETE FROM Person WHERE partyId IN ('a', 'b'); -DELETE FROM Party WHERE partyId IN ('a', 'b'); -CREATE VIEW viewOne AS SELECT a.* FROM Party a; -CREATE INDEX testIndex ON Party USING btree (partyId); -/* -UPDATE Person SET firstName = partyId || '-auto' WHERE partyId IN ('a', 'b'); -*/ diff --git a/framework/sql/src/org/ofbiz/sql/test/Recorder.java b/framework/sql/src/org/ofbiz/sql/test/Recorder.java deleted file mode 100644 index 83f6cace06..0000000000 --- a/framework/sql/src/org/ofbiz/sql/test/Recorder.java +++ /dev/null @@ -1,36 +0,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. - */ - -package org.ofbiz.sql.test; - -import java.util.HashMap; -import java.util.Map; - -public abstract class Recorder { - public Map counts = new HashMap(); - - protected void record(I key) { - Integer count = counts.get(key); - if (count == null) { - counts.put(key, Integer.valueOf(1)); - } else { - counts.put(key, Integer.valueOf(count.intValue() + 1)); - } - } -} diff --git a/framework/sql/src/org/ofbiz/sql/test/SelectTest.java b/framework/sql/src/org/ofbiz/sql/test/SelectTest.java deleted file mode 100644 index f5480b39a8..0000000000 --- a/framework/sql/src/org/ofbiz/sql/test/SelectTest.java +++ /dev/null @@ -1,116 +0,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. - */ -package org.ofbiz.sql.test; - -import java.util.Collections; -import java.util.Set; - -import org.ofbiz.base.lang.SourceMonitored; -import org.ofbiz.base.test.GenericTestCaseBase; -import org.ofbiz.sql.ConstantValue; -import org.ofbiz.sql.FieldAll; -import org.ofbiz.sql.FieldDef; -import org.ofbiz.sql.FieldValue; -import org.ofbiz.sql.FunctionCall; -import org.ofbiz.sql.OrderByItem; -import org.ofbiz.sql.StaticValue; -import org.ofbiz.sql.Value; - -@SourceMonitored -public class SelectTest extends GenericTestCaseBase { - private static final FieldValue fv1 = new FieldValue("partyId"); - private static final FieldValue fv4 = new FieldValue(null, "firstName"); - private static final FunctionCall fc1 = new FunctionCall("LOWER", GenericTestCaseBase.list(fv1)); - - public SelectTest(String name) { - super(name); - } - - private static void basicTest(String label, Class clz, V v, V o, boolean matches) { - assertNotEquals(label + ":not-equals-this", v, SelectTest.class); - if (o != null) { - if (matches) { - assertEquals(label + ":equals", o, v); - } else { - assertNotEquals(label + ":not-equals", o, v); - } - } - } - - private static void fieldAllTest(String label, FieldAll v, String alias, Set exclude, FieldAll o, boolean matches) throws Exception { - assertEquals(label + ":alias", alias, v.getAlias()); - assertEquals(label + ":exclude", exclude, set(v)); - basicTest(label, FieldAll.class, v, o, matches); - } - - public void testFieldAll() throws Exception { - FieldAll v1 = new FieldAll("a", set("a", "b")); - fieldAllTest("v1", v1, "a", set("a", "b"), null, false); - FieldAll v2 = new FieldAll("b", set("a", "b")); - fieldAllTest("v2", v2, "b", set("a", "b"), v1, false); - FieldAll v3 = new FieldAll("a", set("b", "c")); - fieldAllTest("v3", v3, "a", set("b", "c"), v1, false); - FieldAll v4 = new FieldAll("a", Collections.emptySet()); - fieldAllTest("v4", v4, "a", Collections.emptySet(), v1, false); - FieldAll v5 = new FieldAll("a", set("b", "a")); - fieldAllTest("v5", v5, "a", set("b", "a"), v1, true); - } - - private static void fieldDefTest(String label, FieldDef v, StaticValue value, String alias, String defaultName, FieldDef o, boolean matches) throws Exception { - assertEquals(label + ":value", value, v.getValue()); - assertEquals(label + ":alias", alias, v.getAlias()); - assertEquals(label + ":default-name", defaultName, v.getDefaultName()); - basicTest(label, FieldDef.class, v, o, matches); - } - - public void testFieldDef() throws Exception { - FieldDef v1 = new FieldDef(fv1, null); - fieldDefTest("v1", v1, fv1, null, "partyId", null, false); - FieldDef v2 = new FieldDef(fv1, "partyId"); - fieldDefTest("v2", v2, fv1, "partyId", "partyId", v1, false); - FieldDef v3 = new FieldDef(fv4, null); - fieldDefTest("v3", v3, fv4, null, "firstName", v1, false); - FieldDef v4 = new FieldDef(fv4, "partyId"); - fieldDefTest("v4", v4, fv4, "partyId", "partyId", v1, false); - FieldDef v5 = new FieldDef(fv1, null); - fieldDefTest("v5", v5, fv1, null, "partyId", v1, true); - } - - private static void orderByItemTest(String label, OrderByItem v, OrderByItem.Order order, OrderByItem.Nulls nulls, ConstantValue value, OrderByItem o, boolean matches) throws Exception { - assertEquals(label + ":order", order, v.getOrder()); - assertEquals(label + ":nulls", nulls, v.getNulls()); - assertEquals(label + ":value", value, v.getValue()); - basicTest(label, OrderByItem.class, v, o, matches); - } - - public void testOrderByItem() throws Exception { - OrderByItem v1 = new OrderByItem(OrderByItem.Order.DEFAULT, OrderByItem.Nulls.DEFAULT, fv1); - orderByItemTest("v1", v1, OrderByItem.Order.DEFAULT, OrderByItem.Nulls.DEFAULT, fv1, null, false); - OrderByItem v2 = new OrderByItem(OrderByItem.Order.ASCENDING, OrderByItem.Nulls.FIRST, fv1); - orderByItemTest("v3", v2, OrderByItem.Order.ASCENDING, OrderByItem.Nulls.FIRST, fv1, v1, false); - OrderByItem v3 = new OrderByItem(OrderByItem.Order.DESCENDING, OrderByItem.Nulls.LAST, fv1); - orderByItemTest("v2", v3, OrderByItem.Order.DESCENDING, OrderByItem.Nulls.LAST, fv1, v1, false); - OrderByItem v4 = new OrderByItem(OrderByItem.Order.DEFAULT, OrderByItem.Nulls.DEFAULT, fc1); - orderByItemTest("v4", v4, OrderByItem.Order.DEFAULT, OrderByItem.Nulls.DEFAULT, fc1, v1, false); - OrderByItem v5 = new OrderByItem(OrderByItem.Order.DEFAULT, OrderByItem.Nulls.DEFAULT, fv4); - orderByItemTest("v5", v5, OrderByItem.Order.DEFAULT, OrderByItem.Nulls.DEFAULT, fv4, v1, false); - OrderByItem v6 = new OrderByItem(OrderByItem.Order.DEFAULT, OrderByItem.Nulls.LAST, fv4); - orderByItemTest("v6", v6, OrderByItem.Order.DEFAULT, OrderByItem.Nulls.LAST, fv4, v1, false); - } -} diff --git a/framework/sql/src/org/ofbiz/sql/test/TestSelect.sql b/framework/sql/src/org/ofbiz/sql/test/TestSelect.sql deleted file mode 100644 index f326d657f9..0000000000 --- a/framework/sql/src/org/ofbiz/sql/test/TestSelect.sql +++ /dev/null @@ -1,44 +0,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. - */ - -SELECT - a.*, - b.firstName, - b.lastName -FROM - Party a JOIN Person b ON a.partyId = b.partyId -WHERE - a.partyTypeId = 'PERSON' - AND - b.lastName LIKE ?lastName -HAVING - b.firstName LIKE '%foo%' -OFFSET 5 -LIMIT 10 -; -SELECT - a.partyTypeId, - COUNT(a.partyId) AS count -FROM - Party a LEFT JOIN Person b USING partyId - LEFT JOIN PartyGroup c USING partyId -GROUP BY - partyTypeId -; - diff --git a/framework/sql/src/org/ofbiz/sql/test/ValuesTest.java b/framework/sql/src/org/ofbiz/sql/test/ValuesTest.java deleted file mode 100644 index 5f2846f5b1..0000000000 --- a/framework/sql/src/org/ofbiz/sql/test/ValuesTest.java +++ /dev/null @@ -1,239 +0,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. - */ -package org.ofbiz.sql.test; - -import java.util.List; -import org.ofbiz.sql.ConstantValue; -import org.ofbiz.sql.CountAllFunction; -import org.ofbiz.sql.AggregateFunction; -import org.ofbiz.sql.FieldValue; -import org.ofbiz.sql.FunctionCall; -import org.ofbiz.sql.MathValue; -import org.ofbiz.sql.NumberValue; -import org.ofbiz.sql.ParameterValue; -import org.ofbiz.sql.StaticValue; -import org.ofbiz.sql.StringValue; -import org.ofbiz.sql.Value; - -import org.ofbiz.base.lang.SourceMonitored; -import org.ofbiz.base.test.GenericTestCaseBase; - -@SourceMonitored -public class ValuesTest extends GenericTestCaseBase { - private static final FieldValue fv1 = new FieldValue("partyId"); - private static final FieldValue fv2 = new FieldValue("a", "partyId"); - private static final FieldValue fv3 = new FieldValue(null, "partyId"); - private static final FieldValue fv4 = new FieldValue(null, "firstName"); - private static final NumberValue nv1 = NumberValue.valueOf(1); - private static final NumberValue nv2 = NumberValue.valueOf(2D); - private static final NumberValue nv3 = NumberValue.valueOf(3); - - public ValuesTest(String name) { - super(name); - } - - private static void basicTest(String label, Class clz, V v, String defaultName, String s, V o, boolean matches) { - if (v instanceof StaticValue) { - assertEquals(label + ":default-name", defaultName, ((StaticValue) v).getDefaultName()); - } - assertEquals(label + ":toString", s, v.toString()); - assertNotEquals(label + ":not-equals-this", v, ValuesTest.class); - if (o != null) { - if (matches) { - assertEquals(label + ":equals", o, v); - } else { - assertNotEquals(label + ":not-equals", o, v); - } - } - ValueVisitorRecorder visitor = new ValueVisitorRecorder(); - v.accept(visitor); - v.accept(visitor); - assertEquals(label + ":visited", 2, visitor.counts.remove(clz).intValue()); - assertTrue(label + ":nothing-else-visited", visitor.counts.isEmpty()); - } - - private static void countAllFunctionTest(String label, CountAllFunction v, String tableName, String s, CountAllFunction o, boolean matches) { - assertEquals(label + ":left", tableName, v.getTableName()); - basicTest(label, CountAllFunction.class, v, "COUNT", s, o, matches); - } - - public void testCountAllFunction() { - CountAllFunction v1 = new CountAllFunction("a"); - countAllFunctionTest("v1", v1, "a", "COUNT(a.*)", null, false); - CountAllFunction v2 = new CountAllFunction(null); - countAllFunctionTest("v2", v2, null, "COUNT(*)", v1, false); - CountAllFunction v3 = new CountAllFunction("a"); - countAllFunctionTest("v3", v3, "a", "COUNT(a.*)", v1, true); - } - - private static void aggregateFunctionTest(String label, AggregateFunction v, String name, boolean isDistinct, FieldValue fv, String s, AggregateFunction o, boolean matches) { - assertEquals(label + ":name", name, v.getName()); - assertEquals(label + ":left", isDistinct, v.isDistinct()); - assertEquals(label + ":field-value", fv, v.getValue()); - basicTest(label, AggregateFunction.class, v, name, s, o, matches); - } - - public void testAggregateFunction() { - AggregateFunction v1 = new AggregateFunction("COUNT", false, fv2); - aggregateFunctionTest("v1", v1, "COUNT", false, fv2, "COUNT(a.partyId)", null, false); - AggregateFunction v2 = new AggregateFunction("COUNT", true, fv2); - aggregateFunctionTest("v2", v2, "COUNT", true, fv2, "COUNT(DISTINCT a.partyId)", v1, false); - AggregateFunction v3 = new AggregateFunction("COUNT", true, fv1); - aggregateFunctionTest("v3", v3, "COUNT", true, fv1, "COUNT(DISTINCT partyId)", v1, false); - AggregateFunction v4 = new AggregateFunction("COUNT", false, fv1); - aggregateFunctionTest("v4", v4, "COUNT", false, fv1, "COUNT(partyId)", v1, false); - AggregateFunction v5 = new AggregateFunction("MAX", false, fv2); - aggregateFunctionTest("v5", v5, "MAX", false, fv2, "MAX(a.partyId)", v1, false); - AggregateFunction v6 = new AggregateFunction("COUNT", false, fv2); - aggregateFunctionTest("v6", v6, "COUNT", false, fv2, "COUNT(a.partyId)", v1, true); - } - - private static void fieldValueTest(String label, FieldValue v, String tableName, String fieldName, String s, FieldValue o, boolean matches) { - assertEquals(label + ":table-name", tableName, v.getTableName()); - assertEquals(label + ":field-name", fieldName, v.getFieldName()); - basicTest(label, FieldValue.class, v, fieldName, s, o, matches); - } - - public void testFieldValue() { - fieldValueTest("fv1", fv1, null, "partyId", "partyId", null, false); - fieldValueTest("fv2", fv2, "a", "partyId", "a.partyId", fv1, false); - fieldValueTest("fv3", fv3, null, "partyId", "partyId", fv1, true); - fieldValueTest("fv4", fv4, null, "firstName", "firstName", fv1, false); - } - - private static void functionCallTest(String label, FunctionCall v, String name, List values, String s, FunctionCall o, boolean matches) { - assertEquals(label + ":name", name, v.getName()); - assertEquals(label + ":arg-count", values.size(), v.getArgCount()); - assertEqualsIterable(label, values, v); - basicTest(label, FunctionCall.class, v, name, s, o, matches); - } - - @SuppressWarnings("unchecked") - public void testFunctionCall() { - FunctionCall v1 = new FunctionCall("LENGTH", GenericTestCaseBase.list(nv1, nv2)); - functionCallTest("v1", v1, "LENGTH", list(nv1, nv2), "LENGTH(1, 2.0)", null, false); - FunctionCall v2 = new FunctionCall("LENGTH", GenericTestCaseBase.list(nv1, nv3)); - functionCallTest("v2", v2, "LENGTH", list(nv1, nv3), "LENGTH(1, 3)", v1, false); - FunctionCall v3 = new FunctionCall("LENGTH", GenericTestCaseBase.list(nv1, nv2)); - functionCallTest("v3", v3, "LENGTH", list(nv1, nv2), "LENGTH(1, 2.0)", v1, true); - FunctionCall v4 = new FunctionCall("TRIM", GenericTestCaseBase.list(nv1, nv2)); - functionCallTest("v4", v4, "TRIM", list(nv1, nv2), "TRIM(1, 2.0)", v1, false); - } - - private static void mathValueTest(String label, MathValue v, String op, List values, String s, MathValue o, boolean matches) { - assertEquals(label + ":op", op, v.getOp()); - assertEqualsIterable(label, values, v); - basicTest(label, MathValue.class, v, null, s, o, matches); - } - - @SuppressWarnings("unchecked") - public void testMathValue() { - MathValue v1 = new MathValue("+", GenericTestCaseBase.list(nv1, nv2)); - mathValueTest("v1", v1, "+", list(nv1, nv2), "(1 + 2.0)", null, false); - MathValue v2 = new MathValue("+", GenericTestCaseBase.list(nv1, nv3)); - mathValueTest("v2", v2, "+", list(nv1, nv3), "(1 + 3)", v1, false); - MathValue v3 = new MathValue("+", GenericTestCaseBase.list(nv1, nv2)); - mathValueTest("v3", v3, "+", list(nv1, nv2), "(1 + 2.0)", v1, true); - MathValue v4 = new MathValue("-", GenericTestCaseBase.list(nv1, nv3)); - mathValueTest("v4", v4, "-", list(nv1, nv3), "(1 - 3)", v1, false); - } - - public void testNull() { - basicTest("null", Value.Null.class, Value.NULL, null, "NULL", null, false); - } - - private static void numberValueTest(String label, NumberValue v, N n, String s, NumberValue o, boolean matches) { - assertEquals(label + ":number", n, v.getNumber()); - basicTest(label, NumberValue.class, v, null, s, o, matches); - } - - public void testNumberValue() { - numberValueTest("nv1", nv1, Long.valueOf(1), "1", null, false); - numberValueTest("nv2", nv2, Double.valueOf(2), "2.0", nv1, false); - NumberValue nv3 = NumberValue.valueOf(1); - numberValueTest("nv3", nv3, Long.valueOf(1), "1", nv1, true); - } - - private static void parameterValueTest(String label, ParameterValue v, String name, String s, ParameterValue o, boolean matches) { - assertEquals(label + ":name", name, v.getName()); - basicTest(label, ParameterValue.class, v, null, s, o, matches); - } - - public void testParameterValue() { - ParameterValue v1 = new ParameterValue("a"); - parameterValueTest("v1", v1, "a", "?a", null, false); - ParameterValue v2 = new ParameterValue("b"); - parameterValueTest("v2", v2, "b", "?b", v1, false); - ParameterValue v3 = new ParameterValue("a"); - parameterValueTest("v3", v3, "a", "?a", v1, true); - } - - private static void stringValueTest(String label, StringValue v, String string, String s, StringValue o, boolean matches) { - assertEquals(label + ":name", string, v.getString()); - basicTest(label, StringValue.class, v, null, s, o, matches); - } - - public void testStringValue() { - StringValue v1 = new StringValue("foo"); - stringValueTest("v1", v1, "foo", "'foo'", null, false); - StringValue v2 = new StringValue("b'r"); - stringValueTest("v2", v2, "b'r", "'b''r'", v1, false); - StringValue v3 = new StringValue("foo"); - stringValueTest("v3", v3, "foo", "'foo'", v1, true); - } - - public static class ValueVisitorRecorder extends Recorder> implements Value.Visitor { - - public void visit(AggregateFunction value) { - record(AggregateFunction.class); - } - - public void visit(FieldValue value) { - record(FieldValue.class); - } - - public void visit(FunctionCall value) { - record(FunctionCall.class); - } - - public void visit(MathValue value) { - record(MathValue.class); - } - - public void visit(Value.Null value) { - record(Value.Null.class); - } - - public void visit(NumberValue value) { - record(NumberValue.class); - } - - public void visit(ParameterValue value) { - record(ParameterValue.class); - } - - public void visit(StringValue value) { - record(StringValue.class); - } - - public void visit(CountAllFunction value) { - record(CountAllFunction.class); - } - } -}