home *** CD-ROM | disk | FTP | other *** search
- // EODatabaseChannel.h
- // Copyright (c) 1994, NeXT Computer, Inc. All rights reserved.
-
- #import <foundation/NSArray.h>
- #import <foundation/NSData.h>
- #import <foundation/NSDictionary.h>
- #import <foundation/NSObject.h>
- #import <foundation/NSString.h>
-
- @class EODatabaseContext;
- @class EOQualifier;
- @class EODatabaseChannel;
- @class EOAdaptorChannel;
- @class EORelationship;
- @class EOEntity;
-
- @interface NSObject(EODatabaseChannelNotification)
- - (void)awakeForDatabaseChannel:(EODatabaseChannel *)channel;
- // Invoked when an object has been fully instantiated from a database.
- // Your Enterprise Object classes should implement this method as needed.
- @end
-
-
- // An EODatabaseChannel manipulates records as instances of classes specified
- // in the EOModel.
- //
- // An EODatabaseChannel works with an EODatabaseContext object, which handles
- // transactions. All of an EODatabaseChannel operations take place within the
- // context of transactions controlled or tracked by the EODatabaseContext.
- // An EODatabaseContext may work with several EODatabaseChannels, but a
- // channel is associated with only one context.
- //
- // Not all adaptors support multiple channels per context.
- //
- // An EODatabaseChannel creates a EOAdaptorChannel when initialized, and uses
- // this object to actually communicate with the database server.
-
-
- @interface EODatabaseChannel:NSObject
- {
- EODatabaseContext *_databaseContext;
- id _delegate;
- EOAdaptorChannel *_adaptorChannel;
- EOEntity *_currentEntity;
- NSMutableArray *_fetchProperties;
- NSMutableArray *_faultProperties; // Not used, kept for 1.0 compatibility
- NSMutableArray *_writeProperties; // Not used, kept for 1.0 compatibility
- EORelationship *_currentRelationship;
- }
-
- - initWithDatabaseContext:(EODatabaseContext *)databaseContext;
- // Initializes a newly allocated EODatabaseChannel with databaseContext
- // as the context it works in. Returns self, or nil if no more channels
- // can be associated with databaseContext.
-
- - (BOOL)isOpen;
- // Returns YES if the channel has been opened with -openChannel,
- // NO if not.
-
- - (BOOL)openChannel;
- // This method puts the channel and both its context and database into a
- // state where they are ready to perform operations. Returns YES
- // on success, NO on failure for any reason.
-
- - (void)closeChannel;
- // This method disconnects the channel, disconnects the channel's context
- // if the context has no other channels open, and then disconnects the
- // database if it has no additional contexts open.
-
- - (BOOL)insertObject:object;
- // Inserts object's attribute values as a row into the database. Returns
- // YES if successful, NO if not.
-
- - (BOOL)updateObject:object;
- // Updates the row in the database corresponding to object. Returns YES
- // if successful, NO if not.
-
- - (BOOL)deleteObject:object;
- // Deletes the row in the database corresponding to object. Returns YES
- // if successful, NO if not.
-
- - (void)setCurrentEntity:(EOEntity *)entity;
- // Sets an internal entity variable that is used for fetching.
- // -fetchWithZone: uses the currentEntity to determine the class of object
- // to fetch. EODatabaseChannel clients can invoke this method after
- // issuing a select statement by sending -evaluateExpression: to the
- // database channel's adaptor channel to set the class of object fetched.
-
- - (BOOL)selectObjectsDescribedByQualifier:(EOQualifier *)qualifier
- fetchOrder:(NSArray *)fetchOrder;
- // Selects objects by evaluating the qualifier; when fetched, objects will
- // be returned in the order prescribed by the fetch order. Returns YES on
- // success, NO on failure of any kind.
-
- - fetchWithZone:(NSZone *)zone;
- // Fetches and returns the next selected object; returns nil when there
- // are no more objects in the result set.
-
- - (BOOL)isFetchInProgress;
- // Returns YES if the database channel is fetching, NO otherwise. A
- // database channel is fetching if it's been sent a successful
- // -selectObjectsDescribedByQualifier:... message. A database channel
- // stops fetching when there are no more objects to fetch or when it's
- // sent a -cancelFetch message.
-
- - (void)cancelFetch;
- // Cancels any fetch currently in progress.
-
- - (BOOL)refetchObject:object;
- // Refetches the row associated with object from the database. object
- // is modified by this method. Returns YES on success, NO on failure for
- // any reason.
-
- - (BOOL)lockObject:object;
- // Fetches the properties comprising object's snapshot and compares the
- // fetched values with the values stored in the snapshot, locking the
- // constituent rows in the process. Returns YES if all values are the
- // same; returns NO and fails if any of the values differ.
-
- - (EODatabaseContext *)databaseContext;
- // Returns the EODatabaseContext that controls transactions for the
- // channel.
-
- - (EOAdaptorChannel *)adaptorChannel;
- // Returns the EOAdaptorChannel used by the EODatabaseChannel for
- // communication with the database server.
-
- - (void)setDelegate:delegate;
- - delegate;
- // These methods return/set the delegate of the database channel.
-
- @end
-
-
- @interface NSObject (EODatabaseChannelDelegatation)
-
- - databaseChannel:channel willInsertObject:object;
- // Invoked from -insertObject: to tell the delegate that an object will
- // be inserted. The delegate may return the object, a substitute, or nil
- // to prevent insertion.
-
- - (void)databaseChannel:channel didInsertObject:object;
- // Invoked from -insertObject: to tell the delegate that an object was
- // inserted.
-
- - databaseChannel:channel willDeleteObject:object;
- // Invoked from -deleteObject: to tell the delegate that an object will
- // be deleted. The delegate may return the object, a substitute, or nil
- // to prevent deletion.
-
- - (void)databaseChannel:channel didDeleteObject:object;
- // Invoked from -deleteObject: to tell the delegate that an object was
- // deleted.
-
- - databaseChannel:channel willUpdateObject:object;
- // Invoked from -updateObject: to tell the delegate that an object will
- // be updated. The delegate may return the object, a substitute, or nil
- // to prevent updating.
-
- - (void)databaseChannel:channel didUpdateObject:object;
- // Invoked from -updateObject: to tell the delegate that an object was
- // updated.
-
- - (NSDictionary *)databaseChannel:channel
- willRefetchObject:object
- fromSnapshot:(NSDictionary *)snapshot;
- // Invoked whenever an object that was previously fetched is fetched again
- // and the re-fetched data is different from that in the object. The
- // object will be refetched with the dictionary returned by this method,
- // which may be the snapshot provided or a substitute. The delegate may
- // also return nil to prevent the object from being refetched.
-
- - (NSDictionary *)databaseChannel:channel
- willRefetchConflictingObject:object
- withSnapshot:(NSMutableDictionary *)snapshot;
- // Invoked whenever an object is refetched in one transaction while an
- // update on the object is pending in another transaction. This situation
- // is highly suspect because it probably represents a programming error.
- // It involves one object that has two or more potential states and there
- // is no way that EOF can determine the correct one. In this case, a
- // delegate MUST exist and MUST respond to this method or EOF will raise
- // an error.
-
- - (BOOL)databaseChannel:channel
- willSelectObjectsDescribedByQualifier:(EOQualifier *)qualifier
- fetchOrder:(NSArray *)fetchOrder;
- // Invoked from -selectObjectsDescribedByQualifier:... to tell the
- // delegate that the channel will select objects as specified by
- // qualifier. The delegate should not modify the qualifier or fetch order.
- // If the delegate returns YES the channel will go ahead and select the
- // object; if the delegate returns NO the channel will abort the select
- // and return NO.
-
- - (void)databaseChannel:channel
- didSelectObjectsDescribedByQualifier:(EOQualifier *)qualifier
- fetchOrder:(NSArray *)fetchOrder;
- // Invoked from -selectObjectsDescribedByQualifier:... to tell the
- // delegate that the channel selected objects as specified by qualifier.
-
- - (void)databaseChannel:channel
- willFetchObjectOfClass:(Class)class
- withZone:(NSZone *)zone;
- // Invoked from -fetchWithZone: to tell the delegate that the channel will
- // fetch the next selected object.
-
- - (void)databaseChannel:channel didFetchObject:object;
- // Invoked from -fetchWithZone: to tell the delegate that the channel
- // fetched the next selected object.
-
- - (BOOL)databaseChannel:channel willLockObject:object;
- // Invoked from -lockObject: to tell the delegate that object will be
- // locked using snapshot data to determine whether the database has been
- // modified. The delegate may return YES to allow the channel to proceed,
- // or NO to cause the operation to fail and -lockObject: to return NO.
-
- - (void)databaseChannel:channel didLockObject:object;
- // Invoked from -lockObject: to tell the delegate that object was locked.
-
- - (Class)databaseChannel:channel failedToLookupClassNamed:(const char *)name;
- // Invoked when an attempt to lookup class name fails. The delegate can
- // take action (such as loading a bundle) to provide the channel with a
- // class for name.
-
- - (EORelationship *)databaseChannel:channel
- relationshipForRow:(NSDictionary *)row
- relationship:(EORelationship *)relationship;
- // Invoked when relationships are instantiated on a newly
- // fetched object. The delegate can use the information in the row to
- // determine which entity the target eo should be associated and replace
- // the relationship appropriately.
- @end
-
-