PATH Documentation > WebObjects

Table of Contents

EOEditingContext


Inherits from: EOObjectStore

Implements:
EOObserving
NSDisposable
NSLocking
EOKeyValueArchiving
Serializable

Package: com.webobjects.eocontrol


Class at a Glance


An EOEditingContext object manages a graph of enterprise objects in an application; this object graph represents an internally consistent view of one or more external stores (most often a database).

Principal Attributes


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 true if any of the receiver has any pending changes to the parent EOObjectStore.
saveChanges Commits changes made in the receiver to the parent EOObjectStore.
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.


Class Description


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 interface) 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:




Constants


EOEditingContext defines the following int constant to specifies the order in which editing contexts perform 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.

EOEditingContext also defines String constants for the names of the notifications it posts. See the section "Notifications" (page 181) for more information.



Interfaces Implemented


EOObserving
objectWillChange

NSLocking
lock
unlock



Method Types


Constructors
EOEditingContext

Committing or discarding changes
saveChanges
refaultObjects
refetch
invalidateAllObjects

Registering changes
deleteObject
insertObject
insertObjectWithGlobalID
objectWillChange
processRecentChanges

Checking changes
deletedObjects
insertedObjects
updatedObjects
hasChanges

Object registration and snapshotting
forgetObject
recordObject
committedSnapshotForObject
currentEventSnapshotForObject
objectForGlobalID
globalIDForObject
registeredObjects

Timestamping snapshots
defaultFetchTimestampLag
setDefaultFetchTimestampLag
fetchTimestamp
setFetchTimestamp

Locking objects
lockObject
lockObjectWithGlobalID
isObjectLockedWithGlobalID
setLocksObjectsBeforeFirstModification
locksObjectsBeforeFirstModification

Undoing operations
redo
undo
setUndoManager
undoManager

Accessing the shared editing context
sharedEditingContext
setSharedEditingContext

Deletion and Validation Behavior
setPropagatesDeletesAtEndOfEvent
propagatesDeletesAtEndOfEvent
setStopsValidationAfterFirstError
stopsValidationAfterFirstError

Returning related object stores
parentObjectStore
rootObjectStore

Managing editors
editorsaddEditor
removeEditor

Setting the delegate
setDelegatedelegate

Setting the message handler
setMessageHandler
messageHandler

Invalidating objects
invalidatesObjectsWhenFinalized

Interacting with the server
invokeRemoteMethod

Locking
lock
unlock

Working with raw rows
faultForRawRow

Unarchiving from nib
defaultParentObjectStore
setDefaultParentObjectStore
setSubstitutionEditingContext
substitutionEditingContext

Nested EOEditingContext support
objectsWithFetchSpecification
objectsForSourceGlobalID
arrayFaultWithSourceGlobalID
faultForGlobalID
saveChangesInEditingContext
refaultObject
invalidateObjectsWithGlobalIDs
initializeObject

Archiving and unarchiving objects
encodeObjectWithCoder
initObjectWithCoder
setUsesContextRelativeEncoding
usesContextRelativeEncoding



Constructors



EOEditingContext

public EOEditingContext()

Creates a new EOEditingContext object with the default parent object store as its parent object store. Shares objects with the default shared editing context (if any) unless you change its shared editing context with setSharedEditingContext.

public EOEditingContext(EOObjectStore anObjectStore)

Creates a new EOEditingContext object with anObjectStore as its parent object store. Shares objects with the default shared editing context (if any) unless you change its shared editing context with setSharedEditingContext. For more discussion of parent object stores, see "Other Classes That Participate in Object Graph Management" (page 71).

See Also: parentObjectStore, defaultParentObjectStore




Static Methods



decodeWithKeyValueUnarchiver

public static Object decodeWithKeyValueUnarchiver(EOKeyValueUnarchiver unarchiver)

Conformance to EOKeyValueArchiving.



defaultFetchTimestampLag

public static long defaultFetchTimestampLag()

Returns the default timestamp lag.



defaultParentObjectStore

public static 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 static method defaultCoordinator.

See Also: setDefaultParentObjectStore



encodeObjectWithCoder

