Project Wonder 2.0

er.extensions
Class ERXEC

java.lang.Object
  extended bycom.webobjects.eocontrol.EOObjectStore
      extended bycom.webobjects.eocontrol.EOEditingContext
          extended byer.extensions.ERXEC
All Implemented Interfaces:
EOKeyValueArchiving, EOObserving, NSDisposable, NSLocking, Serializable

public class ERXEC
extends EOEditingContext

Subclass that has every public method overridden to support automatic lock/unlock handling for you. This is very useful, as is is potentially very dangerous to rely on EOFs automatic lock handling - it will invariably lead into deadlocks. As you will need to use this class and its subclasses exclusively as your ECs, it also contains a factory class to create editing contexts. The Factory also sets a default delegate for you and is used everywhere in ERExtensions and ERDirectToWeb. The Factory is actually and interface and you would create a new EC by using: ERXEC.newEditingContext() You can also install your own Factory classes. It is recommended to subclass ERXEC.DefaultFactory and override _createEditingContext()

See Also:
Serialized Form

Nested Class Summary
static class ERXEC.DefaultFactory
          Default implementation of the Factory interface.
static interface ERXEC.Factory
           
 
Nested classes inherited from class com.webobjects.eocontrol.EOEditingContext
EOEditingContext._EventLoggingEnabler, EOEditingContext.Delegate, EOEditingContext.EditingContextEvent, EOEditingContext.Editor, EOEditingContext.MessageHandler
 
Nested classes inherited from class com.webobjects.eocontrol.EOKeyValueArchiving
EOKeyValueArchiving._NullValueSupport, EOKeyValueArchiving._NumberSupport, EOKeyValueArchiving._TimestampSupport, EOKeyValueArchiving.Awaking, EOKeyValueArchiving.FinishInitialization, EOKeyValueArchiving.Support
 
Field Summary
static String EditingContextDidCreateNotification
          name of the notification that is posted after editing context is created.
protected static ERXEC.Factory factory
          holds a reference to the factory used to create editing contexts
static ERXLogger lockLogger
          logs a message when set to DEBUG, autoLocking is enabled and an EC is used without a lock.
static ERXLogger lockLoggerTrace
          logs a message with a stack trace when set to DEBUG and an EC is locked/unlocked.
static ERXLogger lockTrace
          logs a message when set to DEBUG and an EC is locked/unlocked.
static ERXLogger log
          general logging
 
Fields inherited from class com.webobjects.eocontrol.EOEditingContext
_CLASS, _EditingContextDidChangeSharedEditingContextNotification, _EditingContextEditorHasChangesNotification, _IsEventLoggingEnabled, EditingContextDidSaveChangesNotification, EditingContextFlushChangesRunLoopOrdering, ObjectsChangedInEditingContextNotification
 
Fields inherited from class com.webobjects.eocontrol.EOObjectStore
_doAssertLock, _doAssertLockInitialized, _wasDisposed, DeletedKey, InsertedKey, InvalidatedAllObjectsInStoreNotification, InvalidatedKey, ObjectsChangedInStoreNotification, UpdatedKey
 
Fields inherited from interface com.webobjects.foundation.NSLocking
OneCentury, OneDay, OneHour, OneMinute, OneSecond, OneWeek, OneYear
 
Constructor Summary
ERXEC()
          default constructor
ERXEC(EOObjectStore os)
          alternative constructor
 
Method Summary
 NSArray arrayFaultWithSourceGlobalID(EOGlobalID eoglobalid, String s, EOEditingContext eoeditingcontext)
          Overriden to support autoLocking.
protected  boolean autoLock(String method)
          Utility to actually emit the log messages and do the locking, based on the result of useAutoLock().
protected  void autoUnlock(boolean wasAutoLocked)
          Utility to unlock the EC is it was locked in the previous invocation.
 NSDictionary committedSnapshotForObject(EOEnterpriseObject eoenterpriseobject)
          Overriden to support autoLocking.
 NSDictionary currentEventSnapshotForObject(EOEnterpriseObject eoenterpriseobject)
          Overriden to support autoLocking.
static boolean defaultAutomaticLockUnlock()
           
 NSArray deletedObjects()
          Overriden to support autoLocking.
 void deleteObject(EOEnterpriseObject eoenterpriseobject)
          Overriden to support autoLocking.
 void deleteObjects(NSArray objects)
          Utility to delete a bunch of objects.
 void editingContextDidForgetObjectWithGlobalID(EOEditingContext eoeditingcontext, EOGlobalID eoglobalid)
          Overriden to support autoLocking.
