From a9ac2afbdbfdb0159ea61d1b4929f601b39dcfa5 Mon Sep 17 00:00:00 2001 From: Adam Heath Date: Fri, 30 Jul 2010 03:28:09 +0000 Subject: [PATCH] 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). git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@980642 13f79535-47bb-0310-9956-ffa450edef68 --- .../ofbiz/entity/condition/EntityExpr.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/framework/entity/src/org/ofbiz/entity/condition/EntityExpr.java b/framework/entity/src/org/ofbiz/entity/condition/EntityExpr.java index 287e8b16f8..c10318a5fd 100644 --- a/framework/entity/src/org/ofbiz/entity/condition/EntityExpr.java +++ b/framework/entity/src/org/ofbiz/entity/condition/EntityExpr.java @@ -260,6 +260,30 @@ public class EntityExpr extends EntityCondition { // 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())) {