Skip to content

Instantly share code, notes, and snippets.

@hprange
Created June 12, 2019 14:17
Show Gist options
  • Save hprange/9ec8752017a8171b5c6cc16c6966404a to your computer and use it in GitHub Desktop.
Save hprange/9ec8752017a8171b5c6cc16c6966404a to your computer and use it in GitHub Desktop.
A class to compare EOs according to the eoEquals contract when evaluating qualifiers in memory.
package org.wocommunity.eof;
import com.webobjects.eocontrol.EOEnterpriseObject;
import com.webobjects.eocontrol.EOQualifier.ComparisonSupport;
import com.webobjects.foundation.NSKeyValueCoding;
import er.extensions.eof.ERXEOControlUtilities;
/**
* The {@code EOComparisonSupport} extends the {@code EOQualifier.ComparisonSupport} class and evaluates all
* {@code EOGenericRecord} objects according to the {@code ERXEOControlUtilities.eoEquals} contract.
* <p>
* Include the code below during the application initialization to enable support for this class:
*
* <pre>
* EOKeyValueQualifier.ComparisonSupport.setSupportForClass(new EOComparisonSupport(), EOGenericRecord.class);
* </pre>
*
* Note: This class fixes the problem when evaluating toOne relationships in memory. It doesn't change the behavior when
* evaluating arrays of EOs using the contains selector.
*
* @author <a href="mailto:hprange@gmail.com.br">Henrique Prange</a>
*/
public class EOComparisonSupport extends ComparisonSupport {
/**
* Compares two {@code EOEnterpriseObject}s according to the {@code ERXEOControlUtilities.eoEquals} contract.
*
* @see com.webobjects.eocontrol.EOQualifier.ComparisonSupport#isEqualTo(java.lang.Object, java.lang.Object)
*/
@Override
public boolean isEqualTo(Object left, Object right) {
Object leftValue = left == NSKeyValueCoding.NullValue ? null : left;
Object rightValue = right == NSKeyValueCoding.NullValue ? null : right;
return ERXEOControlUtilities.eoEquals((EOEnterpriseObject) leftValue, (EOEnterpriseObject) rightValue);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment