Author: jleroux
Date: Sun Nov 30 12:16:04 2008
New Revision: 721887
URL:
http://svn.apache.org/viewvc?rev=721887&view=revLog:
A patch from Luke Prentice "EntityOperator does not correctly construct SQL for BETWEEN clause" (
https://issues.apache.org/jira/browse/OFBIZ-1045) - OFBIZ-1045
Modified:
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityOperator.java
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=721887&r1=721886&r2=721887&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 Sun Nov 30 12:16:04 2008
@@ -33,7 +33,7 @@
import org.ofbiz.entity.model.ModelField;
/**
- * Encapsulates operations between entities and entity fields. This is a immutable class.
+ * Encapsulates operations between entities and entity fields. This is an immutable class.
*
*/
public abstract class EntityOperator<T> extends EntityConditionBase {
@@ -132,7 +132,10 @@
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");
+ public static final EntityComparisonOperator BETWEEN = new EntityComparisonOperator(ID_BETWEEN, "BETWEEN") {
+ 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, DatasourceInfo datasourceInfo) { appendRHSBetweenList(entityConditionParams, sb, field, rhs); }
+ };
static { register( "between", BETWEEN ); }
public static final EntityComparisonOperator NOT = new EntityComparisonOperator(ID_NOT, "NOT");
static { register( "not", NOT ); }
@@ -211,6 +214,22 @@
}
whereStringBuilder.append(')');
}
+
+ protected void appendRHSBetweenList(List<EntityConditionParam> entityConditionParams, StringBuilder whereStringBuilder, ModelField field, Object rhs) {
+ if (rhs instanceof Collection) {
+ Iterator rhsIter = ((Collection) rhs).iterator();
+
+ while (rhsIter.hasNext()) {
+ Object inObj = rhsIter.next();
+
+ addValue(whereStringBuilder, field, inObj, entityConditionParams);
+ if (rhsIter.hasNext()) {
+ whereStringBuilder.append(" AND ");
+ }
+ }
+ }
+ }
+
/*
public T eval(GenericDelegator delegator, Map<String, ? extends Object> map, Object lhs, Object rhs) {