Inherits from | |
Conforms to | |
Framework | /System/Library/Frameworks/CoreData.framework |
Availability | Available in Mac OS X v10.5 and later. |
Companion guide | |
Declared in | NSEntityMigrationPolicy.h |
Instances of NSEntityMigrationPolicy
customize the migration process for an entity mapping.
You set the policy for an entity mapping by passing the name of the migration policy class as the argument to setEntityMigrationPolicyClassName:
(typically you specify the name in the Xcode mapping model editor).
– beginEntityMapping:manager:error:
– createDestinationInstancesForSourceInstance:entityMapping:manager:error:
– endInstanceCreationForEntityMapping:manager:error:
– createRelationshipsForDestinationInstance:entityMapping:manager:error:
– endRelationshipCreationForEntityMapping:manager:error:
– performCustomValidationForEntityMapping:manager:error:
– endEntityMapping:manager:error:
Invoked by the migration manager at the start of a given entity mapping.
- (BOOL)beginEntityMapping:(NSEntityMapping *)mapping manager:(NSMigrationManager *)manager error:(NSError **)error
The mapping object in use.
The migration manager performing the migration.
If an error occurs, upon return contains an NSError
object that describes the problem.
YES
if the method completes successfully, otherwise NO
.
This method is the precursor to the creation stage. In a custom class, you can implement this method to set up any state information that will be useful for the duration of the migration.
NSEntityMigrationPolicy.h
Creates the destination instance(s) for a given source instance.
- (BOOL)createDestinationInstancesForSourceInstance:(NSManagedObject *)sInstance entityMapping:(NSEntityMapping *)mapping manager:(NSMigrationManager *)manager error:(NSError **)error
The source instance for which to create destination instances.
The mapping object in use.
The migration manager performing the migration.
If an error occurs, upon return contains an NSError
object that describes the problem.
YES
if the method completes successfully, otherwise NO
.
This method is invoked by the migration manager on each source instance (as specified by the sourceExpression
in the mapping) to create the corresponding destination instance(s). It also associates the source and destination instances by calling NSMigrationManager
’s associateSourceInstance:withDestinationInstance:forEntityMapping:
method.
If you override this method and do not invoke super
, you must invoke NSMigrationManager
’s associateSourceInstance:withDestinationInstance:forEntityMapping:
to associate the source and destination instances as required. .
NSEntityMigrationPolicy.h
Constructs the relationships between the newly-created destination instances.
- (BOOL)createRelationshipsForDestinationInstance:(NSManagedObject *)dInstance entityMapping:(NSEntityMapping *)mapping manager:(NSMigrationManager *)manager error:(NSError **)error
The destination instance for which to create relationships.
The mapping object in use.
The migration manager performing the migration.
If an error occurs, upon return contains an NSError
object that describes the problem.
YES
if the relationships are constructed correctly, otherwise NO
.
You can use this stage to (re)create relationships between migrated objects—you use the association lookup methods on the NSMigrationManager
instance to determine the appropriate relationship targets.
NSEntityMigrationPolicy.h
Invoked by the migration manager at the end of a given entity mapping.
- (BOOL)endEntityMapping:(NSEntityMapping *)mapping manager:(NSMigrationManager *)manager error:(NSError **)error
The mapping object in use.
The migration manager performing the migration.
If an error occurs, upon return contains an NSError
object that describes the problem.
YES
if the method completes correctly, otherwise NO
.
This is the end to the given entity mapping. You can implement this method to perform any clean-up at the end of the migration (from any of the three phases of the mapping).
NSEntityMigrationPolicy.h
Indicates the end of the creation stage for the specified entity mapping, and the precursor to the next migration stage.
- (BOOL)endInstanceCreationForEntityMapping:(NSEntityMapping *)mapping manager:(NSMigrationManager *)manager error:(NSError **)error
The mapping object in use.
The migration manager performing the migration.
If an error occurs, upon return contains an NSError
object that describes the problem.
YES
if the relationships are constructed correctly, otherwise NO
.
You can override this method to clean up state from the creation of destination or to prepare state for the creation of relationships.
NSEntityMigrationPolicy.h
Indicates the end of the relationship creation stage for the specified entity mapping.
- (BOOL)endRelationshipCreationForEntityMapping:(NSEntityMapping *)mapping manager:(NSMigrationManager *)manager error:(NSError **)error
The mapping object in use.
The migration manager performing the migration.
If an error occurs, upon return contains an NSError
object that describes the problem.
YES
if the method completes correctly, otherwise NO
.
This method is invoked after createRelationshipsForDestinationInstance:entityMapping:manager:error:
; you can override it to clean up state from the creation of relationships, or prepare state for custom validation in performCustomValidationForEntityMapping:manager:error:
.
NSEntityMigrationPolicy.h
Invoked during the validation stage of the entity migration policy, providing the option of performing custom validation on migrated objects.
- (BOOL)performCustomValidationForEntityMapping:(NSEntityMapping *)mapping manager:(NSMigrationManager *)manager error:(NSError **)error
The mapping object in use.
The migration manager performing the migration.
If an error occurs, upon return contains an NSError
object that describes the problem.
YES
if the method completes correctly, otherwise NO
.
This method is called before the default save validation is performed by the framework.
If you implement this method, you must manually obtain the collection of objects you are interested in validating.
NSEntityMigrationPolicy.h
Keys used in value expression right hand sides.
NSString *NSMigrationManagerKey; NSString *NSMigrationSourceObjectKey; NSString *NSMigrationDestinationObjectKey; NSString *NSMigrationEntityMappingKey; NSString *NSMigrationPropertyMappingKey; NSString *NSMigrationEntityPolicyKey;
NSMigrationManagerKey
Key for the migration manager.
To access this key in a custom value expression string in the Xcode mapping model editor use $manager
.
Available in Mac OS X v10.5 and later.
Declared in NSEntityMigrationPolicy.h
.
NSMigrationSourceObjectKey
Key for the source object.
To access this key in a custom value expression string in the Xcode mapping model editor use $source
.
Available in Mac OS X v10.5 and later.
Declared in NSEntityMigrationPolicy.h
.
NSMigrationDestinationObjectKey
Key for the destination object.
To access this key in a custom value expression string in the Xcode mapping model editor use $destination
.
Available in Mac OS X v10.5 and later.
Declared in NSEntityMigrationPolicy.h
.
NSMigrationEntityMappingKey
Key for the entity mapping object.
To access this key in a custom value expression string in the Xcode mapping model editor use $entityMapping
.
Available in Mac OS X v10.5 and later.
Declared in NSEntityMigrationPolicy.h
.
NSMigrationPropertyMappingKey
Key for the property mapping object.
To access this key in a custom value expression string in the Xcode mapping model editor use $propertyMapping
.
Available in Mac OS X v10.5 and later.
Declared in NSEntityMigrationPolicy.h
.
NSMigrationEntityPolicyKey
Key for the entity migration policy object.
To access this key in a custom value expression string in the Xcode mapping model editor use $entityPolicy
.
Available in Mac OS X v10.6 and later.
Declared in NSEntityMigrationPolicy.h
.
You can use these keys in the right hand sides of a value expression.
Last updated: 2010-02-24