static ERXEC.Factory factory()
          Gets the factory used to create editing contexts
 EOEnterpriseObject faultForGlobalID(EOGlobalID eoglobalid, EOEditingContext eoeditingcontext)
          Overriden to support autoLocking.
 void finalize()
          Overriden to support automatic autoLocking.
 void forgetObject(EOEnterpriseObject eoenterpriseobject)
          Overriden to support autoLocking.
 EOGlobalID globalIDForObject(EOEnterpriseObject eoenterpriseobject)
          Overriden to support autoLocking.
 boolean hasChanges()
          Overriden to support autoLocking.
 void initializeObject(EOEnterpriseObject eoenterpriseobject, EOGlobalID eoglobalid, EOEditingContext eoeditingcontext)
          Overriden to support autoLocking.
 NSArray insertedObjects()
          Overriden to support autoLocking.
 void insertObject(EOEnterpriseObject eoenterpriseobject)
          Overriden to support autoLocking.
 void insertObjectWithGlobalID(EOEnterpriseObject eoenterpriseobject, EOGlobalID eoglobalid)
          Overriden to support autoLocking.
 void invalidateAllObjects()
          Overriden to support autoLocking.
 void invalidateObjectsWithGlobalIDs(NSArray nsarray)
          Overriden to support autoLocking.
 Object invokeRemoteMethod(EOEditingContext eoeditingcontext, EOGlobalID eoglobalid, String s, Class[] aclass, Object[] aobj)
          Overriden to support autoLocking.
 boolean isAutoLocked()
          Returns whether we did autolock this instance.
 void lock()
          Overridden to emmit log messages and push this instance to the locked editing contexts in this thread.
 int lockCount()
          Returns the number of outstanding locks.
 void lockObject(EOEnterpriseObject eoenterpriseobject)
          Overriden to support autoLocking.
static EOEditingContext newEditingContext()
          Factory method to create a new editing context.
static EOEditingContext newEditingContext(boolean validation)
          Factory method to create a new editing context with validation disabled.
static EOEditingContext newEditingContext(EOObjectStore objectStore)
          Creates a new editing context with the specified object store as the parent object store.
static EOEditingContext newEditingContext(EOObjectStore parent, boolean validationEnabled)
          Creates a new editing context with the specified object store as the parent object store and with validation turned on or off depending on the flag passed in.
 EOEnterpriseObject objectForGlobalID(EOGlobalID eoglobalid)
          Overriden to support autoLocking.
 NSArray objectsForSourceGlobalID(EOGlobalID eoglobalid, String s, EOEditingContext eoeditingcontext)
          Overriden to support autoLocking.
 NSArray objectsWithFetchSpecification(EOFetchSpecification eofetchspecification, EOEditingContext eoeditingcontext)
          Overriden to support autoLocking.
 void objectWillChange(Object obj)
          Overriden to support autoLocking.
static void popLockedContextForCurrentThread(EOEditingContext ec)
          Pops the given EC from the array of contexts to unlock.
 void processRecentChanges()
          Overriden to support autoLocking.
static void pushLockedContextForCurrentThread(EOEditingContext ec)
          Pushes the given EC to the array of locked ECs in the current thread.
 void recordObject(EOEnterpriseObject eoenterpriseobject, EOGlobalID eoglobalid)
          Overriden to support autoLocking.
 void redo()
          Overriden to support autoLocking.
 void refaultAllObjects()
          Overriden to support autoLocking.
 void refaultObject(EOEnterpriseObject eoenterpriseobject)
          Overriden to support autoLocking.
 void refaultObject(EOEnterpriseObject eoenterpriseobject, EOGlobalID eoglobalid, EOEditingContext eoeditingcontext)
          Overriden to support autoLocking.
 void refreshObject(EOEnterpriseObject eoenterpriseobject)
          Overriden to support autoLocking.
 NSArray registeredObjects()
          Overriden to support autoLocking.
 void reset()
          Overriden to support automatic autoLocking.
 void revert()
          Overriden to support autoLocking.
 void saveChanges()
          Overriden to support autoLocking.
 void saveChanges(Object obj)
          Overriden to support autoLocking.
 void saveChangesInEditingContext(EOEditingContext eoeditingcontext)
          Overriden to support autoLocking.
 void setDelegate(Object d)
          Sets the delegate for this context.
