![](../../../../../../../../../../images/previous.gif)
![](../../../../../../../../../../images/next.gif)
EOEditingContext
Inherits From:
EOObjectStore : NSObject
Conforms To: EOObserving
NSLocking
Declared in: EOControl/EOEditingContext.h
Class At a Glance:
-
Purpose
Principal Attributes |
---|
The set of enterprise objects managed by the EOEditingContext |
The EOEditingContext's parent EOObjectStore |
The set of EOEditor objects messaged by the EOEditingContext |
The EOEditingContext's EOMessageHandler |
-
Creation
- initWithParentObjectStore: Designated initializer.
Commonly Used Methods - objectsWithFetchSpecification: Fetches objects from an external store. - insertObject: Registers a new object to be inserted into the parent EOObjectStore when changes are saved. - deleteObject: Registers that an object should be removed from the parent EOObjectStore when changes are saved. - lockObject: Attempts to lock an object in the external store. - hasChanges Returns YES if any of the receiver has any pending changes to the parent EOObjectStore. - saveChanges Commits changes made in the receiver to the parent EOObjectStore. - revert Removes everything from the undo stack, discards all insertions and deletions, and restores updated objects to their original values. - objectForGlobalID: Given a globalID, returns its associated object. - globalIDForObject: Given an object, returns its globalID. - setDelegate: Sets the receiver's delegate. - parentObjectStore Returns the receiver's parent EOObjectStore. - rootObjectStore Returns the receiver's root EOObjectStore.
An EOEditingContext object represents a single "object space" or document in an application. Its primary responsibility is managing a graph of enterprise objects. This object graph is a group of related business objects that represent an internally consistent view of one or more external stores (usually a database).
All objects fetched from an external store are registered in an editing context along with a global identifier (EOGlobalID) that's used to uniquely identify each object to the external store. The editing context is responsible for watching for changes in its objects (using the EOObserving protocol) and recording snapshots for object-based undo. A single enterprise object instance exists in one and only one editing context, but multiple copies of an object can exist in different editing contexts. Thus object uniquing is scoped to a particular editing context.
For more information on EOEditingContext, see the sections:
- Other Classes that Participate in Object Graph Management
- Programmatically Creating an EOEditingContext
- Using EOEditingContexts in Different Configurations
- Fetching Objects
- Managing Changes in Your Application
- Methods for Managing the Object Graph
- General Guidelines for Managing the Object Graph
- Using EOEditingContext to Archive Custom Objects in Web Objects Framework
Constants
The following string constants name notifications EOEditingContext posts:
See the Notifications section for more information on the notifications.
The following string constants are the keys to the EOObjectsChangedInEditingContextNotification's user info dictionary:
EditingContextFlushChangesRunLoopOrdering, is an integer that defines the order in which the editing context performs end of event processing in processRecentChanges . Messages with lower order numbers are processed before messages with higher order numbers. In an application built with the Application Kit, the constant order value schedules the editing context to perform its processing before the undo stack group is closed or window display is updated.
Adopted Protocols
- EOObserving
- - objectWillChange:
- NSLocking
- - lock
- - unlock
- - unlock
- Initializing an EOEditingContext
- - initWithParentObjectStore:
- Controlling EOEditingContext's memory management strategy
- Fetching objects
- - objectsWithFetchSpecification:
- Committing or discarding changes
- - saveChanges
- - saveChanges:
- - tryToSaveChanges
- - refaultObjects
- - refault:
- - refetch:
- - revert
- - revert:
- - invalidateAllObjects
- - saveChanges:
- Registering changes
- - deleteObject:
- - insertObject:
- - insertObject:withGlobalID:
- - objectWillChange:
- - processRecentChanges
- - insertObject:
- Checking changes
- - deletedObjects
- - insertedObjects
- - updatedObjects
- - hasChanges
- - insertedObjects
- Object registration and snapshotting
- - forgetObject:
- - recordObject:globalID:
- - committedSnapshotForObject:
- - currentEventSnapshotForObject:
- - objectForGlobalID:
- - globalIDForObject:
- - registeredObjects
- - recordObject:globalID:
- Locking objects
- - lockObject:
- - lockObjectWithGlobalID:editingContext:
- - isObjectLockedWithGlobalID:editingContext:
- - setLocksObjectsBeforeFirstModification:
- - locksObjectsBeforeFirstModification
- - lockObjectWithGlobalID:editingContext:
- Undoing operations
- - redo:
- - undo:
- - setUndoManager:
- - undoManager
- - undo:
- Deletion and Validation Behavior
- - setPropagatesDeletesAtEndOfEvent:
- - propagatesDeletesAtEndOfEvent
- - setStopsValidationAfterFirstError:
- - stopsValidationAfterFirstError
- - propagatesDeletesAtEndOfEvent
- Returning related object stores
- - parentObjectStore
- - rootObjectStore
- Managing editors
- - editors
- - addEditor:
- - removeEditor:
- - addEditor:
- Setting the delegate
- - setDelegate:
- - delegate
- Setting the message handler
- - setMessageHandler:
- - messageHandler
- Invalidating objects
- - setInvalidatesObjectsWhenFreed:
- - invalidatesObjectsWhenFreed
- Locking
- - lock
- - unlockWorking with raw rows
- - faultForRawRow:entityNamed:
- Unarchiving from nib
- + defaultParentObjectStore
- + setDefaultParentObjectStore:
- + setSubstitutionEditingContext:
- + substitutionEditingContext
- + setDefaultParentObjectStore:
- Nested EOEditingContext support
- - objectsWithFetchSpecification:editingContext:
- - objectsForSourceGlobalID:relationshipName:editingContext:
- - arrayFaultWithSourceGlobalID:relationshipName:editingContext:
- - faultForGlobalID:editingContext:
- - saveChangesInEditingContext:
- - refaultObject:withGlobalID:editingContext:
- - invalidateObjectsWithGlobalIDs:
- - initializeObject:withGlobalID:editingContext:
- - objectsForSourceGlobalID:relationshipName:editingContext:
- Archiving and unarchiving objects
- + encodeObject:withCoder:
- + initObject:withCoder:
- + setUsesContextRelativeEncoding:
- + usesContextRelativeEncoding
- + initObject:withCoder:
defaultParentObjectStore
+ (EOObjectStore *)defaultParentObjectStore
Returns the EOObjectStore that is the default parent object store for new editing contexts. Normally this is the EOObjectStoreCoordinator returned from the EOObjectStoreCoordinator class method defaultCoordinator .
See also: + setDefaultParentObjectStore:
encodeObject:withCoder:
+ (void)encodeObject:
(id)object
withCoder:
(NSCoder *)encoder
Invoked by an enterprise object object to ask the EOEditingContext to encode object using encoder. For more discussion of this subject, see "Using EOEditingContext to Archive Custom Objects in Web Objects Framework" in the class description.
See also: + initObject:withCoder: , + setUsesContextRelativeEncoding: , + usesContextRelativeEncoding
initObject:withCoder:
+ (id)initObject:
(id)object
withCoder:
(NSCoder *)decoder
Invoked by an enterprise object object to ask the EOEditingContext to initialize object from data in decoder. For more discussion of this subject, see "Using EOEditingContext to Archive Custom Objects in Web Objects Framework" in the class description.
See also: + encodeObject:withCoder: , + setUsesContextRelativeEncoding: , + usesContextRelativeEncoding
setDefaultParentObjectStore:
+ (void)setDefaultParentObjectStore:
(EOObjectStore *)store
Sets the default parent EOObjectStore to store. You use this method before loading a nib file to change the default parent EOObjectStores of the EOEditingContexts in the nib file. The object you supply for store can be a different EOObjectStoreCoordinator or another EOEditingContext (if you're using a nested EOEditingContext). After loading a nib with an EOEditingContext substituted as the default parent EOObjectStore, you should restore the default behavior by setting the default parent EOObjectStore to nil
. For example:
[EOEditingContext setDefaultParentObjectStore:editingContext];
nibLoaded = [NSBundle loadNibNamed:@"thirdNib" owner:self];
[EOEditingContext setDefaultObjectStore:nil]; // Restore default
A default parent object store is global until it is changed again. For more discussion of this topic, see the chapter "Application Configurations" in the Enterprise Objects Framework Developer's Guide.
See also: + defaultParentObjectStore
setSubstitutionEditingContext:
+ (void)setSubstitutionEditingContext:
(EOEditingContext *)anEditingContext
Assigns anEditingContext as the EOEditingContext to substitute for the one specified in a nib file you're about to load. Using this method causes all of the connections in your nib file to be redirected to anEditingContext. This can be useful when you want an interface loaded from a second nib file to use an existing EOEditingContext. After loading a nib with a substitution EOEditingContext, you should restore the default behavior by setting the substitution EOEditingContext to nil
. For example:
[EOEditingContext setSubstitutionEditingContext:editingContext];
nibLoaded = [NSBundle loadNibNamed:@"thirdNib" owner:self];
[EOEditingContext setSubstitutionEditingContext:nil]; // Restore default
A substitution editing context is global until it is changed again. For more discussion of this topic, see the chapter "Application Configurations" in the Enterprise Objects Framework Developer's Guide.
See also: + substitutionEditingContext
setUsesContextRelativeEncoding:
+ (void)setUsesContextRelativeEncoding:
(BOOL)flag
Sets according to flag whether encodeObject:withCoder: uses context-relative encoding. For more discussion of this subject, see "Using EOEditingContext to Archive Custom Objects in Web Objects Framework" in the class description.
See also: + usesContextRelativeEncoding , + encodeObject:withCoder: ,
substitutionEditingContext
+ (EOEditingContext *)substitutionEditingContext
Returns the substitution EOEditingContext if one has been specified. Otherwise returns nil
.
See also: + setSubstitutionEditingContext:
usesContextRelativeEncoding
+ (BOOL)usesContextRelativeEncoding
Returns YES to indicate that encodeObject:withCoder: uses context relative encoding, NO otherwise. For more discussion of this subject, see "Using EOEditingContext to Archive Custom Objects in Web Objects Framework" in the class description.
See also: + setUsesContextRelativeEncoding:
addEditor:
- (void)addEditor:
(id)editor
Adds editor to the receiver's set of EOEditors. For more explanation, see the method description for editors and the EOEditors informal protocol specification.
See also: -
removeEditor:
arrayFaultWithSourceGlobalID:relationshipName:editingContext:
- (NSArray *)arrayFaultWithSourceGlobalID:
(EOGlobalID *)globalID
relationshipName:
(NSString *)name
editingContext:
(EOEditingContext *)anEditingContext
Overrides the implementation inherited from EOObjectStore. If the objects associated with the EOGlobalID globalID are already registered in the receiver, returns those objects. Otherwise, propagates the message down the object store hierarchy, through the parent object store, ultimately to the associated EODatabaseContext. The EODatabaseContext creates and returns a to-many fault.
When a parent EOEditingContext receives this on behalf of a child EOEditingContext and the EOGlobalID globalID identifies a newly inserted object in the parent, the parent returns a copy of its object's relationship array with the member objects translated into objects in the child EOEditingContext.
For more information on faults, see the EOObjectStore, EODatabaseContext (EOAccess), EOFault, and EOFaultHandler class specifications.
See also: - faultForGlobalID:editingContext:
committedSnapshotForObject:
- (NSDictionary *)committedSnapshotForObject:
(id)object
Returns a dictionary containing a snapshot of object that reflects its committed values (that is, its values as they were last committed to the database). In other words, this snapshot represents the state of the object before any modifications were made to it. The snapshot is updated to the newest object state after a save.
See also: - currentEventSnapshotForObject:
currentEventSnapshotForObject:
- (NSDictionary *)currentEventSnapshotForObject:
(id)object
Returns a dictionary containing a snapshot of object that reflects its state as it was at the beginning of the current event loop. After the end of the current event-upon invocation of processRecentChanges -this snapshot is updated to hold the modified state of the object.
See also: - committedSnapshotForObject: , - processRecentChanges
Returns the receiver's delegate.
See also: - setDelegate:
deleteObject:
- (void)deleteObject:
(id)object
Specifies that object should be removed from the receiver's parent EOObjectStore when changes are committed. At that time, the object will be removed from the uniquing tables.
See also: - deletedObjects
deletedObjects
- (NSArray *)deletedObjects
Returns the objects that have been deleted from the receiver's object graph.
See also: -
updatedObjects ,
-
insertedObjects
Returns the receiver's editors. Editors are special-purpose delegate objects that may contain uncommitted changes that need to be validated and applied to enterprise objects before the EOEditingContext saves changes. For example, EODisplayGroups (EOInterface) register themselves as editors with the EOEditingContext of their data sources so that they can save any changes in the key text field. For more information, see the EOEditors informal protocol specification and the EODisplayGroup class specification.
See also: -
addEditor: ,
-
removeEditor:
faultForGlobalID:editingContext:
- (id)faultForGlobalID:
(EOGlobalID *)globalID
editingContext:
(EOEditingContext *)anEditingContext
Overrides the implementation inherited from EOObjectStore. If the object associated with the EOGlobalID globalID is already registered in the receiver, this method returns that object. Otherwise, the method propagates the message down the object store hierarchy, through the parent object store, ultimately to the associated EODatabaseContext. The EODatabaseContext creates and returns a to-one fault.
For example, suppose you want the department object whose deptID has a particular value. The most efficient way to get it is to look it up by its globalID using faultForGlobalID:editingContext: :
EOEntity *entity = [[[editingContext rootObjectStore] modelGroup] entityNamed:entityName];
EOGlobalID *gid = [entity globalIDForRow:[NSDictionary
dictionaryWithObjectsAndKeys:deptIdentifier, @"deptID", nil]];
return [editingContext faultForGlobalID:gid editingContext:editingContext];
If the department object is already registered in the EOEditingContext, this code returns the object (without going to the database). If not, a fault for this object is created, and the object is fetched only when you trigger the fault.
In a nested editing context configuration, when a parent EOEditingContext is sent faultForGlobalID:editingContext: on behalf of a child EOEditingContext and globalID identifies a newly inserted object in the parent, the parent registers a copy of the object in the child.
For more discussion of this method, see the section "Working with Objects Across Multiple EOEditingContexts" in the class description. For more information on faults, see the EOObjectStore, EODatabaseContext (EOAccess), EOFault, and EOFaultHandler class specifications.
See also: - arrayFaultWithSourceGlobalID:relationshipName:editingContext:
faultForRawRow:entityNamed:
- (id)faultForRawRow:
(id)row
entityNamed:
(NSString *)entityName
Returns a fault for the raw row row by invoking faultForRawRow:entityNamed:editingContext: with self as the editing context.
forgetObject:
- (void)forgetObject:
(id)object
Removes object from the uniquing tables and causes the receiver to remove itself as the object's observer. This method is invoked whenever an object being observed by an EOEditingContext is deallocated. Note that this method does not have the effect of releasing and freeing the object. You should never invoke this method directly. The correct way to remove an object from its editing context is to remove every reference to the object by refaulting any object that references it (using refaultObjects or invalidateAllObjects ). Also note that this method does not have the effect of deleting an object-to delete an object you should either use the deleteObject: method or remove the object from an owning relationship.
globalIDForObject:
- (EOGlobalID *)globalIDForObject:
object
Returns the EOGlobalID for object. All objects fetched from an external store are registered in an EOEditingContext along with a global identifier (EOGlobalID) that's used to uniquely identify each object to the external store. If object hasn't been registered in the EOEditingContext (that is, if no match is found), this method returns nil
. Objects are registered in an EOEditingContext using the insertObject: method, or, when fetching, with recordObject:globalID: .
See also: - objectForGlobalID:
hasChanges
- (BOOL)hasChanges
Returns YES if any of the objects in the receiver's object graph have been modified-that is, if any objects have been inserted, deleted, or updated.
initWithParentObjectStore:
- initWithParentObjectStore:
(EOObjectStore *)anObjectStore
Initializes the receiver with anObjectStore as its parent EOObjectStore. Returns self
. This method is the designated initializer for EOEditingContext. For more discussion of parent EOObjectStores, see "Other Classes that Participate in Object Graph Management" in the class description.
initializeObject:withGlobalID:editingContext:
- (void)initializeObject:
(id)object
withGlobalID:
(EOGlobalID *)globalID
editingContext:
(EOEditingContext *)anEditingContext
Overrides the implementation inherited from EOObjectStore to build the properties for the object identified by globalID. When a parent EOEditingContext receives this on behalf of a child EOEditingContext (as represented by anEditingContext), and the globalID identifies an object instantiated in the parent, the parent returns properties extracted from its object and translated into the child's context. This ensures that a nested context "inherits" modified values from its parent EOEditingContext. If the receiver doesn't have object, the request is forwarded the receiver's parent EOObjectStore.
insertedObjects
- (NSArray *)insertedObjects
Returns the objects that have been inserted into the receiver's object graph.
See also: -
deletedObjects ,
-
updatedObjects
insertObject:
- (void)insertObject:
(id)object
Registers (by invoking insertObject:withGlobalID: ) object to be inserted in the receiver's parent EOObjectStore the next time changes are saved. In the meantime, object is registered in the receiver with a temporary globalID.
See also: - insertedObjects , - deletedObjects , - insertObject:withGlobalID:
insertObject:withGlobalID:
- (void)insertObject:
object withGlobalID:
(EOGlobalID *)globalID
Registers a new object identified by globalID that should be inserted in the parent EOObjectStore when changes are saved. Works by invoking recordObject:globalID: , unless the receiver already contains the object. Sends object the message awakeFromInsertionInEditingContext: . globalID must respond YES to isTemporary . When the external store commits object, it re-records it with the appropriate permanent globalID.
It is an error to insert an object that's already registered in an editing context unless you are effectively undeleting the object by reinserting it.
See also: - insertObject:
invalidateAllObjects
- (void)invalidateAllObjects
Overrides the implementation inherited from EOObjectStore to discard the values of objects cached in memory and refault them, which causes them to be refetched from the external store the next time they're accessed. This method sends the message invalidateObjectsWithGlobalIDs: to the parent object store with the globalIDs of all of the objects cached in the receiver. When an EOEditingContext receives this message, it propagates the message down the object store hierarchy. EODatabaseContexts discard their snapshots for invalidated objects and broadcast an EOObjectsChangedInStoreNotification. (EODatabaseContext is defined in EOAccess.)
The final effect of this method is to refault all objects currently in memory. This refaulting in turn releases all objects not retained by your application or by an EODisplayGroup. The next time you access one of these objects, it's refetched from the database.
To flush the entire application's cache of all values fetched from an external store, use a statement such as the following:
[[editingContext rootObjectStore] invalidateAllObjects];
If you just want to discard uncommitted changes but you don't want to sacrifice the values cached in memory, use the EOEditingContext revert method, which reverses all changes and clears the undo stack. For more discussion of this topic, see the section "Methods for Managing the Object Graph" in the class description.
See also: - refetch: , - invalidateObjectsWithGlobalIDs:
invalidateObjectsWithGlobalIDs:
- (void)invalidateObjectsWithGlobalIDs:
(NSArray *)globalIDs
Overrides the implementation inherited from EOObjectStore to signal to the parent object store that the cached values for the objects identified by globalIDs should no longer be considered valid and that they should be refaulted. Invokes processRecentChanges before refaulting the objects. This message is propagated to any underlying object store, resulting in a refetch the next time the objects are accessed. Any related (child or peer) object stores are notified that the objects are no longer valid. All uncommitted changed to the objects are lost. For more discussion of this topic, see the section "Methods for Managing the Object Graph" in the class description.
See also: - invalidateAllObjects
invalidatesObjectsWhenFreed
- (BOOL)invalidatesObjectsWhenFreed
Returns YES to indicate that the receiver clears and "booby-traps" all of the objects registered with it when the receiver is deallocated, NO otherwise. The default is YES. In this method, "invalidate" has a different meaning than it does in the other invalidate...
methods. For more discussion of this topic, see the method description for setInvalidatesObjectsWhenFreed: .
isObjectLockedWithGlobalID:editingContext:
- (BOOL)isObjectLockedWithGlobalID:
(EOGlobalID *)globalID
editingContext:
(EOEditingContext *)anEditingContext
Returns YES if the object identified by globalID in anEditingContext is locked, NO otherwise. This method works by forwarding the message isObjectLockedWithGlobalID:editingContext: to its parent object store.
See also: - lockObject: , - lockObjectWithGlobalID:editingContext: ,
- locksObjectsBeforeFirstModification
lock
Locks access to the receiver to prevent other threads from accessing it. You should lock an editing context when you are accessing or modifying objects managed by the editing context. The thread-saftey provided by Enterprise Objects Framework allows one thread to be active in each EOEditingContext and one thread to be active in each EODatabaseContext (EOAccess). In other words, multiple threads can access and modify objects concurrently in different editing contexts, but only one thread can access the database at a time (to save, fetch, or fault).
Warning: This method creates an NSAutoreleasePool that is released when unlock is called. Consequently, objects that have been autoreleased within the scope of a lock /unlock pair may not be valid after the unlock .
See also: - unlock
lockObject:
- (void)lockObject:
(id)anObject
Attempts to lock anObject in the external store. This method works by invoking lockObjectWithGlobalID:editingContext: . Raises an NSInvalidArgumentException if it can't find the globalID for anObject to pass to lockObjectWithGlobalID:editingContext: .
See also: - isObjectLockedWithGlobalID:editingContext: , - locksObjectsBeforeFirstModification
lockObjectWithGlobalID:editingContext:
- (void)lockObjectWithGlobalID:
(EOGlobalID *)globalID
editingContext:
(EOEditingContext *)anEditingContext
Overrides the implementation inherited from EOObjectStore to attempt to lock the object identified by globalID in anEditingContext in the external store. Raises an NSInternalInconsistencyException if unable to obtain the lock. This method works by forwarding the message lockObjectWithGlobalID:editingContext: to its parent object store.
See also: - lockObject: , - isObjectLockedWithGlobalID:editingContext: , - locksObjectsBeforeFirstModification
locksObjectsBeforeFirstModification
- (BOOL)locksObjectsBeforeFirstModification
Returns YES if the receiver locks object in the external store (with lockObject: ) the first time object is modified.
See also: - setLocksObjectsBeforeFirstModification: , - isObjectLockedWithGlobalID: editingContext: , - lockObject: , - lockObjectWithGlobalID:editingContext:
messageHandler
- (id)messageHandler
Returns the EOEditingContext's message handler. A message handler is a special-purpose delegate responsible for presenting errors to the user. Typically, an EODisplayGroup (EOInterface) registers itself as the message handler for its EOEditingContext. For more information, see the EOMessageHandlers informal protocol specification.
See also: - setMessageHandler:
objectForGlobalID:
- (id)objectForGlobalID:
(EOGlobalID *)globalID
Returns the object identified by globalID, or nil
if no object has been registered in the EOEditingContext with globalID.
See also: - globalIDForObject:
objectsForSourceGlobalID:relationshipName:editingContext:
- (NSArray *)objectsForSourceGlobalID:
(EOGlobalID *)globalID
relationshipName:
(NSString *)name
editingContext:
(EOEditingContext *)anEditingContext
Overrides the implementation inherited from EOObjectStore to service a to-many fault for a relationship named name. When a parent EOEditingContext receives a objectsForSourceGlobalID:relationshipName:editingContext: message on behalf of a child editing context and globalID matches an object instantiated in the parent, the parent returns a copy of its relationship array and translates its objects into the child editing context. This ensures that a child editing context "inherits" modified values from its parent. If the receiving editing context does not have the specified object or if the parent's relationship property is still a fault, the request is fowarded to its parent object store.
objectsWithFetchSpecification:
- (NSArray *)objectsWithFetchSpecification:
(EOFetchSpecification *)fetchSpecification
Invokes objectsWithFetchSpecification: editingContext:
with self
as the EOEditingContext and returns the result.
objectsWithFetchSpecification:editingContext:
- (NSArray *)objectsWithFetchSpecification:
(EOFetchSpecification *)fetchSpecification editingContext:
(EOEditingContext *)anEditingContext
Overrides the implementation inherited from EOObjectStore to fetch objects from an external store according to the criteria specified by fetchSpecification and return them in an array. If one of these objects is already present in memory, this method doesn't overwrite its values with the new values from the database. This method raises an exception if an error occurs; the error message indicates the nature of the problem.
When an EOEditingContext receives this message, it forwards the message to its root object store. Typically the root object store is an EOObjectStoreCoordinator with underlying EODatabaseContexts. In this case, the object store coordinator forwards the request to the appropriate database context based on the entity name in fetchSpecification. The database context then obtains an EODatabaseChannel and performs the fetch, registering all fetched objects in anEditingContext. (EODatabaseContext and EODatabaseChannel are defined in EOAccess.)
objectWillChange:
- (void)objectWillChange:
(id)object
This method is automatically invoked when any of the objects registered in the receiver invokes its willChange method. This method is EOEditingContext's implementation of the EOObserving protocol.
parentObjectStore
- (EOObjectStore *)parentObjectStore
Returns the EOObjectStore from which the receiver fetches and to which it saves objects.
processRecentChanges
- (void)processRecentChanges
Forces the receiver to process pending insertions, deletions, and updates. Normally, when objects are changed, the processing of the changes is deferred until the end of the current event. At that point, an EOEditingContext moves objects to the inserted, updated, and deleted lists, delete propagation is performed, undos are registered, and EOObjectsChangedInStoreNotification and EOObjectsChangedInEditingContextNotification are posted (In a Yellow Box application, this usually causes the user interface to update). You can use this method to explicitly force changes to be processed. An EOEditingContext automatically invokes this method on itself before performing certain operations such as saveChanges .
propagatesDeletesAtEndOfEvent
- (BOOL)propagatesDeletesAtEndOfEvent
Returns YES if the receiver propagates deletes at the end of the event in which a change was made, NO if it propagates deletes only right before saving changes. The default is YES.
See also: - setPropagatesDeletesAtEndOfEvent:
recordObject:globalID:
- (void)recordObject:
(id)object
globalID:
(EOGlobalID *)globalID
Makes the receiver aware of an object identified by globalID existing in its parent object store. EOObjectStores (such as the access layer's EODatabaseContext) usually invoke this method for each object fetched. When it receives this message, the receiver enters the object in its uniquing table and registers itself as an observer of the object.
This method forwards a redo message to the receiver's NSUndoManager, asking it to reverse the latest undo operation applied to objects in the object graph.
See also: - undo:
refault:
- (void)refault:
(id)sender
This action method simply invokes refaultObjects .
refaultObjects
- (void)refaultObjects
Refaults all objects cached in the receiver that haven't been inserted, deleted, or updated. Invokes processRecentChanges , then invokes refaultObject:withGlobalID:editingContext: for all objects that haven't been inserted, deleted, or updated. For more discussion of this topic, see the section "Methods for Managing the Object Graph" in the class description.
refaultObject:withGlobalID:editingContext:
- (void)refaultObject: (id)anObject
withGlobalID: (EOGlobalID *)globalID
editingContext: (EOEditingContext *)anEditingContext
Overrides the implementation inherited from EOObjectStore to refault the enterprise object object identified by globalID in anEditingContext. This method should be used with caution since refaulting an object does not remove the object snapshot from the undo stack. Objects that have been newly inserted or deleted should not be refaulted.
The main purpose of this method is to break retain cycles between enterprise objects. For example, suppose you have an Employee object that has a to-one relationship to its Department, and the Department object in turn has an array of Employee objects. You can use this method to break the retain cycle. Note that retain cycles are automatically broken if you release the EOEditingContext. For more discussion of this topic, see the section "Methods for Managing the Object Graph" in the class description.
See also: - invalidateObjectsWithGlobalIDs:
refetch:
- (void)refetch:
(id)sender
This action method simply invokes the invalidateAllObjects method.
registeredObjects
- (NSArray *)registeredObjects
Returns the enterprise objects managed by the receiver.
removeEditor:
- (void)removeEditor:
(id)editor
Unregisters editor from the receiver. For more discussion of EOEditors, see the editors method description and the EOEditors informal protocol specification.
See also: - addEditor:
Removes everything from the undo stack, discards all insertions and deletions, and restores updated objects to their last committed values. Does not refetch from the database. Note that revert doesn't automatically cause higher level display groups (WebObject's WODisplayGroups or the interface layer's EODisplayGroups) to refetch. Display groups that allow insertion and deletion of objects need to be explicitly synchronized whenever this method is invoked on their EOEditingContext.
See also: - invalidateAllObjects
revert:
- (void)revert:
(id)sender
This action method simply invokes revert
.
rootObjectStore
- (EOObjectStore *)rootObjectStore
Returns the EOObjectStore at the base of the object store hierarchy (usually an EOObjectStoreCoordinator).
saveChanges
- (void)saveChanges
Commits changes made in the receiver to its parent EOObjectStore by sending it the message saveChangesInEditingContext: . If the parent is an EOObjectStoreCoordinator, it guides its EOCooperatingObjectStores, typically EODatabaseContexts, through a multi-pass save operation (see the EOObjectStoreCoordinator class specification for more information). If a database error occurs, an exception is raised; the error message indicates the nature of the problem.
saveChanges:
- (void)saveChanges
:(id)sender
This action method invokes saveChanges , handling an exception by passing it to the message handler. For example, if a validation error occurs, the message handler (usually an EODisplayGroup) presents an alert panel with the text of the validation exception.
See also: - editingContext:presentErrorMessage: (EOMessageHandlers), - editingContext: shouldPresentException: (EOEditingContext Delegate)
saveChangesInEditingContext:
- (void)saveChangesInEditingContext: (EOEditingContext *)anEditingContext
Overrides the implementation inherited from EOObjectStore to tell the receiver's EOObjectStore to accept changes from a child EOEditingContext. This method shouldn't be invoked directly. It's invoked by a nested EOEditingContext when it's committing changes to a parent EOEditingContext. The receiving parent EOEditingContext incorporates all changes from the nested EOEditingContext into its own copies of the objects, but it doesn't immediately save those changes to the database. If the parent itself is later sent saveChanges , it propagates any changes received from the child along with any other changes to its parent EOObjectStore. Raises an exception if an error occurs; the error message indicates the nature of the problem.
setDelegate:
- (void)setDelegate:
(id)anObject
Set the receiver's delegate to be anObject, without retaining it.
See also: - delegate
setInvalidatesObjectsWhenFreed:
- (void)setInvalidatesObjectsWhenFreed:
(BOOL)flag
Sets according to flag whether the receiver clears and "booby-traps" all of the objects registered with it when the receiver is deallocated. If an editing context invalidates objects when it's deallocated, it sends a clearProperties message to all of its objects, thereby breaking any retain cycles between objects that would prevent them from being deallocated. This method leaves the objects in a state in which sending them any message other than dealloc
or release
raises an exception.
The default is YES, and as a general rule, this setting must be YES for enterprise objects with cyclic references to be freed when their EOEditingContext is freed.
Note that the word "invalidate" in this method name has a different meaning than it does in the other invalidate...
methods, which discard object values and refault them.
See also: - invalidatesObjectsWhenFreed
setLocksObjectsBeforeFirstModification:
- (void)setLocksObjectsBeforeFirstModification:
(BOOL)flag
Sets according to flag whether the receiver locks object in the external store (with lockObject: ) the first time object is modified. The default is NO. If flag is YES, an exception will be thrown raised if a lock can't be obtained when object invokes willChange . There are two reasons a lock might fail: because the row is already locked in the server, or because your snapshot is out of date. If your snapshot is out of date, you can explicitly refetch the object using an EOFetchSpecification with setRefreshesRefetchedObjects: set to YES. To handle the exception, you can implement the EODatabaseContext delegate method databaseContextShouldRaiseExceptionForLockFailure: .
You should avoid using this method or pessimistic locking in an interactive end-user application. For example, a user might make a change in a text field and neglect to save it, thereby leaving the data locked in the server indefinitely. Consider using optimistic locking or application level explicit check-in/check-out instead.
See also: - locksObjectsBeforeFirstModification
setMessageHandler:
- (void)setMessageHandler:
(id)handler
Set the receiver's message handler to be handler.
See also: - messageHandler
setPropagatesDeletesAtEndOfEvent:
- (void)setPropagatesDeletesAtEndOfEvent:
(BOOL)flag
Sets according to flag whether the receiver propagates deletes at the end of the event in which a change was made, or only just before saving changes.
If flag is YES, deleting an enterprise object triggers delete propagation at the end of the event in which the deletion occurred (this is the default behavior). If flag is NO, delete propagation isn't performed until saveChanges is invoked.
You can delete enterprise objects explicitly by using the deleteObject: method or implicitly by removing the enterprise object from an owning relationship. Delete propagation uses the delete rules in the EOClassDescription to determine whether objects related to the deleted object should also be deleted (for more information, see the EOClassDescription class specification and the EOEnterpriseObject informal protocol specification). If delete propagation fails (that is, if an enterprise object refuses to be deleted-possibly due to a deny rule), all changes made during the event are rolled back.
See also: - propagatesDeletesAtEndOfEvent
setStopsValidationAfterFirstError:
- (void)setStopsValidationAfterFirstError:
(BOOL)flag
Sets according to flag whether the receiver stops validating after the first error is encountered, or continues for all objects (validation typically occurs during a save operation). The default is YES. Setting it to NO is useful if the delegate implements editingContext:shouldPresentException: to handle the presentation of aggregate exceptions.
See also: - stopsValidationAfterFirstError
setUndoManager:
- (void)setUndoManager:
(NSUndoManager *)undoManager
Sets the receiver's NSUndoManager to undoManager. You might invoke this method with nil if your application doesn't need undo and you want to avoid the overhead of an undo stack. For more information on editing context's undo support, see the section "Undo and Redo."
See also: - undoManager
stopsValidationAfterFirstError
- (BOOL)stopsValidationAfterFirstError
Returns YES to indicate that the receiver should stop validating after it encounters the first error, or NO to indicate that it should continue for all objects.
See also: - setStopsValidationAfterFirstError:
tryToSaveChanges
- (NSException *)tryToSaveChanges
Invokes the saveChanges
method, and catches and returns any exceptions that are raised.
This action method forwards an undo message to the receiver's NSUndoManager, asking it to reverse the latest uncommitted changes applied to objects in the object graph. For more information on editing context's undo support, see the section "Undo and Redo."
See also: redo:
undoManager
- (NSUndoManager *)undoManager
Returns the receiver's NSUndoManager.
See also: - setUndoManager:
Unlocks access to the receiver so that other threads may access it.
Warning: This method creates an NSAutoreleasePool that is released when unlock is called. Consequently, objects that have been autoreleased within the scope of a lock /unlock pair may not be valid after the unlock .
See also: - lock
updatedObjects
- (NSArray *)updatedObjects
Returns the objects in the receiver's object graph that have been updated.
See also: -
deletedObjects ,
-
insertedObjects
The following notifications are declared (except where otherwise noted) and posted by EOEditingContext.
EOEditingContextDidSaveChangesNotification
This notification is broadcast after changes are saved to the EOEditingContext's parent EOObjectStore. The notification contains:
Notification Object | The EOEditingContext |
userInfo Dictionary | |
Key | Value |
updated | An NSArray containing the changed objects |
deleted | An NSArray containing the deleted objects |
inserted | An NSArray containing the inserted objects |
EOInvalidatedAllObjectsInStoreNotification
This notification is defined by EOObjectStore. When posted by an EOEditingContext, it's the result of the editing context invalidating all its objects. When an EOEditingContext receives an EOInvalidatedAllObjectsInStoreNotification from its parent EOObjectStore, it clears its lists of inserted, updated, and deleted objects, and resets its undo stack. The notification contains:
Notification Object
The EOEditingContext
userInfo Dictionary
None.
An interface layer EODisplayGroup (not a WebObjects WODisplayGroup) listens for this notification to refetch its contents. See the EOObjectStore class specification for more information on this notification.
EOObjectsChangedInStoreNotification
This notification is defined by EOObjectStore. When posted by an EOEditingContext, it's the result of the editing context processing objectWillChange: observer notifications in processRecentChanges , which is usually as the end of the event in which the changes occurred. See the EOObjectStore class specification for more information on EOObjectsChangedInStoreNotification.
This notification contains:
Notification Object | The EOEditingContext |
userInfo Dictionary | |
Key | Value |
updated | An NSArray of EOGlobalIDs for objects whose properties have changed. A receiving EOEditingContext typically responds by refaulting the objects. |
inserted | An NSArray of EOGlobalIDs for objects that have been inserted into the EOObjectStore. |
deleted | An NSArray of EOGlobalIDs for objects that have been deleted from the EOObjectStore. |
invalidated | An NSArray of EOGlobalIDs for objects that have been turned into faults. Invalidated objects are those for which the cached view should no longer be trusted. Invalidated objects should be refaulted so that they are refetched when they're next examined. |
EOObjectsChangedInEditingContextNotification
This notification is broadcast whenever changes are made in an EOEditingContext. It's similar to EOObjectsChangedInStoreNotification, except that it contains objects rather than globalIDs. The notification contains:
Notification Object | The EOEditingContext |
userInfo Dictionary | |
Key | Value |
updated | An NSArray containing the changed objects |
deleted | An NSArray containing the deleted objects |
inserted | An NSArray containing the inserted objects |
invalidated | An NSArray containing invalidated objects. |
Interface layer EODisplayGroups (not WebObjects WODisplayGroups) listen for this notification to redisplay their contents.
![](../../../../../../../../../../images/previous.gif)
![](../../../../../../../../../../images/next.gif)
Copyright © 1998, Apple Computer, Inc. All rights reserved.