home *** CD-ROM | disk | FTP | other *** search
- // EOAdaptorContext.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 EOAdaptor;
- @class EOAdaptorChannel;
-
- typedef enum {
- EODelegateRejects, EODelegateApproves, EODelegateOverrides
- } EODelegateResponse;
- // EODelegateResponse is used to indicate the result a delegate demands
- // on notification that a particular action will be taken. If a delegate
- // returns EODelegateRejects, the sender of the delegation message must
- // abort the current operation and return a failure result. If the
- // delegate returns EODelegateApproves, the sender may continue the
- // operation and return whatever result is appropriate. If the delegate
- // returns EODelegateOverrides, the sender must do nothing, but return a
- // success result. When a delegate overrides an operation it's
- // responsible for seeing that the result of that operation is performed
- // successfully.
-
-
- // An EOAdaptorContext represents a single transaction scope on the database
- // server. It's managed by an EOAdaptor object, which represents the main
- // connection to the server. If the server supports multiple concurrent
- // transaction sessions, the EOAdaptor may have several EOAdaptorContexts.
- // An EOAdaptorContext may in turn have several EOAdaptorChannels, which
- // handle actual access to the data on the server. An EOAdaptorContext by
- // default has no EOAdaptorChannels; to create a new EOAdaptorChannel, send
- // your EOAdaptorContext a -createAdaptorChannel message. See EOAdaptor.h and
- // EOAdaptorChannel.h for more information.
- //
- // 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.
- //
- // CONCCURRENT ACCESS
- //
- // When you use multiple EOAdaptorContexts, you can have several transactions
- // occurring simultaneously on the database server. You should be aware of
- // the issues involved in concurrent access if you do this.
-
-
- @interface EOAdaptorContext:NSObject
- {
- id _delegate;
- struct {
- unsigned willBegin:1;
- unsigned didBegin:1;
- unsigned willCommit:1;
- unsigned didCommit:1;
- unsigned willRollback:1;
- unsigned didRollback:1;
- unsigned int _RESERVED:26;
- } _delegateRespondsTo;
- }
-
- - (BOOL)hasBusyChannels;
- // Returns YES if the receiver has channels that have outstanding
- // operations (that is, have a fetch in progress), NO otherwise.
-
- - (EOAdaptor *)adaptor;
- // Returns the EOAdaptor that handles the connection within which the
- // adaptor context works.
-
- - (EOAdaptorChannel *)createAdaptorChannel;
- // Returns a new EOAdaptorChannel. Returns nil if a new channel cannot
- // be created. EOAdaptorContexts by default have no channels at all. The
- // newly created channel retains its context.
-
- - delegate;
- - (void)setDelegate:delegate;
- // These methods return/set the delegate of the adaptor context.
-
- @end
-
-
- // This category defines an interface for a basic transaction model
- // that incorporates begin, commit and rollback operations.
-
- @interface EOAdaptorContext (EOTransactions)
-
- - (BOOL)beginTransaction;
- // Attempts to begin a new transaction, nested within the current one if
- // nested transaction are supported, returning YES if successful and NO
- // if not.
-
- - (BOOL)commitTransaction;
- // Attempts to commit the last transaction begun, returning YES if
- // successful and NO if not. This method will raise an exception if any
- // of the context's channels have a fetch in progress or if the
- // transactionNestingLevel of the databaseContext is out of sync with
- // the adaptorContext.
-
- - (BOOL)rollbackTransaction;
- // Attempts to roll back the last transaction begun, returning YES if
- // successful and NO if not. This method will raise an exception if any
- // of the context's channels have a fetch in progress or if the
- // transactionNestingLevel of the databaseContext is out of sync with
- // the adaptorContext.
-
- - (BOOL)canNestTransactions;
- // Returns YES if the database server can nest transactions, NO
- // otherwise.
-
- - (unsigned)transactionNestingLevel;
- // Returns the number of transactions in progress. If transactions
- // can nest, this number may be greater than one.
-
- // Since databases vary widely in their ability to report transactions
- // generated automatically--for example through stored procedures--the
- // following notification methods help the caller keep the transaction objects
- // synchronized with the database. These methods are also invoked by the
- // -beginTransaction, -commitTransaction, and -rollbackTransaction methods.
-
- - (void)transactionDidBegin;
- // Informs the receiver that the server has begun a transaction.
-
- - (void)transactionDidCommit;
- // Informs the receiver that the server has committed a transaction.
-
- - (void)transactionDidRollback;
- // Informs the receiver that the server has rolled back a transaction.
-
- @end
-
-
- // EOAdaptorContext sends messages to its delegate for any transaction
- // begin, commit, or rollback. The delegate can use these methods to
- // preempt these operations, modify their results, or simply track activity.
- //
- // IMPORTANT: read the comments for the EODelegateResponse at the top of this
- // header file for information on how the adaptor context interprets delegate
- // responses.
-
- @interface NSObject(EOAdaptorContextDelegation)
-
- - (EODelegateResponse)adaptorContextWillBegin:context;
- // Invoked from -beginTransaction to tell the delegate that a transaction
- // is being started.
-
- - (void)adaptorContextDidBegin:context;
- // Invoked from -beginTransaction or -transactionDidBegin to tell the
- // delegate that a transaction has begun. The delegate may take whatever
- // action it needs based on this information.
-
- - (EODelegateResponse)adaptorContextWillCommit:context;
- // Invoked from -commitTransaction to tell the delegate that a transaction
- // is being committed.
-
- - (void)adaptorContextDidCommit:context;
- // Invoked from -commitTransaction or -transactionDidCommit to tell the
- // delegate that a transaction has been committed. The delegate may take
- // whatever action it needs based on this information.
-
- - (EODelegateResponse)adaptorContextWillRollback:context;
- // Invoked from -rollbackTransaction to tell the delegate that a
- // transaction is being started.
-
- - (void)adaptorContextDidRollback:context;
- // Invoked from -rollbackTransaction or -transactionDidRollback to tell
- // the delegate that a transaction has been rolled back. The delegate may
- // take whatever action it needs based on this information.
-
- @end
-