static void setFactory(ERXEC.Factory aFactory)
          Sets the default editing context factory
 void setSharedEditingContext(EOSharedEditingContext eosharededitingcontext)
          Overriden to support autoLocking.
 void setUseAutoLock(boolean value)
          Sets whether to use autoLocking on this EC.
static void setUseUnlocker(boolean value)
           
 void undo()
          Overriden to support autoLocking.
 void unlock()
          Overridden to emmit log messages and pull this instance from the locked editing contexts in this thread.
static void unlockAllContextsForCurrentThread()
          Unlocks all remaining locked contexts in the current thread.
 NSArray updatedObjects()
          Overriden to support autoLocking.
 boolean useAutoLock()
          Decides on a per-EC-level if autoLocking should be used.
 
Methods inherited from class com.webobjects.eocontrol.EOEditingContext
_clearChangedThisTransaction, _clearOriginalSnapshotAndInitializeRec, _clearOriginalSnapshotForObject, _defaultEditingContextNowInitialized, _defaultSharedEditingContextWasInitialized, _editorHasChanges, _EOAssertSafeMultiThreadedAccess, _EOAssertSafeMultiThreadedAccess, _EOAssertSafeMultiThreadedReadAccess, _globalIDChanged, _globalIDsForObjects, _initWithParentObjectStore, _insertObjectWithGlobalID, _invalidatedAllObjectsInStore, _invalidateObjectsDuringSave, _noop, _objectBasedChangeInfoForGIDInfo, _objectsChangedInStore, _objectsInitializedInSharedContext, _processEndOfEventNotification, _processGlobalIDChanges, _processInitializedObjectsInSharedContext, _processNotificationQueue, _processObjectStoreChanges, _processRecentChanges, _resetAllChanges, _resetAllChanges, _retainCountForObjectWithGlobalID, _undoDelete, _undoManagerCheckpoint, _undoUpdate, addEditor, decodeWithKeyValueUnarchiver, defaultFetchTimestampLag, defaultParentObjectStore, delegate, dispose, editors, editorsHaveChanges, encodeObjectWithCoder, encodeWithKeyValueArchiver, faultForRawRow, faultForRawRow, fetchTimestamp, initObjectWithCoder, instancesRetainRegisteredObjects, invalidatesObjectsWhenFinalized, isObjectLockedWithGlobalID, lockObjectStore, lockObjectWithGlobalID, locksObjectsBeforeFirstModification, messageHandler, objectsWithFetchSpecification, parentObjectStore, propagatesDeletesAtEndOfEvent, readResolve, refaultObjects, refetch, refreshAllObjects, removeEditor, retainsRegisteredObjects, rootObjectStore, setDefaultFetchTimestampLag, setDefaultParentObjectStore, setFetchTimestamp, setInstancesRetainRegisteredObjects, setInvalidatesObjectsWhenFinalized, setLocksObjectsBeforeFirstModification, setMessageHandler, setPropagatesDeletesAtEndOfEvent, setRetainsRegisteredObjects, setStopsValidationAfterFirstError, setSubstitutionEditingContext, setUndoManager, setUsesContextRelativeEncoding, sharedEditingContext, stopsValidationAfterFirstError, substitutionEditingContext, tryLock, tryToSaveChanges, undoManager, unlockObjectStore, usesContextRelativeEncoding
 
Methods inherited from class com.webobjects.eocontrol.EOObjectStore
_checkAssertLock, _resetAssertLock, _suppressAssertLock
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

public static final ERXLogger log
general logging


lockLogger

public static final ERXLogger lockLogger
logs a message when set to DEBUG, autoLocking is enabled and an EC is used without a lock.


lockLoggerTrace

public static final ERXLogger lockLoggerTrace
logs a message with a stack trace when set to DEBUG and an EC is locked/unlocked.


lockTrace

public static final ERXLogger lockTrace
logs a message when set to DEBUG and an EC is locked/unlocked.


EditingContextDidCreateNotification

public static final String EditingContextDidCreateNotification
name of the notification that is posted after editing context is created.

See Also:
Constant Field Values

factory

protected static ERXEC.Factory factory
holds a reference to the factory used to create editing contexts

Constructor Detail

ERXEC

public ERXEC()
default constructor


ERXEC

public ERXEC(EOObjectStore os)
alternative constructor

Method Detail

setUseUnlocker

public static void setUseUnlocker(boolean value)

pushLockedContextForCurrentThread

public static void pushLockedContextForCurrentThread(EOEditingContext ec)
Pushes the given EC to the array of locked ECs in the current thread. The ECs left over after the RR-loop will be automagically unlocked.

