Documentation Archive Developer
Search
PATH  Documentation > WebObjects 4.5 > EOAccess Reference

Table of Contents

EODatabase


Inherits from: NSObject
Conforms to: NSObject
(NSObject)
Declared in: EOAccess/EODatabase.h




Class Description


An EODatabase object represents a single database server. It contains an EOAdaptor which is capable of communicating with the server, a list of EOModels that describe the server's schema, a list of EODatabaseContexts that are connected to the server, and a set of snapshots representing the state of all objects stored in the server.

Each of an EODatabase's EODatabaseContexts forms a separate transaction scope, and is in effect a separate logical user to the server. An EODatabaseContext uses one or more pairs of EODatabaseChannel and EOAdaptorChannel objects to manage data operations (insert, update, delete, and fetch). Adaptors may support a limited number of contexts per database or channels per context, but an application is guaranteed at least one of each.

For more information on the EODatabase class, see the sections:




Constants


EOAccess declares the following constants in EODatabase.h.


Constant Type Description
EODistantPastTimeInterval NSTimeInterval The lower bound on timestamps.
EOGeneralDatabaseException NSString The name of exceptions raised by the database sublayer when errors occur during interactions with a database server.



Method Types


Creating instances
- initWithModel:
- initWithAdaptor:
Adding and removing models
- addModel:
- addModelIfCompatible:
- removeModel:
- models
Accessing entities
- entityForObject:
- entityNamed:
Recording snapshots
- recordSnapshot:forGlobalID:
- recordSnapshot:forSourceGlobalID:relationshipName:
- recordSnapshots:
- recordToManySnapshots:
Forgetting snapshots
- forgetSnapshotForGlobalID:
- forgetSnapshotsForGlobalIDs:
- forgetAllSnapshots
Accessing snapshots and snapshot timestamps
- snapshotForGlobalID:after:
- snapshotForGlobalID:
- snapshotForSourceGlobalID:relationshipName:after:
- snapshotForSourceGlobalID:relationshipName:
- snapshots
- timestampForGlobalID:
- timestampForSourceGlobalID:relationshipName:
Snapshot reference counting
- incrementSnapshotCountForGlobalID:
- decrementSnapshotCountForGlobalID:
+ disableSnapshotRefcounting
Registering database contexts
- registerContext:
- unregisterContext:
- registeredContexts
Accessing the adaptor
- adaptor
Managing the database connection
- handleDroppedConnection
Managing the result cache
- invalidateResultCache
- invalidateResultCacheForEntityNamed:
- resultCacheForEntityNamed:
- setResultCache:forEntityNamed:


Class Methods



disableSnapshotRefcounting

+ (void)disableSnapshotRefcounting

Configures EODatabase instances not to release unreferenced snapshots.


Instance Methods



adaptor

- (EOAdaptor *)adaptor

Returns the EOAdaptor used by the receiver for communication with the database server. Your application can interact directly with the EOAdaptor, but should avoid altering its state (for example, by starting a transaction with one of its adaptor contexts).

See Also: - initWithAdaptor:, - initWithModel:



addModel:

- (void)addModel:(EOModel *)aModel

Adds aModel to the receiver's list of EOModels. This allows EODatabases to load entities and their properties only as they're needed, by dividing them among separate EOModels. aModel must use the same EOAdaptor as the receiver and use the same connection dictionary as the receiver's other EOModels.

See Also: - addModelIfCompatible:, - models, - removeModel:



addModelIfCompatible:

- (BOOL)addModelIfCompatible:(EOModel *)aModel

Adds aModel to the receiver's list of EOModels, checking first to see whether it's compatible with those other EOModels. Returns YES if aModel is already in the list or if it's successfully added. Returns NO if aModel's adaptor name differs from that of the receivers or if the receiver's adaptor returns NO to a canServiceModel: message.

See Also: - addModel:, - models, - removeModel:



decrementSnapshotCountForGlobalID:

- (void)decrementSnapshotCountForGlobalID:(EOGlobalID *)globalId

If the receiver releases unreferenced snapshots, decrements the reference count for the shared snapshot associated with globalID; and if no more objects refer to the snapshot, removes it from the snapshot table. (If the receiver doesn't release snapshots, this method does nothing.)

entityForObject:

- (EOEntity *)entityForObject:(id)anObject

Returns the EOEntity from one of the receiver's Models that's mapped to anObject, or nil if there is no such EOEntity. This method works by sending entityForObject: messages to each of the receiver's EOModels and returning the first one found.

See Also: - entityNamed:



entityNamed:

- (EOEntity *)entityNamed:(NSString *)entityName

Returns the EOEntity from one of the receiver's Models that's named entityName, or nil if there is no such EOEntity. This method works by sending entityNamed: messages to each of the receiver's EOModels and returning the first one found.

See Also: - entityForObject:



forgetAllSnapshots

- (void)forgetAllSnapshots

Clears all of the receiver's snapshots and posts an EOObjectsChangedInStoreNotification (defined in the EOControl framework's EOObjectStore class) describing the invalidated object. For a description of snapshots and their role in an application, see the class description.

