From d39357273835c74b64c7b390dc93c3121c2545bd Mon Sep 17 00:00:00 2001 From: Samuel Pelletier Date: Mon, 10 Jun 2024 12:11:51 -0400 Subject: [PATCH] Add support for any object in ERXExisitsQualifier (memory evaluation) Fixed by replacing the assumption that the objects are conforming to NSKeyValueCodingAdditions and use the utility implementation instead. --- .../eof/qualifiers/ERXExistsQualifier.java | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/Frameworks/Core/ERExtensions/Sources/er/extensions/eof/qualifiers/ERXExistsQualifier.java b/Frameworks/Core/ERExtensions/Sources/er/extensions/eof/qualifiers/ERXExistsQualifier.java index b7708e9b1a1..c9f650ab7da 100644 --- a/Frameworks/Core/ERExtensions/Sources/er/extensions/eof/qualifiers/ERXExistsQualifier.java +++ b/Frameworks/Core/ERExtensions/Sources/er/extensions/eof/qualifiers/ERXExistsQualifier.java @@ -44,7 +44,6 @@ import er.extensions.eof.ERXKey; import er.extensions.foundation.ERXArrayUtilities; import er.extensions.foundation.ERXStringUtilities; -import er.extensions.qualifiers.ERXPrefixQualifierTraversal; /** * A qualifier that qualifies using an EXISTS clause. @@ -68,7 +67,7 @@ public class ERXExistsQualifier extends EOQualifier implements Cloneable, NSCodi */ static final Logger log = LoggerFactory.getLogger(ERXExistsQualifier.class); - private static final Pattern PATTERN = Pattern.compile("([ '\"\\(]|^)(t)([0-9])([ ,\\.'\"\\(]|$)"); + static final Pattern PATTERN = Pattern.compile("([ '\"\\(]|^)(t)([0-9])([ ,\\.'\"\\(]|$)"); public static final String EXISTS_ALIAS = "exists"; public static final boolean UseSQLInClause = true; @@ -95,6 +94,7 @@ public class ERXExistsQualifier extends EOQualifier implements Cloneable, NSCodi * Public single argument constructor. Use this constructor for sub-qualification on the same table. * @param subqualifier sub-qualifier */ + @SuppressWarnings("hiding") public ERXExistsQualifier(EOQualifier subqualifier) { this(subqualifier, null); } @@ -106,6 +106,7 @@ public ERXExistsQualifier(EOQualifier subqualifier) { * @param baseKeyPath to the entity to which the subqualifier will be applied. Note that this should end in a * relationship rather than an attribute, e.g., the key path from an Employee might be department.division. */ + @SuppressWarnings("hiding") public ERXExistsQualifier(EOQualifier subqualifier, String baseKeyPath) { super(); /* @@ -136,7 +137,8 @@ public ERXExistsQualifier(EOQualifier subqualifier, String baseKeyPath) { * relationship rather than an attribute, e.g., the key path from an Employee might be department.division. * @param usesInQualInstead when true will convert the EXISTS clause into an IN clause - to be used if it makes the query plan faster. */ - public ERXExistsQualifier(EOQualifier subqualifier, String baseKeyPath, boolean usesInQualInstead) { + @SuppressWarnings("hiding") + public ERXExistsQualifier(EOQualifier subqualifier, String baseKeyPath, boolean usesInQualInstead) { this(subqualifier, baseKeyPath); setUsesInQualInstead(usesInQualInstead); } @@ -470,12 +472,13 @@ public static Object decodeWithKeyValueUnarchiver(EOKeyValueUnarchiver unarchive @Override public boolean evaluateWithObject(Object object) { boolean match = false; - NSKeyValueCodingAdditions obj = (NSKeyValueCodingAdditions) object; - if (obj != null && subqualifier != null) { - NSKeyValueCodingAdditions finalObj = baseKeyPath != null ? (NSKeyValueCodingAdditions) obj.valueForKeyPath(baseKeyPath) : obj; - if (finalObj != null) { - if (finalObj instanceof NSArray) { - NSArray objArray = (NSArray) finalObj; + if (object != null && subqualifier != null) { + if (baseKeyPath != null) { + object = NSKeyValueCodingAdditions.Utility.valueForKeyPath(object, baseKeyPath); + } + if (object != null) { + if (object instanceof NSArray) { + NSArray objArray = (NSArray) object; objArray = ERXArrayUtilities.removeNullValues(objArray); if (objArray != null && objArray.count() > 0) { for (NSKeyValueCoding objInArray : objArray) { @@ -491,7 +494,7 @@ public boolean evaluateWithObject(Object object) { } } } else { - match = subqualifier.evaluateWithObject(finalObj); + match = subqualifier.evaluateWithObject(object); } } } @@ -502,8 +505,8 @@ public boolean usesInQualInstead() { return usesInQualInstead; } + @SuppressWarnings("hiding") public void setUsesInQualInstead(boolean usesInQualInstead) { this.usesInQualInstead = usesInQualInstead; } - }