Documentation Archive Developer
Search
PATH  Documentation > WebObjects 4.5 > EOControl Reference

Table of Contents

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

Returns the default EOSharedEditingContext. If a shared context hasn't yet been created, this method creates one and posts an EODefaultSharedEditingContextWasInitializedNotification.

setDefaultSharedEditingContext:

+ (void)setDefaultSharedEditingContext:(EOSharedEditingContext *)context

Sets the default shared editing context. If context is nil, object sharing is disabled in subsequently created EOEditingContexts.


Instance Methods



bindObjectsWithFetchSpecification:toName:

- (void)bindObjectsWithFetchSpecification:(EOFetchSpecification *)fetchSpecification toName:(NSString *)name

Fetches objects with fetchSpecification and binds the results to fetchSpecification's entity and fetchSpecification's name, which is provided with the name argument. You can later retrieve the resulting shared objects using the methods objectsByEntityName and objectsByEntityNameAndFetchSpecificationName.

deleteObject:

- (void)deleteObject:object

Raises an exception. You can't modify or delete the shared objects in a shared editing context.

deletedObjects

- (NSArray *)deletedObjects

Returns an empty array. The shared objects in a shared editing context can't be deleted.

faultForGlobalID:editingContext:

- (id)faultForGlobalID:(EOGlobalID *)gid editingContext:(EOEditingContext *)context

A thread-safe version of the superclass implementation.

See Also: - faultForGlobalID:editingContext: ( EOEditingContext)



hasChanges

- (BOOL)hasChanges

Returns NO. You can't modify or delete the shared objects in a shared editing context.

insertedObjects

- (NSArray *)insertedObjects

Returns an empty array. You can't insert objects into a shared editing context.

insertObject:

- (void)insertObject:object

Raises an exception. You can't insert objects into a shared editing context. Instead, insert an enterprise object into a regular editing context and then fetch it into the shared context.

lockForReading

- (void)lockForReading

Locks the receiver for reading.

See Also: - tryLockForReading



objectForGlobalID:

- (id)objectForGlobalID:(EOGlobalID *)gid

A thread-safe version of the superclass implementation.

See Also: - objectForGlobalID: ( EOEditingContext)



objectsByEntityName

- (NSDictionary *)objectsByEntityName

Returns a dictionary of all the objects fetched into the shared context. The dictionary keys are entity names and the corresponding values are NSArrays of enterprise objects for that entity.

See Also: bindObjectsWithFetchSpecification:toName:



objectsByEntityNameAndFetchSpecificationName

- (NSDictionary *)objectsByEntityNameAndFetchSpecificationName

Returns the objects fetched into the receiver with bindObjectsWithFetchSpecification:toName:. The return value is a dictionary whose keys are entity names and whose values are subdictionaries. The keys of the subdictionaries are fetch specification names, and the values are NSArrays of the enterprise objects fetched with the corresponding fetch specification. The fetch specification names are the names specified in bindObjectsWithFetchSpecification:toName:. Generally these names are the same names used to identify stored fetch specifications in EOModeler.
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

A thread-safe version of the superclass implementation that binds the results to fetchSpecification's entity. You can later retrieve the resulting shared objects using the method objectsByEntityName.

See Also: - objectsWithFetchSpecification:editingContext: ( EOEditingContext)



objectWillChange:

- (void)objectWillChange:object

Raises an exception. You can't modify the shared objects in a shared editing context.

refaultObject:withGlobalID:editingContext:

- (void)refaultObject:object withGlobalID:(EOGlobalID *)gid editingContext:(EOEditingContext *)context

See the refaultObject:withGlobalID:editingContext: method description in the EOEditingContext class specification. Note that this method is not thread safe.

registeredObjects

- (NSArray *)registeredObjects

A thread-safe version of the superclass implementation.

See Also: - registeredObjects ( EOEditingContext)



reset

- (void)reset

Overrides the superclass implementation to do nothing.

saveChanges

- (void)saveChanges

Raises an exception. You can't modify the shared objects in a shared editing context.

setSharedEditingContext:

- (void)setSharedEditingContext:(EOSharedEditingContext *)sharedEC

Raises an exception unless sharedEC is nil.

setUndoManager:

- (void)setUndoManager:(NSUndoManager *)undoManager

Raises an exception unless undoManager is nil.

sharedEditingContext

- (EOSharedEditingContext *)sharedEditingContext

Returns nil.

tryLockForReading

- (BOOL)tryLockForReading

Tries to lock the receiver for reading. Returns YES if the receiver is successfully locked, NO otherwise.

unlockForReading

- (void)unlockForReading

Unlocks the receiver for reading.

updatedObjects

- (NSArray *)updatedObjects

Returns an empty array. You can't modify objects that are in a shared editing context.

validateChangesForSave

- (void)validateChangesForSave

Overrides the superclass implementation to do nothing.


Notifications


EODefaultSharedEditingContextWasInitializedNotification

EOCONTROL_EXTERN NSString *EODefaultSharedEditingContextWasInitializedNotification

Posted when an EOSharedEditingContext is created and assigned as the defaultSharedEditingContext.
Notification Object None
userInfo Dictionary None

EOSharedEditingContextInitializedObjectsNotification

EOCONTROL_EXTERN NSString *EOSharedEditingContextInitializedObjectsNotification

Posted when new objects are added to a shared editing context (by fetching or fault firing).
Notification Object The shared editing context
userInfo Dictionary NSArray of global IDs of the initialized objects



Table of Contents