svn commit: r980642 - /ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityExpr.java

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

svn commit: r980642 - /ofbiz/trunk/framework/entity/src/org/ofbiz/entity/condition/EntityExpr.java

doogie-3
Author: doogie
Date: Fri Jul 30 03:28:09 2010
New Revision: 980642

URL: http://svn.apache.org/viewvc?rev=980642&view=rev
Log:
In checkRhs, add support for the rhs being an EntityFieldValue(this is a
partial fix, rhs can actually be *any* EntityConditionValue, so this
logic really needs to be revisited).

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

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=980642&r1=980641&r2=980642&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 Fri Jul 30 03:28:09 2010
@@ -260,6 +260,30 @@ public class EntityExpr extends EntityCo
                 // eventually we should do this, but for now we'll do a "soft" failure: throw new IllegalArgumentException(errMsg);
                 Debug.logWarning(e, "=-=-=-=-=-=-=-=-= Database type warning in EntityExpr =-=-=-=-=-=-=-=-= " + errMsg, module);
              }
+        } else if (value instanceof EntityFieldValue) {
+            EntityFieldValue efv = (EntityFieldValue) this.lhs;
+            String rhsFieldName = efv.getFieldName();
+            ModelField rhsField = modelEntity.getField(fieldName);
+            if (rhsField == null) {
+                throw new IllegalArgumentException("FieldName " + rhsFieldName + " not found for entity: " + modelEntity.getEntityName());
+            }
+            ModelFieldType rhsType = null;
+            try {
+                rhsType = delegator.getEntityFieldType(modelEntity, rhsField.getType());
+            } catch (GenericEntityException e) {
+                Debug.logWarning(e, module);
+            }
+            try {
+                if (!ObjectType.instanceOf(ObjectType.loadClass(rhsType.getJavaType()), type.getJavaType())) {
+                    String errMsg = "Warning using ["+ value.getClass().getName() + "] and entity field [" + modelEntity.getEntityName() + "." + curField.getName() + "]. The Java type [" + rhsType.getJavaType() + "] of rhsFieldName : [" + rhsFieldName + "] is not compatible with the Java type of the field [" + type.getJavaType() + "]";
+                    // eventually we should do this, but for now we'll do a "soft" failure: throw new IllegalArgumentException(errMsg);
+                    Debug.logWarning(new Exception("Location of database type warning"), "=-=-=-=-=-=-=-=-= Database type warning in EntityExpr =-=-=-=-=-=-=-=- " + errMsg, module);
+                }
+            } catch (ClassNotFoundException e) {
+                String errMsg = "Warning using ["+ value.getClass().getName() + "] and entity field [" + modelEntity.getEntityName() + "." + curField.getName() + "]. The Java type [" + rhsType.getJavaType() + "] of rhsFieldName : [" + rhsFieldName + "] could not be found]";
+                // eventually we should do this, but for now we'll do a "soft" failure: throw new IllegalArgumentException(errMsg);
+                Debug.logWarning(e, "=-=-=-=-=-=-=-=-= Database type warning in EntityExpr =-=-=-=-=-=-=-=-= " + errMsg, module);
+            }
         } else {
         // make sure the type matches the field Java type
             if (!ObjectType.instanceOf(value, type.getJavaType())) {