home *** CD-ROM | disk | FTP | other *** search
- // EOAdaptorChannel.h
- // Copyright (c) 1994, NeXT Software, Inc. All rights reserved.
-
- #import <EOAccess/EODefines.h>
- #import <EOAccess/EOAdaptorContext.h>
-
- #import <EOControl/EOControl.h>
-
- @class EOEntity;
- @class EOAttribute;
- @class EOQualifier;
- @class EOStoredProcedure;
- @class EOModel;
- @class EOAdaptorOperation;
- @class EOSQLExpression;
-
- // 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;
- EOAdaptorContext *_context;
- id _delegate;
- struct {
- unsigned willPerformOperations:1;
- unsigned didPerformOperations:1;
- unsigned shouldSelectAttributes:1;
- unsigned didSelectAttributes:1;
- unsigned willFetchRow:1;
- unsigned didFetchRow:1;
- unsigned didChangeResultSet:1;
- unsigned didFinishFetching:1;
- unsigned shouldEvaluateExpression:1;
- unsigned didEvaluateExpression:1;
- unsigned shouldExecuteStoredProcedure:1;
- unsigned didExecuteStoredProcedure:1;
- unsigned shouldConstructStoredProcedureReturnValues:1;
- unsigned shouldReturnValuesForStoredProcedure:1;
- unsigned int _RESERVED:18;
- } _delegateRespondsTo;
- }
-
- - initWithAdaptorContext:(EOAdaptorContext *)adaptorContext;
- // designated initializer
-
- - (BOOL)isOpen;
- // Returns YES if the channel has been opened with -openChannel,
- // NO if not.
-
- - (void)openChannel;
- // This method puts the channel and both its context and adaptor into a
- // state where they are ready to perform database operations. Raises an
- // exception if error occurs.
-
- - (void)closeChannel;
- // This method disconnects the channel and then disconnects the
- // channel's context if the context has no other channels open.
-
- - (EOAdaptorContext *)adaptorContext;
- // Returns the EOAdaptorContext that controls transactions for the
- // channel.
-
- - (void)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. Row keys must refer to attributes that all
- // belong to entity and that are either non-flattened or all flattened
- // through the same relationshipPath. Raise an exception if error occurs.
-
- - (void)updateValues:(NSDictionary *)values
- inRowDescribedByQualifier:(EOQualifier *)qualifier entity:(EOEntity *)entity;
- // Updates the row described by qualifier so that its values are equal to
- // those in the values dictionary. The values dictionary contains a set
- // of attribute name/value pairs. All keys in the row and qualifer
- // must refer to attributes that all belong to entity and that are either
- // non-flattened or all flattened through the same relationshipPath.
- // This method may raise an exception if an error occurs or if exactly
- // one row is not updated.
- // SubClassers: superclass provides default implementation.
-
- - (unsigned)updateValues:(NSDictionary *)values
- inRowsDescribedByQualifier:(EOQualifier *)qualifier entity:(EOEntity *)entity;
- // Similar to the preceding method, except this one may affect an arbitrary
- // number of rows. Returns the number of rows affected by this method. Raises
- // if an error occurs.
-
- - (void)deleteRowDescribedByQualifier:(EOQualifier *)qualifier entity:(EOEntity *)entity;
- // Deletes the row described by the qualifier. This methods may raise an
- // exception if an error occurs or if exactly 1 row is not deleted.
- // All keys in the qualifer must refer to attributes that all belong
- // to entity and that are either non-flattened or all flattened
- // through the same relationshipPath.
- // SubClassers: superclass provides default implementation.
-
- - (unsigned)deleteRowsDescribedByQualifier:(EOQualifier *)qualifier entity:(EOEntity *)entity;
- // Similar to the preceding method, except this one may delete an arbitrary
- // number of rows. Returns the number of rows deleted by this method. Raises
- // if an error occurs.
-
- - (void)selectAttributes:(NSArray *)attributes fetchSpecification:(EOFetchSpecification *)fetchSpecification lock:(BOOL)flag entity:(EOEntity *)entity;
- // 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 -fetchRowWithZone: messages according
- // to the given fetchOrder (see EOSortOrdering.h). If flag is YES,
- // the rows are locked if possible so that no other user can modify them.
- // This methods may raise an exception if an error occurs.
-
- - (void)lockRowComparingAttributes:(NSArray *)atts entity:(EOEntity *)entity
- qualifier:(EOQualifier *)qualifier snapshot:(NSDictionary *)snapshot;
- // Attempts to lock a row in the database by selecting it with the locking
- // on. The qualifier should contain the primary key of the row to be locked
- // as well as any comparisons that can be done in the database server to
- // ensure that the current snapshot is not out of date with respect to the
- // row in the database. The atts array should contain any values that need
- // to be fetched and compared in memory (such as blob columns in the database).
- // The atts array can be nil if the row doesn't contain any blobs. The
- // snapshot must contain any values needed to compare with the fetched atts and
- // the primary key values for this row. This method raises if an error occurs.
- // This method is implemented by the superclass, subclasses should not have to
- // override.
-
- - (void)evaluateExpression:(EOSQLExpression *)expression;
- // Sends expression to the database server for evaluation. This methods
- // may raise an exception if an error occurs.
-
- - (BOOL)isFetchInProgress;
- // Returns YES if the adaptor channel is fetching, NO otherwise. An
- // adaptor channel is fetching if an operation has been performed which
- // can return row. An adaptor channel may be fetching after a
- // -selectAttributes:... message, an executeStoredProcdure: 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:.
- // This methods may raise an exception if an error occurs
-
- - (NSMutableDictionary *)fetchRowWithZone:(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 no rows are left, this method invokes
- // adaptorChannel:didFinishFetching:, and returns nil.
- // For adaptors that can have multiple result sets (ODBC and Sybase),
- // This method will return nil at the end of each result set, however
- // isFetchInProgress will return NO. The channel will also send the
- // delegate an an adaptorChannelDidChangeResultSet: message whenever
- // the end of one result set has been reached and another one is
- // pending.
- // This methods may raise an exception if an error occurs.
-
- - (void)setAttributesToFetch:(NSArray *)attributes;
- // Allows the user to change the set of attributes used to describe the
- // fetch data in the middle of a select. This is especially useful for
- // DBMS's that have non-rectangular result sets (like Sybase) or when
- // evaluating an expression using the evaluateExpression: method.
- // This method raises if invoked when there is no fetch in progress.
-
- - (NSArray *)attributesToFetch;
- // Returns the set of attributes used by the adaptor for a particular fetch.
-
- - (void)cancelFetch;
- // Clears the result set created by the last selectAttributes:...
- // message, and terminates the current fetch, so that
- // -isFetchInProgress returns NO and new operations can be performed
- // with the channel.
-
- - (NSDictionary *)primaryKeyForNewRowWithEntity:(EOEntity *)entity;
- // If information in the entity specifies an adaptor-specific
- // means to assign a new primary key (e.g. a sequence name, or
- // stored procedure) then returns a new primary key. Otherwise,
- // if the key is a simple integer, the adaptor will attempt to
- // fetch a new key from the database using an adaptor specific
- // scheme. Otherwise, returns nil.
-
- - (NSArray *)describeTableNames;
- // Reads and returns an array of table names from the database. This
- // method is used in conjunction with describeModelWithTableNames: to
- // build a default model in EOModeler. This methods may raise an
- // exception if an error occurs
-
- - (void)describeStoredProceduresForModel:(EOModel *)model;
- // This method may raise an exception if an error occcurs.
-
- - (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 methods may raise an exception if an error occurs.
-
- - (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.
-
- - (id)delegate;
- - (void)setDelegate:(id)delegate;
- // These methods return/set the delegate of the adaptor channel. The channel's
- // delegate is normally set by the adaptor context whenever it's delegate method
- // is set or whenever the adaptor channel is created. This means that an adaptor
- // context and all of it's channels will have the same delegate.
-
- - (NSMutableDictionary *)dictionaryWithObjects:(id *)objects forAttributes:(NSArray *)attributes zone:(NSZone *)zone;
- // Used by AdaptorChannel subclasses to create dictionaries to return from
- // fetchRowWithZone:
- @end
-
-
- @interface EOAdaptorChannel(EOStoredProcedures)
- - (void)executeStoredProcedure:(EOStoredProcedure *)storedProcedure withValues:(NSDictionary *)values;
- // Execute the given stored procedure. On successful completion you can
- // call -returnValuesForStoredProcedure to get the return arguments, if any.
- // This method may raise an exception if an error occcurs.
-
- - (NSDictionary *)returnValuesForLastStoredProcedureInvocation;
- // Returns a dictionary with all the OUT parameters and a special entry
- // with the @"returnValue" key. Stored procedures that have void return
- // types will return an empty dictionary.
- // If this method returns nil, then you need to fetchRowithZone:
- // until all data has been processed before the return value will be
- // available.
- @end
-
- @interface EOAdaptorChannel(EOBatchProcessing)
- - (void)performAdaptorOperation:(EOAdaptorOperation *)adaptorOperation;
- // Invokes the insertRow, updateRow, or deleteRow methods depending
- // on the information in the adaptorOperation. This method may raise
- // an exception if an error occurs.
-
- - (void)performAdaptorOperations:(NSArray *)adaptorOperations;
- // The superclass implementation of this method, calls
- // [self performAdaptorOperation] with each adaptorOperation in the
- // array. Specific adaptors may be able to implement this method in a more
- // intelligent way to take advantage of a particular database specific
- // API. By default, the database layer will sort the adaptorOperations in
- // alphabetical order by entityName with the insert operations first in the
- // list for the entity, followed by update operations, followed by deletes.
- // This order can be affected, however, by delegate methods in the EODatabase
- // layer. In addition, this method may be called by other clients than the
- // EODatabase layer which may not conform to this convention.
- @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.
-
- @interface NSObject(EOAdaptorChannelDelegation)
-
- - (NSArray *)adaptorChannel:channel
- willPerformOperations:(NSArray *)operations;
- // Invoked from -performAdaptorOperations. The delegate may return a the same
- // or different NSArray to continue the method or nil to cause the method to
- // return immediately.
-
- - (NSException *)adaptorChannel:channel
- didPerformOperations:(NSArray *)operations
- exception:(NSException *)exception;
- // Invoked from -performAdaptorOperations. The exception will be nil if no
- // exception was raised during while performing the operations. Otherwise, the
- // raised exception will be passed to the delegate. The delegate can return the
- // the same or a different exception which will then be re-raised by the method
- // or they can return nil to supress the raising of the exception.
-
- - (BOOL)adaptorChannel:channel
- shouldSelectAttributes:(NSArray *)attributes
- fetchSpecification:(EOFetchSpecification *)fetchSpecification
- lock:(BOOL)flag entity:(EOEntity *)entity;
- // Invoked from -selectAttributes:fetchSpecification:lock:entity:
- // to ask the delegate whether a select operation should be performed.
- // The delegate can modify the fetchSpecification to alter the select.
- // The delegate may return NO which causes the select not to happen.
- // In this case the delegate may perform the select itself.
-
- - (void)adaptorChannel:channel
- didSelectAttributes:(NSArray *)attributes
- fetchSpecification:(EOFetchSpecification *)fetchSpecification
- lock:(BOOL)flag entity:(EOEntity *)entity;
- // Invoked from -selectAttributes:fetchSpecification:lock:entity:
- // to tell the delegate that some rows have been selected. The delegate
- // may take whatever action it needs based on this information.
-
- - (void)adaptorChannelWillFetchRow:channel;
- // Invoked from -fetchRowWithZone: to tell the delegate that a
- // single row will be fetched. Delegates can get and reset the attributes
- // used in the fetch through the -attributesToFetch and the
- // -setAttributesToFetch: methods.
- // the adaptor channel perfoms the fetch itself.
-
- - (void)adaptorChannel:channel didFetchRow:(NSMutableDictionary *)row;
- // Invoked at the end of -fetchRowWithZone: whenever a row is successfully
- // fetched. This method is not invoked if an exception occurs during the
- // fetch or if the end of the fetch set is reached. Delegates can change
- // the row dictionary.
-
- - (void)adaptorChannelDidChangeResultSet:channel;
- // Invoked from -fetchRowWithZone: 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
- // -fetchRowWithZone: returns nil when there are still result sets
- // left to fetch.
-
- - (void)adaptorChannelDidFinishFetching:channel;
- // Invoked from -fetchRowWithZone: to tell the delegate that
- // fetching is finished for the current select operation. This method is
- // invoked when a fetch ends in -fetchRowWithZone: because there
- // are no more result sets.
-
- - (BOOL)adaptorChannel:channel
- shouldEvaluateExpression:(EOSQLExpression *)expression;
- // Invoked from -evaluateExpression: to ask the delegate whether to
- // send an expression to the database server.
-
- - (void)adaptorChannel:channel
- didEvaluateExpression:(EOSQLExpression *)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.
-
- - (NSDictionary *)adaptorChannel:channel
- shouldExecuteStoredProcedure:(EOStoredProcedure *)procedure
- withValues:(NSDictionary *)values;
- // Invoked from -executeStoredProcedure:withArguments:
- // If the delegate returns a value other than nil, that returned dictionary
- // will will be used as the arguments to the stored procedure
-
- - (void)adaptorChannel:channel
- didExecuteStoredProcedure:(EOStoredProcedure *)procedure
- withValues:(NSDictionary *)values;
- // Invoked from -executeStoredProcedure:withValues: after the execution
- // has succeeded.
-
- - (NSDictionary *)adaptorChannelShouldConstructStoredProcedureReturnValues:channel;
- // Invoked from -returnValuesForLastStoredProcedureInvocation.
- // If the delegate returns a value other than nil, that value will be
- // returned immediately to the calling method.
-
- - (NSDictionary *)adaptorChannel:channel shouldReturnValuesForStoredProcedure:(NSDictionary *)returnValues;
- // Invoked from -returnValuesForLastStoredProcedureInvocation
- // If the delegate returns a dictionary, that dictionary will be returned to the
- // calling method.
- @end
-
-