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<EORelationship>> |
_classRelationshipsDictionary |
protected static NSMutableDictionary<String,NSArray<EOAttribute>> |
_exposedPKAndFKAttributeDictionary |
Constructor and Description |
---|
Utility() |
Modifier and Type | Method and Description |
---|---|
static NSArray<EOAttribute> |
classAttributes(EOEntity entity) |
static NSArray<EORelationship> |
classRelationships(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(EOProperty property) |
static ERXCopyable.CopyType |
copyType(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<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<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<EOGlobalID,ERXCopyable<?>> copiedObjects,
T source,
T destination,
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<EOGlobalID,ERXCopyable<?>> copiedObjects,
T source,
T destination,
EORelationship relationship) |
static <T extends ERXCopyable<T>> |
deepCopyToOneRelationship(NSMutableDictionary<EOGlobalID,ERXCopyable<?>> copiedObjects,
T source,
T destination,
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
EOAttribute s from the
EOEntity of source that are used in the primary key,
or in forming EORelationship s. |
static EOGlobalID |
globalIDForObject(ERXEnterpriseObject enterpriseObject)
|
static void |
handleMissingERXCopyableKey(Class<?> invalidClass) |
static void |
handleMissingOrInvalidCopyType(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<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<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<EOGlobalID,ERXCopyable<?>> copiedObjects,
T source,
T destination,
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(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,
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,
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,
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,
EORelationship relationship) |
static <T extends ERXEnterpriseObject> |
shallowCopyToManyRelationship(T source,
T destination,
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,
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<EORelationship>> _classRelationshipsDictionary
public static <T extends ERXEnterpriseObject> EOEntity entity(T enterpriseObject)
ERXEOAccessUtilities.entityNamed()
for the actual work.T
- the Type of the enterpriseObject
enterpriseObject
- EOEntity
of the enterpriseObject
public static <T extends ERXEnterpriseObject> void cleanRelationships(T source, T destination)
T
- the Type of the source
and destination
source
- 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 destination
source
- 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 destination
source
- 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<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 EOGlobalID
s 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<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 destination
copiedObjects
- 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<EORelationship> classRelationships(EOEntity entity)
entity
- the EOEntity
for the object being copiedEOAttribute
s that are designated as class
attributes in the entity
public static <T extends ERXCopyable<T>> void deepCopyRelationship(NSMutableDictionary<EOGlobalID,ERXCopyable<?>> copiedObjects, T source, T destination, 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 destination
copiedObjects
- 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<EOGlobalID,ERXCopyable<?>> copiedObjects, T source, T destination, EORelationship relationship)
T
- the Type of the source
and destination
copiedObjects
- 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<EOGlobalID,ERXCopyable<?>> copiedObjects, T source, T destination, EORelationship relationship)
T
- the Type of the source
and destination
copiedObjects
- 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
EORelationship
s.public static NSArray<EOAttribute> exposedPKAndFKAttributes(ERXEnterpriseObject source)
EOAttribute
s from the
EOEntity
of source
that are used in the primary key,
or in forming EORelationship
s. 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(EOEntity entity)
entity
- the EOEntity
for the object being copiedEOAttribute
s that are designated as class
attributes in the entity
public static EOGlobalID globalIDForObject(ERXEnterpriseObject enterpriseObject)
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 source
source
- the subclass of ERXCopyable
to copypublic static <T extends ERXEnterpriseObject> T referenceCopy(T source)
T
- the Type of the source
source
- the subclass of ERXCopyable
to copypublic static <T extends ERXEnterpriseObject> T shallowCopy(T source)
T
- the Type of the source
source
- 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 destination
source
- 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, EORelationship relationship)
T
- the Type of the source
and destination
source
- 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 destination
public 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 destination
source
- 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, EORelationship relationship)
T
- the Type of the source
and destination
E
- 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 destination
public 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 destination
source
- 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, EORelationship relationship)
T
- the Type of the source
and destination
E
- 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 destination
public static <T extends ERXEnterpriseObject> void shallowCopyRelationship(T source, T destination, EORelationship relationship)
T
- the Type of the source
and destination
source
- 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 destination
public static <T extends ERXEnterpriseObject> void shallowCopyToManyRelationship(T source, T destination, EORelationship relationship)
T
- the Type of the source
and destination
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 destination
public static <T extends ERXEnterpriseObject> void shallowCopyToOneRelationship(T source, T destination, EORelationship relationship)
T
- the Type of the source
and destination
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 destination
public static <T extends ERXCopyable<T>> T modelCopy(NSMutableDictionary<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
EOEditingContext
public static <T extends ERXCopyable<T>> void modelCopyClassRelationships(NSMutableDictionary<EOGlobalID,ERXCopyable<?>> copiedObjects, T source, T destination)
source
object is copied.T
- the Type of the source
and destination
copiedObjects
- 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<EOGlobalID,ERXCopyable<?>> copiedObjects, T source, T destination, 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 destination
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 destination
public 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 destination
public static ERXCopyable.CopyType copyType(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(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(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(EOProperty property)
property
- the attribute or relationship being copiedEOAttribute
, "relationship" if it is an instance of
EORelationship
public static NSArray<EOAttribute> primaryAndForeignKeyAttributes(ERXEnterpriseObject source)
source
- the subclass of ERXCopyable
that is being copiedEOAttribute
s that are the Primary- and
Foreign-Key attributes for the source
subclass of
ERXCopyable
Copyright © 2002 – 2024 Project Wonder.