Parameters:
ec - locked EOEditingContext

popLockedContextForCurrentThread

public static void popLockedContextForCurrentThread(EOEditingContext ec)
Pops the given EC from the array of contexts to unlock. The ECs left over after the RR-loop will be automagically unlocked.

Parameters:
ec - unlocked EOEditingContext

unlockAllContextsForCurrentThread

public static void unlockAllContextsForCurrentThread()
Unlocks all remaining locked contexts in the current thread. You shouldn't call this yourself, but let the Unlocker handle it for you.


defaultAutomaticLockUnlock

public static boolean defaultAutomaticLockUnlock()

deleteObjects

public void deleteObjects(NSArray objects)
Utility to delete a bunch of objects.


useAutoLock

public boolean useAutoLock()
Decides on a per-EC-level if autoLocking should be used.


setUseAutoLock

public void setUseAutoLock(boolean value)
Sets whether to use autoLocking on this EC.


lockCount

public int lockCount()
Returns the number of outstanding locks.


lock

public void lock()
Overridden to emmit log messages and push this instance to the locked editing contexts in this thread.


unlock

public void unlock()
Overridden to emmit log messages and pull this instance from the locked editing contexts in this thread.


autoLock

protected boolean autoLock(String method)
Utility to actually emit the log messages and do the locking, based on the result of useAutoLock().

Parameters:
method - method name which to prepend to log message
Returns:
whether we did lock automatically

autoUnlock

protected void autoUnlock(boolean wasAutoLocked)
Utility to unlock the EC is it was locked in the previous invocation.

Parameters:
wasAutoLocked - true if the EC was autolocked

isAutoLocked

public boolean isAutoLocked()
Returns whether we did autolock this instance.

Returns:
true if we were autolocked.

finalize

public void finalize()
              throws Throwable
Overriden to support automatic autoLocking.

Throws:
Throwable

reset

public void reset()
Overriden to support automatic autoLocking.


recordObject

public void recordObject(EOEnterpriseObject eoenterpriseobject,
                         EOGlobalID eoglobalid)
Overriden to support autoLocking.


forgetObject

public void forgetObject(EOEnterpriseObject eoenterpriseobject)
Overriden to support autoLocking.


processRecentChanges

public void processRecentChanges()
Overriden to support autoLocking.


updatedObjects

public NSArray updatedObjects()
Overriden to support autoLocking.


registeredObjects

public NSArray registeredObjects()
Overriden to support autoLocking.


insertedObjects

public NSArray insertedObjects()
Overriden to support autoLocking.


deletedObjects

public NSArray deletedObjects()
Overriden to support autoLocking.


setSharedEditingContext

public void setSharedEditingContext(EOSharedEditingContext eosharededitingcontext)
Overriden to support autoLocking.


objectForGlobalID

public EOEnterpriseObject objectForGlobalID(EOGlobalID eoglobalid)
Overriden to support autoLocking.


globalIDForObject

public EOGlobalID globalIDForObject(EOEnterpriseObject eoenterpriseobject)
Overriden to support autoLocking.


committedSnapshotForObject

public NSDictionary committedSnapshotForObject(EOEnterpriseObject eoenterpriseobject)
Overriden to support autoLocking.


currentEventSnapshotForObject

public NSDictionary currentEventSnapshotForObject(EOEnterpriseObject eoenterpriseobject)
Overriden to support autoLocking.


objectWillChange

public void objectWillChange(Object obj)
Overriden to support autoLocking.


insertObjectWithGlobalID

public void insertObjectWithGlobalID(EOEnterpriseObject eoenterpriseobject,
                                     EOGlobalID eoglobalid)
Overriden to support autoLocking.


insertObject

public void insertObject(EOEnterpriseObject eoenterpriseobject)
Overriden to support autoLocking.


deleteObject

public void deleteObject(EOEnterpriseObject eoenterpriseobject)
Overriden to support autoLocking.


hasChanges

public boolean hasChanges()
Overriden to support autoLocking.


saveChanges

public void saveChanges()
Overriden to support autoLocking.


faultForGlobalID

public EOEnterpriseObject faultForGlobalID(EOGlobalID eoglobalid,
                                           EOEditingContext eoeditingcontext)
Overriden to support autoLocking.


arrayFaultWithSourceGlobalID

public NSArray arrayFaultWithSourceGlobalID(EOGlobalID eoglobalid,
                                            String s,
                                            EOEditingContext eoeditingcontext)
Overriden to support autoLocking.


initializeObject

