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 2009/07/03 07:14:01 UTC

svn commit: r790791 - in /ofbiz/trunk/framework/entity/src/org/ofbiz/entity: datasource/GenericDAO.java finder/ByAndFinder.java model/ModelEntity.java

Author: jonesde
Date: Fri Jul  3 05:14:00 2009
New Revision: 790791

URL: http://svn.apache.org/viewvc?rev=790791&view=rev
Log:
Fixed bug reported by Hans and Adrian that broke the ByAndFinder class where string because method that overrides one on ListFinder wasn't doing that any more because the ListFinder method signature had changed; also did a few little cleanups related to this

Modified:
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/finder/ByAndFinder.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java?rev=790791&r1=790790&r2=790791&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/datasource/GenericDAO.java Fri Jul  3 05:14:00 2009
@@ -674,14 +674,13 @@
         sqlBuffer.append(SqlJdbcUtil.makeFromClause(modelEntity, datasourceInfo));
 
         // WHERE clause
-        StringBuilder whereString = new StringBuilder();
-        String entityCondWhereString = "";
         List<EntityConditionParam> whereEntityConditionParams = FastList.newInstance();
+        
+        String entityCondWhereString = "";
         if (whereEntityCondition != null) {
             entityCondWhereString = whereEntityCondition.makeWhereString(modelEntity, whereEntityConditionParams, this.datasourceInfo);
         }
 
-        String viewClause = SqlJdbcUtil.makeViewWhereClause(modelEntity, datasourceInfo.joinStyle);
         String viewEntityCondWhereString = null;
         if (modelViewEntity != null && modelViewEntity.getByConditionFinder() != null) {
             EntityCondition viewWhereEntityCondition = modelViewEntity.getByConditionFinder().getWhereEntityCondition(FastMap.<String, Object>newInstance(), modelEntity, this.modelFieldTypeReader);
@@ -690,22 +689,33 @@
             }
         }
 
