EODatabaseContext
Inherits from: EOCooperatingObjectStore : EOObjectStore : NSObject
Conforms to: NSObject
(NSObject)
Declared in: EOAccess/EODatabaseContext.h
Class Description
An EODatabaseContext object is an EOObjectStore (EOControl) for accessing relational databases, creating and saving objects based on EOEntity definitions in an EOModel.
An EODatabaseContext represents a single connection to a database server, and it determines the updating and locking strategy used by its EODatabaseChannel objects. An EODatabaseContext has a corresponding EODatabase object. If the server supports multiple concurrent transactions, the EODatabase object may have several database contexts. If the server and adaptor support it, a database context may in turn have several database channels, which handle access to the data on the server.
For a more information on EODatabaseContext, see the sections:
- "EODatabaseContext's Interaction with Other Classes"
- "Creating and Using an EODatabaseContext"
- "Fetching and Saving Objects"
- "Using a Custom Query"
- "Faulting"
- "Delegate Methods"
- "Snapshots"
- "Updating And Locking Strategies"
Constants
In EODatabaseContext.h, EOAccess defines
an enumeration type, EOUpdateStrategy
,
to identify update strategies. It's constants and the other constants
defined in the EODatabaseContext.h are described
in the following table:
Constant | Type | Description |
EOUpdateWithOptimisticLocking |
EOUpdateStrategy |
Identifies the locking strategy as optimistic. |
EOUpdateWithPessimisticLocking |
EOUpdateStrategy |
Identifies the locking strategy as pessimistic |
EOUpdateWithNoLocking |
EOUpdateStrategy |
Identifies the locking strategy as no locking |
EOCustomQueryExpressionHintKey | NSString | A key in an EOFetchSpecification's hint dictionary |
EOStoredProcedureNameHintKey | NSString | A key in an EOFetchSpecification's hint dictionary |
EODatabaseContextKey | NSString | A key in an EOGenericAdaptorException 's userInfo
dictionary |
EODatabaseOperationsKey | NSString | A key in an EOGenericAdaptorException 's userInfo
dictionary |
EOFailedDatabaseOperationKey | NSString | A key in an EOGenericAdaptorException 's userInfo
dictionary |
In addition, EODatabaseContext defines a constant for the name of the notification it posts. For more information on the notification, see "Notifications" .
Method Types
- Initializing instances
- - initWithDatabase:
- Fetching objects
- - objectsWithFetchSpecification:editingContext:
- - objectsForSourceGlobalID:relationshipName:editingContext:
- - arrayFaultWithSourceGlobalID:relationshipName:editingContext:
- - faultForGlobalID:editingContext:
- - faultForRawRow:entityNamed:editingContext:
- - batchFetchRelationship:forSourceObjects:editingContext:
- - missingObjectGlobalIDs
- Enabling shared object loading
- + setSharedObjectLoadingEnabled:
- + isSharedObjectLoadingEnabled
- Accessing the adaptor context
- - adaptorContext
- Managing the database connection
- + forceConnectionWithModel:connectionDictionaryOverrides:editingContext:
- - handleDroppedConnection
- Accessing the database object
- - database
- Accessing the coordinator
- - coordinator
- Managing channels
- - availableChannel
- - registerChannel:
- - registeredChannels
- - unregisterChannel:
- - hasBusyChannels
- Accessing the delegate
- - setDelegate:
- - delegate
- + setDefaultDelegate:
- + defaultDelegate
- Committing or discarding changes
- - saveChangesInEditingContext:
- - invalidateAllObjects
- - invalidateObjectsWithGlobalIDs:
- - rollbackChanges
- - commitChanges
- - prepareForSaveWithCoordinator:editingContext:
- - recordUpdateForObject:changes:
- - recordChangesInEditingContext
- - refaultObject:withGlobalID:editingContext:
- Determining if the EODatabaseContext is responsible for a particular operation
- - ownsObject:
- - ownsGlobalID:
- - handlesFetchSpecification:
- Recording snapshots
- - recordSnapshot:forGlobalID:
- - recordSnapshots:
- - recordSnapshot:forSourceGlobalID:relationshipName:
- - recordToManySnapshots:
- Forgetting snapshots
- - forgetSnapshotForGlobalID:
- - forgetSnapshotsForGlobalIDs:
- Accessing snapshots
- - localSnapshotForGlobalID:
- - localSnapshotForSourceGlobalID:relationshipName:
- - snapshotForGlobalID:after:
- - snapshotForGlobalID:
- - snapshotForSourceGlobalID:relationshipName:after:
- - snapshotForSourceGlobalID:relationshipName:
- Initializing objects
- - initializeObject:withGlobalID:editingContext:
- Obtaining an EODatabaseContext
- + registeredDatabaseContextForModel:editingContext:
- Locking objects
- - setUpdateStrategy:
- - updateStrategy
- - registerLockedObjectWithGlobalID:
- - isObjectLockedWithGlobalID:
- - isObjectLockedWithGlobalID:editingContext:
- - forgetAllLocks
- - forgetLocksForObjectsWithGlobalIDs:
- - lockObjectWithGlobalID:editingContext:
- Returning information about objects
- - valuesForKeys:object:
- Setting the context class
- + contextClassToRegister
- + setContextClassToRegister:
- Thread safety
- - lock
- - unlock
Class Methods
contextClassToRegister
+ (Class)contextClassToRegister
EOCooperatingObjectStoreNeeded
notification.
By default this is EODatabaseContext, but you can use setContextClassToRegister: to specify
your own subclass of EODatabaseContext.When an EOObjectStoreCoordinator
sends an EOCooperatingObjectStoreNeeded
notification
for an EOEntity in the default model group, if contextClassToRegister is
non-nil (and it should be-it makes no sense to set contextClassToRegister to nil),
an instance of the that class is created, the EOModel for the EOEntity
is registered, and the context class is registered with the requesting EOObjectStoreCoordinator.
defaultDelegate
+ (id)defaultDelegate
forceConnectionWithModel:connectionDictionaryOverrides:editingContext:
+ (EODatabaseContext *)forceConnectionWithModel:(EOModel
*)amodel
connectionDictionaryOverrides:(NSDictionary
*)overrides
editingContext:(EOEditingContext
*)anEditingContext
isSharedObjectLoadingEnabled
+ (BOOL)isSharedObjectLoadingEnabled
YES
if
database contexts automatically load enterprise objects into the
default shared editing context when they load models; NO
otherwise.
The objects loaded into the shared editing context are those identified
by entities' shared fetch specifications.See Also: - sharedObjectFetchSpecificationNames ( EOEntity)
registeredDatabaseContextForModel:editingContext:
+ (EODatabaseContext *)registeredDatabaseContextForModel:(EOModel
*)aModel
editingContext:(EOEditingContext
*)anEditingContext
setContextClassToRegister:
+ (void)setContextClassToRegister:(Class)contextClass
setDefaultDelegate:
+ (void)setDefaultDelegate:(id)defaultDelegate
setSharedObjectLoadingEnabled:
+ (void)setSharedObjectLoadingEnabled:(BOOL)flag
YES
(the database
automatically loads shared objects). The objects loaded into the
shared editing context are those identified by entities' shared
fetch specifications.See Also: - sharedObjectFetchSpecificationNames ( EOEntity)
Instance Methods
adaptorContext
- (EOAdaptorContext *)adaptorContext
arrayFaultWithSourceGlobalID:relationshipName:editingContext:
- (NSArray *)arrayFaultWithSourceGlobalID:(EOGlobalID
*)globalID
relationshipName:(NSString *)name
editingContext:(EOEditingContext
*)anEditingContext
See Also: - faultForGlobalID:editingContext:
availableChannel
- (EODatabaseChannel *)availableChannel
See Also: - registerChannel:, - registeredChannels, - unregisterChannel:
batchFetchRelationship:forSourceObjects:editingContext:
- (void)batchFetchRelationship:(EORelationship
*)relationship
forSourceObjects:(NSArray *)objects
editingContext:(EOEditingContext
*)anEditingContext
commitChanges
- (void)commitChanges
EOCooperatingObjectStoreNeeded
(defined
in EOControl's EOObjectStore) is posted describing the committed
changes. Raises an exception if the adaptor is unable to commit
the transaction; the error message indicates the nature of the problem.
You should never need to invoke this method directly.See Also: - ownsGlobalID:, - rollbackChanges
coordinator
- (EOObjectStoreCoordinator *)coordinator
database
- (EODatabase *)database
See Also: - initWithDatabase:
delegate
- (id)delegate
See Also: - setDelegate:
faultForGlobalID:editingContext:
- (id)faultForGlobalID:(EOGlobalID
*)globalID
editingContext:(EOEditingContext
*)anEditingContext
See Also: - arrayFaultWithSourceGlobalID:relationshipName:editingContext:
faultForRawRow:entityNamed:editingContext:
- (id <EOEnterpriseObject>)faultForRawRow:(id)row
entityNamed:(NSString *)entityName
editingContext:(EOEditingContext
*)context
forgetAllLocks
- (void)forgetAllLocks
See Also: - registerLockedObjectWithGlobalID:, - isObjectLockedWithGlobalID:, - isObjectLockedWithGlobalID:editingContext:, - forgetLocksForObjectsWithGlobalIDs:, - lockObjectWithGlobalID:editingContext:, - lockObject: (EOEditingContext)
forgetLocksForObjectsWithGlobalIDs:
- (void)forgetLocksForObjectsWithGlobalIDs:(NSArray
*)globalIDs
See Also: - registerLockedObjectWithGlobalID:, - isObjectLockedWithGlobalID:, - isObjectLockedWithGlobalID:editingContext:, - forgetAllLocks, - lockObjectWithGlobalID:editingContext:, - lockObject: (EOEditingContext)
forgetSnapshotForGlobalID:
- (void)forgetSnapshotForGlobalID:(EOGlobalID
*)globalID
See Also: - recordSnapshot:forGlobalID:, - localSnapshotForGlobalID:, - recordSnapshots:, - snapshotForGlobalID:, - forgetSnapshotsForGlobalIDs:
forgetSnapshotsForGlobalIDs:
- (void)forgetSnapshotsForGlobalIDs:(NSArray
*)globalIDs
See Also: - recordSnapshot:forGlobalID:, - localSnapshotForGlobalID:, - recordSnapshots:, - snapshotForGlobalID:
handleDroppedConnection
- (void)handleDroppedConnection
handlesFetchSpecification:
- (BOOL)handlesFetchSpecification:(EOFetchSpecification
*)fetchSpec
See Also: - ownsObject:, - ownsGlobalID:
hasBusyChannels
- (BOOL)hasBusyChannels
initializeObject:withGlobalID:editingContext:
- (void)initializeObject:(id)object
withGlobalID:(EOGlobalID *)globalID
editingContext:(EOEditingContext
*)anEditingContext
initWithDatabase:
- initWithDatabase:(EODatabase
*)aDatabase
invalidateAllObjects
- (void)invalidateAllObjects
EOInvalidatedAllObjectsInStoreNotification
,
as well as an EOObjectsChangedInStoreNotification
with
the invalidated global IDs in the userInfo dictionary.
Both of these notifications are defined in EOObjectStore (EOControl).
This method works by invoking - invalidateObjectsWithGlobalIDs: for
all of the snapshots in the receiver's EODatabase.invalidateObjectsWithGlobalIDs:
- (void)invalidateObjectsWithGlobalIDs:(NSArray
*)globalIDs
EOObjectsChangedInStoreNotification
(defined
in EOObjectStore), which causes the EOEditingContext containing
objects fetched from the receiver to refault those objects. The
result is that these objects will be refetched from the database
the next time they're accessed.isObjectLockedWithGlobalID:
- (BOOL)isObjectLockedWithGlobalID:(EOGlobalID
*)globalID
See Also: - registerLockedObjectWithGlobalID:, - forgetAllLocks, - isObjectLockedWithGlobalID:editingContext:, - forgetLocksForObjectsWithGlobalIDs:, - lockObjectWithGlobalID:editingContext:, - lockObject: (EOEditingContext)
isObjectLockedWithGlobalID:editingContext:
- (BOOL)isObjectLockedWithGlobalID:(EOGlobalID
*)globalID
editingContext:(EOEditingContext
*)anEditingContext
See Also: - registerLockedObjectWithGlobalID:, - isObjectLockedWithGlobalID:, - forgetAllLocks, - forgetLocksForObjectsWithGlobalIDs:, - lockObjectWithGlobalID:editingContext:, - lockObject: (EOEditingContext)
localSnapshotForGlobalID:
- (NSDictionary *)localSnapshotForGlobalID:(EOGlobalID
*)globalID
See Also: - recordSnapshot:forGlobalID:, - forgetSnapshotForGlobalID:, - recordSnapshots:, - snapshotForGlobalID:
localSnapshotForSourceGlobalID:relationshipName:
- (NSArray *)localSnapshotForSourceGlobalID:(EOGlobalID
*)globalID
relationshipName:(NSString *)name
See Also: - recordSnapshot:forSourceGlobalID:relationshipName:, - snapshotForSourceGlobalID:relationshipName:
lock
- (void)lock
See Also: - unlock
lockObjectWithGlobalID:editingContext:
- (void)lockObjectWithGlobalID:(EOGlobalID
*)globalID
editingContext:(EOEditingContext
*)anEditingContext
NSInternalInconsistencyException
if
unable to obtain the lock.See Also: - registerLockedObjectWithGlobalID:, - isObjectLockedWithGlobalID:, - forgetAllLocks, - forgetLocksForObjectsWithGlobalIDs:, - lockObject: (EOEditingContext)
missingObjectGlobalIDs
- (NSArray *)missingObjectGlobalIDs
To be notified when a missing object is discovered, implement the delegate method databaseContext:failedToFetchObject:globalID:.
If an application tries to save a missing object, an exception is raised.
objectsForSourceGlobalID:relationshipName:editingContext:
- (NSArray *)objectsForSourceGlobalID:(EOGlobalID
*)globalID
relationshipName:(NSString *)name
editingContext:(EOEditingContext
*)anEditingContext
objectsWithFetchSpecification:editingContext:
- (NSArray *)objectsWithFetchSpecification:(EOFetchSpecification
*)fetchSpecification
editingContext:(EOEditingContext
*)anEditingContext
You can fine-tune the fetching behavior by adding hints to fetchSpecification's hints dictionary. For this purpose, Enterprise Objects Framework defines the following keys:
Constant | Corresponding value in the hints dictionary |
EOCustomQueryExpressionHintKey |
An NSString specifying raw SQL with which to perform the fetch. There is no way to pass down parameters with this hint. |
EOStoredProcedureNameHintKey |
An NSString specifying a name for a stored procedure in the model that should be used rather than building the SQL statement. The stored procedure must query the exact same attributes in the same order as EOF would query if generating the SELECT expression dynamically. If this key is supplied, other aspects of the EOFetchSpecification such as isDeep, qualifier, and sortOrderings are ignored (in that sense, this key is more of a directive than a hint). There is no way to pass down parameters with this hint. |
The class description contains additional information on using these hints. See "Using a Custom Query."
You can also use this method to implement "on-demand" locking by using a fetchSpecification that includes locking. For more discussion of this subject, see "Updating And Locking Strategies" in the class description.
Raises an exception if an error occurs; the error message indicates the nature of the problem.
See Also: - objectsWithFetchSpecification: (EOEditingContext)
ownsGlobalID:
- (BOOL)ownsGlobalID:(EOGlobalID
*)globalID
See Also: - handlesFetchSpecification:, - ownsObject:
ownsObject:
- (BOOL)ownsObject:(id)object
See Also: - ownsGlobalID:, - handlesFetchSpecification:
performChanges
- (void)performChanges
This method raises an exception if the adaptor is unable to perform the operations. The exception's userInfo dictionary contains these keys:
Key (NSString Constant) | Value |
EODatabaseContextKey |
The EODatabaseContext object that was trying to save to its underlying repository when the exception was raised. |
EODatabaseOperationsKey |
The list of database operations the EODatabaseContext was trying to perform when the failure occurred. |
EOFailedDatabaseOperationKey |
The database operation the EODatabaseContext failed to perform. |
The userInfo dictionary may also contain some of the keys listed in the method description for the EOAdaptorChannel method performAdaptorOperation:. For more information, see the EOAdaptorChannel class specification.
See Also: - commitChanges, - rollbackChanges
prepareForSaveWithCoordinator:editingContext:
- (void)prepareForSaveWithCoordinator:(EOObjectStoreCoordinator
*)coordinator
editingContext:(EOEditingContext
*)anEditingContext
recordChangesInEditingContext
- (void)recordChangesInEditingContext
recordSnapshot:forGlobalID:
- (void)recordSnapshot:(NSDictionary
*)snapshot
forGlobalID:(EOGlobalID *)globalID
See Also: - forgetSnapshotForGlobalID:, - localSnapshotForGlobalID:, - recordSnapshots:, - snapshotForGlobalID:
recordSnapshot:forSourceGlobalID:relationshipName:
- (void)recordSnapshot:(NSArray
*)globalIDs
forSourceGlobalID:(EOGlobalID
*)globalID
relationshipName:(NSString *)name
See Also: - snapshotForSourceGlobalID:relationshipName:, - localSnapshotForSourceGlobalID:relationshipName:, - recordToManySnapshots:
recordSnapshots:
- (void)recordSnapshots:(NSDictionary
*)snapshots
See Also: - recordSnapshot:forGlobalID:, - localSnapshotForGlobalID:, - forgetSnapshotForGlobalID:, - snapshotForGlobalID:
recordToManySnapshots:
- (void)recordToManySnapshots:(NSDictionary
*)snapshots
This method only records snapshots locally (in the transaction scope). If you want to record snapshots globally, use the corresponding EODatabase method.
See Also: - recordSnapshot:forSourceGlobalID:relationshipName:, - snapshotForSourceGlobalID:relationshipName:, - localSnapshotForSourceGlobalID:relationshipName:
recordUpdateForObject:changes:
- (void)recordUpdateForObject:(id)object
changes:(NSDictionary *)changes
refaultObject:withGlobalID:editingContext:
- (void)refaultObject:(id)anObject
withGlobalID:(EOGlobalID *)globalID
editingContext:(EOEditingContext
*)anEditingContext
This method should be used with caution since refaulting an object doesn't remove the object snapshot from the undo stack, after which the object snapshot may not refer to the proper object.
registerChannel:
- (void)registerChannel:(EODatabaseChannel
*)channel
See Also: - availableChannel, - registeredChannels, - unregisterChannel:
registeredChannels
- (NSArray *)registeredChannels
See Also: - registerChannel:, - availableChannel, - unregisterChannel:
registerLockedObjectWithGlobalID:
- (void)registerLockedObjectWithGlobalID:(EOGlobalID
*)globalID
See Also: - forgetAllLocks, - isObjectLockedWithGlobalID:, - forgetLocksForObjectsWithGlobalIDs:, - lockObjectWithGlobalID:editingContext:, - lockObject: (EOEditingContext)
rollbackChanges
- (void)rollbackChanges
See Also: - ownsGlobalID:, - commitChanges
saveChangesInEditingContext:
- (void)saveChangesInEditingContext:(EOEditingContext
*)context
setDelegate:
- (void)setDelegate:(id)delegate
See Also: - delegate
setUpdateStrategy:
- (void)setUpdateStrategy:(EOUpdateStrategy)strategy
EOUpdateWithOptimisticLocking
EOUpdateWithPessimisticLocking
EOUpdateWithNoLocking
Raises an NSInvalidArgumentException if
the receiver has any transactions in progress or if you try to set strategy to EOUpdateWithPessimisticLocking
and
the receiver's EODatabase already has snapshots.
See Also: - updateStrategy
snapshotForGlobalID:
- (NSDictionary *)snapshotForGlobalID:(EOGlobalID
*)globalID
See Also: - recordSnapshot:forGlobalID:, - localSnapshotForGlobalID:, - forgetSnapshotForGlobalID:, - recordSnapshots:
snapshotForGlobalID:after:
- (NSDictionary *)snapshotForGlobalID:(EOGlobalID
*)globalId
after:(NSTimeInterval)timestamp
nil
if there
isn't a snapshot for the globalID or if the corresponding timestamp
is less than timestamp. Searches
first locally (in the transaction scope) and then in the EODatabase.snapshotForSourceGlobalID:relationshipName:
- (NSArray *)snapshotForSourceGlobalID:(EOGlobalID
*)globalID
relationshipName:(NSString *)name
See Also: - recordSnapshot:forSourceGlobalID:relationshipName:, - localSnapshotForSourceGlobalID:relationshipName:, - recordToManySnapshots:
snapshotForSourceGlobalID:relationshipName:after:
- (NSArray *)snapshotForSourceGlobalID:(EOGlobalID
*)globalId
relationshipName:(NSString *)name
after:(NSTimeInterval)timestamp
nil
if
there isn't a to-many snapshot for globalId or
if the timestamp is less than timestamp.
Searches first locally (in the transaction scope) and then in the
EODatabase.unlock
- (void)unlock
See Also: - lock
unregisterChannel:
- (void)unregisterChannel:(EODatabaseChannel
*)channel
See Also: - registerChannel:, - registeredChannels, - availableChannel
updateStrategy
- (EOUpdateStrategy)updateStrategy
EOUpdateWithOptimisticLocking
EOUpdateWithPessimisticLocking
EOUpdateWithNoLocking
The
default strategy is EOUpdateWithOptimisticLocking
.
See Also: - setUpdateStrategy:
valuesForKeys:object:
- (NSDictionary *)valuesForKeys:(NSArray
*)keys
object:(id)object
Notifications
EODatabaseChannelNeededNotification
This notification is broadcast whenever an EODatabaseContext is asked to perform an object store operation and it doesn't have an available EODatabaseChannel. Subscribers can create a new channel and add it to the EODatabaseContext at this time.Notification Object | The EODatabaseContext. |
userInfo Dictionary | None. |