Author: doogie
Date: Wed Oct 17 20:43:26 2007 New Revision: 585835 URL: http://svn.apache.org/viewvc?rev=585835&view=rev Log: Java 1.5 markup for entity condition. Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearch.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityClause.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityComparisonOperator.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityCondition.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionBase.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionFunction.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionList.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionListBase.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionSubSelect.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionValue.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityDateFilterCondition.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityExpr.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFieldMap.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFieldValue.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFunction.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityJoinOperator.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityOperator.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityWhereString.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/OrderByItem.java ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/OrderByList.java Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearch.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearch.java?rev=585835&r1=585834&r2=585835&view=diff ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearch.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearch.java Wed Oct 17 20:43:26 2007 @@ -42,6 +42,7 @@ import org.ofbiz.entity.GenericValue; import org.ofbiz.entity.condition.EntityCondition; import org.ofbiz.entity.condition.EntityConditionList; +import org.ofbiz.entity.condition.EntityConditionParam; import org.ofbiz.entity.condition.EntityConditionSubSelect; import org.ofbiz.entity.condition.EntityConditionValue; import org.ofbiz.entity.condition.EntityExpr; @@ -649,7 +650,7 @@ this.entityConditionList.add(topCond); - Debug.logInfo("topCond=" + topCond.makeWhereString(null, FastList.newInstance(), EntityConfigUtil.getDatasourceInfo(delegator.getEntityHelperName("Product"))), module); + Debug.logInfo("topCond=" + topCond.makeWhereString(null, FastList.<EntityConditionParam>newInstance(), EntityConfigUtil.getDatasourceInfo(delegator.getEntityHelperName("Product"))), module); } public EntityListIterator doQuery(GenericDelegator delegator) { Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityClause.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityClause.java?rev=585835&r1=585834&r2=585835&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityClause.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityClause.java Wed Oct 17 20:43:26 2007 @@ -36,13 +36,13 @@ private String secondField = ""; private ModelEntity firstModelEntity = null; private ModelEntity secondModelEntity = null; - private EntityOperator interFieldOperation = null; - private EntityOperator intraFieldOperation = null; + private EntityOperator<?> interFieldOperation = null; + private EntityOperator<?> intraFieldOperation = null; private Object value = null; public EntityClause() {} - public EntityClause(String firstEntity, String secondEntity, String firstField, String secondField, EntityOperator interFieldOperation, EntityOperator intraFieldOperation) { + public EntityClause(String firstEntity, String secondEntity, String firstField, String secondField, EntityOperator<?> interFieldOperation, EntityOperator<?> intraFieldOperation) { this.firstEntity = firstEntity; this.secondEntity = secondEntity; this.firstField = firstField; @@ -51,7 +51,7 @@ this.intraFieldOperation = intraFieldOperation; } - public EntityClause(String firstEntity, String firstField, Object value, EntityOperator interFieldOperation, EntityOperator intraFieldOperation) { + public EntityClause(String firstEntity, String firstField, Object value, EntityOperator<?> interFieldOperation, EntityOperator<?> intraFieldOperation) { this.firstEntity = firstEntity; this.firstField = firstField; this.value = value; @@ -80,11 +80,11 @@ return value; } - public EntityOperator getInterFieldOperation() { + public EntityOperator<?> getInterFieldOperation() { return interFieldOperation; } - public EntityOperator getIntraFieldOperation() { + public EntityOperator<?> getIntraFieldOperation() { return intraFieldOperation; } @@ -104,11 +104,11 @@ this.secondField = secondField; } - public void setInterFieldOperation(EntityOperator interFieldOperation) { + public void setInterFieldOperation(EntityOperator<?> interFieldOperation) { this.interFieldOperation = interFieldOperation; } - public void setIntraFieldOperation(EntityOperator intraFieldOperation) { + public void setIntraFieldOperation(EntityOperator<?> intraFieldOperation) { this.intraFieldOperation = intraFieldOperation; } Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityComparisonOperator.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityComparisonOperator.java?rev=585835&r1=585834&r2=585835&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityComparisonOperator.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityComparisonOperator.java Wed Oct 17 20:43:26 2007 @@ -41,7 +41,7 @@ /** * Encapsulates operations between entities and entity fields. This is a immutable class. */ -public class EntityComparisonOperator extends EntityOperator { +public class EntityComparisonOperator extends EntityOperator<Boolean> { public static final String module = EntityComparisonOperator.class.getName(); @@ -83,7 +83,7 @@ visitor.accept(rhs); } - public void addSqlValue(StringBuilder sql, ModelEntity entity, List entityConditionParams, boolean compat, Object lhs, Object rhs, DatasourceInfo datasourceInfo) { + public void addSqlValue(StringBuilder sql, ModelEntity entity, List<EntityConditionParam> entityConditionParams, boolean compat, Object lhs, Object rhs, DatasourceInfo datasourceInfo) { //Debug.logInfo("EntityComparisonOperator.addSqlValue field=" + lhs + ", value=" + rhs + ", value type=" + (rhs == null ? "null object" : rhs.getClass().getName()), module); // if this is an IN operator and the rhs Object isEmpty, add "FALSE" instead of the normal SQL @@ -112,12 +112,12 @@ makeRHSWhereString(entity, entityConditionParams, sql, field, rhs, datasourceInfo); } - protected void makeRHSWhereString(ModelEntity entity, List entityConditionParams, StringBuilder sql, ModelField field, Object rhs, DatasourceInfo datasourceInfo) { + protected void makeRHSWhereString(ModelEntity entity, List<EntityConditionParam> entityConditionParams, StringBuilder sql, ModelField field, Object rhs, DatasourceInfo datasourceInfo) { sql.append(' ').append(getCode()).append(' '); makeRHSWhereStringValue(entity, entityConditionParams, sql, field, rhs, datasourceInfo); } - protected void makeRHSWhereStringValue(ModelEntity entity, List entityConditionParams, StringBuilder sql, ModelField field, Object rhs, DatasourceInfo datasourceInfo) { + protected void makeRHSWhereStringValue(ModelEntity entity, List<EntityConditionParam> entityConditionParams, StringBuilder sql, ModelField field, Object rhs, DatasourceInfo datasourceInfo) { if (rhs instanceof EntityConditionValue) { EntityConditionValue ecv = (EntityConditionValue) rhs; ecv.addSqlValue(sql, entity, entityConditionParams, false, datasourceInfo); @@ -130,11 +130,11 @@ throw new UnsupportedOperationException(codeString); } - public Object eval(GenericDelegator delegator, Map map, Object lhs, Object rhs) { + public Boolean eval(GenericDelegator delegator, Map<String, ? extends Object> map, Object lhs, Object rhs) { return mapMatches(delegator, map, lhs, rhs) ? Boolean.TRUE : Boolean.FALSE; } - public boolean mapMatches(GenericDelegator delegator, Map map, Object lhs, Object rhs) { + public boolean mapMatches(GenericDelegator delegator, Map<String, ? extends Object> map, Object lhs, Object rhs) { Object leftValue; if (lhs instanceof EntityConditionValue) { EntityConditionValue ecv = (EntityConditionValue) lhs; @@ -173,7 +173,7 @@ super(id, code); } - public static final boolean compareEqual(Object lhs, Object rhs) { + public static final boolean compareEqual(Comparable lhs, Object rhs) { if (lhs == null) { if (rhs != null) { return false; @@ -184,7 +184,7 @@ return true; } - public static final boolean compareNotEqual(Object lhs, Object rhs) { + public static final boolean compareNotEqual(Comparable lhs, Object rhs) { if (lhs == null) { if (rhs == null) { return false; @@ -195,45 +195,45 @@ return true; } - public static final boolean compareGreaterThan(Object lhs, Object rhs) { + public static final boolean compareGreaterThan(Comparable lhs, Object rhs) { if (lhs == null) { if (rhs != null) { return false; } - } else if (((Comparable) lhs).compareTo(rhs) <= 0) { + } else if (lhs.compareTo(rhs) <= 0) { return false; } return true; } - public static final boolean compareGreaterThanEqualTo(Object lhs, Object rhs) { + public static final boolean compareGreaterThanEqualTo(Comparable lhs, Object rhs) { if (lhs == null) { if (rhs != null) { return false; } - } else if (((Comparable) lhs).compareTo(rhs) < 0) { + } else if (lhs.compareTo(rhs) < 0) { return false; } return true; } - public static final boolean compareLessThan(Object lhs, Object rhs) { + public static final boolean compareLessThan(Comparable lhs, Object rhs) { if (lhs == null) { if (rhs != null) { return false; } - } else if (((Comparable) lhs).compareTo(rhs) >= 0) { + } else if (lhs.compareTo(rhs) >= 0) { return false; } return true; } - public static final boolean compareLessThanEqualTo(Object lhs, Object rhs) { + public static final boolean compareLessThanEqualTo(Comparable lhs, Object rhs) { if (lhs == null) { if (rhs != null) { return false; } - } else if (((Comparable) lhs).compareTo(rhs) > 0) { + } else if (lhs.compareTo(rhs) > 0) { return false; } return true; Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityCondition.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityCondition.java?rev=585835&r1=585834&r2=585835&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityCondition.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityCondition.java Wed Oct 17 20:43:26 2007 @@ -44,14 +44,14 @@ public abstract class EntityCondition extends EntityConditionBase { public String toString() { - return makeWhereString(null, FastList.newInstance(), null); + return makeWhereString(null, FastList.<EntityConditionParam>newInstance(), null); } public void accept(EntityConditionVisitor visitor) { throw new IllegalArgumentException(getClass().getName() + ".accept not implemented"); } - abstract public String makeWhereString(ModelEntity modelEntity, List entityConditionParams, DatasourceInfo datasourceInfo); + abstract public String makeWhereString(ModelEntity modelEntity, List<EntityConditionParam> entityConditionParams, DatasourceInfo datasourceInfo); abstract public void checkCondition(ModelEntity modelEntity) throws GenericModelException; @@ -59,15 +59,15 @@ return mapMatches(entity.getDelegator(), entity); } - public Object eval(GenericEntity entity) { + public Boolean eval(GenericEntity entity) { return eval(entity.getDelegator(), entity); } - public Object eval(GenericDelegator delegator, Map map) { + public Boolean eval(GenericDelegator delegator, Map<String, ? extends Object> map) { return mapMatches(delegator, map) ? Boolean.TRUE : Boolean.FALSE; } - abstract public boolean mapMatches(GenericDelegator delegator, Map map); + abstract public boolean mapMatches(GenericDelegator delegator, Map<String, ? extends Object> map); abstract public EntityCondition freeze(); Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionBase.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionBase.java?rev=585835&r1=585834&r2=585835&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionBase.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionBase.java Wed Oct 17 20:43:26 2007 @@ -46,6 +46,10 @@ */ public abstract class EntityConditionBase implements Serializable { + public static final List emptyList = Collections.unmodifiableList(FastList.newInstance()); + public static final Map _emptyMap = Collections.unmodifiableMap(FastMap.newInstance()); + public static final Map<String, String> emptyAliases = Collections.unmodifiableMap(FastMap.<String, String>newInstance()); + protected ModelField getField(ModelEntity modelEntity, String fieldName) { ModelField modelField = null; if (modelEntity != null) { @@ -54,7 +58,7 @@ return modelField; } - protected String getColName(Map tableAliases, ModelEntity modelEntity, String fieldName, boolean includeTableNamePrefix, DatasourceInfo datasourceInfo) { + protected String getColName(Map<String, String> tableAliases, ModelEntity modelEntity, String fieldName, boolean includeTableNamePrefix, DatasourceInfo datasourceInfo) { if (modelEntity == null) return fieldName; return getColName(tableAliases, modelEntity, getField(modelEntity, fieldName), fieldName, includeTableNamePrefix, datasourceInfo); } @@ -69,7 +73,7 @@ return colName; } - protected String getColName(Map tableAliases, ModelEntity modelEntity, ModelField modelField, String fieldName, boolean includeTableNamePrefix, DatasourceInfo datasourceInfo) { + protected String getColName(Map<String, String> tableAliases, ModelEntity modelEntity, ModelField modelField, String fieldName, boolean includeTableNamePrefix, DatasourceInfo datasourceInfo) { if (modelEntity == null || modelField == null) return fieldName; // if this is a view entity and we are configured to alias the views, use the alias here instead of the composite (ie table.column) field name @@ -85,14 +89,14 @@ if (includeTableNamePrefix && datasourceInfo != null) { String tableName = modelEntity.getTableName(datasourceInfo); if (tableAliases.containsKey(tableName)) { - tableName = (String) tableAliases.get(tableName); + tableName = tableAliases.get(tableName); } colName = tableName + "." + colName; } return colName; } - protected void addValue(StringBuilder buffer, ModelField field, Object value, List params) { + protected void addValue(StringBuilder buffer, ModelField field, Object value, List<EntityConditionParam> params) { SqlJdbcUtil.addValue(buffer, params == null ? null : field, value, params); } Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionFunction.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionFunction.java?rev=585835&r1=585834&r2=585835&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionFunction.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionFunction.java Wed Oct 17 20:43:26 2007 @@ -37,7 +37,7 @@ public static class NOT extends EntityConditionFunction { public NOT(EntityCondition nested) { super(ID_NOT, "NOT", nested); } - public boolean mapMatches(GenericDelegator delegator, Map map) { + public boolean mapMatches(GenericDelegator delegator, Map<String, ? extends Object> map) { return !condition.mapMatches(delegator, map); } public EntityCondition freeze() { @@ -85,7 +85,7 @@ return idInt ^ condition.hashCode(); } - public String makeWhereString(ModelEntity modelEntity, List entityConditionParams, DatasourceInfo datasourceInfo) { + public String makeWhereString(ModelEntity modelEntity, List<EntityConditionParam> entityConditionParams, DatasourceInfo datasourceInfo) { StringBuilder sb = new StringBuilder(); sb.append(codeString).append('('); sb.append(condition.makeWhereString(modelEntity, entityConditionParams, datasourceInfo)); Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionList.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionList.java?rev=585835&r1=585834&r2=585835&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionList.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionList.java Wed Oct 17 20:43:26 2007 @@ -25,18 +25,18 @@ * Encapsulates a list of EntityConditions to be used as a single EntityCondition combined as specified * */ -public class EntityConditionList extends EntityConditionListBase { +public class EntityConditionList<T extends EntityCondition> extends EntityConditionListBase<T> { public static final String module = EntityConditionList.class.getName(); protected EntityConditionList() { super(); } - public EntityConditionList(EntityJoinOperator operator, EntityCondition... conditionList) { + public EntityConditionList(EntityJoinOperator operator, T... conditionList) { super(operator, conditionList); } - public EntityConditionList(List conditionList, EntityJoinOperator operator) { + public EntityConditionList(List<T> conditionList, EntityJoinOperator operator) { super(conditionList, operator); } @@ -44,7 +44,7 @@ return super.getConditionListSize(); } - public Iterator getConditionIterator() { + public Iterator<T> getConditionIterator() { return super.getConditionIterator(); } Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionListBase.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionListBase.java?rev=585835&r1=585834&r2=585835&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionListBase.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionListBase.java Wed Oct 17 20:43:26 2007 @@ -32,20 +32,20 @@ * Encapsulates a list of EntityConditions to be used as a single EntityCondition combined as specified * */ -public abstract class EntityConditionListBase extends EntityCondition { +public abstract class EntityConditionListBase<T extends EntityCondition> extends EntityCondition { public static final String module = EntityConditionListBase.class.getName(); - protected List conditionList; + protected List<T> conditionList; protected EntityJoinOperator operator; protected EntityConditionListBase() {} - public EntityConditionListBase(EntityJoinOperator operator, EntityCondition... conditionList) { + public EntityConditionListBase(EntityJoinOperator operator, T... conditionList) { this.conditionList = Arrays.asList(conditionList); this.operator = operator; } - public EntityConditionListBase(List conditionList, EntityJoinOperator operator) { + public EntityConditionListBase(List<T> conditionList, EntityJoinOperator operator) { this.conditionList = conditionList; this.operator = operator; } @@ -54,15 +54,15 @@ return this.operator; } - public EntityCondition getCondition(int index) { - return (EntityCondition) this.conditionList.get(index); + public T getCondition(int index) { + return this.conditionList.get(index); } protected int getConditionListSize() { return this.conditionList.size(); } - protected Iterator getConditionIterator() { + protected Iterator<T> getConditionIterator() { return this.conditionList.iterator(); } @@ -70,7 +70,7 @@ visitor.acceptEntityJoinOperator(operator, conditionList); } - public String makeWhereString(ModelEntity modelEntity, List entityConditionParams, DatasourceInfo datasourceInfo) { + public String makeWhereString(ModelEntity modelEntity, List<EntityConditionParam> entityConditionParams, DatasourceInfo datasourceInfo) { // if (Debug.verboseOn()) Debug.logVerbose("makeWhereString for entity " + modelEntity.getEntityName(), module); StringBuilder sql = new StringBuilder(); operator.addSqlValue(sql, modelEntity, entityConditionParams, conditionList, datasourceInfo); @@ -82,7 +82,7 @@ operator.validateSql(modelEntity, conditionList); } - public boolean mapMatches(GenericDelegator delegator, Map map) { + public boolean mapMatches(GenericDelegator delegator, Map<String, ? extends Object> map) { return operator.mapMatches(delegator, map, conditionList); } @@ -91,9 +91,7 @@ } public void encryptConditionFields(ModelEntity modelEntity, GenericDelegator delegator) { - Iterator conditionIter = this.conditionList.iterator(); - while (conditionIter.hasNext()) { - EntityCondition cond = (EntityCondition) conditionIter.next(); + for (T cond: this.conditionList) { cond.encryptConditionFields(modelEntity, delegator); } } Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionSubSelect.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionSubSelect.java?rev=585835&r1=585834&r2=585835&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionSubSelect.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionSubSelect.java Wed Oct 17 20:43:26 2007 @@ -51,7 +51,7 @@ this.requireAll = requireAll; } - public void addSqlValue(StringBuilder sql, Map tableAliases, ModelEntity parentModelEntity, List entityConditionParams, + public void addSqlValue(StringBuilder sql, Map<String, String> tableAliases, ModelEntity parentModelEntity, List<EntityConditionParam> entityConditionParams, boolean includeTableNamePrefix, DatasourceInfo datasourceInfo) { if (localModelEntity instanceof ModelViewEntity && datasourceInfo == null) { throw new IllegalArgumentException("Call to EntityConditionSubSelect.addSqlValue with datasourceInfo=null which is not allowed because the local entity [" + this.localModelEntity.getEntityName() + "] is a view entity"); @@ -114,7 +114,7 @@ return null; } - public Object getValue(GenericDelegator delegator, Map map) { + public Comparable getValue(GenericDelegator delegator, Map<String, ? extends Object> map) { // do nothing for now return null; } Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionValue.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionValue.java?rev=585835&r1=585834&r2=585835&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionValue.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionValue.java Wed Oct 17 20:43:26 2007 @@ -19,7 +19,6 @@ package org.ofbiz.entity.condition; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Map; @@ -38,12 +37,12 @@ public abstract ModelField getModelField(ModelEntity modelEntity); - public void addSqlValue(StringBuilder sql, ModelEntity modelEntity, List entityConditionParams, boolean includeTableNamePrefix, + public void addSqlValue(StringBuilder sql, ModelEntity modelEntity, List<EntityConditionParam> entityConditionParams, boolean includeTableNamePrefix, DatasourceInfo datasourceinfo) { - addSqlValue(sql, Collections.emptyMap(), modelEntity, entityConditionParams, includeTableNamePrefix, datasourceinfo); + addSqlValue(sql, emptyAliases, modelEntity, entityConditionParams, includeTableNamePrefix, datasourceinfo); } - public abstract void addSqlValue(StringBuilder sql, Map tableAliases, ModelEntity modelEntity, List entityConditionParams, + public abstract void addSqlValue(StringBuilder sql, Map<String, String> tableAliases, ModelEntity modelEntity, List<EntityConditionParam> entityConditionParams, boolean includeTableNamePrefix, DatasourceInfo datasourceinfo); public abstract void validateSql(ModelEntity modelEntity) throws GenericModelException; @@ -55,7 +54,7 @@ return getValue(entity.getDelegator(), entity); } - public abstract Object getValue(GenericDelegator delegator, Map map); + public abstract Object getValue(GenericDelegator delegator, Map<String, ? extends Object> map); public abstract EntityConditionValue freeze(); @@ -66,7 +65,7 @@ } public void toString(StringBuilder sb) { - addSqlValue(sb, null, new ArrayList(), false, null); + addSqlValue(sb, null, new ArrayList<EntityConditionParam>(), false, null); } public String toString() { Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityDateFilterCondition.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityDateFilterCondition.java?rev=585835&r1=585834&r2=585835&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityDateFilterCondition.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityDateFilterCondition.java Wed Oct 17 20:43:26 2007 @@ -38,7 +38,7 @@ this.thruDateName = thruDateName; } - public String makeWhereString(ModelEntity modelEntity, List entityConditionParams, DatasourceInfo datasourceInfo) { + public String makeWhereString(ModelEntity modelEntity, List<EntityConditionParam> entityConditionParams, DatasourceInfo datasourceInfo) { EntityCondition condition = makeCondition(); return condition.makeWhereString(modelEntity, entityConditionParams, datasourceInfo); } @@ -48,7 +48,7 @@ condition.checkCondition(modelEntity); } - public boolean mapMatches(GenericDelegator delegator, Map map) { + public boolean mapMatches(GenericDelegator delegator, Map<String, ? extends Object> map) { EntityCondition condition = makeCondition(); return condition.mapMatches(delegator, map); } Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityExpr.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityExpr.java?rev=585835&r1=585834&r2=585835&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityExpr.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityExpr.java Wed Oct 17 20:43:26 2007 @@ -39,7 +39,7 @@ public static final String module = EntityExpr.class.getName(); private Object lhs; - private EntityOperator operator; + private EntityOperator<?> operator; private Object rhs; protected EntityExpr() {} @@ -144,14 +144,14 @@ return rhs; } - public String makeWhereString(ModelEntity modelEntity, List entityConditionParams, DatasourceInfo datasourceInfo) { + public String makeWhereString(ModelEntity modelEntity, List<EntityConditionParam> entityConditionParams, DatasourceInfo datasourceInfo) { // if (Debug.verboseOn()) Debug.logVerbose("makeWhereString for entity " + modelEntity.getEntityName(), module); StringBuilder sql = new StringBuilder(); operator.addSqlValue(sql, modelEntity, entityConditionParams, true, lhs, rhs, datasourceInfo); return sql.toString(); } - public boolean mapMatches(GenericDelegator delegator, Map map) { + public boolean mapMatches(GenericDelegator delegator, Map<String, ? extends Object> map) { return operator.mapMatches(delegator, map, lhs, rhs); } @@ -163,7 +163,7 @@ } } - protected void addValue(StringBuilder buffer, ModelField field, Object value, List params) { + protected void addValue(StringBuilder buffer, ModelField field, Object value, List<EntityConditionParam> params) { if (rhs instanceof EntityFunction.UPPER) { if (value instanceof String) { value = ((String) value).toUpperCase(); Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFieldMap.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFieldMap.java?rev=585835&r1=585834&r2=585835&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFieldMap.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFieldMap.java Wed Oct 17 20:43:26 2007 @@ -25,53 +25,49 @@ import java.util.List; import java.util.Map; -import org.ofbiz.base.util.UtilMisc; +import org.ofbiz.entity.util.EntityUtil; /** * Encapsulates simple expressions used for specifying queries * */ -public class EntityFieldMap extends EntityConditionListBase { +public class EntityFieldMap extends EntityConditionListBase<EntityExpr> { - protected Map fieldMap; + protected Map<String, ? extends Object> fieldMap; protected EntityFieldMap() { super(); } public static List<EntityExpr> makeConditionList(EntityComparisonOperator op, Object... keysValues) { - return makeConditionList(UtilMisc.toMap(keysValues), op); + return makeConditionList(EntityUtil.makeFields(keysValues), op); } - public static List makeConditionList(Map fieldMap, EntityComparisonOperator op) { - if (fieldMap == null) return new ArrayList(); - List list = new ArrayList(fieldMap.size()); - Iterator it = fieldMap.entrySet().iterator(); - while (it.hasNext()) { - Map.Entry entry = (Map.Entry) it.next(); - String field = (String)entry.getKey(); - Object value = entry.getValue(); - list.add(new EntityExpr(field, op, value)); + public static List<EntityExpr> makeConditionList(Map<String, ? extends Object> fieldMap, EntityComparisonOperator op) { + if (fieldMap == null) return new ArrayList<EntityExpr>(); + List<EntityExpr> list = new ArrayList<EntityExpr>(fieldMap.size()); + for (Map.Entry<String, ? extends Object> entry: fieldMap.entrySet()) { + list.add(new EntityExpr(entry.getKey(), op, entry.getValue())); } return list; } public EntityFieldMap(EntityComparisonOperator compOp, EntityJoinOperator joinOp, Object... keysValues) { - this(UtilMisc.toMap(keysValues), compOp, joinOp); + this(EntityUtil.makeFields(keysValues), compOp, joinOp); } - public EntityFieldMap(Map fieldMap, EntityComparisonOperator compOp, EntityJoinOperator joinOp) { + public EntityFieldMap(Map<String, ? extends Object> fieldMap, EntityComparisonOperator compOp, EntityJoinOperator joinOp) { super(makeConditionList(fieldMap, compOp), joinOp); this.fieldMap = fieldMap; - if (this.fieldMap == null) this.fieldMap = new LinkedHashMap(); + if (this.fieldMap == null) this.fieldMap = new LinkedHashMap<String, Object>(); this.operator = joinOp; } - public EntityFieldMap(EntityJoinOperator joinOp, Object... keysValues) { - this(UtilMisc.toMap(keysValues), joinOp); + public EntityFieldMap(EntityJoinOperator operator, Object... keysValues) { + this(EntityOperator.EQUALS, operator, keysValues); } - public EntityFieldMap(Map fieldMap, EntityJoinOperator operator) { + public EntityFieldMap(Map<String, ? extends Object> fieldMap, EntityJoinOperator operator) { this(fieldMap, EntityOperator.EQUALS, operator); } @@ -83,12 +79,12 @@ return this.fieldMap.containsKey(name); } - public Iterator getFieldKeyIterator() { + public Iterator<String> getFieldKeyIterator() { return Collections.unmodifiableSet(this.fieldMap.keySet()).iterator(); } - public Iterator getFieldEntryIterator() { - return Collections.unmodifiableSet(this.fieldMap.entrySet()).iterator(); + public Iterator<Map.Entry<String, Object>> getFieldEntryIterator() { + return Collections.unmodifiableMap(this.fieldMap).entrySet().iterator(); } public void accept(EntityConditionVisitor visitor) { Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFieldValue.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFieldValue.java?rev=585835&r1=585834&r2=585835&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFieldValue.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFieldValue.java Wed Oct 17 20:43:26 2007 @@ -59,7 +59,7 @@ return getField(modelEntity, fieldName); } - public void addSqlValue(StringBuilder sql, Map tableAliases, ModelEntity modelEntity, List entityConditionParams, boolean includeTableNamePrefix, DatasourceInfo datasourceInfo) { + public void addSqlValue(StringBuilder sql, Map<String, String> tableAliases, ModelEntity modelEntity, List<EntityConditionParam> entityConditionParams, boolean includeTableNamePrefix, DatasourceInfo datasourceInfo) { sql.append(getColName(tableAliases, modelEntity, fieldName, includeTableNamePrefix, datasourceInfo)); } @@ -70,7 +70,7 @@ } } - public Object getValue(GenericDelegator delegator, Map map) { + public Object getValue(GenericDelegator delegator, Map<String, ? extends Object> map) { if (map == null) { return null; } Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFunction.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFunction.java?rev=585835&r1=585834&r2=585835&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFunction.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityFunction.java Wed Oct 17 20:43:26 2007 @@ -132,7 +132,7 @@ (this.value != null ? value.equals(otherFunc.value) : otherFunc.value == null)); } - public void addSqlValue(StringBuilder sql, Map tableAliases, ModelEntity modelEntity, List entityConditionParams, boolean includeTableNamePrefix, DatasourceInfo datasourceinfo) { + public void addSqlValue(StringBuilder sql, Map<String, String> tableAliases, ModelEntity modelEntity, List<EntityConditionParam> entityConditionParams, boolean includeTableNamePrefix, DatasourceInfo datasourceinfo) { sql.append(codeString).append('('); if (nested != null) { nested.addSqlValue(sql, tableAliases, modelEntity, entityConditionParams, includeTableNamePrefix, datasourceinfo); @@ -167,7 +167,7 @@ } } - public Object getValue(GenericDelegator delegator, Map map) { + public Object getValue(GenericDelegator delegator, Map<String, ? extends Object> map) { Object value = nested != null ? nested.getValue(delegator, map) : this.value; return value != null ? fetcher.getValue(value) : null; } Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityJoinOperator.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityJoinOperator.java?rev=585835&r1=585834&r2=585835&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityJoinOperator.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityJoinOperator.java Wed Oct 17 20:43:26 2007 @@ -34,7 +34,7 @@ * Encapsulates operations between entities and entity fields. This is a immutable class. * */ -public class EntityJoinOperator extends EntityOperator { +public class EntityJoinOperator extends EntityOperator<Boolean> { protected boolean shortCircuitValue; @@ -43,7 +43,7 @@ this.shortCircuitValue = shortCircuitValue; } - public void addSqlValue(StringBuilder sql, ModelEntity modelEntity, List entityConditionParams, boolean compat, Object lhs, Object rhs, DatasourceInfo datasourceInfo) { + public void addSqlValue(StringBuilder sql, ModelEntity modelEntity, List<EntityConditionParam> entityConditionParams, boolean compat, Object lhs, Object rhs, DatasourceInfo datasourceInfo) { sql.append('('); sql.append(((EntityCondition) lhs).makeWhereString(modelEntity, entityConditionParams, datasourceInfo)); sql.append(' '); @@ -57,12 +57,12 @@ sql.append(')'); } - public void addSqlValue(StringBuilder sql, ModelEntity modelEntity, List entityConditionParams, List conditionList, DatasourceInfo datasourceInfo) { + public void addSqlValue(StringBuilder sql, ModelEntity modelEntity, List<EntityConditionParam> entityConditionParams, List<? extends EntityCondition> conditionList, DatasourceInfo datasourceInfo) { if (conditionList != null && conditionList.size() > 0) { sql.append('('); - Iterator conditionIter = conditionList.iterator(); + Iterator<? extends EntityCondition> conditionIter = conditionList.iterator(); while (conditionIter.hasNext()) { - EntityCondition condition = (EntityCondition) conditionIter.next(); + EntityCondition condition = conditionIter.next(); sql.append(condition.makeWhereString(modelEntity, entityConditionParams, datasourceInfo)); if (conditionIter.hasNext()) { sql.append(' '); @@ -82,19 +82,18 @@ return new EntityExpr(freeze(lhs), this, freeze(rhs)); } - public EntityCondition freeze(List conditionList) { - List newList = new ArrayList(conditionList.size()); - for (int i = 0; i < conditionList.size(); i++) { - EntityCondition condition = (EntityCondition) conditionList.get(i); + public EntityCondition freeze(List<? extends EntityCondition> conditionList) { + List<EntityCondition> newList = new ArrayList<EntityCondition>(conditionList.size()); + for (EntityCondition condition: conditionList) { newList.add(condition.freeze()); } - return new EntityConditionList(newList, this); + return new EntityConditionList<EntityCondition>(newList, this); } - public void visit(EntityConditionVisitor visitor, List conditionList) { + public void visit(EntityConditionVisitor visitor, List<? extends EntityCondition> conditionList) { if (conditionList != null && conditionList.size() > 0) { - for (int i = 0; i < conditionList.size(); i++) { - visitor.visit(conditionList.get(i)); + for (EntityCondition condition: conditionList) { + visitor.visit(condition); } } } @@ -108,7 +107,7 @@ return entityMatches(entity, (EntityCondition) lhs, (EntityCondition) rhs); } - public Object eval(GenericEntity entity, EntityCondition lhs, EntityCondition rhs) { + public Boolean eval(GenericEntity entity, EntityCondition lhs, EntityCondition rhs) { return entityMatches(entity, lhs, rhs) ? Boolean.TRUE : Boolean.FALSE; } @@ -118,28 +117,27 @@ return !shortCircuitValue; } - public boolean entityMatches(GenericEntity entity, List conditionList) { + public boolean entityMatches(GenericEntity entity, List<? extends EntityCondition> conditionList) { return mapMatches(entity.getDelegator(), entity, conditionList); } - public Object eval(GenericDelegator delegator, Map map, Object lhs, Object rhs) { + public Boolean eval(GenericDelegator delegator, Map<String, ? extends Object> map, Object lhs, Object rhs) { return castBoolean(mapMatches(delegator, map, lhs, rhs)); } - public boolean mapMatches(GenericDelegator delegator, Map map, Object lhs, Object rhs) { + public boolean mapMatches(GenericDelegator delegator, Map<String, ? extends Object> map, Object lhs, Object rhs) { if (((EntityCondition) lhs).mapMatches(delegator, map)) return shortCircuitValue; if (((EntityCondition) rhs).mapMatches(delegator, map)) return shortCircuitValue; return !shortCircuitValue; } - public Object eval(GenericDelegator delegator, Map map, List conditionList) { + public Boolean eval(GenericDelegator delegator, Map<String, ? extends Object> map, List<? extends EntityCondition> conditionList) { return castBoolean(mapMatches(delegator, map, conditionList)); } - public boolean mapMatches(GenericDelegator delegator, Map map, List conditionList) { + public boolean mapMatches(GenericDelegator delegator, Map<String, ? extends Object> map, List<? extends EntityCondition> conditionList) { if (conditionList != null && conditionList.size() > 0) { - for (int i = 0; i < conditionList.size(); i++) { - EntityCondition condition = (EntityCondition) conditionList.get(i); + for (EntityCondition condition: conditionList) { if (condition.mapMatches(delegator, map) == shortCircuitValue) return shortCircuitValue; } } @@ -155,16 +153,11 @@ rhs.checkCondition(modelEntity); } - public void validateSql(ModelEntity modelEntity, List conditionList) throws GenericModelException { + public void validateSql(ModelEntity modelEntity, List<? extends EntityCondition> conditionList) throws GenericModelException { if (conditionList == null) { throw new GenericModelException("Condition list is null"); } - for (int i = 0; i < conditionList.size(); i++) { - Object condObj = conditionList.get(i); - if (!(condObj instanceof EntityCondition)) { - throw new GenericModelException("Object is not a valid EntityCondition [" + condObj.getClass().getName() + "]"); - } - EntityCondition condition = (EntityCondition) condObj; + for (EntityCondition condition: conditionList) { condition.checkCondition(modelEntity); } } Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityOperator.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityOperator.java?rev=585835&r1=585834&r2=585835&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityOperator.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityOperator.java Wed Oct 17 20:43:26 2007 @@ -36,7 +36,7 @@ * Encapsulates operations between entities and entity fields. This is a immutable class. * */ -public abstract class EntityOperator extends EntityConditionBase { +public abstract class EntityOperator<T> extends EntityConditionBase { public static final int ID_EQUALS = 1; public static final int ID_NOT_EQUAL = 2; @@ -53,14 +53,14 @@ public static final int ID_NOT_IN = 13; public static final int ID_NOT_LIKE = 14; - private static HashMap registry = new HashMap(); + private static HashMap<String, EntityOperator> registry = new HashMap<String, EntityOperator>(); private static void register(String name, EntityOperator operator) { registry.put(name, operator); } public static EntityOperator lookup(String name) { - return (EntityOperator) registry.get(name); + return registry.get(name); } public static EntityComparisonOperator lookupComparison(String name) { @@ -78,8 +78,8 @@ } public static final EntityComparisonOperator EQUALS = new EntityComparisonOperator(ID_EQUALS, "=") { - public boolean compare(Object lhs, Object rhs) { return EntityComparisonOperator.compareEqual(lhs, rhs); } - protected void makeRHSWhereString(ModelEntity entity, List entityConditionParams, StringBuilder sb, ModelField field, Object rhs, DatasourceInfo datasourceInfo) { + public boolean compare(Comparable lhs, Object rhs) { return EntityComparisonOperator.compareEqual(lhs, rhs); } + protected void makeRHSWhereString(ModelEntity entity, List<EntityConditionParam> entityConditionParams, StringBuilder sb, ModelField field, Object rhs, DatasourceInfo datasourceInfo) { if (rhs == null || rhs == GenericEntity.NULL_FIELD) { //Debug.logInfo("makeRHSWhereString: field IS NULL: " + field.getName(), module); sb.append(" IS NULL"); @@ -91,8 +91,8 @@ }; static { register( "equals", EQUALS ); } public static final EntityComparisonOperator NOT_EQUAL = new EntityComparisonOperator(ID_NOT_EQUAL, "<>") { - public boolean compare(Object lhs, Object rhs) { return EntityComparisonOperator.compareNotEqual(lhs, rhs); } - protected void makeRHSWhereString(ModelEntity entity, List entityConditionParams, StringBuilder sb, ModelField field, Object rhs, DatasourceInfo datasourceInfo) { + public boolean compare(Comparable lhs, Object rhs) { return EntityComparisonOperator.compareNotEqual(lhs, rhs); } + protected void makeRHSWhereString(ModelEntity entity, List<EntityConditionParam> entityConditionParams, StringBuilder sb, ModelField field, Object rhs, DatasourceInfo datasourceInfo) { if (rhs == null || rhs == GenericEntity.NULL_FIELD) { sb.append(" IS NOT NULL"); } else { @@ -104,32 +104,32 @@ static { register( "not-equals", NOT_EQUAL ); } static { register( "notEqual", NOT_EQUAL ); } public static final EntityComparisonOperator LESS_THAN = new EntityComparisonOperator(ID_LESS_THAN, "<") { - public boolean compare(Object lhs, Object rhs) { return EntityComparisonOperator.compareLessThan(lhs, rhs); } + public boolean compare(Comparable lhs, Object rhs) { return EntityComparisonOperator.compareLessThan(lhs, rhs); } }; static { register( "less", LESS_THAN ); } static { register( "less-than", LESS_THAN ); } static { register( "lessThan", LESS_THAN ); } public static final EntityComparisonOperator GREATER_THAN = new EntityComparisonOperator(ID_GREATER_THAN, ">") { - public boolean compare(Object lhs, Object rhs) { return EntityComparisonOperator.compareGreaterThan(lhs, rhs); } + public boolean compare(Comparable lhs, Object rhs) { return EntityComparisonOperator.compareGreaterThan(lhs, rhs); } }; static { register( "greater", GREATER_THAN ); } static { register( "greater-than", GREATER_THAN ); } static { register( "greaterThan", GREATER_THAN ); } public static final EntityComparisonOperator LESS_THAN_EQUAL_TO = new EntityComparisonOperator(ID_LESS_THAN_EQUAL_TO, "<=") { - public boolean compare(Object lhs, Object rhs) { return EntityComparisonOperator.compareLessThanEqualTo(lhs, rhs); } + public boolean compare(Comparable lhs, Object rhs) { return EntityComparisonOperator.compareLessThanEqualTo(lhs, rhs); } }; static { register( "less-equals", LESS_THAN_EQUAL_TO ); } static { register( "less-than-equal-to", LESS_THAN_EQUAL_TO ); } static { register( "lessThanEqualTo", LESS_THAN_EQUAL_TO ); } public static final EntityComparisonOperator GREATER_THAN_EQUAL_TO = new EntityComparisonOperator(ID_GREATER_THAN_EQUAL_TO, ">=") { - public boolean compare(Object lhs, Object rhs) { return EntityComparisonOperator.compareGreaterThanEqualTo(lhs, rhs); } + public boolean compare(Comparable lhs, Object rhs) { return EntityComparisonOperator.compareGreaterThanEqualTo(lhs, rhs); } }; static { register( "greater-equals", GREATER_THAN_EQUAL_TO ); } static { register( "greater-than-equal-to", GREATER_THAN_EQUAL_TO ); } static { register( "greaterThanEqualTo", GREATER_THAN_EQUAL_TO ); } public static final EntityComparisonOperator IN = new EntityComparisonOperator(ID_IN, "IN") { - public boolean compare(Object lhs, Object rhs) { return EntityComparisonOperator.compareIn(lhs, rhs); } - protected void makeRHSWhereStringValue(ModelEntity entity, List entityConditionParams, StringBuilder sb, ModelField field, Object rhs) { appendRHSList(entityConditionParams, sb, field, rhs); } + public boolean compare(Comparable lhs, Object rhs) { return EntityComparisonOperator.compareIn(lhs, rhs); } + protected void makeRHSWhereStringValue(ModelEntity entity, List<EntityConditionParam> entityConditionParams, StringBuilder sb, ModelField field, Object rhs) { appendRHSList(entityConditionParams, sb, field, rhs); } }; static { register( "in", IN ); } public static final EntityComparisonOperator BETWEEN = new EntityComparisonOperator(ID_BETWEEN, "BETWEEN"); @@ -141,16 +141,16 @@ public static final EntityJoinOperator OR = new EntityJoinOperator(ID_OR, "OR", true); static { register( "or", OR ); } public static final EntityComparisonOperator LIKE = new EntityComparisonOperator(ID_LIKE, "LIKE") { - public boolean compare(Object lhs, Object rhs) { return EntityComparisonOperator.compareLike(lhs, rhs); } + public boolean compare(Comparable lhs, Object rhs) { return EntityComparisonOperator.compareLike(lhs, rhs); } }; static { register( "like", LIKE ); } public static final EntityComparisonOperator NOT_LIKE = new EntityComparisonOperator(ID_NOT_LIKE, "NOT LIKE") { - public boolean compare(Object lhs, Object rhs) { return !EntityComparisonOperator.compareLike(lhs, rhs); } + public boolean compare(Comparable lhs, Object rhs) { return !EntityComparisonOperator.compareLike(lhs, rhs); } }; static { register( "not-like", NOT_LIKE); } public static final EntityComparisonOperator NOT_IN = new EntityComparisonOperator(ID_NOT_IN, "NOT IN") { - public boolean compare(Object lhs, Object rhs) { return !EntityComparisonOperator.compareIn(lhs, rhs); } - protected void makeRHSWhereStringValue(ModelEntity entity, List entityConditionParams, StringBuilder sb, ModelField field, Object rhs) { appendRHSList(entityConditionParams, sb, field, rhs); } + public boolean compare(Comparable lhs, Object rhs) { return !EntityComparisonOperator.compareIn(lhs, rhs); } + protected void makeRHSWhereStringValue(ModelEntity entity, List<EntityConditionParam> entityConditionParams, StringBuilder sb, ModelField field, Object rhs) { appendRHSList(entityConditionParams, sb, field, rhs); } }; static { register( "not-in", NOT_IN ); } @@ -182,6 +182,7 @@ return this.codeString.hashCode(); } + // FIXME: CCE public boolean equals(Object obj) { EntityOperator otherOper = (EntityOperator) obj; return this.idInt == otherOper.idInt; @@ -191,8 +192,8 @@ return mapMatches(entity.getDelegator(), entity, lhs, rhs); } - protected void appendRHSList(List entityConditionParams, StringBuilder whereStringBuffer, ModelField field, Object rhs) { - whereStringBuffer.append('('); + protected void appendRHSList(List<EntityConditionParam> entityConditionParams, StringBuilder whereStringBuilder, ModelField field, Object rhs) { + whereStringBuilder.append('('); if (rhs instanceof Collection) { Iterator rhsIter = ((Collection) rhs).iterator(); @@ -200,28 +201,30 @@ while (rhsIter.hasNext()) { Object inObj = rhsIter.next(); - addValue(whereStringBuffer, field, inObj, entityConditionParams); + addValue(whereStringBuilder, field, inObj, entityConditionParams); if (rhsIter.hasNext()) { - whereStringBuffer.append(", "); + whereStringBuilder.append(", "); } } } else { - addValue(whereStringBuffer, field, rhs, entityConditionParams); + addValue(whereStringBuilder, field, rhs, entityConditionParams); } - whereStringBuffer.append(')'); + whereStringBuilder.append(')'); } - public Object eval(GenericDelegator delegator, Map map, Object lhs, Object rhs) { + /* + public T eval(GenericDelegator delegator, Map<String, ? extends Object> map, Object lhs, Object rhs) { return castBoolean(mapMatches(delegator, map, lhs, rhs)); } + */ - public abstract boolean mapMatches(GenericDelegator delegator, Map map, Object lhs, Object rhs); + public abstract boolean mapMatches(GenericDelegator delegator, Map<String, ? extends Object> map, Object lhs, Object rhs); public abstract void validateSql(ModelEntity entity, Object lhs, Object rhs) throws GenericModelException; - public void addSqlValue(StringBuilder sql, ModelEntity entity, List entityConditionParams, Object lhs, Object rhs, DatasourceInfo datasourceInfo) { + public void addSqlValue(StringBuilder sql, ModelEntity entity, List<EntityConditionParam> entityConditionParams, Object lhs, Object rhs, DatasourceInfo datasourceInfo) { addSqlValue(sql, entity, entityConditionParams, true, lhs, rhs, datasourceInfo); } - public abstract void addSqlValue(StringBuilder sql, ModelEntity entity, List entityConditionParams, boolean compat, Object rhs, Object lhs, DatasourceInfo datasourceInfo); + public abstract void addSqlValue(StringBuilder sql, ModelEntity entity, List<EntityConditionParam> entityConditionParams, boolean compat, Object rhs, Object lhs, DatasourceInfo datasourceInfo); public abstract EntityCondition freeze(Object lhs, Object rhs); public abstract void visit(EntityConditionVisitor visitor, Object lhs, Object rhs); Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityWhereString.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityWhereString.java?rev=585835&r1=585834&r2=585835&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityWhereString.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityWhereString.java Wed Oct 17 20:43:26 2007 @@ -48,7 +48,7 @@ this.sqlString = sqlString; } - public String makeWhereString(ModelEntity modelEntity, List entityConditionParams, DatasourceInfo datasourceInfo) { + public String makeWhereString(ModelEntity modelEntity, List<EntityConditionParam> entityConditionParams, DatasourceInfo datasourceInfo) { return sqlString; } @@ -59,7 +59,7 @@ throw new UnsupportedOperationException("Cannot do entityMatches on a WhereString, ie no SQL evaluation in EE; Where String is: " + sqlString); } - public boolean mapMatches(GenericDelegator delegator, Map map) { + public boolean mapMatches(GenericDelegator delegator, Map<String, ? extends Object> map) { throw new UnsupportedOperationException("Cannot do mapMatches on a WhereString, ie no SQL evaluation in EE; Where String is: " + sqlString); } Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/OrderByItem.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/OrderByItem.java?rev=585835&r1=585834&r2=585835&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/OrderByItem.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/OrderByItem.java Wed Oct 17 20:43:26 2007 @@ -128,8 +128,8 @@ } public int compare(GenericEntity obj1, GenericEntity obj2) { - Object value1 = value.getValue(obj1); - Object value2 = value.getValue(obj2); + Comparable value1 = (Comparable) value.getValue(obj1); + Comparable value2 = (Comparable) value.getValue(obj2); int result; // null is defined as the largest possible value @@ -138,7 +138,7 @@ } else if (value2 == null) { result = value1 == null ? 0 : -1; } else { - result = ((Comparable) value1).compareTo(value2); + result = value1.compareTo(value2); } // if (Debug.infoOn()) Debug.logInfo("[OrderByComparator.compareAsc] Result is " + result + " for [" + value + "] and [" + value2 + "]", module); return descending ? -result : result; Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/OrderByList.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/OrderByList.java?rev=585835&r1=585834&r2=585835&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/OrderByList.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/OrderByList.java Wed Oct 17 20:43:26 2007 @@ -32,7 +32,7 @@ import org.ofbiz.entity.model.ModelEntity; public class OrderByList implements Comparator<GenericEntity> { - protected List orderByList = new ArrayList(); + protected List<OrderByItem> orderByList = new ArrayList<OrderByItem>(); public OrderByList() { } @@ -41,20 +41,19 @@ addOrderBy(orderByList); } - public OrderByList(Collection orderByList) { + public OrderByList(Collection<String> orderByList) { addOrderBy(orderByList); } - + public void addOrderBy(String... orderByList) { for (String orderByItem: orderByList) { addOrderBy(orderByItem); } } - public void addOrderBy(Collection orderByList) { - Iterator it = orderByList.iterator(); - while (it.hasNext()) { - addOrderBy(OrderByItem.parse(it.next())); + public void addOrderBy(Collection<String> orderByList) { + for (String orderByItem: orderByList) { + addOrderBy(orderByItem); } } @@ -75,8 +74,7 @@ } public void checkOrderBy(ModelEntity modelEntity) throws GenericModelException { - for (int i = 0; i < orderByList.size(); i++) { - OrderByItem orderByItem = (OrderByItem) orderByList.get(i); + for (OrderByItem orderByItem: orderByList) { orderByItem.checkOrderBy(modelEntity); } } @@ -93,15 +91,14 @@ } for (int i = 0; i < orderByList.size(); i++) { if (i != 0) sb.append(", "); - OrderByItem orderByItem = (OrderByItem) orderByList.get(i); + OrderByItem orderByItem = orderByList.get(i); orderByItem.makeOrderByString(sb, modelEntity, includeTablenamePrefix, datasourceInfo); } } public int compare(GenericEntity entity1, GenericEntity entity2) { int result = 0; - for (int i = 0; i < orderByList.size() && result == 0; i++) { - OrderByItem orderByItem = (OrderByItem) orderByList.get(i); + for (OrderByItem orderByItem: orderByList) { result = orderByItem.compare(entity1, entity2); } return result; |
Free forum by Nabble | Edit this page |