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

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

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

doogie-3
Author: doogie
Date: Tue May 29 04:10:44 2012
New Revision: 1343475

URL: http://svn.apache.org/viewvc?rev=1343475&view=rev
Log:
FEATURE: Add Delegator.getRelatedOne variant that takes a boolean useCache parameter.
Rework internal GenericDelegator methods to call the new method, but no
other external classes directly call this new one yet.

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=1343475&r1=1343474&r2=1343475&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:10:44 2012
@@ -830,6 +830,23 @@ public interface Delegator {
      */
     public GenericValue getRelatedOneCache(String relationName, GenericValue value) throws GenericEntityException;
 
+    /**
+     * Get related entity where relation is of type one, uses findByPrimaryKey
+     *
+     * @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 value
+     *            GenericValue instance containing the entity
+     * @param useCache
+     *            Whether to cache the results
+     * @return GenericValue that is the related entity
+     * @throws IllegalArgumentException
+     *             if the list found has more than one item
+     */
+    public GenericValue getRelatedOne(String relationName, GenericValue value, boolean useCache) throws GenericEntityException;
+
     public void initEntityEcaHandler();
 
     public void initDistributedCacheClear();

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=1343475&r1=1343474&r2=1343475&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:10:44 2012
@@ -2015,30 +2015,21 @@ public class GenericDelegator implements
      * @see org.ofbiz.entity.Delegator#getRelatedOne(java.lang.String, org.ofbiz.entity.GenericValue)
      */
     public GenericValue getRelatedOne(String relationName, GenericValue value) throws GenericEntityException {
-        ModelRelation relation = value.getModelEntity().getRelation(relationName);
-
-        if (relation == null) {
-            throw new GenericModelException("Could not find relation for relationName: " + relationName + " for value " + value);
-        }
-        if (!"one".equals(relation.getType()) && !"one-nofk".equals(relation.getType())) {
-            throw new GenericModelException("Relation is not a 'one' or a 'one-nofk' relation: " + relationName + " of entity " + value.getEntityName());
-        }
-
-        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.findOne(relation.getRelEntityName(), fields, false);
+        return this.getRelatedOne(relationName, value, false);
     }
 
     /* (non-Javadoc)
      * @see org.ofbiz.entity.Delegator#getRelatedOneCache(java.lang.String, org.ofbiz.entity.GenericValue)
      */
     public GenericValue getRelatedOneCache(String relationName, GenericValue value) throws GenericEntityException {
-        ModelEntity modelEntity = value.getModelEntity();
-        ModelRelation relation = modelEntity.getRelation(relationName);
+        return this.getRelatedOne(relationName, value, true);
+    }
+
+    /* (non-Javadoc)
+     * @see org.ofbiz.entity.Delegator#getRelatedOne(java.lang.String, org.ofbiz.entity.GenericValue, boolean)
+     */
+    public GenericValue getRelatedOne(String relationName, GenericValue value, boolean useCache) throws GenericEntityException {
+        ModelRelation relation = value.getModelEntity().getRelation(relationName);
 
         if (relation == null) {
             throw new GenericModelException("Could not find relation for relationName: " + relationName + " for value " + value);
@@ -2053,7 +2044,7 @@ public class GenericDelegator implements
             fields.put(keyMap.getRelFieldName(), value.get(keyMap.getFieldName()));
         }
 
-        return this.findOne(relation.getRelEntityName(), fields, true);
+        return this.findOne(relation.getRelEntityName(), fields, useCache);
     }
 
 

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=1343475&r1=1343474&r2=1343475&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:10:44 2012
@@ -313,7 +313,7 @@ public class GenericValue extends Generi
      *@return List of GenericValue instances as specified in the relation definition
      */
     public GenericValue getRelatedOne(String relationName) throws GenericEntityException {
-        return this.getDelegator().getRelatedOne(relationName, this);
+        return this.getDelegator().getRelatedOne(relationName, this, false);
     }
 
     /** Get the named Related Entity for the GenericValue from the persistent
@@ -322,7 +322,7 @@ public class GenericValue extends Generi
      *@return List of GenericValue instances as specified in the relation definition
      */
     public GenericValue getRelatedOneCache(String relationName) throws GenericEntityException {
-        return this.getDelegator().getRelatedOneCache(relationName, this);
+        return this.getDelegator().getRelatedOne(relationName, this, true);
     }
 
     /** Get the named Related Entity for the GenericValue from the persistent