+        String viewClause = SqlJdbcUtil.makeViewWhereClause(modelEntity, datasourceInfo.joinStyle);
+
+        StringBuilder whereString = new StringBuilder();
         if (entityCondWhereString.length() > 0) {
-            whereString.append("(");
+            boolean addParens = false;
+            if (entityCondWhereString.charAt(0) != '(') addParens = true;
+            if (addParens) whereString.append("(");
             whereString.append(entityCondWhereString);
-            whereString.append(")");
+            if (addParens) whereString.append(")");
         }
         
         if (UtilValidate.isNotEmpty(viewEntityCondWhereString)) {
             if (whereString.length() > 0) whereString.append(" AND ");
-            whereString.append("(");
+            boolean addParens = false;
+            if (viewEntityCondWhereString.charAt(0) != '(') addParens = true;
+            if (addParens) whereString.append("(");
             whereString.append(viewEntityCondWhereString);
-            whereString.append(")");
+            if (addParens) whereString.append(")");
         }
 
         if (viewClause.length() > 0) {
             if (whereString.length() > 0) whereString.append(" AND ");
+            boolean addParens = false;
+            if (viewClause.charAt(0) != '(') addParens = true;
+            if (addParens) whereString.append("(");
             whereString.append(viewClause);
+            if (addParens) whereString.append(")");
         }
 
         if (whereString.length() > 0) {
@@ -740,15 +750,19 @@
 
         StringBuilder havingString = new StringBuilder();
         if (UtilValidate.isNotEmpty(entityCondHavingString)) {
-            havingString.append("(");
+            boolean addParens = false;
+            if (entityCondHavingString.charAt(0) != '(') addParens = true;
+            if (addParens) havingString.append("(");
             havingString.append(entityCondHavingString);
-            havingString.append(")");
+            if (addParens) havingString.append(")");
         }
         if (UtilValidate.isNotEmpty(viewEntityCondHavingString)) {
             if (havingString.length() > 0) havingString.append(" AND ");
-            havingString.append("(");
+            boolean addParens = false;
+            if (viewEntityCondHavingString.charAt(0) != '(') addParens = true;
+            if (addParens) havingString.append("(");
             havingString.append(viewEntityCondHavingString);
-            havingString.append(")");
+            if (addParens) havingString.append(")");
         }
         
         if (havingString.length() > 0) {
@@ -802,9 +816,9 @@
         if (Debug.timingOn()) {
             long queryEndTime = System.currentTimeMillis();
             long queryTotalTime = queryEndTime - queryStartTime;
-            if (queryTotalTime > 150) {
+            //if (queryTotalTime > 150) {
                 Debug.logTiming("Ran query in " + queryTotalTime + " milli-seconds: " + sql, module);
-            }
+            //}
         }
         return new EntityListIterator(sqlP, modelEntity, selectFields, modelFieldTypeReader);
     }

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/finder/ByAndFinder.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/finder/ByAndFinder.java?rev=790791&r1=790790&r2=790791&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/finder/ByAndFinder.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/finder/ByAndFinder.java Fri Jul  3 05:14:00 2009
@@ -23,17 +23,16 @@
 import javolution.util.FastMap;
 
 import org.ofbiz.base.util.collections.FlexibleMapAccessor;
-import org.ofbiz.entity.GenericDelegator;
-import org.ofbiz.entity.condition.EntityFieldMap;
-import org.ofbiz.entity.condition.EntityOperator;
 import org.ofbiz.entity.condition.EntityCondition;
 import org.ofbiz.entity.model.ModelEntity;
+import org.ofbiz.entity.model.ModelFieldTypeReader;
 import org.w3c.dom.Element;
 
 /**
  * Uses the delegator to find entity values by a and
  *
  */
+@SuppressWarnings("serial")
 public class ByAndFinder extends ListFinder {
 
     public static final String module = ByAndFinder.class.getName();
@@ -47,12 +46,12 @@
         this.fieldMap = EntityFinderUtil.makeFieldMap(element);
     }
 
-    protected EntityCondition getWhereEntityCondition(Map<String, Object> context, ModelEntity modelEntity, GenericDelegator delegator) {
+    public EntityCondition getWhereEntityCondition(Map<String, Object> context, ModelEntity modelEntity, ModelFieldTypeReader modelFieldTypeReader) {
         // create the by and map
         Map<String, Object> entityContext = FastMap.newInstance();
         EntityFinderUtil.expandFieldMapToContext(this.fieldMap, context, entityContext);
         // then convert the types...
-        modelEntity.convertFieldMapInPlace(entityContext, delegator);
+        modelEntity.convertFieldMapInPlace(entityContext, modelFieldTypeReader);
         return EntityCondition.makeCondition(entityContext);
     }
 }

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java?rev=790791&r1=790790&r2=790791&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelEntity.java Fri Jul  3 05:14:00 2009
@@ -1254,13 +1254,16 @@
     }
 
     public void convertFieldMapInPlace(Map<String, Object> inContext, GenericDelegator delegator) {
+        convertFieldMapInPlace(inContext, delegator.getModelFieldTypeReader(this));
+    }
+    public void convertFieldMapInPlace(Map<String, Object> inContext, ModelFieldTypeReader modelFieldTypeReader) {
         Iterator<ModelField> modelFields = this.getFieldsIterator();
         while (modelFields.hasNext()) {
             ModelField modelField = modelFields.next();
             String fieldName = modelField.getName();
             Object oldValue = inContext.get(fieldName);
             if (oldValue != null) {
-                inContext.put(fieldName, this.convertFieldValue(modelField, oldValue, delegator, inContext));
+                inContext.put(fieldName, this.convertFieldValue(modelField, oldValue, modelFieldTypeReader, inContext));
             }
         }
     }



Re: svn commit: r790791 - in /ofbiz/trunk/framework/entity/src/org/ofbiz/entity: datasource/GenericDAO.java finder/ByAndFinder.java model/ModelEntity.java

