public class ERXEOControlUtilities extends Object
Constructor and Description |
---|
ERXEOControlUtilities() |
Modifier and Type | Method and Description |
---|---|
static Object |
_aggregateFunctionWithQualifier(EOEditingContext ec,
String entityName,
String attributeName,
String function,
Class valueClass,
String valueType,
EOQualifier qualifier) |
static Object |
_aggregateFunctionWithQualifierAndAggregateAttribute(EOEditingContext ec,
String entityName,
EOQualifier qualifier,
EOAttribute aggregateAttribute)
Returns the number of objects in the database with the qualifier and counting attribute.
|
static String |
_stringForPrimaryKey(Object pk)
Returns the propertylist-encoded string representation of the primary key for
a given object.
|
static void |
addObjectToObjectOnBothSidesOfRelationshipWithKey(EOEnterpriseObject addedObject,
EOEnterpriseObject referenceObject,
String key)
Adds an object to another objects relationship.
|
static Number |
aggregateFunctionWithQualifier(EOEditingContext ec,
String entityName,
String attributeName,
String function,
EOQualifier qualifier)
Computes an aggregate function for a given string attribute
restricted by a given qualifier.
|
static Number |
aggregateFunctionWithQualifier(EOEditingContext ec,
String entityName,
String attributeName,
String function,
String fetchSpecificationName,
NSDictionary bindings)
Computes an aggregate function for a given attribute
restricted by a given qualifier.
|
static String |
aggregateStringWithQualifier(EOEditingContext ec,
String entityName,
String attributeName,
String function,
EOQualifier qualifier)
Computes an aggregate function for a given attribute
restricted by a given qualifier.
|
static NSTimestamp |
aggregateTimestampWithQualifier(EOEditingContext ec,
String entityName,
String attributeName,
String function,
EOQualifier qualifier)
Computes an aggregate function for a given attribute
restricted by a given qualifier.
|
static EOQualifier |
andQualifier(EOQualifier q1,
EOQualifier q2)
Joins the given qualifiers with an AND.
|
static NSArray |
arrayFromDataSource(EODataSource dataSource)
Converts a data source into an array.
|
static NSDictionary<String,Integer> |
changedRegisteredObjectCount(NSDictionary<String,Integer> currentCounts,
NSDictionary<String,Integer> oldCounts)
Returns the changes in count registered objects in the EC grouped by entity name, which is useful for memory debugging.
|
static void |
clearSnapshotForRelationshipNamed(EOEnterpriseObject eo,
String relationshipName)
Clears snapshot the relationship of a given enterprise so it will be read again when next accessed.
|
static void |
clearSnapshotForRelationshipNamedInDatabase(EOEnterpriseObject eo,
String relationshipName,
EODatabase database)
Clears snapshot the relationship of a given enterprise so it will be read again when next accessed.
|
static Object |
convertEOtoGID(Object obj)
Given a dictionary, array, set, EO, etc, this will recursively turn
EO's into GID's.
|
static Object |
convertGIDtoEO(EOEditingContext editingContext,
Object obj)
Given a dictionary, array, set, EO, etc, this will recursively turn
GID's into EO's.
|
static EOEnterpriseObject |
createAndAddObjectToRelationship(EOEditingContext editingContext,
EOEnterpriseObject source,
String relationshipName,
String destinationEntityName,
NSDictionary objectInfo)
Creates an object using the utility method
createEO
from this utility class. |
static <T extends EOEnterpriseObject> |
createAndInsertObject(EOEditingContext ec,
Class<T> eoClass)
Creates an enterprise object for the given entity
name by first looking up the class description
of the entity to create the enterprise object.
|
static EOEnterpriseObject |
createAndInsertObject(EOEditingContext editingContext,
String entityName)
Creates an enterprise object for the given entity
name by first looking up the class description
of the entity to create the enterprise object.
|
static EOEnterpriseObject |
createAndInsertObject(EOEditingContext editingContext,
String entityName,
NSDictionary objectInfo)
Creates an enterprise object for the given entity
name by first looking up the class description
of the entity to create the enterprise object and
then adding values from the dictionary.
|
static EOArrayDataSource |
dataSourceForArray(EOEditingContext ec,
String entityName,
NSArray array)
Simple utility method that will convert an array
of enterprise objects into an EOArrayDataSource.
|
static EOArrayDataSource |
dataSourceForArray(NSArray<? extends EOEnterpriseObject> array)
Simple utility method that will convert an array
of enterprise objects into an EOArrayDataSource.
|
static EODetailDataSource |
dataSourceForObjectAndKey(EOEnterpriseObject object,
String key)
Creates a detail data source for a given enterprise
object and a relationship key.
|
static NSMutableArray |
deletedObjects(EOEditingContext editingContext,
NSArray<String> entityNames,
EOQualifier qualifier)
Return the array of objects of the given type that have been deleted from
the editing context and match the given qualifier.
|
static String |
destinationEntityNameForKeyPath(EOEnterpriseObject eo,
String keyPath)
Convenience to get the destination entity name from a key path of an object.
|
static <T> NSArray<T> |
distinctValuesForKeyPath(EOEditingContext editingContext,
String entityName,
String keyPath,
EOQualifier qualifier,
NSArray<EOSortOrdering> sortOrderings)
Returns an NSArray of distinct values available for the given entity and key path.
|
static <T extends EOEnterpriseObject> |
editableInstanceOfObject(T eo,
boolean createNestedContext)
Creates a new, editable instance of the supplied object.
|
static boolean |
eoEquals(EOEnterpriseObject firstEO,
EOEnterpriseObject secondEO)
Determines if two EOs are equal by comparing their EOGlobalIDs.
|
static <T extends EOEnterpriseObject> |
faultsForGlobalIDs(EOEditingContext ec,
NSArray<? extends EOGlobalID> gids)
Returns a NSArray containing EOEnterpriseObjects (actually faults...) for the provided EOGlobalIDs.
|
static <T extends EOEnterpriseObject> |
faultsForRawRowsFromEntity(EOEditingContext ec,
NSArray primKeys,
String entityName) |
static EOFetchSpecification |
fetchSpecificationNamedWithBindings(String entityName,
String fetchSpecificationName,
NSDictionary bindings)
Gets a fetch specification from a given entity.
|
static NSArray |
filteredObjectsWithQualifier(EOEditingContext editingContext,
NSArray objectsToFilter,
String entityName,
EOQualifier qualifier,
NSArray sortOrderings,
boolean usesDistinct,
boolean isDeep,
boolean includeNewObjects,
boolean includeNewObjectsInParentEditingContext,
boolean filterUpdatedObjects,
boolean removeDeletedObjects)
Utility method used to filter an array of objects given a qualifier.
|
static EOGlobalID |
globalIDForString(EOEditingContext ec,
String entityName,
String string)
Returns the decoded global id for an propertylist encoded string representation
of the primary key for a given object.
|
static NSArray<EOGlobalID> |
globalIDsForObjects(NSArray<? extends EOEnterpriseObject> eos)
Returns a NSArray containing EOGlobalIDs from the provided eos.
|
static NSMutableArray |
insertedObjects(EOEditingContext editingContext,
NSArray<String> entityNames,
EOQualifier qualifier)
Returns the array of objects of the given type that have been inserted into
the editing context and match the given qualifier.
|
static boolean |
isNewObject(EOEnterpriseObject eo)
Determines if an enterprise object is a new object and
hasn't been saved to the database yet.
|
static <T extends EOEnterpriseObject> |
localInstanceOfObject(EOEditingContext ec,
T eo)
This has one advantage over the standard EOUtilites
method of first checking if the editingcontexts are
equal before creating a fault for the object in the
editing context.
|
static EOQualifier |
localInstancesInQualifier(EOEditingContext ec,
EOQualifier q)
Faults every EO in the qualifiers into the specified editingContext.
|
static <T extends EOEnterpriseObject> |
localInstancesOfObjects(EOEditingContext ec,
NSArray<T> eos)
Provides the same functionality as the equivalent method
in
EOUtilities
except it will use the localInstanceOfObject
method from this utilities class which has a few enhancements. |
static void |
makeQualifierTrue(EOQualifier qualifier,
Object obj)
Given a qualifier of EOAndQualifiers and EOKVQualifiers, make then evaluate to
true on the given object.
|
static NSDictionary<String,Object> |
newPrimaryKeyDictionaryForEntityNamed(EOEditingContext ec,
String entityName)
Utility method to generate a new primary key dictionary using
the adaptor for a given entity.
|
static NSDictionary<String,Object> |
newPrimaryKeyDictionaryForObject(EOEnterpriseObject eo)
Utility method to generate a new primary key for an object.
|
static NSDictionary<String,Object> |
newPrimaryKeyDictionaryForObjectFromClassProperties(EOEnterpriseObject eo)
Utility method to generate a new primary key dictionary using
the objects class properties.
|
static Integer |
objectCountForToManyRelationship(EOEnterpriseObject object,
String relationshipName)
Counts the objects in a toMany relationship in an effective way.
|
static Integer |
objectCountUniqueWithQualifierAndAttribute(EOEditingContext ec,
String entityName,
EOQualifier qualifier,
String attributeName)
Returns the number of unique objects matching the given
qualifier for a given entity name.
|
static Integer |
objectCountWithQualifier(EOEditingContext ec,
String entityName,
EOQualifier qualifier)
Returns the number of objects matching the given
qualifier for a given entity name.
|
static NSArray |
objectsForFaults(EOEditingContext ec,
NSArray possibleFaults)
Triggers all faults in an efficient manner.
|
static NSArray |
objectsForFaultWithSortOrderings(EOEditingContext ec,
NSArray possibleFaults,
NSArray sortOrderings)
Uses
ERXEOControlUtilities.objectForFaults to turn the faults into objects, then does in memory
ordering with EOSortOrdering.EOSortOrdering.sortedArrayUsingKeyOrderArray() |
static <T extends EOEnterpriseObject> |
objectsForGlobalIDs(EOEditingContext ec,
NSArray<EOGlobalID> globalIDs)
Aggregate method for
EOEditingContext.objectForGlobalID() . |
static <T extends EOEnterpriseObject> |
objectsInRange(EOEditingContext ec,
EOFetchSpecification spec,
int start,
int end)
Returns an
NSArray containing the objects from the resulting rows starting
at start and stopping at end using a custom SQL, derived from the SQL
which the EOFetchSpecification would use normally setHints() |
static <T extends EOEnterpriseObject> |
objectsInRange(EOEditingContext ec,
EOFetchSpecification spec,
int start,
int end,
boolean rawRowsForCustomQueries)
Returns an
NSArray containing the objects from the resulting rows starting
at start and stopping at end using a custom SQL, derived from the SQL
which the EOFetchSpecification would use normally setHints() |
static NSArray |
objectsWithQualifier(EOEditingContext ec,
String entityName,
EOQualifier qualifier,
NSArray prefetchKeyPaths,
boolean includeNewObjects)
Calls objectsWithQualifier(ec, entityName, qualifier, prefetchKeyPaths, includeNewObjects, false).
|
static NSArray |
objectsWithQualifier(EOEditingContext _editingContext,
String _entityName,
EOQualifier _qualifier,
NSArray _prefetchKeyPaths,
boolean _includeNewObjects,
boolean _includeNewObjectsInParentEditingContext) |
static NSArray |
objectsWithQualifier(EOEditingContext editingContext,
String entityName,
EOQualifier qualifier,
NSArray prefetchKeyPaths,
boolean includeNewObjects,
boolean includeNewObjectsInParentEditingContext,
boolean filterUpdatedObjects,
boolean removeDeletedObjects)
Utility method used to fetch an array of objects given a qualifier.
|
static NSArray |
objectsWithQualifier(EOEditingContext editingContext,
String entityName,
EOQualifier qualifier,
NSArray prefetchKeyPaths,
NSArray sortOrderings,
boolean usesDistinct,
boolean isDeep,
NSDictionary hints,
boolean includeNewObjects,
boolean includeNewObjectsInParentEditingContext,
boolean filterUpdatedObjects,
boolean removeDeletedObjects)
Utility method used to fetch an array of objects given a qualifier.
|
static NSArray |
objectsWithQualifier(EOEditingContext editingContext,
String entityName,
EOQualifier qualifier,
NSArray prefetchKeyPaths,
NSArray sortOrderings,
int fetchLimit,
boolean usesDistinct,
boolean isDeep,
NSDictionary hints,
boolean includeNewObjects,
boolean includeNewObjectsInParentEditingContext,
boolean filterUpdatedObjects,
boolean removeDeletedObjects)
Utility method used to fetch an array of objects given a qualifier.
|
static NSArray |
objectsWithQualifierFormat(EOEditingContext ec,
String entityName,
String qualifierFormat,
NSArray args,
NSArray prefetchKeyPaths,
boolean includeNewObjects)
Calls
objectsWithQualifierFormat(ec, entityName, qualifierFormat, args, prefetchKeyPaths, includeNewObjects, false) . |
static NSArray |
objectsWithQualifierFormat(EOEditingContext ec,
String entityName,
String qualifierFormat,
NSArray args,
NSArray prefetchKeyPaths,
boolean includeNewObjects,
boolean includeNewObjectsInParentEditingContexts)
Enhanced version of the utility method found in EOUtilities.
|
static EOEnterpriseObject |
objectWithPrimaryKeyValue(EOEditingContext ec,
String entityName,
Object primaryKeyValue,
NSArray prefetchingKeyPaths)
Fetches an enterprise object based on a given primary key value.
|
static EOEnterpriseObject |
objectWithPrimaryKeyValue(EOEditingContext ec,
String entityName,
Object primaryKeyValue,
NSArray prefetchingKeyPaths,
boolean refreshRefetchedObjects)
Fetches an enterprise object based on a given primary key value.
|
static EOEnterpriseObject |
objectWithPrimaryKeyValue(EOEditingContext ec,
String entityName,
Object primaryKeyValue,
NSArray prefetchingKeyPaths,
boolean refreshRefetchedObjects,
boolean throwIfMissing)
Fetches an enterprise object based on a given primary key value.
|
static EOEnterpriseObject |
objectWithQualifier(EOEditingContext editingContext,
String entityName,
EOQualifier qualifier)
Returns the single object of the given type matching the qualifier.
|
static EOQualifier |
orQualifier(EOQualifier q1,
EOQualifier q2)
Joins the given qualifiers with an OR.
|
static EOQualifier |
orQualifierForKeyPaths(NSArray keyPaths,
NSSelector selector,
NSArray values)
Creates an OR qualifier with the given selector for all the given key
paths and all the given search terms.
|
static EOQualifier |
orQualifierForKeyPaths(NSArray keyPaths,
NSSelector selector,
Object value)
Creates an OR qualifier with the given selector for all the given key paths.
|
static NSArray |
primaryKeyArrayForObject(EOEnterpriseObject obj)
Gives the primary key array for a given enterprise
object.
|
static NSDictionary<String,Object> |
primaryKeyDictionaryForString(EOEditingContext ec,
String entityName,
String string)
Returns the decoded dictionary for an propertylist encoded string representation
of the primary key for a given object.
|
static EOFetchSpecification |
primaryKeyFetchSpecificationForEntity(EOEditingContext ec,
String entityName,
EOQualifier eoqualifier,
NSArray<EOSortOrdering> sortOrderings,
NSArray<String> additionalKeys)
Constructs a fetch specification that will only fetch the primary
keys for a given qualifier.
|
static Object |
primaryKeyObjectForObject(EOEnterpriseObject eo)
Returns either the single object the PK consist of or the NSArray of its values if the key is compound.
|
static NSArray |
primaryKeysMatchingQualifier(EOEditingContext ec,
String entityName,
EOQualifier eoqualifier,
NSArray<EOSortOrdering> sortOrderings)
Fetches an array of primary keys matching a given qualifier
and sorted with a given array of sort orderings.
|
static String |
primaryKeyStringForGlobalID(EOKeyGlobalID gid)
Returns the propertylist-encoded string representation of the global ID.
|
static String |
primaryKeyStringForObject(EOEnterpriseObject eo)
Returns the propertylist-encoded string representation of the primary key for
a given object.
|
static NSArray<NSDictionary<String,Object>> |
primaryKeyValuesInRange(EOEditingContext ec,
EOFetchSpecification spec,
int start,
int end)
Returns an
NSArray containing the primary keys from the resulting rows starting
at start and stopping at end using a custom SQL, derived from the SQL
which the EOFetchSpecification would use normally setHints() |
static EOQualifier |
qualifierMatchingAnyKey(NSArray keys,
NSSelector selector,
Object value)
Creates an OR qualifier of EOKeyValueQualifiers for every keypath in the given array of keys.
|
static void |
refaultObject(EOEnterpriseObject eo)
Turns a given enterprise object back into a fault.
|
static void |
refreshObject(EOEnterpriseObject eo)
Sets the fetch time stamp of the eo's ec to now to ensure fresh data.
|
static NSDictionary<String,Integer> |
registeredObjectCount(EOEditingContext ec)
Returns the count of registered objects in the EC grouped by entity name, which is useful for memory debugging.
|
static EOEnterpriseObject |
requiredObjectWithQualifier(EOEditingContext editingContext,
String entityName,
EOQualifier qualifier)
Returns the single object of the given type matching the qualifier.
|
static EOEntity |
rootEntity(EOEnterpriseObject eo)
Returns the root entity from the EOEnterpriseObject
|
static String |
rootEntityName(EOEnterpriseObject eo)
Returns the name from the root entity from the EOEnterpriseObject
|
static EOFetchSpecification |
schemaBasedFetchSpecification(EOEditingContext ec,
EOFetchSpecification fetchSpecification)
Useful for ensuring a fetch specification is safe to pass around between
threads and not having to be concerned about references to EOs in the
qualifier.
|
static EOQualifier |
schemaBasedQualifier(EOEditingContext ec,
String entityName,
EOQualifier qualifier)
Useful for ensuring a qualifier is safe to pass around between threads and not having to be
concerned about references to EOs in it.
|
static EOEnterpriseObject |
sharedObjectMatchingKeyAndValue(String entityName,
String key,
Object value)
Finds an object in the shared editing context matching a key
and value.
|
static NSArray |
sharedObjectsForEntityNamed(String entityName)
Gets all of the shared objects for a given entity name.
|
static NSArray |
sharedObjectsMatchingKeyAndValue(String entityName,
String key,
Object value)
Finds objects in the shared editing context matching a key
and value.
|
static NSArray |
sharedObjectsWithFetchSpecificationNamed(String entityName,
String fetchSpecName)
Fetches a shared enterprise object from the default shared editing context
given the name of a fetch specification.
|
static EOEnterpriseObject |
sharedObjectWithFetchSpec(String entityName,
String fetchSpec)
Fetches a shared enterprise object for a given fetch
specification from the default shared editing context.
|
static EOEnterpriseObject |
sharedObjectWithPrimaryKey(String entityName,
Object primaryKey)
Gets the shared enterprise object with the given primary
from the default shared editing context.
|
static NSArray |
stringAttributeListForEntityNamed(EOEditingContext ec,
String entityName)
Calculates all of the EOAttributes of a given entity that
are mapped to String objects.
|
static void |
trimSpaces(EOEnterpriseObject object)
Trims all values from string attributes from the given EO unless the EO itself
or the string attribute is flagged as read-only.
|
static NSMutableArray |
updatedObjects(EOEditingContext editingContext,
NSArray<String> entityNames,
EOQualifier qualifier)
Returns the array of objects of the given type that have been updated in
the editing context and match the given qualifier.
|
static void |
validateUniquenessOf(EOEnterpriseObject eo,
EOQualifier restrictingQualifier,
String... keys)
Convenience method which passes
null for
entityName . |
static void |
validateUniquenessOf(EOEnterpriseObject eo,
String... keys)
Convenience method which passes
null for
restrictingQualifier and entityName . |
static void |
validateUniquenessOf(String entityName,
EOEnterpriseObject eo,
EOQualifier restrictingQualifier,
String... keys)
Validates whether the values of the specified keyPaths are unique for an
Entity.
|
static void |
validateUniquenessOf(String entityName,
EOEnterpriseObject eo,
String... keys)
Convenience method which passes
null for
restrictingQualifier . |
public static <T extends EOEnterpriseObject> NSArray<T> localInstancesOfObjects(EOEditingContext ec, NSArray<T> eos)
EOUtilities
except it will use the localInstanceOfObject
method from this utilities class which has a few enhancements.T
- data type of enterprise objectsec
- editing context to pull local object copieseos
- array of enterprise objectspublic static EOArrayDataSource dataSourceForArray(NSArray<? extends EOEnterpriseObject> array)
Note that the data source that is constructed uses the class description and editing context of the first object of the array.
array
- collection of objects to be turned into a
data sourcepublic static EOArrayDataSource dataSourceForArray(EOEditingContext ec, String entityName, NSArray array)
Note that the data source that is constructed uses the class description and editing context of the first object of the array.
ec
- editing context for the data sourceentityName
- entity namearray
- collection of objects to be turned into a
data sourcepublic static NSArray arrayFromDataSource(EODataSource dataSource)
dataSource
- data source to be convertedpublic static EODetailDataSource dataSourceForObjectAndKey(EOEnterpriseObject object, String key)
Note: the relationship key does not have to be an eo relationship, instead it just has to return an array of enterprise objects.
object
- that has the relationshipkey
- relationship keypublic static <T extends EOEnterpriseObject> T editableInstanceOfObject(T eo, boolean createNestedContext)
T
- data type of the enterprise objecteo
- object for the new instancecreateNestedContext
- true, if we should create a nested context (otherwise we create a peer context)public static <T extends EOEnterpriseObject> T localInstanceOfObject(EOEditingContext ec, T eo)
T
- data type of the enterprise objectec
- editing context to get a local instance of the object ineo
- object to get a local copy ofpublic static boolean eoEquals(EOEnterpriseObject firstEO, EOEnterpriseObject secondEO)
firstEO
- first EO to comparesecondEO
- second EO to comparepublic static <T extends EOEnterpriseObject> T createAndInsertObject(EOEditingContext ec, Class<T> eoClass)
T
- data type of the enterprise objectec
- editingContext to insert the created object intoeoClass
- class of the enterprise object to be createdpublic static EOEnterpriseObject createAndInsertObject(EOEditingContext editingContext, String entityName)
editingContext
- editingContext to insert the created object intoentityName
- name of the entity to be created.public static EOEnterpriseObject createAndInsertObject(EOEditingContext editingContext, String entityName, NSDictionary objectInfo)
editingContext
- editingContext to insert the created object intoentityName
- name of the entity to be created.objectInfo
- dictionary of values pushed onto the object
before being inserted into the editing context.public static EOEnterpriseObject createAndAddObjectToRelationship(EOEditingContext editingContext, EOEnterpriseObject source, String relationshipName, String destinationEntityName, NSDictionary objectInfo)
createEO
from this utility class. After creating the enterprise object it
is added to the relationship of the enterprise object passed in.
For instance:createAndAddObjectToRelationship(ec, foo, "toBars", "Bar", dictValues);
editingContext
- editing context to create the object insource
- enterprise object to whose relationship the newly created
object will be added.relationshipName
- relationship name of the enterprise object
that is passed in to which the newly created eo should be
added.destinationEntityName
- name of the entity of the object to be created.objectInfo
- dictionary of values to be set on the newly created
object before it is inserted into the editing context.public static void addObjectToObjectOnBothSidesOfRelationshipWithKey(EOEnterpriseObject addedObject, EOEnterpriseObject referenceObject, String key)
addedObject
- object to be added to the relationshipreferenceObject
- object that has the relationshipkey
- relationship keypublic static void refaultObject(EOEnterpriseObject eo)
eo
- enterprise object to refaultpublic static void refreshObject(EOEnterpriseObject eo)
eo
- EO to be refreshedpublic static void clearSnapshotForRelationshipNamed(EOEnterpriseObject eo, String relationshipName)
eo
- enterprise objectrelationshipName
- relationship namepublic static void clearSnapshotForRelationshipNamedInDatabase(EOEnterpriseObject eo, String relationshipName, EODatabase database)
eo
- enterprise objectrelationshipName
- relationship namedatabase
- database objectpublic static EOFetchSpecification primaryKeyFetchSpecificationForEntity(EOEditingContext ec, String entityName, EOQualifier eoqualifier, NSArray<EOSortOrdering> sortOrderings, NSArray<String> additionalKeys)
ec
- editing context, only used to determine the entityentityName
- name of the entity, only used to determine the entityeoqualifier
- to construct the fetch specification withsortOrderings
- array of sort orderings to sort the result set with.additionalKeys
- array of additional key paths to construct the
raw rows key paths to fetch.public static NSArray primaryKeysMatchingQualifier(EOEditingContext ec, String entityName, EOQualifier eoqualifier, NSArray<EOSortOrdering> sortOrderings)
ec
- editing context to fetch intoentityName
- name of the entityeoqualifier
- to restrict matching primary keyssortOrderings
- array of sort orders to sort result setpublic static EOEnterpriseObject objectWithPrimaryKeyValue(EOEditingContext ec, String entityName, Object primaryKeyValue, NSArray prefetchingKeyPaths)
ec
- editing context to fetch intoentityName
- name of the entityprimaryKeyValue
- primary key value. Compound primary keys are given as NSDictionaries.prefetchingKeyPaths
- key paths to fetch off of the eopublic static EOEnterpriseObject objectWithPrimaryKeyValue(EOEditingContext ec, String entityName, Object primaryKeyValue, NSArray prefetchingKeyPaths, boolean refreshRefetchedObjects)
ec
- editing context to fetch intoentityName
- name of the entityprimaryKeyValue
- primary key value. Compound primary keys are given as NSDictionaries.prefetchingKeyPaths
- key paths to fetch off of the eorefreshRefetchedObjects
- if true, the object will be refetched and refreshedIllegalStateException
- if the entity has a compound key and only one key is provided or
if more than one object is found matching the value.public static EOEnterpriseObject objectWithPrimaryKeyValue(EOEditingContext ec, String entityName, Object primaryKeyValue, NSArray prefetchingKeyPaths, boolean refreshRefetchedObjects, boolean throwIfMissing)
ec
- editing context to fetch intoentityName
- name of the entityprimaryKeyValue
- primary key value. Compound primary keys are given as NSDictionaries.prefetchingKeyPaths
- key paths to prefetch for the eorefreshRefetchedObjects
- if true, the object will be refetched and refreshedthrowIfMissing
- if true, an exception is thrown for a missing objectIllegalStateException
- if the entity has a compound key and only one key is provided or
if more than one object is found matching the value.EOObjectNotAvailableException
- if throwIfMissing is true and the object is missingpublic static <T extends EOEnterpriseObject> NSArray<T> objectsInRange(EOEditingContext ec, EOFetchSpecification spec, int start, int end)
NSArray
containing the objects from the resulting rows starting
at start and stopping at end using a custom SQL, derived from the SQL
which the EOFetchSpecification
would use normally setHints()
T
- data type of the enterprise objectsec
- editing context to fetch objects intospec
- fetch specification for the fetchstart
- the starting row numberend
- the last row numberpublic static <T extends EOEnterpriseObject> NSArray<T> objectsInRange(EOEditingContext ec, EOFetchSpecification spec, int start, int end, boolean rawRowsForCustomQueries)
NSArray
containing the objects from the resulting rows starting
at start and stopping at end using a custom SQL, derived from the SQL
which the EOFetchSpecification
would use normally setHints()
T
- data type of the enterprise objectsec
- editing context to fetch objects intospec
- fetch specification for the fetchstart
- the starting row numberend
- the last row numberrawRowsForCustomQueries
- if true, raw rows will be returned from the fetch when there is a custom querypublic static NSArray<NSDictionary<String,Object>> primaryKeyValuesInRange(EOEditingContext ec, EOFetchSpecification spec, int start, int end)
NSArray
containing the primary keys from the resulting rows starting
at start and stopping at end using a custom SQL, derived from the SQL
which the EOFetchSpecification
would use normally setHints()
ec
- editing context to fetch objects intospec
- fetch specification for the fetchstart
- the starting row numberend
- the last row numberpublic static Integer objectCountWithQualifier(EOEditingContext ec, String entityName, EOQualifier qualifier)
ec
- editing context to use for the count qualificationentityName
- name of the entity to fetchqualifier
- to find the matching objectspublic static Integer objectCountUniqueWithQualifierAndAttribute(EOEditingContext ec, String entityName, EOQualifier qualifier, String attributeName)
ec
- editing context to use for the count qualificationentityName
- name of the entity to fetchqualifier
- to find the matching objectsattributeName
- name of attribute in same entity to consider in order to determine uniquenesspublic static Integer objectCountForToManyRelationship(EOEnterpriseObject object, String relationshipName)
object
- the EOEnterpriseObject whose relationship is being counted.relationshipName
- the name of the relationship being counted.relationshipName
NullPointerException
- if either object
or relationshipName
are nullIllegalArgumentException
- if relationshipName
is not a toMany relationship keypublic static Object _aggregateFunctionWithQualifierAndAggregateAttribute(EOEditingContext ec, String entityName, EOQualifier qualifier, EOAttribute aggregateAttribute)
ec
- the editing contextentityName
- the name of the entityqualifier
- the qualifier to filter withaggregateAttribute
- the attribute that contains the "count(*)" definitionpublic static Number aggregateFunctionWithQualifier(EOEditingContext ec, String entityName, String attributeName, String function, String fetchSpecificationName, NSDictionary bindings)
ec
- editing context used for the fetchentityName
- name of the entityattributeName
- attribute for the function to be performed onfunction
- name, ie MAX, MIN, AVG, etc.fetchSpecificationName
- name of a fetch specificationbindings
- bindings for the fetch specificationpublic static Number aggregateFunctionWithQualifier(EOEditingContext ec, String entityName, String attributeName, String function, EOQualifier qualifier)
ec
- editing context used for the fetchentityName
- name of the entityattributeName
- attribute for the function to be performed onfunction
- name, ie MAX, MIN, AVG, etc.qualifier
- to restrict data setpublic static String aggregateStringWithQualifier(EOEditingContext ec, String entityName, String attributeName, String function, EOQualifier qualifier)
ec
- editing context used for the fetchentityName
- name of the entityattributeName
- attribute for the function to be performed onfunction
- name, ie MAX, MIN, AVG, etc.qualifier
- to restrict data setpublic static NSTimestamp aggregateTimestampWithQualifier(EOEditingContext ec, String entityName, String attributeName, String function, EOQualifier qualifier)
ec
- editing context used for the fetchentityName
- name of the entityattributeName
- attribute for the function to be performed onfunction
- name, ie MAX, MIN, AVG, etc.qualifier
- to restrict data setpublic static Object _aggregateFunctionWithQualifier(EOEditingContext ec, String entityName, String attributeName, String function, Class valueClass, String valueType, EOQualifier qualifier)
public static EOEnterpriseObject sharedObjectMatchingKeyAndValue(String entityName, String key, Object value)
entityName
- name of the shared entitykey
- to match againstvalue
- value to matchpublic static NSArray sharedObjectsMatchingKeyAndValue(String entityName, String key, Object value)
entityName
- name of the shared entitykey
- to match againstvalue
- value to matchpublic static NSArray sharedObjectsForEntityNamed(String entityName)
EODatabaseContext.setSharedObjectLoadingEnabled(boolean)
).
Returns an empty array if no shared objects were found.entityName
- name of the shared entitypublic static EOEnterpriseObject sharedObjectWithFetchSpec(String entityName, String fetchSpec)
fetchSpec
- specification on the shared objectentityName
- name of the shared entitypublic static NSArray sharedObjectsWithFetchSpecificationNamed(String entityName, String fetchSpecName)
fetchSpecName
- name of the fetch specification on the shared object.entityName
- name of the shared entitypublic static EOEnterpriseObject sharedObjectWithPrimaryKey(String entityName, Object primaryKey)
entityName
- name of the entityprimaryKey
- primary key of object to be foundpublic static EOFetchSpecification fetchSpecificationNamedWithBindings(String entityName, String fetchSpecificationName, NSDictionary bindings)
entityName
- name of the entity that the fetch specification is bound tofetchSpecificationName
- name of the fetch specificationbindings
- dictionary of qualifier bindingspublic static NSDictionary<String,Object> newPrimaryKeyDictionaryForObjectFromClassProperties(EOEnterpriseObject eo)
eo
- object in questionpublic static NSDictionary<String,Object> newPrimaryKeyDictionaryForObject(EOEnterpriseObject eo)
newPrimaryKeyDictionaryForObjectFromClassProperties(EOEnterpriseObject)
and if that returns null,
newPrimaryKeyDictionaryForEntityNamed(EOEditingContext, String)
eo
- enterprise object to create keys forpublic static NSDictionary<String,Object> newPrimaryKeyDictionaryForEntityNamed(EOEditingContext ec, String entityName)
ERXGeneratesPrimaryKeyInterface
for more information
about using a newly created dictionary as the primary key for
an enterprise object.ec
- editing contextentityName
- name of the entity to generate the primary
key dictionary for.public static String primaryKeyStringForObject(EOEnterpriseObject eo)
eo
- object to get the primary key for.public static String primaryKeyStringForGlobalID(EOKeyGlobalID gid)
gid
- the global id of the object to get the primary key for.public static String _stringForPrimaryKey(Object pk)
pk
- the primary keypublic static NSDictionary<String,Object> primaryKeyDictionaryForString(EOEditingContext ec, String entityName, String string)
public static EOGlobalID globalIDForString(EOEditingContext ec, String entityName, String string)
public static Object primaryKeyObjectForObject(EOEnterpriseObject eo)
eo
- object to get the primary key for.public static NSArray primaryKeyArrayForObject(EOEnterpriseObject obj)
EOUtilities
.obj
- enterprise object to get the primary key array from.public static NSArray objectsWithQualifierFormat(EOEditingContext ec, String entityName, String qualifierFormat, NSArray args, NSArray prefetchKeyPaths, boolean includeNewObjects)
objectsWithQualifierFormat(ec, entityName, qualifierFormat, args, prefetchKeyPaths, includeNewObjects, false)
.
That is, passes false for includeNewObjectsInParentEditingContexts
. This method exists
to maintain API compatibility.public static NSArray objectsWithQualifierFormat(EOEditingContext ec, String entityName, String qualifierFormat, NSArray args, NSArray prefetchKeyPaths, boolean includeNewObjects, boolean includeNewObjectsInParentEditingContexts)
ec
- editing context to fetch it intoentityName
- name of the entityqualifierFormat
- format of the qualifier stringargs
- qualifier argumentsprefetchKeyPaths
- prefetching key pathsincludeNewObjects
- option to include newly inserted objects in the result setincludeNewObjectsInParentEditingContexts
- option to include newly inserted objects in parent editing contextspublic static NSArray objectsWithQualifier(EOEditingContext ec, String entityName, EOQualifier qualifier, NSArray prefetchKeyPaths, boolean includeNewObjects)
includeNewObjectsInParentEditingContexts
. This method
exists to maintain API compatibility.public static NSArray objectsWithQualifier(EOEditingContext _editingContext, String _entityName, EOQualifier _qualifier, NSArray _prefetchKeyPaths, boolean _includeNewObjects, boolean _includeNewObjectsInParentEditingContext)
public static NSArray objectsWithQualifier(EOEditingContext editingContext, String entityName, EOQualifier qualifier, NSArray prefetchKeyPaths, boolean includeNewObjects, boolean includeNewObjectsInParentEditingContext, boolean filterUpdatedObjects, boolean removeDeletedObjects)
editingContext
- editing context to fetch it intoentityName
- name of the entityqualifier
- qualifierprefetchKeyPaths
- prefetching key pathsincludeNewObjects
- option to include newly inserted objects in the result setincludeNewObjectsInParentEditingContext
- option to include newly inserted objects in parent editing
contexts. if true, the editing context lineage is explored, any newly-inserted objects matching the
qualifier are collected and faulted down through all parent editing contexts of ec.filterUpdatedObjects
- option to include updated objects that now match the qualifier or remove updated
objects thats no longer match the qualifierremoveDeletedObjects
- option to remove objects that have been deletedpublic static NSArray objectsWithQualifier(EOEditingContext editingContext, String entityName, EOQualifier qualifier, NSArray prefetchKeyPaths, NSArray sortOrderings, boolean usesDistinct, boolean isDeep, NSDictionary hints, boolean includeNewObjects, boolean includeNewObjectsInParentEditingContext, boolean filterUpdatedObjects, boolean removeDeletedObjects)
editingContext
- editing context to fetch it intoentityName
- name of the entityqualifier
- qualifierprefetchKeyPaths
- prefetching key pathssortOrderings
- the sort orderings to use on the resultsusesDistinct
- whether or not to distinct the resultsisDeep
- whether or not to fetch deeplyhints
- fetch hints to applyincludeNewObjects
- option to include newly inserted objects in the result setincludeNewObjectsInParentEditingContext
- option to include newly inserted objects in parent editing
contexts. if true, the editing context lineage is explored, any newly-inserted objects matching the
qualifier are collected and faulted down through all parent editing contexts of ec.filterUpdatedObjects
- option to include updated objects that now match the qualifier or remove updated
objects thats no longer match the qualifierremoveDeletedObjects
- option to remove objects that have been deletedpublic static NSArray objectsWithQualifier(EOEditingContext editingContext, String entityName, EOQualifier qualifier, NSArray prefetchKeyPaths, NSArray sortOrderings, int fetchLimit, boolean usesDistinct, boolean isDeep, NSDictionary hints, boolean includeNewObjects, boolean includeNewObjectsInParentEditingContext, boolean filterUpdatedObjects, boolean removeDeletedObjects)
editingContext
- editing context to fetch it intoentityName
- name of the entityqualifier
- qualifierprefetchKeyPaths
- prefetching key pathssortOrderings
- the sort orderings to use on the resultsfetchLimit
- the fetch limit to useusesDistinct
- whether or not to distinct the resultsisDeep
- whether or not to fetch deeplyhints
- fetch hints to applyincludeNewObjects
- option to include newly inserted objects in the result setincludeNewObjectsInParentEditingContext
- option to include newly inserted objects in parent editing
contexts. if true, the editing context lineage is explored, any newly-inserted objects matching the
qualifier are collected and faulted down through all parent editing contexts of ec.filterUpdatedObjects
- option to include updated objects that now match the qualifier or remove updated
objects thats no longer match the qualifierremoveDeletedObjects
- option to remove objects that have been deletedpublic static NSArray filteredObjectsWithQualifier(EOEditingContext editingContext, NSArray objectsToFilter, String entityName, EOQualifier qualifier, NSArray sortOrderings, boolean usesDistinct, boolean isDeep, boolean includeNewObjects, boolean includeNewObjectsInParentEditingContext, boolean filterUpdatedObjects, boolean removeDeletedObjects)
editingContext
- editing context to fetch it intoobjectsToFilter
- objects to filterentityName
- name of the entityqualifier
- qualifiersortOrderings
- the sort orderings to use on the resultsusesDistinct
- whether or not to distinct the resultsisDeep
- whether or not to fetch deeplyincludeNewObjects
- option to include newly inserted objects in the result setincludeNewObjectsInParentEditingContext
- option to include newly inserted objects in parent editing
contexts. if true, the editing context lineage is explored, any newly-inserted objects matching the
qualifier are collected and faulted down through all parent editing contexts of ec.filterUpdatedObjects
- option to include updated objects that now match the qualifier or remove updated
objects thats no longer match the qualifierremoveDeletedObjects
- option to remove objects that have been deletedpublic static EOEnterpriseObject objectWithQualifier(EOEditingContext editingContext, String entityName, EOQualifier qualifier)
editingContext
- the editing context to look inentityName
- the name of the entity to look forqualifier
- the qualifier to restrict byEOUtilities.MoreThanOneException
- if more than one object matches the qualifierpublic static EOEnterpriseObject requiredObjectWithQualifier(EOEditingContext editingContext, String entityName, EOQualifier qualifier)
editingContext
- the editing context to look inentityName
- the name of the entity to look forqualifier
- the qualifier to restrict byEOObjectNotAvailableException
- if no objects match the qualifierEOUtilities.MoreThanOneException
- if more than one object matches the qualifierpublic static NSMutableArray insertedObjects(EOEditingContext editingContext, NSArray<String> entityNames, EOQualifier qualifier)
editingContext
- the editing context to look inentityNames
- the names of the entity to look forqualifier
- the qualifier to restrict bypublic static NSMutableArray updatedObjects(EOEditingContext editingContext, NSArray<String> entityNames, EOQualifier qualifier)
editingContext
- the editing context to look inentityNames
- the names of the entity to look forqualifier
- the qualifier to restrict bypublic static NSMutableArray deletedObjects(EOEditingContext editingContext, NSArray<String> entityNames, EOQualifier qualifier)
editingContext
- the editing context to look inentityNames
- the names of the entity to look forqualifier
- the qualifier to restrict bypublic static EOQualifier localInstancesInQualifier(EOEditingContext ec, EOQualifier q)
ec
- q
- public static NSArray<EOGlobalID> globalIDsForObjects(NSArray<? extends EOEnterpriseObject> eos)
eos
- the NSArray of EOEnterpriseObjectspublic static <T extends EOEnterpriseObject> NSArray<T> objectsForGlobalIDs(EOEditingContext ec, NSArray<EOGlobalID> globalIDs)
EOEditingContext.objectForGlobalID()
.
NOTE: this only returns objects that are already registered, if you
need all objects from the GIDs, use faultsForGlobalIDs(EOEditingContext, NSArray)
.ec
- the EOEditingContext in which the EOEnterpriseObjects should be faultedglobalIDs
- the EOGlobalIDsEOEditingContext.objectForGlobalID(EOGlobalID)
public static <T extends EOEnterpriseObject> NSArray<T> faultsForGlobalIDs(EOEditingContext ec, NSArray<? extends EOGlobalID> gids)
ec
- the EOEditingContext in which the EOEnterpriseObjects should be faultedgids
- the EOGlobalIDspublic static <T extends EOEnterpriseObject> NSArray<T> faultsForRawRowsFromEntity(EOEditingContext ec, NSArray primKeys, String entityName)
public static boolean isNewObject(EOEnterpriseObject eo)
Note: An object that has been deleted will have it's editing context set to null which means this method would report true for an object that has been deleted from the database.
eo
- enterprise object to checkpublic static EOQualifier qualifierMatchingAnyKey(NSArray keys, NSSelector selector, Object value)
keys
- selector
- value
- public static NSArray objectsForFaultWithSortOrderings(EOEditingContext ec, NSArray possibleFaults, NSArray sortOrderings)
ERXEOControlUtilities.objectForFaults
to turn the faults into objects, then does in memory
ordering with EOSortOrdering.EOSortOrdering.sortedArrayUsingKeyOrderArray()
ec
- possibleFaults
- sortOrderings
- public static NSArray objectsForFaults(EOEditingContext ec, NSArray possibleFaults)
ec
- possibleFaults
- globalIDspublic static String rootEntityName(EOEnterpriseObject eo)
eo
- the EOEnterpriseObject from which to the the root entitypublic static EOEntity rootEntity(EOEnterpriseObject eo)
eo
- the EOEnterpriseObject from which to the the root entitypublic static NSArray stringAttributeListForEntityNamed(EOEditingContext ec, String entityName)
public static void trimSpaces(EOEnterpriseObject object)
object
- the EO whose string attributes should be trimmedpublic static String destinationEntityNameForKeyPath(EOEnterpriseObject eo, String keyPath)
eo
- an enterprise objectkeyPath
- key pathpublic static EOQualifier orQualifierForKeyPaths(NSArray keyPaths, NSSelector selector, Object value)
keyPaths
- selector
- value
- public static EOQualifier orQualifierForKeyPaths(NSArray keyPaths, NSSelector selector, NSArray values)
keyPaths
- selector
- values
- public static EOQualifier andQualifier(EOQualifier q1, EOQualifier q2)
q1
- first qualifierq2
- second qualifierpublic static EOQualifier orQualifier(EOQualifier q1, EOQualifier q2)
q1
- first qualifierq2
- second qualifierpublic static void makeQualifierTrue(EOQualifier qualifier, Object obj)
qualifier
- the qualifier to apply to the objectobj
- the object to make qualifier evaluate to true forpublic static Object convertEOtoGID(Object obj)
obj
- the object to recursively turn EO's into GID's forpublic static Object convertGIDtoEO(EOEditingContext editingContext, Object obj)
obj
- the object to recursively turn GID's into EO's forpublic static void validateUniquenessOf(String entityName, EOEnterpriseObject eo, EOQualifier restrictingQualifier, String... keys)
ERXValidationException
if there is already an EO
with the same values on the given key paths.
Should be combined with a constraint on the corresponding database
columns.
Based on Zak Burke's idea he posted to WOCode a while ago.
Use in validateForSave
like this:
...
public class WikiPage extends _WikiPage {
...
public void validateForSave() throws ValidationException {
super.validateForSave();
ERXEOControlUtilities.validateUniquenessOf(null, this, ERXQ.equals("active", true), "title", "wiki");
}
...
}
Combine with entries in ValidationTemplate.strings
like:
"WikiPage.title,space.UniquenessViolationNewObject" = "The page cannot be created. There is already a page named <b>@@value.title@@</b> in Wiki <b>@@value.wiki.name@@</b>."; "WikiPage.title,space.UniquenessViolationExistingObject" = "The page cannot be changed this way. There is already a page named <b>@@value.title@@</b> in Wiki <b>@@value.wiki.name@@</b>.";
eo
- the EOEnterpriseObject
to validatekeys
- an arbitrary number of keyPaths to validate.restrictingQualifier
- an optional restricting qualifier to exclude certain objects
from the checkentityName
- the name of the entity to check. Defaults to eo.entityName().
It can be necessary to set this to the name of the parent
entity when using single table inheritance.ERXValidationException
- if an EO with the same property values already exists. If you
specify more than one keyPath to validate, the 'key' property
will be a comma separated string of the provided keyPaths.
'value' will be a dictionary with the supplied keyPaths as
keys and the values corresponding to these keys in the
supplied eo as values.public static void validateUniquenessOf(EOEnterpriseObject eo, EOQualifier restrictingQualifier, String... keys)
null
for
entityName
.eo
- the EOEnterpriseObject
to validaterestrictingQualifier
- an optional restricting qualifier to exclude certain objects
from the checkkeys
- an arbitrary number of keyPaths to validate.public static void validateUniquenessOf(EOEnterpriseObject eo, String... keys)
null
for
restrictingQualifier
and entityName
.eo
- the EOEnterpriseObject
to validatekeys
- an arbitrary number of keyPaths to validate.public static void validateUniquenessOf(String entityName, EOEnterpriseObject eo, String... keys)
null
for
restrictingQualifier
.eo
- the EOEnterpriseObject
to validatekeys
- an arbitrary number of keyPaths to validate.entityName
- the name of the entity to check. Defaults to eo.entityName().
It can be necessary to set this to the name of the parent
entity when using single table inheritance.public static <T> NSArray<T> distinctValuesForKeyPath(EOEditingContext editingContext, String entityName, String keyPath, EOQualifier qualifier, NSArray<EOSortOrdering> sortOrderings)
T
- type of values for the key patheditingContext
- editingContextentityName
- entityNamekeyPath
- keyPathqualifier
- restricting qualifier (optional)sortOrderings
- sortOrderings to be applied (optional)public static NSDictionary<String,Integer> registeredObjectCount(EOEditingContext ec)
ec
- editing context to get count ofpublic static NSDictionary<String,Integer> changedRegisteredObjectCount(NSDictionary<String,Integer> currentCounts, NSDictionary<String,Integer> oldCounts)
currentCounts
- current count of objectsoldCounts
- previous count of objectspublic static EOFetchSpecification schemaBasedFetchSpecification(EOEditingContext ec, EOFetchSpecification fetchSpecification)
ec
- a locked EOEditingContext that can be used for getting the
entityfetchSpecification
- public static EOQualifier schemaBasedQualifier(EOEditingContext ec, String entityName, EOQualifier qualifier)
ec
- a locked EOEditingContext that can be used for getting the entityentityName
- the entity being qualifiedqualifier
- original qualifierCopyright © 2002 – 2024 Project Wonder.