You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jo...@apache.org on 2007/03/24 11:00:58 UTC

svn commit: r522000 - in /ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition: EntityComparisonOperator.java EntityExpr.java

Author: jonesde
Date: Sat Mar 24 03:00:57 2007
New Revision: 522000

URL: http://svn.apache.org/viewvc?view=rev&rev=522000
Log:
Added a bit of code to put FALSE in an SQL where clause instead of an empty IN set when that is detected; not sure if this is the best way to go, but it should be close to what we want and avoid a database error as happens now; chose FALSE because even though a value in the db could either always or never match an empty set, the never match seems to make more sense because if you would normally select various values and select none, you would be excluding all, unless you consider selecting none to mean that you want to include everything...

Modified:
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityComparisonOperator.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityExpr.java

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?view=diff&rev=522000&r1=521999&r2=522000
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityComparisonOperator.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityComparisonOperator.java Sat Mar 24 03:00:57 2007
@@ -31,6 +31,7 @@
 import org.apache.oro.text.regex.Perl5Compiler;
 import org.apache.oro.text.regex.Perl5Matcher;
 import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.UtilValidate;
 import org.ofbiz.entity.GenericDelegator;
 import org.ofbiz.entity.GenericModelException;
 import org.ofbiz.entity.model.ModelEntity;
@@ -83,6 +84,13 @@
 
     public void addSqlValue(StringBuffer sql, ModelEntity entity, List entityConditionParams, boolean compat, Object lhs, Object rhs) {
         //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
+        if (this.idInt == EntityOperator.ID_IN && UtilValidate.isEmpty(rhs)) {
+            sql.append("FALSE");
+            return;
+        }
+        
         ModelField field;
         if (lhs instanceof EntityConditionValue) {
             EntityConditionValue ecv = (EntityConditionValue) lhs;

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?view=diff&rev=522000&r1=521999&r2=522000
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityExpr.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityExpr.java Sat Mar 24 03:00:57 2007
@@ -162,14 +162,14 @@
         }
     }
 
-	protected void addValue(StringBuffer buffer, ModelField field, Object value, List params) {
-		if (rhs instanceof EntityFunction.UPPER) {
-			if (value instanceof String) {
-				value = ((String) value).toUpperCase();
-			}
-		}
-		super.addValue(buffer, field, value, params);
-	}
+    protected void addValue(StringBuffer buffer, ModelField field, Object value, List params) {
+        if (rhs instanceof EntityFunction.UPPER) {
+            if (value instanceof String) {
+                value = ((String) value).toUpperCase();
+            }
+        }
+        super.addValue(buffer, field, value, params);
+    }
 
     public EntityCondition freeze() {
         return operator.freeze(lhs, rhs);