Posted by David E Jones <de...@me.com>.
On Jul 3, 2009, at 11:11 AM, Adam Heath wrote:

> jonesde@apache.org wrote:
>> Author: jonesde
>> Date: Fri Jul  3 05:14:00 2009
>> New Revision: 790791
>>
>> URL: http://svn.apache.org/viewvc?rev=790791&view=rev
>> Log:
>> Fixed bug reported by Hans and Adrian that broke the ByAndFinder  
>> class where string because method that overrides one on ListFinder  
>> wasn't doing that any more because the ListFinder method signature  
>> had changed; also did a few little cleanups related to this
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> =====================================================================
>> --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/finder/ 
>> ByAndFinder.java (original)
>> +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/finder/ 
>> ByAndFinder.java Fri Jul  3 05:14:00 2009
>> @@ -47,12 +46,12 @@
>>         this.fieldMap = EntityFinderUtil.makeFieldMap(element);
>>     }
>>
>
> @Override
>> -    protected EntityCondition getWhereEntityCondition(Map<String,  
>> Object> context, ModelEntity modelEntity, GenericDelegator  
>> delegator) {
>> +    public EntityCondition getWhereEntityCondition(Map<String,  
>> Object> context, ModelEntity modelEntity, ModelFieldTypeReader  
>> modelFieldTypeReader) {
>>         // create the by and map
>>         Map<String, Object> entityContext = FastMap.newInstance();
>>         EntityFinderUtil.expandFieldMapToContext(this.fieldMap,  
>> context, entityContext);
>>         // then convert the types...
>> -        modelEntity.convertFieldMapInPlace(entityContext,  
>> delegator);
>> +        modelEntity.convertFieldMapInPlace(entityContext,  
>> modelFieldTypeReader);
>>         return EntityCondition.makeCondition(entityContext);
>>     }
>> }
>
> The above annotation should have been added originally; it would have
> caught this error, as the signature in the parent class changed, so
> that would mean this class wasn't overriding something from it's  
> parent.

Thanks Adam. I've added those to help with this in rev 791054.

-David


Re: svn commit: r790791 - in /ofbiz/trunk/framework/entity/src/org/ofbiz/entity: datasource/GenericDAO.java finder/ByAndFinder.java model/ModelEntity.java

Posted by Adam Heath <do...@brainfood.com>.
jonesde@apache.org wrote:
> Author: jonesde
> Date: Fri Jul  3 05:14:00 2009
> New Revision: 790791
> 
> URL: http://svn.apache.org/viewvc?rev=790791&view=rev
> Log:
> Fixed bug reported by Hans and Adrian that broke the ByAndFinder class where string because method that overrides one on ListFinder wasn't doing that any more because the ListFinder method signature had changed; also did a few little cleanups related to this
> ==============================================================================
> --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/finder/ByAndFinder.java (original)
> +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/finder/ByAndFinder.java Fri Jul  3 05:14:00 2009
> @@ -47,12 +46,12 @@
>          this.fieldMap = EntityFinderUtil.makeFieldMap(element);
>      }
>  

@Override
> -    protected EntityCondition getWhereEntityCondition(Map<String, Object> context, ModelEntity modelEntity, GenericDelegator delegator) {
> +    public EntityCondition getWhereEntityCondition(Map<String, Object> context, ModelEntity modelEntity, ModelFieldTypeReader modelFieldTypeReader) {
>          // create the by and map
>          Map<String, Object> entityContext = FastMap.newInstance();
>          EntityFinderUtil.expandFieldMapToContext(this.fieldMap, context, entityContext);
>          // then convert the types...
> -        modelEntity.convertFieldMapInPlace(entityContext, delegator);
> +        modelEntity.convertFieldMapInPlace(entityContext, modelFieldTypeReader);
>          return EntityCondition.makeCondition(entityContext);
>      }
>  }

The above annotation should have been added originally; it would have
caught this error, as the signature in the parent class changed, so
that would mean this class wasn't overriding something from it's parent.