public void initializeObject(EOEnterpriseObject eoenterpriseobject,
                             EOGlobalID eoglobalid,
                             EOEditingContext eoeditingcontext)
Overriden to support autoLocking.


editingContextDidForgetObjectWithGlobalID

public void editingContextDidForgetObjectWithGlobalID(EOEditingContext eoeditingcontext,
                                                      EOGlobalID eoglobalid)
Overriden to support autoLocking.


objectsForSourceGlobalID

public NSArray objectsForSourceGlobalID(EOGlobalID eoglobalid,
                                        String s,
                                        EOEditingContext eoeditingcontext)
Overriden to support autoLocking.


refaultObject

public void refaultObject(EOEnterpriseObject eoenterpriseobject)
Overriden to support autoLocking.


refaultObject

public void refaultObject(EOEnterpriseObject eoenterpriseobject,
                          EOGlobalID eoglobalid,
                          EOEditingContext eoeditingcontext)
Overriden to support autoLocking.


objectsWithFetchSpecification

public NSArray objectsWithFetchSpecification(EOFetchSpecification eofetchspecification,
                                             EOEditingContext eoeditingcontext)
Overriden to support autoLocking.


saveChangesInEditingContext

public void saveChangesInEditingContext(EOEditingContext eoeditingcontext)
Overriden to support autoLocking.


refaultAllObjects

public void refaultAllObjects()
Overriden to support autoLocking.


invalidateObjectsWithGlobalIDs

public void invalidateObjectsWithGlobalIDs(NSArray nsarray)
Overriden to support autoLocking.


invalidateAllObjects

public void invalidateAllObjects()
Overriden to support autoLocking.


lockObject

public void lockObject(EOEnterpriseObject eoenterpriseobject)
Overriden to support autoLocking.


revert

public void revert()
Overriden to support autoLocking.


saveChanges

public void saveChanges(Object obj)
Overriden to support autoLocking.


refreshObject

public void refreshObject(EOEnterpriseObject eoenterpriseobject)
Overriden to support autoLocking.


undo

public void undo()
Overriden to support autoLocking.


redo

public void redo()
Overriden to support autoLocking.


invokeRemoteMethod

public Object invokeRemoteMethod(EOEditingContext eoeditingcontext,
                                 EOGlobalID eoglobalid,
                                 String s,
                                 Class[] aclass,
                                 Object[] aobj)
Overriden to support autoLocking.


setDelegate

public void setDelegate(Object d)
Sets the delegate for this context.


factory

public static ERXEC.Factory factory()
Gets the factory used to create editing contexts

Returns:
editing context factory

setFactory

public static void setFactory(ERXEC.Factory aFactory)
Sets the default editing context factory


newEditingContext

public static EOEditingContext newEditingContext()
Factory method to create a new editing context. Sets the current default delegate on the newly created editing context.

Returns:
a newly created editing context with the default delegate set.

newEditingContext

public static EOEditingContext newEditingContext(EOObjectStore parent,
                                                 boolean validationEnabled)
Creates a new editing context with the specified object store as the parent object store and with validation turned on or off depending on the flag passed in. This method is useful when creating nested editing contexts. After creating the editing context the default delegate is set on the editing context if validation is enabled or the default no validation delegate is set if validation is disabled.

Note: an EOEditingContext is a subclass of EOObjectStore so passing in another editing context to this method is completely kosher.

Parameters:
parent - object store for the newly created editing context.
validationEnabled - determines if the editing context should perform validation
Returns:
new editing context with the given parent object store and the delegate corresponding to the validation flag

newEditingContext

public static EOEditingContext newEditingContext(boolean validation)
Factory method to create a new editing context with validation disabled. Sets the default no validation delegate on the editing context. Becareful an editing context that does not perform validation means that none of the usual validation methods are called on the enterprise objects before they are saved to the database.

Parameters:
validation - flag that determines if validation should or should not be enabled.
Returns:
a newly created editing context with a delegate set that has disabled validation.

newEditingContext

public static EOEditingContext newEditingContext(EOObjectStore objectStore)
Creates a new editing context with the specified object store as the parent object store. This method is useful when creating nested editing contexts. After creating the editing context the default delegate is set on the editing context.

Note: an EOEditingContext is a subclass of EOObjectStore so passing in another editing context to this method is completely kosher.

Parameters:
objectStore - parent object store for the newly created editing context.
Returns:
new editing context with the given parent object store

Last updated: Do, Dez 9, 2004 • 12:46 PM CET

Copyright © 2002 – 2004 Project Wonder.