Documentation Archive Developer
Search
PATH Documentation > WebObjects

Table of Contents

EOSharedEditingContext


Inherits from:
EOEditingContext : EOObjectStore
Package:
com.webobjects.eocontrol


Class Description


The EOSharedEditingContext class defines a mechanism that allows EOEditingContexts to share enterprise objects for reading. This mechanism can reduce redundant data 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. 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 bindObjectsWithFetchSpecification, faultForGlobalID, 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 null. Fetch the object that you want to change into the regular context, modify or delete it, and save. Since shared editing contexts listen for ObjectsChangedInStoreNotifications, 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


EOSharedEditingContext defines constants for the notifications it post. For more information, see "Notifications" (page 346).



Method Types


Accessing a shared editing context
defaultSharedEditingContext
setDefaultSharedEditingContext
sharedEditingContext
setSharedEditingContext
Accessing shared objects
bindObjectsWithFetchSpecification
objectsByEntityName
objectsByEntityNameAndFetchSpecificationName
objectsWithFetchSpecification
Locking a shared editing context
lockForReading
tryLockForReading
unlockForReading
Overridden EOEditingContext methods
deleteObject
deletedObjects
faultForGlobalID
hasChanges insertedObjects
insertObject
objectForGlobalID
objectWillChange
refaultObject registeredObjects
reset
saveChanges
setUndoManager
updatedObjects
validateChangesForSave


Constructors



EOSharedEditingContext

public EOSharedEditingContext(EOObjectStore anObjectStore)

Creates a new EOSharedEditingContext object with the defaultParentObjectStore as its parent object store. anObjectStore is ignored.

public EOSharedEditingContext()

Description forthcoming.


Static Methods



defaultSharedEditingContext

public static EOSharedEditingContext defaultSharedEditingContext()

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

setDefaultSharedEditingContext

public static synchronized void setDefaultSharedEditingContext(EOSharedEditingContext context)

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


Instance Methods



bindObjectsWithFetchSpecification

public void bindObjectsWithFetchSpecification( EOFetchSpecification fetchSpecification, String 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

public void deleteObject(EOEnterpriseObject object)

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

deletedObjects

public NSArray deletedObjects()

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

dispose

public void dispose()

Description forthcoming.

faultForGlobalID

public EOEnterpriseObject faultForGlobalID( EOGlobalID gid, EOEditingContext context)

A thread-safe version of the superclass implementation.

See Also: faultForGlobalID (EOEditingContext)



forgetObject

public void forgetObject(EOEnterpriseObject anEO)

Description forthcoming.

globalIDForObject

public EOGlobalID globalIDForObject(EOEnterpriseObject anEO)

Description forthcoming.

hasChanges

public boolean hasChanges()

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

initializeObject

public void initializeObject( EOEnterpriseObject anEO, EOGlobalID anID, EOEditingContext aEC)

Description forthcoming.

insertedObjects

public NSArray insertedObjects()

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

insertObject

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

insertObjectWithGlobalID

public void insertObjectWithGlobalID( EOEnterpriseObject anEO, EOGlobalID anID)

Description forthcoming.

invalidateAllObjects

public void invalidateAllObjects()

Description forthcoming.

invalidateObjectsWithGlobalIDs

public void invalidateObjectsWithGlobalIDs(NSArray arrayOfIDs)

Description forthcoming.

lock

public void lock()

Description forthcoming.

lockForReading

public void lockForReading()

Locks the receiver for reading.

See Also: tryLockForReading



objectForGlobalID

public EOEnterpriseObject objectForGlobalID(EOGlobalID gid)

A thread-safe version of the superclass implementation.

See Also: objectForGlobalID (EOEditingContext)



objectsByEntityName

public 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



objectsByEntityNameAndFetchSpecificationName

public NSDictionary objectsByEntityNameAndFetchSpecificationName()

Returns the objects fetched into the receiver with bindObjectsWithFetchSpecification. 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. 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. Shared objects fetched into the receiver with other methods are not returned from this method.



objectsWithFetchSpecification

public NSArray objectsWithFetchSpecification( EOFetchSpecification fetchSpecification, 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 (EOEditingContext)



objectWillChange

public void objectWillChange(Object object)

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

refaultObject

public void refaultObject( EOEnterpriseObject object, EOGlobalID gid, EOEditingContext context)

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

refaultObjects

public void refaultObjects()

Description forthcoming.

registeredObjects

public NSArray registeredObjects()

A thread-safe version of the superclass implementation.

See Also: registeredObjects (EOEditingContext)



reset

public void reset()

Overrides the superclass implementation to do nothing.

retrieveReaderLocks

public void retrieveReaderLocks()

Description forthcoming.

saveChanges

public void saveChanges()

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

setSharedEditingContext

public void setSharedEditingContext(EOSharedEditingContext sharedEC)

Raises an exception unless sharedEC is null.

setUndoManager

public void setUndoManager(NSUndoManager undoManager)

Raises an exception unless undoManager is null.

sharedEditingContext

public EOSharedEditingContext sharedEditingContext()

Returns null.

suspendReaderLocks

public void suspendReaderLocks()

Description forthcoming.

tryLock

public boolean tryLock()

Description forthcoming.

tryLockForReading

public boolean tryLockForReading()

Tries to lock the receiver for reading. Returns true if the receiver is successfully locked, false otherwise.

unlock

public void unlock()

Description forthcoming.

unlockForReading

public void unlockForReading()

Unlocks the receiver for reading.

updatedObjects

public NSArray updatedObjects()

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

validateChangesForSave

public void validateChangesForSave()

Overrides the superclass implementation to do nothing.


Notifications


DefaultSharedEditingContextWasInitializedNotification

public static final String DefaultSharedEditingContextWasInitializedNotification

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

SharedEditingContextInitializedObjectsNotification

public static final String SharedEditingContextInitializedObjectsNotification

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


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


Table of Contents