public static void encodeObjectWithCoder( EOEnterpriseObject object, 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 WebObjects Framework" (page 83).

See Also: initObjectWithCoder, setUsesContextRelativeEncoding, usesContextRelativeEncoding



initObjectWithCoder

public static Object initObjectWithCoder( EOEnterpriseObject object, 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 WebObjects Framework" (page 83).

See Also: encodeObjectWithCoder, setUsesContextRelativeEncoding, usesContextRelativeEncoding



setDefaultFetchTimestampLag

public static void setDefaultFetchTimestampLag(long lag)

Sets the default timestamp lag for newly instantiated editing contexts to lag. The default lag is 3600.0 seconds (one hour).

When a new editing context is initialized, it is assigned a fetch timestamp equal to the current time less the default timestamp lag. Setting the lag to a large number might cause every new editing context to accept very old cached data. Setting the lag to too low a value might degrade performance due to excessive fetching. A negative lag value is treated as 0.0.



setDefaultParentObjectStore

public static 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 null.

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

public static 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 null.

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

public static void setUsesContextRelativeEncoding(boolean flag)

Sets according to flag whether encodeObjectWithCoder uses context-relative encoding. For more discussion of this subject, see "Using EOEditingContext to Archive Custom Objects in WebObjects Framework" (page 83).

See Also: usesContextRelativeEncoding, encodeObjectWithCoder



substitutionEditingContext

public static EOEditingContext substitutionEditingContext()

Returns the substitution EOEditingContext if one has been specified. Otherwise returns null.

See Also: setSubstitutionEditingContext



usesContextRelativeEncoding

public static boolean usesContextRelativeEncoding()

Returns true to indicate that encodeObjectWithCoder uses context relative encoding, false otherwise. For more discussion of this subject, see "Using EOEditingContext to Archive Custom Objects in WebObjects Framework" (page 83).

See Also: setUsesContextRelativeEncoding




Instance Methods



addEditor

public void addEditor(Object editor)

Adds editor to the receiver's set of EOEditingContext.Editors. For more explanation, see the method description for editors and the EOEditingContext.Editors interface specification.

See Also: removeEditor



arrayFaultWithSourceGlobalID

public NSArray arrayFaultWithSourceGlobalID( EOGlobalID globalID, String name, 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), and EOFaultHandler class specifications.

See Also: faultForGlobalID



committedSnapshotForObject

public NSDictionary committedSnapshotForObject(EOEnterpriseObject 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

public NSDictionary currentEventSnapshotForObject(EOEnterpriseObject 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



delegate

public Object delegate()

Returns the receiver's delegate.

See Also: setDelegate



deleteObject

public void deleteObject(EOEnterpriseObject 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

public NSArray deletedObjects()

Returns the objects that have been deleted from the receiver's object graph.

See Also: updatedObjects, insertedObjects



dispose

public void dispose()

Description forthcoming.



editingContextDidForgetObjectWithGlobalID

public void editingContextDidForgetObjectWithGlobalID( EOEditingContext context, EOGlobalID gid)

See the superclass's method description of editingContextDidForgetObjectWithGlobalID in the class specification for EOObjectStore.



editors

public NSArray editors()

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 EOEditingContext.Editors interface specification and the EODisplayGroup class specification.

See Also: addEditor, removeEditor



encodeWithKeyValueUnarchiver

public Object encodeWithKeyValueUnarchiver(EOKeyValueUnarchiver unarchiver)

Conformance to EOKeyValueArchiving.



faultForGlobalID

public EOEnterpriseObject faultForGlobalID( EOGlobalID globalID, EOEditingContext anEditingContext)

Overrides the implementation inherited from EOObjectStore. If the object associated with the EOGlobalID globalID is already registered in the receiver (or in the receiver's sharedEditingContext), 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.

If the department object is already registered in the EOEditingContext, faultForGlobalID 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 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" (page 81). For more information on faults, see the EOObjectStore, EODatabaseContext (EOAccess), and EOFaultHandler class specifications.

See Also: arrayFaultWithSourceGlobalID



faultForRawRow

public EOEnterpriseObject faultForRawRow( NSDictionary row, String entityName)

public EOEnterpriseObject faultForRawRow( NSDictionary row, String entityName, EOEditingContext context)

Returns a fault for the raw row row by invoking faultForRawRow with this as the editing context.



fetchTimestamp

public long fetchTimestamp()

Returns the receiver's fetch timestamp.



forgetObject

public void forgetObject(EOEnterpriseObject 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 finalized. 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

public EOGlobalID globalIDForObject(EOEnterpriseObject 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 or in its sharedEditingContext (that is, if no match is found), this method returns null. Objects are registered in an EOEditingContext using the insertObject method, or, when fetching, with recordObject.

See Also: objectForGlobalID



hasChanges

public boolean hasChanges()

Returns true 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.



initializeObject

public void initializeObject( EOEnterpriseObject object, EOGlobalID globalID, 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

public NSArray insertedObjects()

Returns the objects that have been inserted into the receiver's object graph.

See Also: deletedObjects, updatedObjects



insertObject

public void insertObject(EOEnterpriseObject object)

Registers (by invoking insertObjectWithGlobalID) 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, insertObjectWithGlobalID



insertObjectWithGlobalID

public void insertObjectWithGlobalID( EOEnterpriseObject anEOEnterpriseObject, EOGlobalID anEOGlobalID)

Registers a new object identified by globalID that should be inserted in the parent EOObjectStore when changes are saved. Works by invoking recordObject, unless the receiver already contains the object. Sends object the message awakeFromInsertion. globalID must respond true 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

public 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 ObjectsChangedInStoreNotification. (EODatabaseContext is defined in EOAccess.)

The final effect of this method is to refault all objects currently in memory. 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:





EOEditingContext.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" (page 78).

See Also: refetch, invalidateObjectsWithGlobalIDs



invalidateObjectsWithGlobalIDs

public 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" (page 78).

See Also: invalidateAllObjects



invalidatesObjectsWhenFinalized

public boolean invalidatesObjectsWhenFinalized()

Returns true to indicate that the receiver clears and "booby-traps" all of the objects registered with it when the receiver is finalized, false otherwise. The default is true. In this method, "invalidate" has a different meaning than it does in the other invalidate... methods.



invokeRemoteMethod

public Object invokeRemoteMethod( EOEditingContext editingContext, EOGlobalID globalID, String methodName, Class[] argumentTypes Object[] objects)

Executes a remote method on the server. This method has the side effect of saving the changes in the receiver to the editing context in the server session. Note that none of the arguments or the result should be enterprise objects: use globalIDs to specify enterprise objects. The argumentTypes argument holds the types of the remote method's (specified by methodName) arguments.



isObjectLockedWithGlobalID

public boolean isObjectLockedWithGlobalID( EOGlobalID globalID, EOEditingContext anEditingContext)

Returns true if the object identified by globalID in anEditingContext is locked, false otherwise. This method works by forwarding the message isObjectLockedWithGlobalID to its parent object store.

See Also: lockObject, lockObjectWithGlobalID, locksObjectsBeforeFirstModification



lock

public void lock()

Locks access to the receiver to prevent other threads from accessing it. If the receiver has a sharedEditingContext, the receiver takes a reader lock on it, as well. You should lock an editing context when you are accessing or modifying objects managed by the editing context. The thread-safety 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).

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.

Similarly, when you catch exceptions, you need to retain the local exception before raising because the exception is in the lock's pool.



lockObject

public void lockObject(EOEnterpriseObject anObject)

Attempts to lock anObject in the external store. This method works by invoking lockObjectWithGlobalID. Throws an exception if it can't find the globalID for anObject to pass to lockObjectWithGlobalID.

See Also: isObjectLockedWithGlobalID, locksObjectsBeforeFirstModification



lockObjectWithGlobalID

public void lockObjectWithGlobalID( EOGlobalID globalID, EOEditingContext anEditingContext)

Overrides the implementation inherited from EOObjectStore to attempt to lock the object identified by globalID in anEditingContext in the external store. Throws an exception if unable to obtain the lock. This method works by forwarding the message lockObjectWithGlobalID to its parent object store.

See Also: lockObject, isObjectLockedWithGlobalID, locksObjectsBeforeFirstModification



locksObjectsBeforeFirstModification

public boolean locksObjectsBeforeFirstModification()

Returns true if the receiver locks object in the external store (with lockObject) the first time object is modified.

See Also: setLocksObjectsBeforeFirstModification, isObjectLockedWithGlobalID, lockObject, lockObjectWithGlobalID



messageHandler

public Object 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 EOEditingContext.MessageHandler interface specification.

See Also: setMessageHandler



objectForGlobalID

public EOEnterpriseObject objectForGlobalID(EOGlobalID globalID)

Returns the object identified by globalID, or null if no object has been registered in the EOEditingContext (or its sharedEditingContext) with globalID.

See Also: globalIDForObject



objectsForSourceGlobalID

public NSArray objectsForSourceGlobalID( EOGlobalID globalID, String name, 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 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

public NSArray objectsWithFetchSpecification(EOFetchSpecification fetchSpecification)

public NSArray objectsWithFetchSpecification( EOFetchSpecification fetchSpecification, 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 throws 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 or in the receiver if anEditingContext isn't provided. (Note that EODatabaseContext and EODatabaseChannel are defined in EOAccess.)



objectWillChange

public void objectWillChange(Object 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

public EOObjectStore parentObjectStore()

Returns the EOObjectStore from which the receiver fetches and to which it saves objects.



processRecentChanges

public 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 ObjectsChangedInStoreNotification and ObjectsChangedInEditingContextNotification are posted. 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. This method does nothing in Java Client applications.



propagatesDeletesAtEndOfEvent

public boolean propagatesDeletesAtEndOfEvent()

Returns true if the receiver propagates deletes at the end of the event in which a change was made, false if it propagates deletes only right before saving changes. The default is true.

See Also: setPropagatesDeletesAtEndOfEvent



recordObject

public void recordObject( EOEnterpriseObject object, 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.



redo

public void redo()

Sends editingContextWillSaveChanges messages to the receiver's editors, and sends 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



refaultObject

public void refaultObject( EOEnterpriseObject anObject, EOGlobalID globalID, 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 reference 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 reference cycle. Note that reference cycles are automatically broken if the EOEditingContext is finalized. For more discussion of this topic, see the section "Methods for Managing the Object Graph" (page 78).

See Also: invalidateObjectsWithGlobalIDs



refaultObjects

public void refaultObjects()

Refaults all objects cached in the receiver that haven't been inserted, deleted, or updated. Invokes processRecentChanges, then invokes refaultObject 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" (page 78) in the class description.



refetch

public void refetch()

Sends editingContextWillSaveChanges messages to the receiver's editors, and invokes the invalidateAllObjects method.



registeredObjects

public NSArray registeredObjects()

Returns the enterprise objects managed by the receiver.



removeEditor

public void removeEditor(Object anObject)

Unregisters editor from the receiver. For more discussion of EOEditors, see the editors method description and the EOEditingContext.Editors interface specification.

See Also: addEditor



reset

public void reset()

Forgets all objects and makes them unusable. This method also resets the fetchTimestamp as if the editing context were just initialized.



revert

public void revert()

Sends editingContextWillSaveChanges messages to the receiver's editors, and 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



rootObjectStore

public EOObjectStore rootObjectStore()

Returns the EOObjectStore at the base of the object store hierarchy (usually an EOObjectStoreCoordinator).



saveChanges

public void saveChanges()

Sends editingContextWillSaveChanges messages to the receiver's editors, and 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 thrown. The error message indicates the nature of the problem.

public void saveChanges(Object anObject)

Invokes the no-argument version, handling an exception using 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.



saveChangesInEditingContext

public 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. Throws an exception if an error occurs; the error message indicates the nature of the problem.



setDelegate

public void setDelegate(Object anObject)

Set the receiver's delegate to be anObject.

See Also: delegate



setFetchTimestamp

public void setFetchTimestamp(long timestamp)

Sets the receiver's fetch timestamp. When an editing context fetches objects from its parent object store, the parent object store can use the timestamp to determine whether to use cached data or to refetch the most current values. An editing context prefers that fetched values are at least as recent as its fetch timestamp. Note that the parent object store is free to ignore the timestamp; so this value should be considered a hint or request and not a guarantee.
Note: Changing the fetch timestamp has no effect on existing objects in the editing context; it can affect only subsequent fetches. To refresh existing objects, invoke refaultObjects before you invoke setFetchTimestamp:.

The initial value for the fetch timestamp of a new non-nested editing context is the current time less the defaultFetchTimestampLag. A nested editing context always uses its parent's fetch timestamp. setFetchTimestamp: raises if it's invoked on a nested editing context.



setInvalidatesObjectsWhenFinalized

public void setInvalidatesObjectsWhenFinalized(boolean flag)

Description forthcoming.



setSharedEditingContext

public void setSharedEditingContext(EOSharedEditingContext sharedEC)

Sets the receiver's shared editing context. Raises if the receiver and sharedEC both contain the same object (otherwise object uniquing would be violated) or if sharedEC is not an instance of the EOSharedEditingContext class.By default, an editing context that has no shared editing context listens for DefaultSharedEditingContextWasInitializedNotifications. If a notification is posted while the context has no registered objects, the editing context sets its shared editing context to the newly initialized default shared editing context. Invoke this method with null to remove the receiver as an observer of this notification and to prevent the context from accessing any objects in the default shared editing context.



setLocksObjectsBeforeFirstModification

public void setLocksObjectsBeforeFirstModification(boolean 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 false. If flag is true, an exception will be thrown 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 true. 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

public void setMessageHandler(Object handler)

Set the receiver's message handler to be handler.

See Also: messageHandler



setPropagatesDeletesAtEndOfEvent

public void setPropagatesDeletesAtEndOfEvent(boolean 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 true, 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 false, 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 interface 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

public void setStopsValidationAfterFirstError(boolean 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 true. Setting it to false is useful if the delegate implements editingContextShouldPresentException to handle the presentation of aggregate exceptions.

See Also: stopsValidationAfterFirstError



setUndoManager

public void setUndoManager(NSUndoManager undoManager)

Sets the receiver's NSUndoManager to undoManager. You might invoke this method with null 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" (page 77).

See Also: undoManager



sharedEditingContext

public EOSharedEditingContext sharedEditingContext()

Returns the shared editing context used by the receiver.



stopsValidationAfterFirstError

public boolean stopsValidationAfterFirstError()

Returns true to indicate that the receiver should stop validating after it encounters the first error, or false to indicate that it should continue for all objects.

See Also: setStopsValidationAfterFirstError



tryToSaveChanges

public Throwable tryToSaveChanges()

Description forthcoming.



undo

public void undo()

Sends editingContextWillSaveChanges messages to the receiver's editors, and sends 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" (page 77).

See Also: redo



undoManager

public NSUndoManager undoManager()

Returns the receiver's NSUndoManager.

See Also: setUndoManager



unlock

public void unlock()

Unlocks access to the receiver so that other threads may access it. If the receiver has a sharedEditingContext, the receiver unlocks a reader lock on the shared context.

See Also: lock



updatedObjects

public NSArray updatedObjects()

Returns the objects in the receiver's object graph that have been updated.

See Also: deletedObjects, insertedObjects




Notifications


The following notifications are declared (except where otherwise noted) and posted by EOEditingContext.

 

EditingContextDidSaveChangesNotification

public static final String EditingContextDidSaveChangesNotification

This notification is broadcast after changes are saved to the EOEditingContext's parent EOObjectStore. The notification contains: Notification ObjectThe EOEditingContextuserInfoA dictionary with the following keys (constants) and values
Key Value
EOObjectStore.UpdatedKey An NSArray containing the changed objects
EOObjectStore.InsertedKey An NSArray containing the inserted objects
EOObjectStore.DeletedKey An NSArray containing the deleted objects

InvalidatedAllObjectsInStoreNotification

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 InvalidatedAllObjectsInStoreNotification 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.

 

ObjectsChangedInStoreNotification

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 ObjectsChangedInStoreNotification.

This notification contains:

Notification ObjectThe EOEditingContextuserInfoA dictionary with the following keys (constants) and values
Key Value
EOObjectStore.UpdatedKey An NSArray of EOGlobalIDs for objects whose properties have changed. A receiving EOEditingContext typically responds by refaulting the objects.
EOObjectStore.InsertedKey An NSArray of EOGlobalIDs for objects that have been inserted into the EOObjectStore.
EOObjectStore.DeletedKey An NSArray of EOGlobalIDs for objects that have been deleted from the EOObjectStore.
EOObjectStore.InvalidatedKey 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.

ObjectsChangedInEditingContextNotification

public static final String ObjectsChangedInEditingContextNotification

This notification is broadcast whenever changes are made in an EOEditingContext. It's similar to ObjectsChangedInStoreNotification, except that it contains objects rather than globalIDs. The notification contains: Notification ObjectThe EOEditingContextuserInfoA dictionary with the following keys (constants) and values
Key Value
EOObjectStore.UpdatedKey An NSArray containing the changed objects
EOObjectStore.DeletedKey An NSArray containing the deleted objects
EOObjectStore.InsertedKey An NSArray containing the inserted objects
EOObjectStore.InvalidatedKey An NSArray containing invalidated objects.

Interface layer EODisplayGroups (not WebObjects WODisplayGroups) listen for this notification to redisplay their contents.


© 2001 Apple Computer, Inc. (Last Published April 19, 2001)


Table of Contents