| 
WebObjects 5.2.2 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Object | +--com.webobjects.eoaccess.EODatabase
An EODatabase object represents a single database server. It contains an EOAdaptor that is capable of communicating with the database 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.
The EODatabase, EODatabaseContext, and EODatabaseChannel classes form the database level of the Enterprise Objects Framework. The database level is a client of the adaptor level, which is defined by the adaptor classes: EOAdaptor, EOAdaptorContext, and EOAdaptorChannel. Together, the database and adaptor levels make up the access layer of the Enterprise Objects Framework.
The database level acts as an intermediary between the adaptor level and the control layer, which includes an EOObjectStoreCoordinator and an EOEditingContext . The control layer operates in terms of Enterprise Objects, while the adaptor level operates in terms of database rows packaged as NSDictionaries. It is the job of the database level to perform the necessary object-to-relational translation between the two.
There's little need for an application's code to interact directly with an EODatabase object. An EOEditingContext creates its own database level objects, which create their own corresponding adaptor level objects. Once the network of objects is in place, the application might interact with an EODatabase to access its corresponding EOAdaptor object, but additional programmatic interaction is usually unnecessary.
EODatabase's most significant responsibility is to record snapshots for its EODatabaseContexts. A snapshot is a dictionary whose keys are attribute names and whose values are the corresponding, last-known database values. Enterprise Objects Framework records snapshots as it successfully fetches, inserts and updates enterprise objects. Snapshot information is used when changes to Enterprise Objects are saved back out to the database to ensure that row data has not been changed by someone else since it was last recorded by the application.
A snapshot contains entries for a row's primary key, class properties, foreign keys for class property relationships, and attributes used for locking. They are recorded under the globalIDs of their Enterprise Objects.
EODatabase also records snapshots for to-many relationships. These snapshots consist of an NSDictionary of NSDictionaries, in which the top-level dictionary has as its key the globalID 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.
The snapshots made by an EODatabase form the global view of data for nearly every other part of the application, representing the current view of data in the server as far as the application is concerned (though other applications may have made changes). This global view is temporarily overridden locally by EODatabaseContexts, which form their own snapshots as they make changes during a transaction. When an EODatabaseContext commits its top-level transaction, it reconciles all changed snapshots with the global view of the database object, so that other database contexts (except those with open transactions) immediately use the new snapshots as well. EODatabaseContexts automatically use their EODatabase to record snapshots, so there's no need for the application to intervene in an EODatabase's snapshotting mechanism.
An EODatabase object also performs the function of caching enterprise
 objects for entities that cache their objects. An EODatabase's entity
 cache stores the globalIDs of Enterprise Objects for entities that cache
 their objects. The first time you perform a fetch against such an
 entity, all of its objects are fetched, regardless of the fetch
 specification used. The globalIDs of the resulting objects are stored in
 the EODatabase's entity cache by entity name. Whenever possible,
 subsequent fetches are performed against the cache (in memory) rather 
 than against the database. With a globalID, Enterprise Objects Framework
 can look up the values for the corresponding object in its snapshot 
 using EODatabase's or EODatabaseContext's 
 snapshotForGlobalID method.
As an example, suppose that you have an entity named Rating that contains all the valid ratings for Movies (G, PG, R, and so on). Rather than store a Movie's rating directly in the Movie as an attribute, Movie maintains a relationship to a Rating. To specify a rating for a movie, users select the rating from a pop-up list of the possible values. Since the ratings in the Rating entity never change, the Rating entity should cache its objects. The values that populate the rating pop-up list are only fetched once, and there's no need to fetch them again; the relationships between Movies and Ratings can be maintained without subsequent fetches.
The entity cache is managed automatically; you shouldn't have to manipulate it explicitly. However, if you need to access or alter the cache, EODatabase provides several methods for interacting with it.
EODatabaseContext, 
EOGlobalID, 
EOEntity| Constructor Summary | |
EODatabase(EOAdaptor adaptor)
Creates and returns a new EODatabase object, specifying adaptor as the new EODatabase's adaptor. | 
|
EODatabase(EOModel model)
Creates and returns a new EODatabase object, also creating an instance of the EOAdaptor named in model and assigning
 it as the new EODatabase's adaptor. | 
