svn commit: r950766 - /ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/

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

svn commit: r950766 - /ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/

doogie-3
Author: doogie
Date: Wed Jun  2 21:24:14 2010
New Revision: 950766

URL: http://svn.apache.org/viewvc?rev=950766&view=rev
Log:
EntityCondition.isEmpty() support.

Modified:
    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/EntityConditionFunction.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityConditionListBase.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/EntityJoinOperator.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityOperator.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityWhereString.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?rev=950766&r1=950765&r2=950766&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 Jun  2 21:24:14 2010
@@ -116,6 +116,11 @@ public abstract class EntityComparisonOp
         makeRHSWhereString(entity, entityConditionParams, sql, field, rhs, datasourceInfo);
     }
 
+    @Override
+    public boolean isEmpty(L lhs, R rhs) {
+        return false;
+    }
+
     protected void makeRHSWhereString(ModelEntity entity, List<EntityConditionParam> entityConditionParams, StringBuilder sql, ModelField field, R rhs, DatasourceInfo datasourceInfo) {
         sql.append(' ').append(getCode()).append(' ');
         makeRHSWhereStringValue(entity, entityConditionParams, sql, field, rhs, datasourceInfo);

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=950766&r1=950765&r2=950766&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 Jun  2 21:24:14 2010
@@ -26,6 +26,7 @@ import java.util.Map;
 import javolution.lang.Reusable;
 import javolution.util.FastList;
 
+import org.ofbiz.base.lang.IsEmpty;
 import org.ofbiz.entity.Delegator;
 import org.ofbiz.entity.GenericEntity;
 import org.ofbiz.entity.GenericModelException;
@@ -43,7 +44,7 @@ import org.ofbiz.entity.model.ModelEntit
  * These can be used in various combinations using the EntityConditionList and EntityExpr objects.
  *
  */
-public abstract class EntityCondition extends EntityConditionBase implements Reusable {
+public abstract class EntityCondition extends EntityConditionBase implements IsEmpty, Reusable {
 
     public static <L,R,LL,RR> EntityExpr makeCondition(L lhs, EntityComparisonOperator<LL,RR> operator, R rhs) {
         EntityExpr expr = EntityExpr.entityExprFactory.object();

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=950766&r1=950765&r2=950766&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 Jun  2 21:24:14 2010
@@ -100,6 +100,11 @@ public abstract class EntityConditionFun
     }
 
     @Override
+    public boolean isEmpty() {
+        return false;
+    }
+
+    @Override
     public String makeWhereString(ModelEntity modelEntity, List<EntityConditionParam> entityConditionParams, DatasourceInfo datasourceInfo) {
         StringBuilder sb = new StringBuilder();
         sb.append(codeString).append('(');

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=950766&r1=950765&r2=950766&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 Jun  2 21:24:14 2010
@@ -86,6 +86,11 @@ public abstract class EntityConditionLis
     }
 
     @Override
+    public boolean isEmpty() {
+        return operator.isEmpty(conditionList);
+    }
+
+    @Override
     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();

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=950766&r1=950765&r2=950766&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 Jun  2 21:24:14 2010
@@ -55,6 +55,11 @@ public class EntityDateFilterCondition e
     }
 
     @Override
+    public boolean isEmpty() {
+        return false;
+    }
+
+    @Override
     public String makeWhereString(ModelEntity modelEntity, List<EntityConditionParam> entityConditionParams, DatasourceInfo datasourceInfo) {
         EntityCondition condition = makeCondition();
         return condition.makeWhereString(modelEntity, entityConditionParams, datasourceInfo);

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=950766&r1=950765&r2=950766&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 Jun  2 21:24:14 2010
@@ -124,6 +124,11 @@ public class EntityExpr extends EntityCo
     }
 
     @Override
+    public boolean isEmpty() {
+        return operator.isEmpty(lhs, rhs);
+    }
+
+    @Override
     public String makeWhereString(ModelEntity modelEntity, List<EntityConditionParam> entityConditionParams, DatasourceInfo datasourceInfo) {
         // if (Debug.verboseOn()) Debug.logVerbose("makeWhereString for entity " + modelEntity.getEntityName(), module);
 

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=950766&r1=950765&r2=950766&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 Jun  2 21:24:14 2010
@@ -56,18 +56,26 @@ public class EntityJoinOperator extends
 
     public void addSqlValue(StringBuilder sql, ModelEntity modelEntity, List<EntityConditionParam> entityConditionParams, List<? extends EntityCondition> conditionList, DatasourceInfo datasourceInfo) {
         if (UtilValidate.isNotEmpty(conditionList)) {
-            sql.append('(');
+            boolean hadSomething = false;
             Iterator<? extends EntityCondition> conditionIter = conditionList.iterator();
             while (conditionIter.hasNext()) {
                 EntityCondition condition = conditionIter.next();
-                sql.append(condition.makeWhereString(modelEntity, entityConditionParams, datasourceInfo));
-                if (conditionIter.hasNext()) {
+                if (condition.isEmpty()) {
+                    continue;
+                }
+                if (hadSomething) {
                     sql.append(' ');
                     sql.append(getCode());
                     sql.append(' ');
+                } else {
+                    hadSomething = true;
+                    sql.append('(');
                 }
+                sql.append(condition.makeWhereString(modelEntity, entityConditionParams, datasourceInfo));
+            }
+            if (hadSomething) {
+                sql.append(')');
             }
-            sql.append(')');
         }
     }
 
@@ -107,6 +115,20 @@ public class EntityJoinOperator extends
     }
 
     @Override
+    public boolean isEmpty(EntityCondition lhs, EntityCondition rhs) {
+        return lhs.isEmpty() && rhs.isEmpty();
+    }
+
+    public boolean isEmpty(List<? extends EntityCondition> conditionList) {
+        for (EntityCondition condition: conditionList) {
+            if (!condition.isEmpty()) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    @Override
     public boolean entityMatches(GenericEntity entity, EntityCondition lhs, EntityCondition rhs) {
         if (lhs.entityMatches(entity) == shortCircuitValue) return shortCircuitValue;
         if (rhs.entityMatches(entity) == shortCircuitValue) return shortCircuitValue;

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=950766&r1=950765&r2=950766&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 Jun  2 21:24:14 2010
@@ -286,6 +286,7 @@ public abstract class EntityOperator<L,
     }
     */
 
+    public abstract boolean isEmpty(L lhs, R rhs);
     public abstract boolean mapMatches(Delegator delegator, Map<String, ? extends Object> map, L lhs, R rhs);
     public abstract void validateSql(ModelEntity entity, L lhs, R rhs) throws GenericModelException;
     public void addSqlValue(StringBuilder sql, ModelEntity entity, List<EntityConditionParam> entityConditionParams, L lhs, R rhs, DatasourceInfo datasourceInfo) {

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=950766&r1=950765&r2=950766&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 Jun  2 21:24:14 2010
@@ -23,6 +23,7 @@ import java.util.Map;
 
 import javolution.context.ObjectFactory;
 
+import org.ofbiz.base.util.UtilValidate;
 import org.ofbiz.entity.Delegator;
 import org.ofbiz.entity.GenericEntity;
 import org.ofbiz.entity.GenericModelException;
@@ -62,6 +63,11 @@ public class EntityWhereString extends E
     }
 
     @Override
+    public boolean isEmpty() {
+        return UtilValidate.isEmpty(sqlString);
+    }
+
+    @Override
     public String makeWhereString(ModelEntity modelEntity, List<EntityConditionParam> entityConditionParams, DatasourceInfo datasourceInfo) {
         return sqlString;
     }