Skip to content

Commit

Permalink
Add containsAnyOfTheseObjects that build a qualifier to find objects …
Browse files Browse the repository at this point in the history
…where a to many key contains at least one the the objects found in the array specified.

Add versions of containsAnyObjectSatisfying and doesNotContainsAnyObjectSatisfying that uses the IN version of ERXExistsQualifier.
  • Loading branch information
spelletier committed May 15, 2016
1 parent 06689a4 commit 45758d4
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions Frameworks/Core/ERExtensions/Sources/er/extensions/eof/ERXKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
import java.util.Locale;

import com.webobjects.eoaccess.EOAttribute;
import com.webobjects.eoaccess.EOEntity;
import com.webobjects.eoaccess.EOModel;
import com.webobjects.eoaccess.EORelationship;
import com.webobjects.eocontrol.EOEnterpriseObject;
import com.webobjects.eocontrol.EOQualifier;
import com.webobjects.eocontrol.EOSortOrdering;
import com.webobjects.foundation.NSArray;
import com.webobjects.foundation.NSDictionary;
import com.webobjects.foundation.NSKeyValueCodingAdditions;
import com.webobjects.foundation.NSRange;
import com.webobjects.foundation.NSSelector;
Expand Down Expand Up @@ -2361,6 +2363,26 @@ public ERXKeyValueQualifier containsObject(Object obj) {
return ERXQ.containsObject(_key, obj);
}

/**
* Uses ERXExistsQualifier with an array of identity qualifiers to build a qualifier that
* returns true if at least one the the objects specified is found in the to many relationship
* represented by this key.
*
* @param valueArray
* an array of {@link ERXGenericRecord} we want to have in this to many relationship.
* @return a qualifier that evaluates to true when at least one the the objects specified in
* {@code valueArray} is found in the to many {@link EORelationship}
* represented by this ERXKey.
*
* @author Samuel Pelletier
* @since May 56, 2016
*/
public ERXExistsQualifier containsAnyOfTheseObjects(NSArray<? extends ERXGenericRecord> valueArray) {
ERXExistsQualifier existsQualifier = new ERXExistsQualifier(ERXQ.isIn(valueArray), _key);
existsQualifier.setUsesInQualInstead(true);
return existsQualifier;
}

/**
* Equivalent to <code>new ERXExistsQualifier(qualifier, key)</code>.
*
Expand Down Expand Up @@ -2403,6 +2425,44 @@ public ERXNotQualifier doesNotContainsAnyObjectSatisfying(EOQualifier qualifier)
return new ERXNotQualifier(containsAnyObjectSatisfying(qualifier));
}

/**
* Equivalent to containsAnyObjectSatisfying() but set the ERXExistsQualifier to uses IN instead of EXISTS.
*
* @param qualifier
* a qualifier for the {@link EORelationship#destinationEntity()
* destinationEntity} of the {@link EORelationship} represented
* by this ERXKey
* @return a qualifier that evaluates to true when the {@link EORelationship}
* represented by this ERXKey contains at least one object matching
* the given {@code qualifier}
*
* @author Samuel Pelletier
* @since May 56, 2016
*/
public ERXExistsQualifier containsAnyObjectSatisfyingUsingIn(EOQualifier qualifier) {
ERXExistsQualifier existsQualifier = new ERXExistsQualifier(qualifier, _key);
existsQualifier.setUsesInQualInstead(true);
return existsQualifier;
}

/**
* Equivalent to doesNotContainsAnyObjectSatisfying() but set the ERXExistsQualifier to uses IN instead of EXISTS.
*
* @param qualifier
* a qualifier for the {@link EORelationship#destinationEntity()
* destinationEntity} of the {@link EORelationship} represented
* by this ERXKey
* @return a qualifier that evaluates to true when the {@link EORelationship}
* represented by this ERXKey does not contains at least one object matching
* the given {@code qualifier}
*
* @author Samuel Pelletier
* @since May 56, 2016
*/
public ERXNotQualifier doesNotContainsAnyObjectSatisfyingUsingIn(EOQualifier qualifier) {
return new ERXNotQualifier(containsAnyObjectSatisfyingUsingIn(qualifier));
}

/**
* Determines if there are any objects in the to-one or to-many
* {@link EORelationship} that this ERXKey represents.
Expand Down

0 comments on commit 45758d4

Please sign in to comment.