|
| Method Summary | |
 EOAdaptor | 
adaptor()
Returns the EOAdaptor used by the receiver for communication with the database server.  | 
 void | 
addModel(EOModel model)
Adds model to the receiver's list of EOModels. | 
 boolean | 
addModelIfCompatible(EOModel model)
Returns true if model is  already in the 
 receiver's list of EOModels, or if model can be added
 to the list. | 
 void | 
decrementSnapshotCountForGlobalID(EOGlobalID gid)
Decrements the reference count for the shared snapshot associated with gid, if the receiver releases unreferenced
 snapshots. | 
static void | 
disableSnapshotRefCounting()
Configures EODatabase instances not to release unreferenced snapshots.  | 
 void | 
dispose()
Conformance to NSDisposable.  | 
 EOEntity | 
entityForObject(EOEnterpriseObject object)
Searches the receiver's list of registered EOModels and returns the first EOEntity found whose name matches the entity name of object. | 
 EOEntity | 
entityNamed(String entityName)
Searches the receiver's list of registered EOModels and returns the first EOEntity found with the name entityName. | 
 void | 
forgetAllSnapshots()
Removes all of the receiver's snapshots and posts an ObjectsChangedInStoreNotification describing
 the invalidated objects. | 
 void | 
forgetSnapshotForGlobalID(EOGlobalID gid)
Removes the snapshot recorded for the Enterprise Object identified by gid and posts an
 ObjectsChangedInStoreNotification describing the
 invalidated object. | 
 void | 
forgetSnapshotsForGlobalIDs(NSArray array)
Removes the snapshots recorded for the Enterprise Objects identified by the globalIDs in array and posts an
 ObjectsChangedInStoreNotification describing
 the invalidated objects. | 
 void | 
handleDroppedConnection()
Invoked to initiate clean up when the Framework detects a dropped database connection.  | 
 void | 
incrementSnapshotCountForGlobalID(EOGlobalID gid)
Increments the reference count for the shared snapshot associated with gid, if the receiver releases unreferenced
 snapshots. | 
 void | 
invalidateResultCache()
Invalidates the receiver's result cache.  | 
 void | 
invalidateResultCacheForEntityNamed(String name)
Invalidates the result cache containing the globalIDs for the objects associated with the EOEntity identified by name. | 
 NSArray | 
models()
Returns the array of EOModels registered for the receiver.  | 
 void | 
recordSnapshotForGlobalID(NSDictionary snapshot,
                          EOGlobalID gid)
Records snapshot for the Enterprise Object identified
 by the globalID gid. | 
 void | 
recordSnapshotForSourceGlobalID(NSArray gids,
                                EOGlobalID gid,
                                String name)
For the object identified by gidgids, which is the array of globalIDs
 identifying the destination objects for the to-many relationship
 named name. | 
 void | 
recordSnapshots(NSDictionary snapshots)
Records the snapshots in snapshots, which is a
 dictionary whose keys are globalIDs and whose values are the
 snapshots for the Enterprise Objects identified by those globalIDs. | 
 void | 
recordToManySnapshots(NSDictionary snapshots)
Records a collection of to-many snapshots from a dictionary keyed by globalID.  | 
 void | 
registerContext(EODatabaseContext context)
Registers context as one of the receiver's database
 contexts. | 
 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.  | 
 void | 
removeModel(EOModel model)
Removes model from the receiver's list of EOModels. | 
 NSArray | 
resultCacheForEntityNamed(String name)
Returns an array containing the globalIDs of all the objects associated with the EOEntity identified by name. | 
 void | 
setResultCache(NSArray cache,
               String name)
Updates the receiver's result cache for name with
 cache. | 
 void | 
setTimestampToNow()
Sets the internal timestamp to the current system time.  | 
 NSDictionary | 
snapshotForGlobalID(EOGlobalID gid)
Returns the snapshot for the Enterprise Object identified by the globalID gid, or null if there isn't 
 a snapshot. | 
 NSDictionary | 
snapshotForGlobalID(EOGlobalID gid,
                    long timestamp)
Returns the snapshot for the Enterprise Object identified by the globalID gid, provided the snapshot's timestamp is 
 greater than or equal to timestamp. | 
 NSArray | 
snapshotForSourceGlobalID(EOGlobalID gid,
                          String name)
Returns the to-many snapshot for the relationship named name belonging to the Enterprise Object identified 
 by the globalID gid, or null if there is
 no to-many snapshot. | 
 NSArray | 
snapshotForSourceGlobalID(EOGlobalID gid,
                          String name,
                          long timestamp)
Returns the to-many snapshot for the globalID gid and 
 relationship name, provided that the timestamp of the 
 snapshot is greater than or equal to timestamp. | 
 NSDictionary | 
snapshots()
Returns a dictionary of all of the receiver's snapshots, keyed by globalID.  | 
 long | 
timestampForGlobalID(EOGlobalID gid)
Returns the timestamp of the snapshot for the object identified by the globalID gid, or 
 DistantPastTimeInterval if there isn't a snapshot. | 
 long | 
timestampForSourceGlobalID(EOGlobalID gid,
                           String name)
Returns the timestamp of the to-many snapshot for the relationship specified by name and the object identified by
 gid. | 
 void | 
unregisterContext(EODatabaseContext context)
Removes context as one of the receiver's database
 contexts. | 
| Methods inherited from class java.lang.Object | 
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
| Constructor Detail | 
public EODatabase(EOAdaptor adaptor)
adaptor as the new EODatabase's adaptor.  Throws an
 exception if adaptor is null. 
 Typically, you don't need to programmatically create EODatabase objects. Rather, they are created automatically by the control layer. If you do need to create an EODatabase programmatically, never associate more than one EODatabase with a given EOAdaptor. In general, create an EODatabase with an EOModel instead of an EOAdaptor.
adaptor - The adaptor for the new EODatabase instance.
IllegalArgumentException - if adaptor is
                null.addModel(EOModel aModel), 
EOModel.adaptorName()public EODatabase(EOModel model)
model and assigning
 it as the new EODatabase's adaptor.
 Typically, you don't need to programmatically create EODatabase objects. Rather, they are created automatically by the control layer.
model - An EOModel which specifies the adaptor to create
              and associate with the new EODatabase object.addModel(EOModel aModel), 
adaptor(), 
EOModel.adaptorName()| Method Detail | 
public EOAdaptor adaptor()
EODatabase(EOAdaptor anAdaptor), 
EODatabase(EOModel aModel)public void addModel(EOModel model)
model to the receiver's list of EOModels. This
 allows EODatabases to load entities and their properties only as
 they are needed, by dividing them among separate EOModels. 
 model must use the same EOAdaptor as the receiver and
 use the same connection dictionary as the receiver's other EOModels.
model - An EOModel to add to the receiver's list of models.addModelIfCompatible(EOModel model), 
models(), 
removeModel(EOModel aModel), 
EOModelpublic boolean addModelIfCompatible(EOModel model)
true if model is  already in the 
 receiver's list of EOModels, or if model can be added
 to the list.  To be added to the list of models, the following
 conditions must be met:
model is not in the receiver's model list, andmodel specifies the same adaptor name as the 
      receiver, andtrue to 
      canServiceModelOtherwise, returns false.
model - A model to add to the receiver's list of EOModels.
true if model is already in the list or
              can be added.addModel(EOModel model), 
models(), 
removeModel(EOModel aModel), 
adaptor()public void decrementSnapshotCountForGlobalID(EOGlobalID gid)
gid, if the receiver releases unreferenced
 snapshots. If no more objects refer to the snapshot, removes it 
 from the snapshot table. Throws an exception if the snapshot
 reference count is already zero or if there is no snapshot recorded
 for gid.
 If snapshot releasing is turned off, this method does nothing.
gid - The globalID for an enteprise object.
IllegalStateException - if the snapshot reference count
              is zero or there is no snapshot for gid.incrementSnapshotCountForGlobalID(EOGlobalID gid), 
recordSnapshotForGlobalID(NSDictionary snapshot, EOGlobalID gid)public static void disableSnapshotRefCounting()
public void dispose()
dispose in interface NSDisposablepublic EOEntity entityForObject(EOEnterpriseObject object)
object.  Returns null if no entity can be
 found that corresponds to object.
object - A EOEnterpriseObject whose entity name is used to
               search for a corresponding EOEntity among the 
               receiver's registered models.
object, or
               null.entityNamed(String entityName)public EOEntity entityNamed(String entityName)
entityName.  
 Returns null if no entity can be found that corresponds
 to entityName.
entityName - The name of the entity to search for in the
                   receiver's registered models.
entityName 
                   found in the receiver's model list, or 
                   null.entityForObject(EOEnterpriseObject object)public void forgetAllSnapshots()
ObjectsChangedInStoreNotification describing
 the invalidated objects.
forgetSnapshotForGlobalID(EOGlobalID gid), 
forgetSnapshotsForGlobalIDs(NSArray array), 
recordSnapshotForGlobalID(NSDictionary aSnapshot,
      com.webobjects.eocontrol.EOGlobalID globalID), 
recordSnapshots(NSDictionary snapshots), 
recordSnapshotForSourceGlobalID(NSArray globalIDs,
      com.webobjects.eocontrol.EOGlobalID globalID, String name), 
recordToManySnapshots(NSDictionary snapshots), 
EOObjectStorepublic void forgetSnapshotForGlobalID(EOGlobalID gid)
gid and posts an
 ObjectsChangedInStoreNotification describing the
 invalidated object.
gid - The globalID for an Enterprise Object.forgetSnapshotsForGlobalIDs(NSArray array), 
forgetAllSnapshots(), 
recordSnapshotForGlobalID(NSDictionary snapshot, EOGlobalID gid), 
EOObjectStorepublic void forgetSnapshotsForGlobalIDs(NSArray array)
array and posts an
 ObjectsChangedInStoreNotification describing
 the invalidated objects.
array - An array of globalIDs for objects whose snapshots to
              remove.forgetSnapshotForGlobalID(EOGlobalID gid), 
forgetAllSnapshots(), 
recordSnapshots(NSDictionary snapshots), 
EOObjectStorepublic void handleDroppedConnection()
handleDroppedConnection first to its adaptor, and then
 to each of its registered database contexts. When the cleanup 
 procedure is complete, the Framework can automatically reconnect to
 the database.
 Never invoke this method yourself; it is invoked automatically by the Framework.
EODatabaseContext.handleDroppedConnection(), 
EOAdaptor.handleDroppedConnection()public void incrementSnapshotCountForGlobalID(EOGlobalID gid)
gid, if the receiver releases unreferenced
 snapshots. Throws an exception if there is no snapshot recorded for
 gid.
 If snapshot releasing is turned off, this method does nothing.
gid - The globalID for an Enterprise Object.
IllegalStateException - if there is no snapshot for 
               gid.decrementSnapshotCountForGlobalID(EOGlobalID gid), 
recordSnapshotForGlobalID(NSDictionary snapshot, EOGlobalID gid)public void invalidateResultCache()
invalidateResultCacheForEntityNamed(String name), 
resultCacheForEntityNamed(String entityName)public void invalidateResultCacheForEntityNamed(String name)
name.
name - The name of an entity.resultCacheForEntityNamed(String entityName), 
invalidateResultCache()public NSArray models()
EODatabase(EOAdaptor anAdaptor), 
EODatabase(EOModel aModel), 
addModel(EOModel aModel), 
addModelIfCompatible(EOModel aModel)
public void recordSnapshotForGlobalID(NSDictionary snapshot,
                                      EOGlobalID gid)
snapshot for the Enterprise Object identified
 by the globalID gid.
snapshot - A dictionary whose keys are attribute names and
                 whose values are the corresponding last-known 
                 database values for the attributes.gid - The globalID (unique identifier) of the enterprise
                 object being snapshotted.recordSnapshots(NSDictionary snapshots), 
forgetSnapshotForGlobalID(EOGlobalID gid), 
EOEntity.globalIDForRow(NSDictionary row), 
EOGlobalID
public void recordSnapshotForSourceGlobalID(NSArray gids,
                                            EOGlobalID gid,
                                            String name)
gidgids, which is the array of globalIDs
 identifying the destination objects for the to-many relationship
 named name.
gids - Identifies the objects at the destination of the
             relationship.gid - Identifies the Enterprise Object whose to-many
             relationship is being snapshotted.name - The name of the to-many relationship being snapshotted.snapshotForSourceGlobalID(EOGlobalID
             gid, String name, long timestamp), 
snapshotForSourceGlobalID(EOGlobalID
             gid, String name), 
forgetSnapshotForGlobalID(EOGlobalID gid), 
recordSnapshots(NSDictionary snapshots), 
EODatabasepublic void recordSnapshots(NSDictionary snapshots)
snapshots, which is a
 dictionary whose keys are globalIDs and whose values are the
 snapshots for the Enterprise Objects identified by those globalIDs.
snapshots - A dictionary of snapshots to record, keyed by
                  globalID.recordSnapshotForGlobalID(NSDictionary snapshot,
                  EOGlobalID gid), 
forgetSnapshotForGlobalID(EOGlobalID gid), 
EOGlobalIDpublic void recordToManySnapshots(NSDictionary snapshots)
snapshots parameter should be a
 dictionary of NSDictionaries. The top-level dictionary has as its
 key the globalID of the Enterprise Object for which to-many 
 relationship snapshots are being recorded. That key's value is a 
 dictionary whose keys are the names of the Enterprise Object's to-
 many relationships, and whose values are arrays of globalIDs that 
 identify the objects at the destination of each relationship.
snapshots - A dictionary of dictionaries, keyed by globalIDs,
                  representing the snapshots for the to-many
                  relationships of the Enterprise Object identifed by
                  the top-level key.recordSnapshotForSourceGlobalID(NSArray gids,
                  EOGlobalID gid, String name), 
recordSnapshotForGlobalID(NSDictionary snapshot,
                  EOGlobalID gid), 
snapshotForSourceGlobalID(EOGlobalID
                  gid, String name)public void registerContext(EODatabaseContext context)
context as one of the receiver's database
 contexts. Throws an exception if context was not
 constructed with the receiver as its EODatabase, or if
 context is already registered with the receiver. 
 You should never invoke this method directly; it is invoked automatically by the EODatabaseContext constructor.
context - The database context to register with the receiver.
IllegalStateException - if context was not
                instantiated with the receiver as its EODatabase, or
                if context is
                already registered.registeredContexts(), 
unregisterContext(EODatabaseContext context)public NSArray registeredContexts()
registeredContexts(), 
unregisterContext(EODatabaseContext context)public void removeModel(EOModel model)
model from the receiver's list of EOModels. 
 Throws an exception if model isn't registered as one 
 of the receiver's models.
model - A model to remove from the receiver's list of
              registered EOModels.
IllegalArgumentException - if model isn't registered as
              one of the receiver's models.models(), 
addModel(EOModel aModel), 
addModelIfCompatible(EOModel aModel)public NSArray resultCacheForEntityNamed(String name)
name.
name - The entity name.
name.invalidateResultCache(), 
invalidateResultCacheForEntityNamed(String entityName)
public void setResultCache(NSArray cache,
                           String name)
