home *** CD-ROM | disk | FTP | other *** search
- // EOAdaptorChannel.h
- // Copyright (c) 1994, NeXT Computer, Inc. All rights reserved.
-
- #import "EOAdaptorContext.h"
-
- #import <foundation/NSArray.h>
- #import <foundation/NSData.h>
- #import <foundation/NSDictionary.h>
- #import <foundation/NSObject.h>
- #import <foundation/NSString.h>
-
- @class EOEntity;
- @class EOAttribute;
- @class EOQualifier;
- @class EOModel;
-
-
- // An EOAdaptorChannel represents an independent communication channel to the
- // database server. You use an EOAdaptorChannel to manipulate rows (records)
- // by selecting, fetching, inserting, updating, and deleting them. An
- // EOAdaptorChannel also gives you access to some of the meta-data on the
- // server (what entities exist, and what their basic attributes or
- // relationships are).
- //
- // An EOAdaptorChannel works with an EOAdaptorContext object, which handles
- // transactions. All of an EOAdaptorChannel's operations take place within
- // the context of transactions controlled or tracked by the EOAdaptorContext.
- // An EOAdaptorContext may manage several EOAdaptorChannels, but a channel is
- // associated with only one context. See EOAdaptor.h and EOAdaptorContext.h
- // for more information.
- //
- // Not all adaptors support multiple channels per context. For example, the
- // Sybase adaptor can have only one channel per context.
- //
- // An EOAdaptorContext retains its adaptor when created and an
- // EOAdaptorChannel retains its context, so when you create an adaptor,
- // adaptor context, and adaptor channel, you need only retain the channel for
- // all objects to remain valid.
- //
- // ATTRIBUTE NAMES
- //
- // Any EOAdaptorChannel method that uses attribute names uses the internal
- // names of the EOAttribute objects, NOT the external names of the database
- // server. External names are only used internally by an adaptor channel and
- // in the -evaluateExpression: method (which sends an expression directly to
- // the server for processing).
-
-
- @interface EOAdaptorChannel:NSObject
- {
- BOOL _debug;
- id _delegate;
- struct {
- unsigned willInsertRow:1;
- unsigned didInsertRow:1;
- unsigned willUpdateRow:1;
- unsigned didUpdateRow:1;
- unsigned willDeleteRows:1;
- unsigned didDeleteRows:1;
- unsigned willSelectAttributes:1;
- unsigned didSelectAttributes:1;
- unsigned willFetchAttributes:1;
- unsigned didFetchAttributes:1;
- unsigned didChangeResultSet:1;
- unsigned didFinishFetching:1;
- unsigned willEvaluateExpression:1;
- unsigned didEvaluateExpression:1;
- unsigned int _RESERVED:18;
- } _delegateRespondsTo;
- }
-
- - (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 adaptor into a
- // state where they are ready to perform database 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
- // adaptor if it has no additional contexts open.
-
- - (EOAdaptorContext *)adaptorContext;
- // Returns the EOAdaptorContext that controls transactions for the
- // channel.
-
- - (BOOL)insertRow:(NSDictionary *)row forEntity:(EOEntity *)entity;
- // Inserts the attributes of row into the database. row is an
- // NSDictionary whose keys are attribute names and whose values are the
- // values that will be inserted. Returns YES on success, NO on failure
- // for any reason.
-
- - (BOOL)updateRow:(NSDictionary *)row
- describedByQualifier:(EOQualifier *)qualifier;
- // Updates the row described by qualifier so that its values are equal to
- // those in row. row is an NSDictionary of attribute name/value pairs.
- // Returns YES on success, NO on failure for any reason.
-
- - (BOOL)deleteRowsDescribedByQualifier:(EOQualifier *)qualifier;
- // Deletes the row described by the qualifier. Returns YES on success,
- // NO on failure for any reason.
-
- - (BOOL)selectAttributes:(NSArray *)attributes
- describedByQualifier:(EOQualifier *)qualifier
- fetchOrder:(NSArray *)fetchOrder
- lock:(BOOL)flag;
- // Selects the given attributes in rows matching the qualifier. The
- // selected rows compose one or more result sets, each row of which will
- // be returned by subsequent -fetchAttributes:withZone: messages according
- // to the given fetchOrder (see EOAttributeOrdering.h). If flag is YES,
- // the rows are locked if possible so that no other user can modify them.
- // Returns YES on success, NO on failure for any reason.
-
- - (BOOL)evaluateExpression:(NSString *)expression;
- // Sends expression to the database server for evaluation. Returns YES
- // if no error occurs, NO if any error occurs.
-
- - (BOOL)isFetchInProgress;
- // Returns YES if the adaptor channel is fetching, NO otherwise. An
- // adaptor channel is fetching if it's been sent a successful
- // -selectAttributes:... message, or if an expression sent through
- // -evaluateExpression: resulted in a select. An adaptor channel stops
- // fetching when there are no more records to fetch or when it's sent
- // a -cancelFetch message
-
- - (NSArray *)describeResults;
- // Returns an array of attributes describing the properties available in
- // the current result set, as determined by -selectAttributes:... or a
- // select statement evaluated by -evaluateExpression:.
-
- - (NSMutableDictionary *)fetchAttributes:(NSArray *)attributes
- withZone:(NSZone *)zone;
- // Fetches the next row from the result set of the last
- // -selectAttributes:... message and returns values for the attribute
- // names in attributes. When there are no more rows in the current result
- // set, this method returns nil, and invokes the delegate method
- // -adaptorChannelDidChangeResultSet: if there are more results sets.
- // When there are no more rows or result sets, this method returns NO,
- // ends the fetch, and invokes -adaptorDidFinishFetching:.
- // -isFetchInProgress returns YES until the fetch is cancelled or until
- // this method exhausts all result sets and returns nil.
-
- - (void)cancelFetch;
- // Clears the result set created by the last selectAttributes:...
- // message, and terminates the current fetch, so that
- // -isFetchInProgress returns NO.
-
- - (BOOL)readTypesForEntity:(EOEntity *)entity;
- // Loads external type information from the database server into all
- // root attributes of entity. Returns YES on sucess, NO on failure
- // for any reason.
-
- - (BOOL)readTypeForAttribute:(EOAttribute *)attribute;
- // Loads external type information from the database server into
- // attribute. Returns YES on sucess, NO on failure for any reason.
-
- - (NSArray *)describeTableNames;
- // Reads and returns an array of table names from the database. This
- // method in conjunction with describeModelWithTableNames: is used for
- // building a default model in EOModeler.
-
- - (EOModel *)describeModelWithTableNames:(NSArray *)tableNames;
- // Constructs a default model out of the database's meta data. It also
- // put the adaptor name and connection dictionary in the new model. This
- // method obsoletes describeEntities, describeAttributes..., and
- // describeRelationships...
-
- - (NSArray *)describeEntities;
- // Returns an array of default entities constructed from meta data
- // returned by the database--for example, from the catalog or system
- // tables. This method is obsolete.
-
- - (NSArray *)describeAttributesForEntity:(EOEntity *)entity;
- - (NSArray *)describeRelationshipsForEntity:(EOEntity *)entity;
- // Returns an array of default attributes or relationships for entity,
- // constructed from meta-data in the database server. These methods don't
- // actually assign the attributes or relationships to the entity--you have
- // to do that yourself. See EOEntity.h for descriptions of -addAttribute:
- // and -addRelationship:. These methods are obsolete.
-
- - (void)setDebugEnabled:(BOOL)yn;
- - (BOOL)isDebugEnabled;
- // These methods return/set the current debug setting. When debug is
- // enabled, the adaptor channel will log any SQL that is evaluated and
- // other useful information.
-
- - delegate;
- - (void)setDelegate:delegate;
- // These methods return/set the delegate of the adaptor channel.
-
- - (NSMutableDictionary *)dictionaryWithObjects:(id *)objects forAttributes:(NSArray *)attributes zone:(NSZone *)zone;
- // Used by AdaptorChannel subclasses to create dictionaries to return from
- // fetchAttributes:withZone:
-
- + (NSCalendarDate *)dateForAttribute:(EOAttribute *)attr year:(int)year month:(unsigned)month day:(unsigned)day hour:(unsigned)hour minute:(unsigned)minute second:(unsigned)second zone:(NSZone *)zone;
- // Used by AdaptorChannel subclasses to create a calendar date object
- // to return in an adaptor row.
- @end
-
-
- // EOAdaptorChannel sends messages to its delegate for nearly every
- // operation that would affect data in the database server. The delegate can
- // use these methods to preempt these operations, modify their results,
- // or simply track activity.
- //
- // IMPORTANT: read the comments for the EODelegateResponse type in
- // EOAdaptorContext.h for information on how the adaptor channel interprets
- // delegate responses.
-
-
- @interface NSObject(EOAdaptorChannelDelegation)
-
- - (EODelegateResponse)adaptorChannel:channel
- willInsertRow:(NSMutableDictionary *)row
- forEntity:(EOEntity *)entity;
- // Invoked from -insertRow:forEntity: to tell the delegate that a row is
- // being inserted. The delegate may modify row, changing the values for
- // particular keys (attributes), or even adding or deleting attributes.
-
- - (void)adaptorChannel:channel
- didInsertRow:(NSDictionary *)row
- forEntity:(EOEntity *)entity;
- // Invoked from -insertRow:forEntity: to tell the delegate that a row has
- // been inserted. The delegate may use this information to update
- // records, redisplay onscreen information, or take whatever other action
- // it needs.
-
- - (EODelegateResponse)adaptorChannel:channel
- willUpdateRow:(NSMutableDictionary *)row
- describedByQualifier:(EOQualifier *)qualifier;
- // Invoked from -updateRow:describedByQualifier: to tell the delegate that
- // a row is being updated. The delegate can change the values for
- // particular attribute names in row, add or delete attributes, or modify
- // the qualifier.
-
- - (void)adaptorChannel:channel
- didUpdateRow:(NSDictionary *)row
- describedByQualifier:(EOQualifier *)qualifier;
- // Invoked from -updateRow:describedByQualifier: to tell the delegate that
- // a row has been updated. The delegate may take whatever action it needs
- // based on this information.
-
- - (EODelegateResponse)adaptorChannel:channel
- willDeleteRowsDescribedByQualifier:(EOQualifier *)qualifier;
- // Invoked from -deleteRowsDescribedByQualifier: to tell the delegate that
- // a row is being deleted. The delegate can modify the qualifier to
- // affect the result of the delete operation.
-
- - (void)adaptorChannel:channel
- didDeleteRowsDescribedByQualifier:(EOQualifier *)qualifier;
- // Invoked from -deleteRowsDescribedByQualifier: to tell the delegate that
- // some rows have been deleted. The delegate may take whatever action it
- // needs based on this information.
-
- - (EODelegateResponse)adaptorChannel:channel
- willSelectAttributes:(NSMutableArray *)attributes
- describedByQualifier:(EOQualifier *)qualifier
- fetchOrder:(NSMutableArray *)fetchOrder
- lock:(BOOL)flag;
- // Invoked from -selectAttributes:describedByQualifier:fetchOrder:lock:
- // to tell the delegate that a select operation is being performed. The
- // delegate can modify attributes or the qualifier to affect the select
- // operation.
-
- - (void)adaptorChannel:channel
- didSelectAttributes:(NSArray *)attributes
- describedByQualifier:(EOQualifier *)qualifier
- fetchOrder:(NSArray *)fetchOrder
- lock:(BOOL)flag;
- // Invoked from -selectAttributes:describedByQualifier:fetchOrder:lock:
- // to tell the delegate that some rows have been selected. The delegate
- // may take whatever action it needs based on this information.
-
- - (NSMutableDictionary *)adaptorChannel:channel
- willFetchAttributes:(NSArray *)attributes
- withZone:(NSZone *)zone;
- // Invoked from -fetchAttributes:withZone: to tell the delegate that a
- // single row will be fetched. If the delegate returns a non-nil
- // value, that value will be treated as a dictionary resulting from a
- // fetch operation; the adaptor channel doesn't perform a fetch, and
- // -fetchAttributes:withZone: returns YES. If the delegate returns nil
- // the adaptor channel perfoms the fetch itself.
-
- - (NSMutableDictionary *)adaptorChannel:channel
- didFetchAttributes:(NSMutableDictionary *)attributes
- withZone:(NSZone *)zone;
- // Invoked from -fetchAttributes:withZone: to tell the delegate that a
- // single row has been fetched. The delegate may modify and return the
- // given dictionary of values, return a substitute dictionary, or nil
- // to cause -fetchAttributes:withZone: to fail and return nil.
-
- - (void)adaptorChannelDidChangeResultSet:channel;
- // Invoked from -fetchAttributes:withZone: to tell the delegate that
- // fetching will start for the next result set, when a select operation
- // resulted in multiple result sets. This method is invoked just after a
- // -fetchAttributes:withZone: returns nil when there are still result sets
- // left to fetch.
-
- - (void)adaptorChannelDidFinishFetching:channel;
- // Invoked from -fetchAttributes:withZone: to tell the delegate that
- // fetching is finished for the current select operation. This method is
- // invoked when a fetch ends in -fetchAttributes:withZone: because there
- // are no more result sets.
-
- - (EODelegateResponse)adaptorChannel:channel
- willEvaluateExpression:(NSMutableString *)expression;
- // Invoked from -evaluateExpression: to tell the delegate that an
- // expression is about to be sent to the database server. The delegate
- // may modify expression to affect the result.
-
- - (void)adaptorChannel:channel
- didEvaluateExpression:(NSString *)expression;
- // Invoked from -evaluateExpression: to tell the delegate that a query
- // language expression has been evaluated by the database server. The
- // delegate may take whatever action it needs based on this information.
-
- @end
-