See Also: - forgetSnapshotForGlobalID:, - forgetSnapshotsForGlobalIDs:, - recordSnapshot:forGlobalID:, - recordSnapshots:, - recordSnapshot:forSourceGlobalID:relationshipName:, - recordToManySnapshots:



forgetSnapshotForGlobalID:

- (void)forgetSnapshotForGlobalID:(EOGlobalID *)globalID

Clears the snapshot made for the enterprise object identified by globalID and posts an EOObjectsChangedInStoreNotification (defined in the EOControl framework's EOObjectStore class) describing the invalidated object. For a description of snapshots and their role in an application, see the class description.

See Also: - forgetSnapshotsForGlobalIDs:, - forgetAllSnapshots, - recordSnapshot:forGlobalID:



forgetSnapshotsForGlobalIDs:

- (void)forgetSnapshotsForGlobalIDs:(NSArray *)globalIDs

Clears the snapshots made for the enterprise objects identified by each of the EOGlobalIDs in globalIDs and posts an EOObjectsChangedInStoreNotification (defined in the EOControl framework's EOObjectStore class) describing the invalidated objects. For a description of snapshots and their role in an application, see the class description.

See Also: - forgetSnapshotForGlobalID:, - forgetAllSnapshots, - recordSnapshots:



handleDroppedConnection

- (void)handleDroppedConnection

Invoked to initiate clean up when the Framework detects a dropped database connection. The receiver cleans up by sending handleDroppedConnection to its adaptor, and then sending handleDroppedConnection to all of its registered database contexts. When the cleanup procedure is complete, the Framework can automatically reconnect to the database.

You should never invoke this method; it's invoked automatically by the Framework.



incrementSnapshotCountForGlobalID:

- (void)incrementSnapshotCountForGlobalID:(EOGlobalID *)globalId

Increments the reference count for the shared snapshot associated with globalID if the receiver releases unreferenced snapshots. (Does nothing if the receiver doesn't release snapshots.)

initWithAdaptor:

- initWithAdaptor:(EOAdaptor *)anAdaptor

The designated initializer, this method initializes a newly allocated EODatabase with anAdaptor as its adaptor and returns self.

Typically, you don't need to programmatically create EODatabase objects. Rather, they are created automatically by the control layer. See the class description for more information. If you do need to create an EODatabase programmatically, you should never associate more than one EODatabase with a given EOAdaptor. In general, use initWithModel:, which automatically selects the adaptor.



initWithModel:

- initWithModel:(EOModel *)aModel

Initializes a newly allocated EODatabase by creating an instance of EOAdaptor named in aModel and invoking initWithAdaptor:. Returns self. Typically, you don't need to programmatically create EODatabase objects. Rather, they are created automatically by the control layer. See the class description for more information.

See Also: + adaptorWithModel: ( EOAdaptor), - adaptorName ( EOModel)



invalidateResultCache

- (void)invalidateResultCache

Invalidates the receiver's result cache. See the class description for more discussion of this topic.

See Also: - invalidateResultCacheForEntityNamed:, - resultCacheForEntityNamed:



invalidateResultCacheForEntityNamed:

- (void)invalidateResultCacheForEntityNamed:(NSString *)entityName

Invalidates the result cache containing an array of globalIDs for the objects associated with the entity entityName. See the class description for more discussion of this topic.

See Also: - invalidateResultCache, - resultCacheForEntityNamed:



models

- (NSArray *)models

Returns the receiver's EOModels.

See Also: - initWithModel:, - addModel:, - addModelIfCompatible:, - removeModel:



recordSnapshot:forGlobalID:

- (void)recordSnapshot:(NSDictionary *)aSnapshot forGlobalID:(EOGlobalID *)globalID

Records aSnapshot under globalID. For a description of snapshots and their role in an application, see the class description.

See Also: - globalIDForRow: ( EOEntity), - recordSnapshots:, - forgetSnapshotForGlobalID:



recordSnapshot:forSourceGlobalID:relationshipName:

- (void)recordSnapshot:(NSArray *)globalIDs forSourceGlobalID:(EOGlobalID *)globalID relationshipName:(NSString *)name

For the object identified by globalID, records an NSArray of globalIDs for the to-many relationship named name. These globalIDs identify the objects at the destination of the relationship. For a description of snapshots and their role in an application, see the class description.

See Also: - recordSnapshot:forGlobalID:, - recordSnapshots:, - recordSnapshot:forGlobalID:, - snapshotForSourceGlobalID:relationshipName:



recordSnapshots:

- (void)recordSnapshots:(NSDictionary *)snapshots

Records the snapshots in snapshots. snapshots is a dictionary whose keys are EOGlobalIDs and whose values are the snapshots for those global IDs. For a description of snapshots and their role in an application, see the class description.

See Also: - recordSnapshot:forGlobalID:, - forgetSnapshotsForGlobalIDs:



recordToManySnapshots:

- (void)recordToManySnapshots:(NSDictionary *)snapshots

Records the objects in snapshots. snapshots should be an NSDictionary of NSDictionaries, in which the top-level dictionary has as its key the globaID of the enterprise object for which to-many relationships are being recorded. The key's value is a dictionary whose keys are the names of the enterprise object's to-many relationships. Each of these keys in turn has as its value an array of globalIDs that identify the objects at the destination of the relationship. For a description of snapshots and their role in an application, see the class description.

See Also: - recordSnapshot:forSourceGlobalID:relationshipName:, - recordSnapshot:forGlobalID:, - snapshotForSourceGlobalID:relationshipName:



registerContext:

- (void)registerContext:(EODatabaseContext *)aContext

Records aContext as one of the receiver's EODatabaseContexts, without retaining it. aContext must have been created with the receiver using EODatabaseContext's initWithDatabase: method, which invokes this method automatically. You should never need to invoke this method directly.

See Also: - unregisterContext:, - registeredContexts



registeredContexts

- (NSArray *)registeredContexts

Returns all the EODatabaseContexts that have been registered with the receiver, generally all the database contexts that were created with the receiver as their EODatabase object.

See Also: - registerContext:, - unregisterContext:



removeModel:

- (void)removeModel:(EOModel *)aModel

Removes aModel from the receiver's list of EOModels. Raises an exception if aModel isn't one of the receiver's models.

See Also: - addModel:, - addModelIfCompatible:, - models



resultCacheForEntityNamed:

- (NSArray *)resultCacheForEntityNamed:(NSString *)entityName

Returns an array containing the globalIDs of the objects associated with entityName. See the class description for more discussion of this topic.

See Also: - invalidateResultCache, - invalidateResultCacheForEntityNamed:



setResultCache:forEntityNamed:

- (void)setResultCache:(NSArray *)cache forEntityNamed:(NSString *)entityName

Updates the receiver's cache for entityName with cache, an array of EOGlobalID objects, for all the enterprise objects associated with the EOEntity named entityName. This method is invoked automatically, and you should never need to invoke it directly. For more information on this topic, see the class description.

See Also: - invalidateResultCache, - invalidateResultCacheForEntityNamed:, - resultCacheForEntityNamed:



setTimestampToNow

- (void)setTimestampToNow

Sets the internal timestamp to the value returned by NSDate's timeIntervalSinceReferenceDate method. Used for recording subsequent snapshots.

snapshotForGlobalID:

- (NSDictionary *)snapshotForGlobalID:(EOGlobalID *)globalID

Equivalent to invoking snapshotForGlobalID:after: with EODistantPastTimeInterval as the time interval, this method returns the snapshot associated with globalID.

snapshotForGlobalID:after:

- (NSDictionary *)snapshotForGlobalID:(EOGlobalID *)globalId after:(NSTimeInterval)timestamp

Returns the snapshot associated with globalID. Returns nil if there isn't a snapshot for the globalID or if the corresponding timestamp is less than timestamp. For a description of snapshots and their role in an application, see the class description.

See Also: - recordSnapshot:forGlobalID:, - forgetSnapshotForGlobalID:



snapshotForSourceGlobalID:relationshipName:

- (NSArray *)snapshotForSourceGlobalID:(EOGlobalID *)globalID relationshipName:(NSString *)name

Equivalent to invoking snapshotForSourceGlobalID:relationshipName:after: with EODistantPastTimeInterval as the time interval, this method returns the to-many snapshot for globalId and name.

snapshotForSourceGlobalID:relationshipName:after:

- (NSArray *)snapshotForSourceGlobalID:(EOGlobalID *)globalID relationshipName:(NSString *)name after:(NSTimeInterval)timestamp

Returns the to-many snapshot for globalId and name. A to-many snapshot is an array of globalIDs. These globalIDs identify the objects at the destination of the to-many relationship named name, which is a property of the object identified by globalID. Returns nil if there isn't a to-many snapshot for globalId or if the timestamp is less than timestamp. For a description of snapshots and their role in an application, see the class description.

snapshots

- (NSDictionary *)snapshots

Returns all of the receiver's snapshots, stored in a dictionary under their EOGlobalIDs.

See Also: - recordSnapshot:forSourceGlobalID:relationshipName:, - recordToManySnapshots:



timestampForGlobalID:

- (NSTimeInterval)timestampForGlobalID:(EOGlobalID *)globalId

Returns the timestamp of the snapshot for globalID. Returns EODistantPastTimeInterval if there isn't a snapshot.

timestampForSourceGlobalID:relationshipName:

- (NSTimeInterval)timestampForSourceGlobalID:(EOGlobalID *)globalId relationshipName:(NSString *)relationshipName

Returns the timestamp of the to-many snapshot for the relationship specified by relationshipName and the object specified by globalID. Returns EODistantPastTimeInterval if there isn't a snapshot.

unregisterContext:

- (void)unregisterContext:(EODatabaseContext *)aContext

Removes aContext as one of the receiver's EODatabaseContexts, without releasing it. An EODatabaseContext automatically invokes this method when it's deallocated; you should never need to invoke it directly.

See Also: - registerContext:, - registeredContexts




Table of Contents