|
WebObjects 5.2 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.webobjects.eocontrol.EOObjectStore | +--com.webobjects.eocontrol.EOEditingContext | +--com.webobjects.eocontrol.EOSharedEditingContext
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 NSMultiReaderLocks to
maintain thread safety. The methods objectsWithFetchSpecification
bindObjectsWithFetchSpecification
, faultForGlobalID
, and
objectForGlobalID
are thread safe, but the context must be locked
before using any other shared context API.
It is possible to modify shared objects while an application is running,
but only indirectly. A regular editing context can be created that doesn't
share objects by setting it's sharedEditingContext
to null.
Fetch the object that is to be changed 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,
it should be refetched.
objectsByEntityName()
,
objectsByEntityNameAndFetchSpecificationName()
,
bindObjectsWithFetchSpecification(com.webobjects.eocontrol.EOFetchSpecification, java.lang.String)
,
objectsWithFetchSpecification(com.webobjects.eocontrol.EOFetchSpecification, com.webobjects.eocontrol.EOEditingContext)
,
DefaultSharedEditingContextWasInitializedNotification
,
SharedEditingContextInitializedObjectsNotification
, Serialized FormInner classes inherited from class com.webobjects.eocontrol.EOEditingContext |
EOEditingContext.Delegate, EOEditingContext.EditingContextEvent, EOEditingContext.Editor, EOEditingContext.MessageHandler |
Inner classes inherited from class com.webobjects.eocontrol.EOKeyValueArchiving |
EOKeyValueArchiving.Awaking, EOKeyValueArchiving.FinishInitialization, EOKeyValueArchiving.Support |
Field Summary | |
static String |
DefaultSharedEditingContextWasInitializedNotification
Posted when an EOSharedEditingContext is created and assigned as the default shared editing context. |
static String |
SharedEditingContextInitializedObjectsNotification
Posted when new objects are added to a shared editing context (by fetching or fault firing). |
Fields inherited from class com.webobjects.eocontrol.EOEditingContext |
EditingContextDidSaveChangesNotification, EditingContextFlushChangesRunLoopOrdering, ObjectsChangedInEditingContextNotification |
Fields inherited from class com.webobjects.eocontrol.EOObjectStore |
DeletedKey, InsertedKey, InvalidatedAllObjectsInStoreNotification, InvalidatedKey, ObjectsChangedInStoreNotification, UpdatedKey |
Fields inherited from interface com.webobjects.foundation.NSLocking |
OneCentury, OneDay, OneHour, OneMinute, OneSecond, OneWeek, OneYear |
Constructor Summary | |
EOSharedEditingContext()
Creates a new EOSharedEditingContext object with the default parent object store as its parent object store. |
|
EOSharedEditingContext(EOObjectStore parent)
Do not use this method. |
Method Summary | |
void |
bindObjectsWithFetchSpecification(EOFetchSpecification fetchSpecification,
String fetchSpecificationName)
Fetches objects with fetchSpecification and binds the results to
fetchSpecification 's entity and fetchSpecification 's
name, which is provided with the fetchSpecificationName argument. |
static EOSharedEditingContext |
defaultSharedEditingContext()
If a shared context hasn't yet been created, this method creates one and posts a DefaultSharedEditingContextWasInitializedNotification. |
NSArray |
deletedObjects()
The shared objects in a shared editing context can't be deleted. |
void |
deleteObject(EOEnterpriseObject object)
Raises an exception. |
void |
dispose()
Invoked when the receiver should prepare itself for destruction. |
EOEnterpriseObject |
faultForGlobalID(EOGlobalID gid,
EOEditingContext editingContext)
Overrides the implementation inherited from EOObjectStore. |
void |
forgetObject(EOEnterpriseObject object)
Removes object from the uniquing tables and causes this EOEditingContext
to remove itself from the object's list of observers. |
EOGlobalID |
globalIDForObject(EOEnterpriseObject object)
Returns the EOGlobalID associated with object in this EOEditingContext or its
shared context. |
boolean |
hasChanges()
Shared objects in a shared editing context cannot be modified or be deleted. |
void |
initializeObject(EOEnterpriseObject object,
EOGlobalID gid,
EOEditingContext editingContext)
Overrides the implementation inherited from EOObjectStore to build the properties for the object identified by gid . |
NSArray |
insertedObjects()
You can't insert objects into a shared editing context. |
void |
insertObject(EOEnterpriseObject object)
Throws an exception. |
void |
insertObjectWithGlobalID(EOEnterpriseObject object,
EOGlobalID gid)
Throws an exception. |
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. |
void |
invalidateObjectsWithGlobalIDs(NSArray gids)
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. |
void |
lock()
Acquires a writer lock to this EOSharedEditingContext to prevent other threads from accessing it. |
void |
lockForReading()
Locks the receiver for reading. |
void |
lockObjectStore()
|
EOEnterpriseObject |
objectForGlobalID(EOGlobalID gid)
Returns the EOEnterpriseObject associated with gid in this EOEditingContext or its
shared context, or null if no such object exists. |
NSDictionary |
objectsByEntityName()
The dictionary keys are entity names and the corresponding values are NSArrays of enterprise objects for that entity. |
NSDictionary |
objectsByEntityNameAndFetchSpecificationName()
Returns the objects fetched into the receiver with bindObjectsWithFetchSpecification . |
NSArray |
objectsWithFetchSpecification(EOFetchSpecification fetchSpecification,
EOEditingContext editingContext)
A thread-safe version of the superclass implementation that binds the results to fetchSpecification 's entity. |
void |
objectWillChange(Object object)
Raises an exception. |
void |
refaultAllObjects()
Refaults all objects cached in this EOEditingContext that have not been inserted, deleted, or updated. |
void |
refaultObject(EOEnterpriseObject object,
EOGlobalID gid,
EOEditingContext editingContext)
Overrides the implementation inherited from EOObjectStore to refault the enterprise object object identified by
gid in ctx . |
NSArray |
registeredObjects()
|
void |
reset()
Overrides the superclass implementation to do nothing. |
void |
retrieveReaderLocks()
Reinstates the current thread's reader locks that have been suspended using suspendReaderLocks . |
void |
saveChanges()
Raises an exception. |
static void |
setDefaultSharedEditingContext(EOSharedEditingContext context)
Sets the default shared editing context. |
void |
setSharedEditingContext(EOSharedEditingContext sharedEditingContext)
Raises an exception unless sharedEditingContext is null. |
void |
setUndoManager(NSUndoManager undoManager)
Raises an exception unless undoManager is null. |
EOSharedEditingContext |
sharedEditingContext()
Always returns null |
void |
suspendReaderLocks()
Temporarily relinquishes all of the current thread's reader locks, releasing the lock if all reader locks are unlocked. |
boolean |
tryLock()
Attempts to take the lock on this EOSharedEditingContext for writing. |
boolean |
tryLockForReading()
Attempts to take the lock on this EOSharedEditingContext for reading. |
void |
unlock()
Releases a previously acquired lock for writing on this EOSharedEditingContext. |
void |
unlockForReading()
Releases a previously acquired lock for reading on this EOSharedEditingContext. |
void |
unlockObjectStore()
|
NSArray |
updatedObjects()
Returns an empty array. |
void |
validateChangesForSave()
Overrides the superclass implementation to do nothing. |
Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final String DefaultSharedEditingContextWasInitializedNotification
Notification Object | None |
userInfo Dictionary | None |
defaultSharedEditingContext()
public static final String SharedEditingContextInitializedObjectsNotification
Notification Object | The shared editing context |
userInfo Dictionary | NSArray of global IDs of the initialized objects |
Constructor Detail |
public EOSharedEditingContext(EOObjectStore parent)
parent
- ignoredEOSharedEditingContext(com.webobjects.eocontrol.EOObjectStore)
public EOSharedEditingContext()
EOEditingContext.defaultParentObjectStore()
Method Detail |
public void bindObjectsWithFetchSpecification(EOFetchSpecification fetchSpecification, String fetchSpecificationName)
fetchSpecification
and binds the results to
fetchSpecification
's entity and fetchSpecification
's
name, which is provided with the fetchSpecificationName
argument.
The resulting shared objects can later be retrieved using the methods
objectsByEntityName
and
objectsByEntityNameAndFetchSpecificationName
.fetchSpecification
- specifies fetchSpecificationfetchSpecificationName
- specifies fetchSpecification's nameobjectsByEntityName()
,
objectsByEntityNameAndFetchSpecificationName()
public static EOSharedEditingContext defaultSharedEditingContext()
DefaultSharedEditingContextWasInitializedNotification
public void deleteObject(EOEnterpriseObject object)
deleteObject
in class EOEditingContext
object
- ignoredpublic NSArray deletedObjects()
deletedObjects
in class EOEditingContext
public void dispose()
NSDisposable
dispose
in class EOEditingContext
public EOEnterpriseObject faultForGlobalID(EOGlobalID gid, EOEditingContext editingContext)
EOEditingContext
globalID
is already registered
in this EOEditingContext (or its shared context), this
method returns that object. Otherwise, the method propagates the
message up 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 that object (without going to the database).
If not, a fault for this object is created, and the object is fetched from the database
only when you trigger the fault.
In a nested editing context configuration, where 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 information refer to: "Working with Objects Across Multiple EOEditingContexts"
faultForGlobalID
in class EOEditingContext
com.webobjects.eocontrol.EOEditingContext
gid
- the identifier for the desired objectcontext
- the EOEditingContext to search and register the faultEOObjectStore.faultForGlobalID(com.webobjects.eocontrol.EOGlobalID, com.webobjects.eocontrol.EOEditingContext)
,
EOUtilities.localInstanceOfObject(com.webobjects.eocontrol.EOEditingContext, com.webobjects.eocontrol.EOEnterpriseObject)
,
EODatabaseContext
,
EOEditingContext.arrayFaultWithSourceGlobalID(com.webobjects.eocontrol.EOGlobalID, java.lang.String, com.webobjects.eocontrol.EOEditingContext)
,
EOFaultHandler
public void forgetObject(EOEnterpriseObject object)
EOEditingContext
object
from the uniquing tables and causes this EOEditingContext
to remove itself from the object's list of observers.
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
refaultAllObjects
or invalidateAllObjects
). Also note that
this method does not have the effect of deleting an object. In order to delete
an object, you should either use the deleteObject
method or remove
the object from an owning relationship.forgetObject
in class EOEditingContext
com.webobjects.eocontrol.EOEditingContext
object
- the object to be forgottenEOEditingContext.refaultAllObjects()
,
EOEditingContext.invalidateAllObjects()
,
EOEditingContext.deleteObject(com.webobjects.eocontrol.EOEnterpriseObject)
public EOGlobalID globalIDForObject(EOEnterpriseObject object)
EOEditingContext
object
in this EOEditingContext or its
shared context. 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
has not been registered
in the EOEditingContext or in its shared editing context (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
.globalIDForObject
in class EOEditingContext
com.webobjects.eocontrol.EOEditingContext
object
- the target of the searchobject
EOGlobalID
,
EOEditingContext.objectForGlobalID(com.webobjects.eocontrol.EOGlobalID)
,
EOEditingContext.insertObject(com.webobjects.eocontrol.EOEnterpriseObject)
,
EOEditingContext.recordObject(com.webobjects.eocontrol.EOEnterpriseObject, com.webobjects.eocontrol.EOGlobalID)
,
EOEditingContext.sharedEditingContext()
public boolean hasChanges()
hasChanges
in class EOEditingContext
public void initializeObject(EOEnterpriseObject object, EOGlobalID gid, EOEditingContext editingContext)
EOEditingContext
gid
. When a parent
EOEditingContext receives this on behalf of a child EOEditingContext
(as represented by context
), and the gid
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 this EOEditingContext does not have
object
, the request is forwarded its parent EOObjectStore.initializeObject
in class EOEditingContext
com.webobjects.eocontrol.EOEditingContext
object
- the object identified by globalIDgid
- the EOGlobalID corresponding to object
context
- the EOEditingContext in which to initialize the objectEOObjectStore.initializeObject(com.webobjects.eocontrol.EOEnterpriseObject, com.webobjects.eocontrol.EOGlobalID, com.webobjects.eocontrol.EOEditingContext)
public void insertObject(EOEnterpriseObject object)
insertObject
in class EOEditingContext
object
- ignoredobjectsWithFetchSpecification(com.webobjects.eocontrol.EOFetchSpecification, com.webobjects.eocontrol.EOEditingContext)
,
EOEditingContext.faultForGlobalID(com.webobjects.eocontrol.EOGlobalID, com.webobjects.eocontrol.EOEditingContext)
,
bindObjectsWithFetchSpecification(com.webobjects.eocontrol.EOFetchSpecification, java.lang.String)
public void insertObjectWithGlobalID(EOEnterpriseObject object, EOGlobalID gid)
insertObjectWithGlobalID
in class EOEditingContext
object
- ignoredgid
- ignoredobjectsWithFetchSpecification(com.webobjects.eocontrol.EOFetchSpecification, com.webobjects.eocontrol.EOEditingContext)
,
EOEditingContext.faultForGlobalID(com.webobjects.eocontrol.EOGlobalID, com.webobjects.eocontrol.EOEditingContext)
,
bindObjectsWithFetchSpecification(com.webobjects.eocontrol.EOFetchSpecification, java.lang.String)
public NSArray insertedObjects()
insertedObjects
in class EOEditingContext
public void invalidateAllObjects()
EOEditingContext
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, you have to use a statement such as the following:
If you just want to discard uncommitted changes but do not want to sacrifice the values cached in memory, the EOEditingContextEOEditingContext.rootObjectStore().invalidateAllObjects();
revert
method is to be used, which reverses all changes and clears
the undo stack.
For more information, see the sections:
invalidateAllObjects
in class EOEditingContext
com.webobjects.eocontrol.EOEditingContext
EOEditingContext.revert()
,
EOEditingContext.refaultAllObjects()
,
EOEditingContext.invalidateObjectsWithGlobalIDs(com.webobjects.foundation.NSArray)
,
EOObjectStore.invalidateAllObjects()
public void invalidateObjectsWithGlobalIDs(NSArray gids)
EOEditingContext
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 information, see the sections:
invalidateObjectsWithGlobalIDs
in class EOEditingContext
com.webobjects.eocontrol.EOEditingContext
gids
- An array of EOGlobalIDs corresponding to objects which should be invalidatedEOEditingContext.invalidateAllObjects()
,
EOObjectStore.invalidateObjectsWithGlobalIDs(com.webobjects.foundation.NSArray)
,
EOEditingContext.processRecentChanges()
public void lock()
lock
in class EOEditingContext
NSLocking.lock()
,
unlock()
,
tryLock()
,
lockForReading()
public void lockForReading()
lock()
,
unlockForReading()
,
tryLockForReading()
public void lockObjectStore()
lockObjectStore
in class EOEditingContext
public EOEnterpriseObject objectForGlobalID(EOGlobalID gid)
EOEditingContext
gid
in this EOEditingContext or its
shared context, or null if no such object exists.objectForGlobalID
in class EOEditingContext
com.webobjects.eocontrol.EOEditingContext
gid
- the identifier to search fornull
EOGlobalID
,
EOEditingContext.globalIDForObject(com.webobjects.eocontrol.EOEnterpriseObject)
,
EOEditingContext.sharedEditingContext()
public void objectWillChange(Object object)
objectWillChange
in class EOEditingContext
object
- specifies object to be changedpublic NSDictionary objectsByEntityName()
bindObjectsWithFetchSpecification(com.webobjects.eocontrol.EOFetchSpecification, java.lang.String)
public NSDictionary objectsByEntityNameAndFetchSpecificationName()
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. |
bindObjectsWithFetchSpecification
.bindObjectsWithFetchSpecification(com.webobjects.eocontrol.EOFetchSpecification, java.lang.String)
public NSArray objectsWithFetchSpecification(EOFetchSpecification fetchSpecification, EOEditingContext editingContext)
fetchSpecification
's entity.
The resulting shared objects can be retrieved later using the method
objectsByEntityName
.objectsWithFetchSpecification
in class EOEditingContext
fetchSpecification
- specifies fetchSpecificationeditingContext
- specifies container in which source
object belong toobjectsByEntityName()
,
bindObjectsWithFetchSpecification(com.webobjects.eocontrol.EOFetchSpecification, java.lang.String)
,
EOEditingContext.objectsWithFetchSpecification(com.webobjects.eocontrol.EOFetchSpecification, com.webobjects.eocontrol.EOEditingContext)
public void refaultAllObjects()
EOEditingContext
processRecentChanges
, then
invokes refaultObject
for all objects that haven't been inserted,
deleted, or updated.refaultAllObjects
in class EOEditingContext
com.webobjects.eocontrol.EOEditingContext
EOEditingContext.refaultObject(com.webobjects.eocontrol.EOEnterpriseObject)
,
EOObjectStore.refaultObject(com.webobjects.eocontrol.EOEnterpriseObject, com.webobjects.eocontrol.EOGlobalID, com.webobjects.eocontrol.EOEditingContext)
,
EOEditingContext.processRecentChanges()
public void refaultObject(EOEnterpriseObject object, EOGlobalID gid, EOEditingContext editingContext)
EOEditingContext
object
identified by
gid
in ctx
.
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 information, see the sections:
refaultObject
in class EOEditingContext
com.webobjects.eocontrol.EOEditingContext
object
- the enterprise object to be refaultedgid
- the EOs corresponding EOGlobalIDctx
- the target EOEditingContextEOObjectStore.refaultObject(com.webobjects.eocontrol.EOEnterpriseObject, com.webobjects.eocontrol.EOGlobalID, com.webobjects.eocontrol.EOEditingContext)
,
EOEditingContext.invalidateObjectsWithGlobalIDs(com.webobjects.foundation.NSArray)
public NSArray registeredObjects()
registeredObjects
in class EOEditingContext
com.webobjects.eocontrol.EOEditingContext
public void reset()
reset
in class EOEditingContext
com.webobjects.eocontrol.EOEditingContext
EOEditingContext.revert()
,
EOEditingContext.fetchTimestamp()
public void retrieveReaderLocks()
suspendReaderLocks
.NSMultiReaderLock.retrieveReaderLocks()
,
suspendReaderLocks()
public void saveChanges()
saveChanges
in class EOEditingContext
com.webobjects.eocontrol.EOEditingContext
EOEditingContext.saveChangesInEditingContext(com.webobjects.eocontrol.EOEditingContext)
,
EOEditingContext.Delegate.editingContextWillSaveChanges(com.webobjects.eocontrol.EOEditingContext)
,
EOEditingContext.editors()
public static void setDefaultSharedEditingContext(EOSharedEditingContext context)
context
is null, object sharing is disabled in subsequently created
EOEditingContexts.
This has no effect on previously created EOEditingContexts.
context
- specifies container in which source
object belong topublic void setSharedEditingContext(EOSharedEditingContext sharedEditingContext)
sharedEditingContext
is null.setSharedEditingContext
in class EOEditingContext
sharedEditingContext
- input sharedEditingContextpublic void setUndoManager(NSUndoManager undoManager)
undoManager
is null.setUndoManager
in class EOEditingContext
undoManager
- input sharedEditingContextpublic EOSharedEditingContext sharedEditingContext()
null
sharedEditingContext
in class EOEditingContext
null
public void suspendReaderLocks()
retrieveReaderLocks
method.NSMultiReaderLock.suspendReaderLocks()
,
retrieveReaderLocks()
public boolean tryLock()
false
if it fails.true
if the lock was successfully acquiredlock()
public boolean tryLockForReading()
false
if it fails.true
if the lock was successfully acquiredlockForReading()
public void unlock()
unlock
in class EOEditingContext
NSLocking.unlock()
,
lock()
,
tryLock()
,
lockForReading()
public void unlockForReading()
lockForReading()
,
tryLockForReading()
,
unlock()
public void unlockObjectStore()
unlockObjectStore
in class EOEditingContext
public NSArray updatedObjects()
updatedObjects
in class EOEditingContext
public void validateChangesForSave()
|
Last updated Fri Feb 21 13:15:00 PST 2003. | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |