home *** CD-ROM | disk | FTP | other *** search
- // EOObjectStoreCoordinator.h
- // Copyright (c) 1995, NeXT Software, Inc. All rights reserved.
- //
- // EOObjectStoreCoordinator provides the abstraction of a single objects
- // store by coordinating the one or more CooperatingObjectStores.
- // For the basic ObjectStore methods, such as
- // objectsWithFetchSpecification:editingContext:, the coordinator forwards
- // the message to the appropriate CoorperatingObjectStore based on entity name.
- // For saveChangesInEditingContext:, the Coordinator guides its coorperating
- // object stores through a multi-pass save protocol in which each coorperating
- // object stores saves its own changes and forwards other changes on to other
- // object stores. For example, if in its recordChangesInEditingContext: method
- // one store notices the removal of an object from an "owning" relationship, but
- // that object comes from another store, it should inform the other store by
- // passing the coordinator forwardPotentialDeleteForObject: message.
- //
-
- #import <Foundation/Foundation.h>
- #import <EOControl/EOObjectStore.h>
- #import <EOControl/EODefines.h>
-
- @class EOCooperatingObjectStore;
- @class EOQualifier;
-
- @interface EOObjectStoreCoordinator:EOObjectStore
- {
- NSMutableArray *_sources;
- NSDictionary *_userInfo;
- }
-
- - init;
- // designated initializer.
-
- - (void)addCooperatingObjectStore:(EOCooperatingObjectStore *)store;
- // Adds an EOCooperatingObjectStore to the list of stores that need to be queried
- // and notified about changes to EOs
-
- - (void)removeCooperatingObjectStore:(EOCooperatingObjectStore *)store;
- // Removes an EOCooperatingObjectStore from the list of stores that need to be queried
- // and notified about changes to EOs
-
- - (NSArray *)cooperatingObjectStores;
- // Returns the array of objectStores currently held by the coordinator
-
- - (void)forwardUpdateForObject:object changes:(NSDictionary *)changes;
- // Communicates from one EOCooperatingObjectStore to another
- // that certain changes need to be made to an object.
- // For example, an insert of an object in a relationship property might
- // require changing a foreign key property in an object owned by another
- // store.
-
- - (NSDictionary *)valuesForKeys:(NSArray *)keys object:object;
- // Communicates with the appropriate EOCooperatingObjectStore to get
- // values. This store might have some notion of a snapshot for the
- // object that augments properties in the object itself. For instance,
- // an EODatabaseContext stores foreign key properties for an object that
- // may no be object properties.
-
- - (EOCooperatingObjectStore *)objectStoreForGlobalID:(EOGlobalID *)gloablID;
- // Returns the object store for the given global or nil if no object store
- // can be found that responds YES to ownsGlobalID:.
-
- - (EOCooperatingObjectStore *)objectStoreForObject:object;
- // Returns the object store for the given global or nil if no object store
- // can be found that responds YES to ownsObject:.
-
- - (EOCooperatingObjectStore *)objectStoreForFetchSpecification:(EOFetchSpecification *)fetchSpecification;
- // Returns the object store responsible for fetching objects with the given
- // fetch specification, or nil if no object store can be found that responds
- // YES to handlesFetchSpecification:.
-
- - (NSDictionary *)userInfo;
- - (void)setUserInfo:(NSDictionary *)info;
- // returns a state dictionary that other objects or categories can use
- // to associate state with this coordinator.
-
- + (void)setDefaultCoordinator:(EOObjectStoreCoordinator *)coordinator;
- + (id)defaultCoordinator;
- // returns a shared instance EOObjectStoreCoordinator.
- @end
-
- // Notifications:
- EOCONTROL_EXTERN NSString *EOCooperatingObjectStoreWasAdded;
- EOCONTROL_EXTERN NSString *EOCooperatingObjectStoreWasRemoved;
-
- EOCONTROL_EXTERN NSString *EOCooperatingObjectStoreNeeded;
- // called when a request is made which the coordinator cannot
- // service with any of its currently registered cooperating
- // object stores. The observer can call back to the coordinator
- // to register an appropriate object store based on the info
- // in the userInfo dictionary.
- // object = sending EOObjectStoreCoordinator
- // userInfo = {
- // // one of the following...
- // globalID = <globalID for operation>;
- // fetchSpecification = <fetchSpec for operation>;
- // object = <fetchSpec for operation>;
- // }
-
- //
- // EOCooperatingObjectStore is an abstract class which defines an object that
- // can cooperate with other EOCooperatingObjectStores to manage data from several
- // distinct data sources when managed by an EOObjectStoreCoordinator.
- // Each CooperatingStore is given a list of changes to commit and can communicate
- // changes for other stores back through the StoreCoordinator.
- //
- @interface EOCooperatingObjectStore:EOObjectStore
- - (BOOL)ownsGlobalID:(EOGlobalID *)globalID;
- // The store should return YES if is is the object store responsible for fetching
- // and saving this object.
-
- - (BOOL)ownsObject:(id)object;
- // The store should return YES if is is the object store responsible for fetching
- // and saving this object.
-
- - (BOOL)handlesFetchSpecification:(EOFetchSpecification *)fetchSpecification;
- // The store should return YES if is is the object store responsible for fetching
- // objects described by the given fetch specification.
-
- - (void)prepareForSaveWithCoordinator:(EOObjectStoreCoordinator *)coordinator editingContext:(EOEditingContext *)context;
- // Notifies the EOCooperatingObjectStore that a multi-store save operation
- // is beginning. The store should now be prepared to receive any of the
- // following messages:
- // recordChangesInEditingContext:
- // recordUpdateForObject:changes:
- // Followed possibly by performChanges and then commitChanges or rollbackChanges.
-
- - (void)recordChangesInEditingContext;
- // Instructs the EOCooperatingObjectStores to examine the changed
- // objects in the context, record any database operations that need to
- // be performed, and notify the storage manager of any changes to be
- // forwarded to other stores.
-
- - (void)recordUpdateForObject:object changes:(NSDictionary *)changes;
- // Used to communicate from one EOCooperatingObjectStore to another
- // (via the EOObjectStoreCoordinator) that certain changes need to be
- // made to an object.
- // For example, an insert of an object in a relationship property might
- // require changing a foreign key property in an object owned by another
- // store.
-
- - (void)performChanges;
- // Causes the EOCooperatingObjectStore to transmit any changes to it's underlying
- // database. Raises an exception if an error occurs.
-
- - (void)commitChanges;
- - (void)rollbackChanges;
- // Causes the EOCooperatingObjectStore to either commit or rollback its changes
- // to the underlying database. If all participating stores return YES to
- // performChanges, then commit is called. Otherwise all stores are told to
- // rollback. Raises an exception if an error occurs.
-
- - (NSDictionary *)valuesForKeys:(NSArray *)keys object:object;
- // Should return values held by the store that augment properties
- // in the object itself. For instance, an EODatabaseContext stores
- // foreign key properties for an object that may not be object properties.
- @end
-