You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by do...@apache.org on 2012/05/29 06:16:43 UTC

svn commit: r1343506 - in /ofbiz/trunk/framework/entity/src/org/ofbiz/entity: Delegator.java GenericDelegator.java GenericValue.java

Author: doogie
Date: Tue May 29 04:16:42 2012
New Revision: 1343506

URL: http://svn.apache.org/viewvc?rev=1343506&view=rev
Log:
FEATURE: Add new Delegator.getRelated that takes a boolean useCache
parameter; all internal calls from GenericDelegator and GenericValue
have been modified to use the new method.

Modified:
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/Delegator.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericValue.java

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/Delegator.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/Delegator.java?rev=1343506&r1=1343505&r2=1343506&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/Delegator.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/Delegator.java Tue May 29 04:16:42 2012
@@ -795,6 +795,29 @@ public interface Delegator {
     public List<GenericValue> getRelatedCache(String relationName, GenericValue value) throws GenericEntityException;
 
     /**
+     * Get the named Related Entity for the GenericValue from the persistent
+     * store
+     *
+     * @param relationName
+     *            String containing the relation name which is the combination
+     *            of relation.title and relation.rel-entity-name as specified in
+     *            the entity XML definition file
+     * @param byAndFields
+     *            the fields that must equal in order to keep; may be null
+     * @param orderBy
+     *            The fields of the named entity to order the query by; may be
+     *            null; optionally add a " ASC" for ascending or " DESC" for
+     *            descending
+     * @param value
+     *            GenericValue instance containing the entity
+     * @param useCache
+     *            Whether to cache the results
+     * @return List of GenericValue instances as specified in the relation
+     *         definition
+     */
+    public List<GenericValue> getRelated(String relationName, Map<String, ? extends Object> byAndFields, List<String> orderBy, GenericValue value, boolean useCache) throws GenericEntityException;
+
+    /**
      * Get a dummy primary key for the named Related Entity for the GenericValue
      * NOTE 20080502: 2 references
      *

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java?rev=1343506&r1=1343505&r2=1343506&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java Tue May 29 04:16:42 2012
@@ -1944,6 +1944,13 @@ public class GenericDelegator implements
      * @see org.ofbiz.entity.Delegator#getRelated(java.lang.String, java.util.Map, java.util.List, org.ofbiz.entity.GenericValue)
      */
     public List<GenericValue> getRelated(String relationName, Map<String, ? extends Object> byAndFields, List<String> orderBy, GenericValue value) throws GenericEntityException {
+        return getRelated(relationName, byAndFields, orderBy, value, false);
+    }
+
+    /* (non-Javadoc)
+     * @see org.ofbiz.entity.Delegator#getRelated(java.lang.String, java.util.Map, java.util.List, org.ofbiz.entity.GenericValue, boolean)
+     */
+    public List<GenericValue> getRelated(String relationName, Map<String, ? extends Object> byAndFields, List<String> orderBy, GenericValue value, boolean useCache) throws GenericEntityException {
         ModelEntity modelEntity = value.getModelEntity();
         ModelRelation relation = modelEntity.getRelation(relationName);
 
@@ -1962,7 +1969,7 @@ public class GenericDelegator implements
             fields.put(keyMap.getRelFieldName(), value.get(keyMap.getFieldName()));
         }
 
-        return this.findByAnd(relation.getRelEntityName(), fields, orderBy, false);
+        return this.findByAnd(relation.getRelEntityName(), fields, orderBy, useCache);
     }
 
     /* (non-Javadoc)
@@ -1995,20 +2002,7 @@ public class GenericDelegator implements
      * @see org.ofbiz.entity.Delegator#getRelatedCache(java.lang.String, org.ofbiz.entity.GenericValue)
      */
     public List<GenericValue> getRelatedCache(String relationName, GenericValue value) throws GenericEntityException {
-        ModelEntity modelEntity = value.getModelEntity();
-        ModelRelation relation = modelEntity.getRelation(relationName);
-
-        if (relation == null) {
-            throw new GenericModelException("Could not find relation for relationName: " + relationName + " for value " + value);
-        }
-
-        Map<String, Object> fields = FastMap.newInstance();
-        for (int i = 0; i < relation.getKeyMapsSize(); i++) {
-            ModelKeyMap keyMap = relation.getKeyMap(i);
-            fields.put(keyMap.getRelFieldName(), value.get(keyMap.getFieldName()));
-        }
-
-        return this.findByAnd(relation.getRelEntityName(), fields, null, true);
+        return getRelated(relationName, null, null, value, true);
     }
 
     /* (non-Javadoc)

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericValue.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericValue.java?rev=1343506&r1=1343505&r2=1343506&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericValue.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericValue.java Tue May 29 04:16:42 2012
@@ -167,7 +167,7 @@ public class GenericValue extends Generi
      *@return List of GenericValue instances as specified in the relation definition
      */
     public List<GenericValue> getRelated(String relationName) throws GenericEntityException {
-        return this.getDelegator().getRelated(relationName, null, null, this);
+        return this.getDelegator().getRelated(relationName, null, null, this, false);
     }
 
     /** Get the named Related Entity for the GenericValue from the persistent store
@@ -177,7 +177,7 @@ public class GenericValue extends Generi
      *@return List of GenericValue instances as specified in the relation definition
      */
     public List<GenericValue> getRelated(String relationName, List<String> orderBy) throws GenericEntityException {
-        return this.getDelegator().getRelated(relationName, FastMap.<String, Object>newInstance(), orderBy, this);
+        return this.getDelegator().getRelated(relationName, FastMap.<String, Object>newInstance(), orderBy, this, false);
     }
 
     /** Get the named Related Entity for the GenericValue from the persistent store
@@ -188,7 +188,7 @@ public class GenericValue extends Generi
      *@return List of GenericValue instances as specified in the relation definition
      */
     public List<GenericValue> getRelated(String relationName, Map<String, ? extends Object> byAndFields, List<String> orderBy) throws GenericEntityException {
-        return this.getDelegator().getRelated(relationName, byAndFields, orderBy, this);
+        return this.getDelegator().getRelated(relationName, byAndFields, orderBy, this, false);
     }
 
     /** Get the named Related Entity for the GenericValue from the persistent
@@ -197,7 +197,7 @@ public class GenericValue extends Generi
      *@return List of GenericValue instances as specified in the relation definition
      */
     public List<GenericValue> getRelatedCache(String relationName) throws GenericEntityException {
-        return this.getDelegator().getRelatedCache(relationName, this);
+        return this.getDelegator().getRelated(relationName, null, null, this, true);
     }
 
     /**
@@ -237,11 +237,7 @@ public class GenericValue extends Generi
      *@return List of GenericValue instances as specified in the relation definition
      */
     public List<GenericValue> getRelatedCache(String relationName, Map<String, ? extends Object> byAndFields, List<String> orderBy) throws GenericEntityException {
-        List<GenericValue> col = getRelatedCache(relationName);
-
-        if (byAndFields != null) col = EntityUtil.filterByAnd(col, byAndFields);
-        if (UtilValidate.isNotEmpty(orderBy)) col = EntityUtil.orderBy(col, orderBy);
-        return col;
+        return this.getDelegator().getRelated(relationName, byAndFields, orderBy, this, true);
     }
 
     /** Get the named Related Entity for the GenericValue from the persistent
@@ -252,7 +248,7 @@ public class GenericValue extends Generi
      *@return List of GenericValue instances as specified in the relation definition
      */
     public List<GenericValue> getRelatedCache(String relationName, List<String> orderBy) throws GenericEntityException {
-        return this.getRelatedCache(relationName, null, orderBy);
+        return this.getDelegator().getRelated(relationName, null, orderBy, this, true);
     }
 
     /** Get the named Related Entity for the GenericValue from the persistent
@@ -361,7 +357,7 @@ public class GenericValue extends Generi
      *@return List of GenericValue instances as specified in the relation definition
      */
     public List<GenericValue> getRelatedByAnd(String relationName, Map<String, ? extends Object> fields) throws GenericEntityException {
-        return this.getDelegator().getRelated(relationName, fields, null, this);
+        return this.getDelegator().getRelated(relationName, fields, null, this, false);
     }
 
     /** Get the named Related Entity for the GenericValue from the persistent
@@ -371,7 +367,7 @@ public class GenericValue extends Generi
      *@return List of GenericValue instances as specified in the relation definition
      */
     public List<GenericValue> getRelatedByAndCache(String relationName, Map<String, ? extends Object> fields) throws GenericEntityException {
-        return EntityUtil.filterByAnd(this.getDelegator().getRelatedCache(relationName, this), fields);
+        return this.getDelegator().getRelated(relationName, fields, null, this, true);
     }
 
     /** Get the named Related Entity for the GenericValue from the persistent
@@ -391,7 +387,7 @@ public class GenericValue extends Generi
      *@return List of GenericValue instances as specified in the relation definition
      */
     public List<GenericValue> getRelatedOrderBy(String relationName, List<String> orderBy) throws GenericEntityException {
-        return this.getDelegator().getRelated(relationName, null, orderBy, this);
+        return this.getDelegator().getRelated(relationName, null, orderBy, this, false);
     }
 
     /** Get the named Related Entity for the GenericValue from the persistent
@@ -401,7 +397,7 @@ public class GenericValue extends Generi
      *@return List of GenericValue instances as specified in the relation definition
      */
     public List<GenericValue> getRelatedOrderByCache(String relationName, List<String> orderBy) throws GenericEntityException {
-        return EntityUtil.orderBy(this.getDelegator().getRelatedCache(relationName, this), orderBy);
+        return this.getDelegator().getRelated(relationName, null, orderBy, this, true);
     }
 
     /** Get the named Related Entity for the GenericValue from the persistent