public static class ERXCopyable.Utility extends Object
ERXCopyable.DefaultImplementation uses them internally. The
implementations of
modelCopy(NSMutableDictionary, ERXCopyable)referenceCopy(ERXEnterpriseObject)Utility#shallowCopy(ERXCopyable)deepCopy(NSMutableDictionary, ERXCopyable)EOEnterpriseObject instances to use
for their ERXCopyable.duplicate(NSMutableDictionary) method.
However there are some situations that can not be handled with this
generic code:ERXCopyable.Utility also provides lower-level
methods that you can use to copy any or all attributes or relationships
when creating a custom duplicate(NSMutableDictionary) method.
Debugging information can be turned on with the DEBUG level of the log4j
logger er.extensions.eof.ERXCopyable.
| Modifier and Type | Field and Description |
|---|---|
protected static NSMutableDictionary<String,NSArray<EOAttribute>> |
_classAttributesDictionary |
protected static NSMutableDictionary<String,NSArray<com.webobjects.eoaccess.EORelationship>> |
_classRelationshipsDictionary |
protected static NSMutableDictionary<String,NSArray<EOAttribute>> |
_exposedPKAndFKAttributeDictionary |
| Constructor and Description |
|---|
Utility() |
| Modifier and Type | Method and Description |
|---|---|
static NSArray<EOAttribute> |
classAttributes(com.webobjects.eoaccess.EOEntity entity) |
static NSArray<com.webobjects.eoaccess.EORelationship> |
classRelationships(com.webobjects.eoaccess.EOEntity entity) |
static <T extends ERXEnterpriseObject> |
cleanRelationships(T source,
T destination)
When an EO object is created it can already have some relationships
set.
|
static <T extends ERXEnterpriseObject> |
copyAttribute(T source,
T destination,
EOAttribute attribute) |
static <T extends ERXEnterpriseObject> |
copyClassAttributes(T source,
T destination)
This copies only the class attributes from the source
ERXCopyable to the destination. |
static ERXCopyable.CopyType |
copyType(com.webobjects.eoaccess.EOProperty property) |
static ERXCopyable.CopyType |
copyType(com.webobjects.eoaccess.EOProperty property,
NSDictionary<String,Object> userInfo)
Abstracted out of
copyType(EOProperty) to handle exceptions
if the userInfo dictionary is null, there is no
ERXCopyable.CopyType key, or the value for the key is null or
invalid. |
static <T extends ERXCopyable<T>> |
deepCopy(NSMutableDictionary<com.webobjects.eocontrol.EOGlobalID,ERXCopyable<?>> copiedObjects,
T source)
Returns a deep copy of this object, the attribute values are
reference copied and the relationships are copied by calling
ERXCopyable.copy(NSMutableDictionary) on them. |
static <T extends ERXCopyable<T>> |
deepCopyClassRelationships(NSMutableDictionary<com.webobjects.eocontrol.EOGlobalID,ERXCopyable<?>> copiedObjects,
T source,
T destination)
This copies related objects from the source
ERXCopyable to
the destination by calling deepCopyRelationship on them. |
static <T extends ERXCopyable<T>> |
deepCopyRelationship(NSMutableDictionary<com.webobjects.eocontrol.EOGlobalID,ERXCopyable<?>> copiedObjects,
T source,
T destination,
com.webobjects.eoaccess.EORelationship relationship)
This copies the object(s) for the named relationship from the source
ERXCopyable to the destination by calling
ERXCopyable.copy(NSMutableDictionary) on them. |
static <T extends ERXCopyable<T>> |
deepCopyToManyRelationship(NSMutableDictionary<com.webobjects.eocontrol.EOGlobalID,ERXCopyable<?>> copiedObjects,
T source,
T destination,
com.webobjects.eoaccess.EORelationship relationship) |
static <T extends ERXCopyable<T>> |
deepCopyToOneRelationship(NSMutableDictionary<com.webobjects.eocontrol.EOGlobalID,ERXCopyable<?>> copiedObjects,
T source,
T destination,
com.webobjects.eoaccess.EORelationship relationship) |
static <T extends ERXEnterpriseObject> |
entity(T enterpriseObject)
Returns the entity for the current object.
|
static NSArray<String> |
exposedPKandFKAttributeNames(ERXEnterpriseObject source)
Returns an array of attribute names from the
EOEntity of
source that are used in the primary key, or in forming
relationships. |
static NSArray<EOAttribute> |
exposedPKAndFKAttributes(ERXEnterpriseObject source)
Returns an array of class
EOAttributes from the
EOEntity of source that are used in the primary key,
or in forming EORelationships. |
static com.webobjects.eocontrol.EOGlobalID |
globalIDForObject(ERXEnterpriseObject enterpriseObject)
Convenience method to get
EOGlobalID for an
EOEnterpriseObject from its own EOEditingContext. |
static void |
handleMissingERXCopyableKey(Class<?> invalidClass) |
static void |
handleMissingOrInvalidCopyType(com.webobjects.eoaccess.EOProperty property,
ERXCopyable.CopyType copyType)
Creates a meaningful error message to be displayed when
modelCopy was specified for the ERXCopyable key in an
Entity's UserInfo dictionary, but not all attributes and
relationships have a valid ERXCopyable.CopyType specified. |
static <T extends ERXCopyable<T>> |
modelCopy(NSMutableDictionary<com.webobjects.eocontrol.EOGlobalID,ERXCopyable<?>> copiedObjects,
T source)
Creates a new instance of the
source's Entity, then steps
through all attributes and relationships, copying them as defined in
each property's UserInfo dictionary in the EOModel. |
static <T extends ERXCopyable<T>> |
modelCopyAttribute(T source,
T destination,
EOAttribute attribute) |
static <T extends ERXCopyable<T>> |
modelCopyClassAttributes(T source,
T destination) |
static <T extends ERXCopyable<T>> |
modelCopyClassRelationships(NSMutableDictionary<com.webobjects.eocontrol.EOGlobalID,ERXCopyable<?>> copiedObjects,
T source,
T destination)
Reads the values set in the EOModel's attribute and relationship
UserInfo dictionaries and then uses them to control how the
source object is copied. |
static <T extends ERXCopyable<T>> |
modelCopyRelationship(NSMutableDictionary<com.webobjects.eocontrol.EOGlobalID,ERXCopyable<?>> copiedObjects,
T source,
T destination,
com.webobjects.eoaccess.EORelationship relationship)
Reads the values set in the EOModel's attribute and relationship
UserInfo dictionaries and then uses them to control how the
source object is copied. |
static <T extends ERXEnterpriseObject> |
newInstance(T source)
This creates and returns a new, completely empty instance of
the same Entity as source.
|
static NSArray<EOAttribute> |
primaryAndForeignKeyAttributes(ERXEnterpriseObject source) |
static String |
propertyType(com.webobjects.eoaccess.EOProperty property) |
static <T extends ERXEnterpriseObject> |
referenceCopy(T source)
Returns a copy of this object by reference.
|
static <T extends ERXEnterpriseObject> |
referenceCopyClassRelationships(T source,
T destination)
This copies all objects for all class-property relationships from the
source onto the destination. |
static <T extends ERXEnterpriseObject> |
referenceCopyRelationship(T source,
T destination,
com.webobjects.eoaccess.EORelationship relationship) |
static <T extends ERXEnterpriseObject> |
referenceCopyToManyClassRelationships(T source,
T destination)
This copies to-one related objects from the source
ERXCopyable to the destination by reference. |
static <T extends ERXEnterpriseObject,E extends ERXEnterpriseObject> |
referenceCopyToManyRelationship(T source,
T destination,
com.webobjects.eoaccess.EORelationship relationship) |
static <T extends ERXEnterpriseObject> |
referenceCopyToOneClassRelationships(T source,
T destination)
This copies related objects from the source
ERXCopyable to
the destination by reference. |
static <T extends ERXEnterpriseObject,E extends ERXEnterpriseObject> |
referenceCopyToOneRelationship(T source,
T destination,
com.webobjects.eoaccess.EORelationship relationship) |
static <T extends ERXEnterpriseObject> |
shallowCopy(T source)
Returns a shallow copy of this object, the attribute and
relationships are copied by reference.
|
static <T extends ERXEnterpriseObject> |
shallowCopyRelationship(T source,
T destination,
com.webobjects.eoaccess.EORelationship relationship) |
static <T extends ERXEnterpriseObject> |
shallowCopyToManyRelationship(T source,
T destination,
com.webobjects.eoaccess.EORelationship relationship)
Creates a new instance for each of the of the source's related
objects' Entity and reference copies the attributes and relationships
to it
|
static <T extends ERXEnterpriseObject> |
shallowCopyToOneRelationship(T source,
T destination,
com.webobjects.eoaccess.EORelationship relationship)
Creates a new instance of the source's related object's Entity and
reference copies the attributes and relationships to it
|
protected static volatile NSMutableDictionary<String,NSArray<EOAttribute>> _exposedPKAndFKAttributeDictionary
protected static volatile NSMutableDictionary<String,NSArray<EOAttribute>> _classAttributesDictionary
protected static volatile NSMutableDictionary<String,NSArray<com.webobjects.eoaccess.EORelationship>> _classRelationshipsDictionary
public static <T extends ERXEnterpriseObject> com.webobjects.eoaccess.EOEntity entity(T enterpriseObject)
ERXEOAccessUtilities.entityNamed() for the actual work.T - the Type of the enterpriseObjectenterpriseObject - EOEntity of the enterpriseObjectpublic static <T extends ERXEnterpriseObject> void cleanRelationships(T source, T destination)
T - the Type of the source and destinationsource - the ERXCopyable that copy was created fromdestination - the newly instantiated copy of source that needs to have
its relationships cleanedpublic static <T extends ERXEnterpriseObject> void copyClassAttributes(T source, T destination)
ERXCopyable to the destination. However if an attribute is a
class property and also used in a relationship it is assumed to be an
exposed primary- or foreign-key and are not copied. Such
attributes are set to null. See
#exposedPKandFKAttributeNames(ERXCopyable) for details on how
this is determined. It can be used when creating custom
implementations of the
ERXCopyable.duplicate(NSMutableDictionary) method.T - the Type of the source and destinationsource - object to copy attribute values fromdestination - object to copy attribute values topublic static <T extends ERXEnterpriseObject> void copyAttribute(T source, T destination, EOAttribute attribute)
T - the Type of the source and destinationsource - object to copy the attribute value fromdestination - object to copy the attribute value toattribute - the EOAttribute that should have its value copiedpublic static <T extends ERXCopyable<T>> T deepCopy(NSMutableDictionary<com.webobjects.eocontrol.EOGlobalID,ERXCopyable<?>> copiedObjects, T source)
ERXCopyable.copy(NSMutableDictionary) on them. Thus each
related object will be copied based on its own implementation of the
ERXCopyable.duplicate(NSMutableDictionary) method. The copy
is registered with copiedObjects dictionary as soon as it is
created so that circular relationships can be safely copied without
triggering infinite loops. This method of copying is suitable for
duplicating complex graphs of objects.T - the Type of the source objectcopiedObjects - the dictionary of objects that have already been copied,
keyed on the EOGlobalIDs of the source
object that the copy was made from.source - the subclass of ERXCopyable to copypublic static <T extends ERXCopyable<T>> void deepCopyClassRelationships(NSMutableDictionary<com.webobjects.eocontrol.EOGlobalID,ERXCopyable<?>> copiedObjects, T source, T destination)
ERXCopyable to
the destination by calling deepCopyRelationship on them. It can be
used when creating custom implementations of the duplicate() method
in ERXCopyable. Only relationships which are class properties are
copied.T - the Type of the source and destinationcopiedObjects - the copied objects keyed on the EOGlobalID of the object
the copy was made fromsource - the subclass of ERXCopyable to copy attribute
values fromdestination - the subclass of ERXCopyable to copy attribute
values topublic static NSArray<com.webobjects.eoaccess.EORelationship> classRelationships(com.webobjects.eoaccess.EOEntity entity)
entity - the EOEntity for the object being copiedEOAttributes that are designated as class
attributes in the entitypublic static <T extends ERXCopyable<T>> void deepCopyRelationship(NSMutableDictionary<com.webobjects.eocontrol.EOGlobalID,ERXCopyable<?>> copiedObjects, T source, T destination, com.webobjects.eoaccess.EORelationship relationship)
ERXCopyable to the destination by calling
ERXCopyable.copy(NSMutableDictionary) on them. Thus each
related object will be copied by its own reference, shallow, deep, or
custom ERXCopyable.duplicate(NSMutableDictionary) method. It
can be used when creating custom implementations of the
ERXCopyable.duplicate(NSMutableDictionary) method.T - the Type of the source and destinationcopiedObjects - the copied objects keyed on the EOGlobalID of the
object the copy was made fromsource - the subclass of ERXCopyable to copy attribute
values fromdestination - the subclass of ERXCopyable to copy attribute
values torelationship - the EORelationship to copypublic static <T extends ERXCopyable<T>> void deepCopyToOneRelationship(NSMutableDictionary<com.webobjects.eocontrol.EOGlobalID,ERXCopyable<?>> copiedObjects, T source, T destination, com.webobjects.eoaccess.EORelationship relationship)
T - the Type of the source and destinationcopiedObjects - the copied objects keyed on the EOGlobalID of the
object the copy was made fromsource - the subclass of ERXCopyable to copy attribute
values fromdestination - the subclass of ERXCopyable to copy attribute
values torelationship - the to-one EORelationship to copypublic static <T extends ERXCopyable<T>> void deepCopyToManyRelationship(NSMutableDictionary<com.webobjects.eocontrol.EOGlobalID,ERXCopyable<?>> copiedObjects, T source, T destination, com.webobjects.eoaccess.EORelationship relationship)
T - the Type of the source and destinationcopiedObjects - the copied objects keyed on the EOGlobalID of the
object the copy was made fromsource - the subclass of ERXCopyable to copy attribute
values fromdestination - the subclass of ERXCopyable to copy attribute
values torelationship - the to-many EORelationship to copypublic static NSArray<String> exposedPKandFKAttributeNames(ERXEnterpriseObject source)
EOEntity of
source that are used in the primary key, or in forming
relationships. These can be presumed to be exposed primary or foreign
keys and must be handled differently when copying an object.source - the ERXCopyable to copy attribute values fromEOAttribute.name() values from the
source's EOEntity that are used in forming
EORelationships.public static NSArray<EOAttribute> exposedPKAndFKAttributes(ERXEnterpriseObject source)
EOAttributes from the
EOEntity of source that are used in the primary key,
or in forming EORelationships. These are presumed to be
exposed primary- or foreign-keys and must be handled differently when
copying an object.source - the subclass of ERXCopyable that will be copiedEOEntity of
source that are used in forming relationships.public static NSArray<EOAttribute> classAttributes(com.webobjects.eoaccess.EOEntity entity)
entity - the EOEntity for the object being copiedEOAttributes that are designated as class
attributes in the entitypublic static com.webobjects.eocontrol.EOGlobalID globalIDForObject(ERXEnterpriseObject enterpriseObject)
EOGlobalID for an
EOEnterpriseObject from its own EOEditingContext.enterpriseObject - the EOEnterpriseObject to return the EOGlobalID
forEOGlobalID of the enterpriseObject
parameterpublic static <T extends ERXEnterpriseObject> T newInstance(T source)
The reason that copying should use this method is because when an EO
object is created it can already have some relationships and
attributes set. These can come from to one relationships that are
marked as 'owns destination' and also from awakeFromInsertion().
Preset/default attributes will be overwritten when all attributes are
copied, but the relationships need some special handling. See the
method Utility#cleanRelationships(ERXCopyable, ERXCopyable)
for details on what is done.
This method is for use in custom implementations of
ERXCopyable.duplicate(NSMutableDictionary).
T - the Type of the sourcesource - the subclass of ERXCopyable to copypublic static <T extends ERXEnterpriseObject> T referenceCopy(T source)
T - the Type of the sourcesource - the subclass of ERXCopyable to copypublic static <T extends ERXEnterpriseObject> T shallowCopy(T source)
T - the Type of the sourcesource - the subclass of ERXCopyable to copypublic static <T extends ERXEnterpriseObject> void referenceCopyClassRelationships(T source, T destination)
source onto the destination. It can be used when
creating custom implementations of
ERXCopyable.duplicate(NSMutableDictionary).T - the Type of the source and destinationsource - the subclass of ERXCopyable to copy attribute
values fromdestination - the subclass of ERXCopyable to copy attribute
values topublic static <T extends ERXEnterpriseObject> void referenceCopyRelationship(T source, T destination, com.webobjects.eoaccess.EORelationship relationship)
T - the Type of the source and destinationsource - the subclass of ERXCopyable to copy attribute
values fromdestination - the subclass of ERXCopyable to copy attribute
values torelationship - the EORelationship to copy from the source
to the destinationpublic static <T extends ERXEnterpriseObject> void referenceCopyToOneClassRelationships(T source, T destination)
ERXCopyable to
the destination by reference. Only relationships which are class
properties are copied. It can be used to streamline creating custom
implementations of the
ERXCopyable.duplicate(NSMutableDictionary) method.T - the Type of the source and destinationsource - the subclass of ERXCopyable to copy to-one
relationships values fromdestination - the subclass of ERXCopyable to copy to-one
relationships values topublic static <T extends ERXEnterpriseObject,E extends ERXEnterpriseObject> void referenceCopyToOneRelationship(T source, T destination, com.webobjects.eoaccess.EORelationship relationship)
T - the Type of the source and destinationE - source - the subclass of ERXCopyable to copy the
relationship's value fromdestination - the subclass of ERXCopyable to copy the
relationship's value torelationship - the EORelationship to copy from the source
to the destinationpublic static <T extends ERXEnterpriseObject> void referenceCopyToManyClassRelationships(T source, T destination)
ERXCopyable to the destination by reference. Only
relationships which are class properties are copied. It can be used
when creating custom implementations of the duplicate() method in
ERXCopyable.T - the Type of the source and destinationsource - the subclass of ERXCopyable to copy to-many
relationship's values fromdestination - the subclass of ERXCopyable to copy to-many
relationship's values topublic static <T extends ERXEnterpriseObject,E extends ERXEnterpriseObject> void referenceCopyToManyRelationship(T source, T destination, com.webobjects.eoaccess.EORelationship relationship)
T - the Type of the source and destinationE - source - the subclass of ERXCopyable to copy the
relationship's value(s) fromdestination - the subclass of ERXCopyable to copy the
relationship's value(s) torelationship - the EORelationship to copy values for from the
source to the destinationpublic static <T extends ERXEnterpriseObject> void shallowCopyRelationship(T source, T destination, com.webobjects.eoaccess.EORelationship relationship)
T - the Type of the source and destinationsource - the subclass of ERXCopyable to copy attribute
values fromdestination - the subclass of ERXCopyable to copy attribute
values torelationship - the EORelationship to copy from the source
to the destinationpublic static <T extends ERXEnterpriseObject> void shallowCopyToManyRelationship(T source, T destination, com.webobjects.eoaccess.EORelationship relationship)
T - the Type of the source and destinationsource - the subclass of ERXCopyable to copy the
relationship's value(s) fromdestination - the subclass of ERXCopyable to copy the
relationship's value(s) torelationship - the EORelationship to copy values for from the
source to the destinationpublic static <T extends ERXEnterpriseObject> void shallowCopyToOneRelationship(T source, T destination, com.webobjects.eoaccess.EORelationship relationship)
T - the Type of the source and destinationsource - the subclass of ERXCopyable to copy the
relationship's value fromdestination - the subclass of ERXCopyable to copy the
relationship's value torelationship - the EORelationship to copy from the source
to the destinationpublic static <T extends ERXCopyable<T>> T modelCopy(NSMutableDictionary<com.webobjects.eocontrol.EOGlobalID,ERXCopyable<?>> copiedObjects, T source)
source's Entity, then steps
through all attributes and relationships, copying them as defined in
each property's UserInfo dictionary in the EOModel.
To make use of this method of copying an EO, simply override the
duplicate(NSMutableDictionary) method in your EO with the following:
public MyEO duplicate(NSMutableDictionary<EOGlobalID, ERXCopyable<?>> copiedObjects) {
MyEO duplicate = ERXCopyable.Utility.modelCopy(copiedObjects, (MyEO) this);
return duplicate;
}
T - the Type of the source and returned objectscopiedObjects - the copied objects keyed on the EOGlobalID of the
object the copy was made from.source - the subclass of ERXCopyable to copysource object in the same
EOEditingContextpublic static <T extends ERXCopyable<T>> void modelCopyClassRelationships(NSMutableDictionary<com.webobjects.eocontrol.EOGlobalID,ERXCopyable<?>> copiedObjects, T source, T destination)
source object is copied.T - the Type of the source and destinationcopiedObjects - the copied objects keyed on the EOGlobalID of the
object the copy was made from.source - the subclass of ERXCopyable to copy all (to-one
and to-many) class relationships values fromdestination - the subclass of ERXCopyable to copy all (to-one
and to-many) class relationships values topublic static <T extends ERXCopyable<T>> void modelCopyRelationship(NSMutableDictionary<com.webobjects.eocontrol.EOGlobalID,ERXCopyable<?>> copiedObjects, T source, T destination, com.webobjects.eoaccess.EORelationship relationship)
source object is copied.T - the Type of the source and destination
objectscopiedObjects - the copied objects keyed on the EOGlobalID of the
object the copy was made from. the Type of the
source and destinationsource - the subclass of ERXCopyable to copy the
relationship's value(s) fromdestination - the subclass of ERXCopyable to copy the
relationship's value(s) torelationship - the EORelationship to copy values for from the
source to the destinationpublic static <T extends ERXCopyable<T>> void modelCopyClassAttributes(T source, T destination)
T - the Type of the source and destination
objectssource - the subclass of ERXCopyable to copy the class
attribute values fromdestination - the subclass of ERXCopyable to copy the class
attribute values topublic static <T extends ERXCopyable<T>> void modelCopyAttribute(T source, T destination, EOAttribute attribute)
T - the Type of the source and destination
objectssource - the subclass of ERXCopyable to copy the
attribute's value fromdestination - the subclass of ERXCopyable to copy the
attribute's value toattribute - the EOAttribute that should have its value copied
from the source to the destinationpublic static ERXCopyable.CopyType copyType(com.webobjects.eoaccess.EOProperty property)
property - the attribute or relationship being copiedERXCopyable.CopyType value specified for the
ERXCopyable.CopyType key in the property's
UserInfo dictionary in the EOModelpublic static ERXCopyable.CopyType copyType(com.webobjects.eoaccess.EOProperty property, NSDictionary<String,Object> userInfo)
copyType(EOProperty) to handle exceptions
if the userInfo dictionary is null, there is no
ERXCopyable.CopyType key, or the value for the key is null or
invalid.property - the attribute or relationship being copieduserInfo - the property's UserInfo dictionary that contains a
ERXCopyable.CopyType keyERXCopyable.CopyType value specified for the
ERXCopyable.CopyType key in userInfo
dictionary for property's UserInfo dictionary in the
EOModelpublic static void handleMissingERXCopyableKey(Class<?> invalidClass)
public static void handleMissingOrInvalidCopyType(com.webobjects.eoaccess.EOProperty property,
ERXCopyable.CopyType copyType)
modelCopy was specified for the ERXCopyable key in an
Entity's UserInfo dictionary, but not all attributes and
relationships have a valid ERXCopyable.CopyType specified.property - the attribute or relationship being copiedcopyType - the invalid ERXCopyable.CopyType specified in the
property's UserInfo dictionary in the EOModelpublic static String propertyType(com.webobjects.eoaccess.EOProperty property)
property - the attribute or relationship being copiedEOAttribute, "relationship" if it is an instance of
EORelationshippublic static NSArray<EOAttribute> primaryAndForeignKeyAttributes(ERXEnterpriseObject source)
source - the subclass of ERXCopyable that is being copiedEOAttributes that are the Primary- and
Foreign-Key attributes for the source subclass of
ERXCopyableCopyright © 2002 – 2020 Project Wonder.