name with
 cache. cache is an array of the globalIDs
 for all the Enterprise Objects associated with the EOEntity
 identified by name. 
 This method is invoked automatically; you should never invoke it directly.
cache - The globalIDs for all objects associated with 
              the entity named name.name - The name of the EOEntity associated with 
              cache.invalidateResultCache(), 
invalidateResultCacheForEntityNamed(String entityName), 
resultCacheForEntityNamed(String name)public void setTimestampToNow()
public NSDictionary snapshotForGlobalID(EOGlobalID gid)
gid, or null if there isn't 
 a snapshot.
gid - The globalID for an Enterprise Object.
gid, or
            null.recordSnapshotForGlobalID(NSDictionary snapshot,
            EOGlobalID gid), 
forgetSnapshotForGlobalID(EOGlobalID gid)
public NSDictionary snapshotForGlobalID(EOGlobalID gid,
                                        long timestamp)
gid, provided the snapshot's timestamp is 
 greater than or equal to timestamp. Returns 
 null if there isn't a snapshot for gid or
 if the snapshot's timestamp is earlier (less) than  the reference 
 timestamp.
gid - The globalID for an Enterprise Object.timestamp - A reference timestamp to compare with the snapshot's timestamp.
gid, or null.recordSnapshotForGlobalID(NSDictionary snapshot,
                  EOGlobalID gid), 
forgetSnapshotForGlobalID(EOGlobalID gid)
public NSArray snapshotForSourceGlobalID(EOGlobalID gid,
                                         String name)
name belonging to the Enterprise Object identified 
 by the globalID gid, or null if there is
 no to-many snapshot.  A to-many snapshot is an array of globalIDs
 which identify the objects at the destination of a to-many 
 relationship.
gid - The globalID for the Enterprise Object that 
             owns the relationship name.name - The name of the to-many relationship whose snapshot to
             return.
gid and 
             name, or null.
public NSArray snapshotForSourceGlobalID(EOGlobalID gid,
                                         String name,
                                         long timestamp)
gid and 
 relationship name, provided that the timestamp of the 
 snapshot is greater than or equal to timestamp. Returns
 null if there isn't a to-many snapshot for
 gid and name, or if the snapshot's
 timestamp is earlier (less) than the reference 
 timestamp.
gid - The globalID for the Enterprise Object that 
                  owns the relationship name.name - The name of the to-many relationship whose snapshot
                  to return.timestamp - The reference timestamp to compare with the 
                  snapshot's timestamp.
gid and 
                  name, or null.snapshotForSourceGlobalID(EOGlobalID gid, String name), 
timestampForSourceGlobalID(EOGlobalID gid, String name)public NSDictionary snapshots()
recordSnapshotForSourceGlobalID(NSArray gids,
         EOGlobalID gid, String name), 
recordToManySnapshots(NSDictionary snapshots)public long timestampForGlobalID(EOGlobalID gid)
gid, or 
 DistantPastTimeInterval if there isn't a snapshot.
gid - The globalID for an Enterprise Object.
gid, or
            DistantPastTimeInterval.EOGlobalID
public long timestampForSourceGlobalID(EOGlobalID gid,
                                       String name)
name and the object identified by
 gid. Returns DistantPastTimeInterval if
 there isn't a snapshot.
gid - The globalID for the Enterprise Object that 
             owns the relationship name.name - The name of the to-many relationship whose snapshot to
             return.
gid and name, or 
             DistantPastTimeInterval.snapshotForSourceGlobalID(EOGlobalID gid, String name, long timestamp)public void unregisterContext(EODatabaseContext context)
context as one of the receiver's database
 contexts. Throws an exception if context is not
 registered with the receiver.
 An EODatabaseContext automatically invokes this method when it is finalized. You should never invoke this method directly.
context - The database context to remove from the list of
                the receiver's registered database contexts.
IllegalStateException - if context is not
                registered with the receiver.registeredContexts(), 
registerContext(EODatabaseContext context)
  | 
Last updated Mon Oct 13 15:42:52 PDT 2003. | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||