EOSharedEditingContext
- Inherits from:
- EOEditingContext : EOObjectStore : NSObject
Declared in:
- EOControl/EOSharedEditingContext.h
Class Description
The EOSharedEditingContext class defines a mechanism that allows EOEditingContexts to share enterprise objects for reading. This mechanism can reduce redundant pointers and the number of fetches an application requires.
Shared enterprise objects are read-only and persist for the life of the application; they can't be modified or deleted. They must be unique in the shared context and across all other editing contexts that share objects from the shared context.
Objects can be fetched into a shared context using objectsWithFetchSpecification: and bindObjectsWithFetchSpecification:toName:. The latter method makes it easier to access result sets, using objectsByEntityNameAndFetchSpecificationName.
In multithreaded applications, shared objects can be used safely by many threads at once. Shared editing contexts use EOMultiReaderLocks to maintain thread safety. The methods objectsWithFetchSpecification:editingContext: (and the inherited objectsWithFetchSpecification:), bindObjectsWithFetchSpecification:toName:, faultForGlobalID:editingContext:, and objectForGlobalID: are thread-safe, but you must lock the context before using any other shared context API.
It is possible to modify shared objects while an application is running, but only indirectly. You can create a regular editing context that doesn't share objects by setting it's sharedEditingContext to nil. Fetch the object that you want to change into the regular context, modify or delete it, and save. Since shared editing contexts listen for EOObjectsChangedInStoreNotifications, the shared editing context updates when it learns that an object was modified. The shared context removes from its objectsByEntityName and objectsByEntityNameAndFetchSpecificationName dictionaries any objects that have been deleted, and it refaults any objects that have been updated. However, to register newly inserted objects in the shared editing context, you should refetch.
Constants
In EOSharedEditingContext.h, EOControl defines constants for the notifications EOSharedEditingContexts posts. For more information, see "Notifications" .
Method Types
- Accessing a shared editing context
- + defaultSharedEditingContext
- + setDefaultSharedEditingContext:
- - sharedEditingContext
- - setSharedEditingContext:
- Accessing shared objects
- - bindObjectsWithFetchSpecification:toName:
- - objectsByEntityName
- - objectsByEntityNameAndFetchSpecificationName
- - objectsWithFetchSpecification:editingContext:
- Locking a shared editing context
- - lockForReading
- - tryLockForReading
- - unlockForReading
- Overridden EOEditingContext methods
- - deleteObject:
- - deletedObjects
- - faultForGlobalID:editingContext:
- - hasChanges - insertedObjects
- - insertObject:
- - objectForGlobalID:
- - objectWillChange:
- - refaultObject:withGlobalID:editingContext:
- - registeredObjects
- - reset
- - saveChanges
- - setUndoManager:
- - updatedObjects
- - validateChangesForSave
Class Methods
defaultSharedEditingContext
+ (EOSharedEditingContext *)defaultSharedEditingContext
setDefaultSharedEditingContext:
+ (void)setDefaultSharedEditingContext:(EOSharedEditingContext
*)context
Instance Methods
bindObjectsWithFetchSpecification:toName:
- (void)bindObjectsWithFetchSpecification:(EOFetchSpecification
*)fetchSpecification
toName:(NSString *)name
deleteObject:
- (void)deleteObject:object
deletedObjects
- (NSArray *)deletedObjects
faultForGlobalID:editingContext:
- (id)faultForGlobalID:(EOGlobalID
*)gid
editingContext:(EOEditingContext
*)context
See Also: - faultForGlobalID:editingContext: ( EOEditingContext)
hasChanges
- (BOOL)hasChanges
insertedObjects
- (NSArray *)insertedObjects
insertObject:
- (void)insertObject:object
lockForReading
- (void)lockForReading
See Also: - tryLockForReading
objectForGlobalID:
- (id)objectForGlobalID:(EOGlobalID
*)gid
See Also: - objectForGlobalID: ( EOEditingContext)
objectsByEntityName
- (NSDictionary *)objectsByEntityName
See Also: bindObjectsWithFetchSpecification:toName:
objectsByEntityNameAndFetchSpecificationName
- (NSDictionary *)objectsByEntityNameAndFetchSpecificationName
Note: The dictionary returned from this method might not contain all the receiver's shared objects. It only contains objects fetched with a named fetch specification using bindObjectsWithFetchSpecification:toName:. Shared objects fetched into the receiver with other methods are not returned from this method. |
objectsWithFetchSpecification:editingContext:
- (NSArray *)objectsWithFetchSpecification:(EOFetchSpecification
*)fetchSpecification
editingContext:(EOEditingContext
*)anEditingContext
See Also: - objectsWithFetchSpecification:editingContext: ( EOEditingContext)
objectWillChange:
- (void)objectWillChange:object
refaultObject:withGlobalID:editingContext:
- (void)refaultObject:object
withGlobalID:(EOGlobalID *)gid
editingContext:(EOEditingContext
*)context
registeredObjects
- (NSArray *)registeredObjects
See Also: - registeredObjects ( EOEditingContext)
reset
- (void)reset
saveChanges
- (void)saveChanges
setSharedEditingContext:
- (void)setSharedEditingContext:(EOSharedEditingContext
*)sharedEC
setUndoManager:
- (void)setUndoManager:(NSUndoManager
*)undoManager
sharedEditingContext
- (EOSharedEditingContext *)sharedEditingContext
tryLockForReading
- (BOOL)tryLockForReading
unlockForReading
- (void)unlockForReading
updatedObjects
- (NSArray *)updatedObjects
validateChangesForSave
- (void)validateChangesForSave
Notifications
EODefaultSharedEditingContextWasInitializedNotification
EOCONTROL_EXTERN NSString *EODefaultSharedEditingContextWasInitializedNotification
Notification Object | None |
userInfo Dictionary | None |
EOSharedEditingContextInitializedObjectsNotification
EOCONTROL_EXTERN NSString *EOSharedEditingContextInitializedObjectsNotification
Notification Object | The shared editing context |
userInfo Dictionary | NSArray of global IDs of the initialized objects |