home *** CD-ROM | disk | FTP | other *** search
- // EOAdaptorContext.h
- // Copyright (c) 1994, NeXT Software, Inc. All rights reserved.
-
- #import <EOControl/EOControl.h>
- #import <EOAccess/EODefines.h>
-
- @class EOAdaptor;
- @class EOAdaptorChannel;
-
-
- // 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
- {
- EOAdaptor *_adaptor;
- NSMutableArray *_channels;
- id _delegate;
- unsigned short _transactionNestingLevel;
- BOOL _debug;
- struct {
- unsigned shouldConnect:1;
- unsigned shouldBegin:1;
- unsigned didBegin:1;
- unsigned shouldCommit:1;
- unsigned didCommit:1;
- unsigned shouldRollback:1;
- unsigned didRollback:1;
- unsigned int _RESERVED:25;
- } _delegateRespondsTo;
- }
-
- - initWithAdaptor:(EOAdaptor *)adaptor;
- // designated initializer
-
- - (BOOL)hasBusyChannels;
- // Returns YES if the receiver has channels that have outstanding
- // operations (that is, have a fetch in progress), NO otherwise.
-
- - (BOOL)hasOpenChannels;
- // Returns YES if the context has any open channels, NO otherwise. See
- // -openChannel in EOAdaptorChannel.h.
-
- - (NSArray *)channels;
- // Returns an array of channels used by this context. Different adaptors
- // may have different limits on the maximum number of channels per context.
-
- - (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;
- // Caches methods that delegate responds to. Does not retain delegate. Propagates
- // the delegate to all of its channels.
- @end
-
-
- // This category defines an interface for a basic transaction model
- // that incorporates begin, commit and rollback operations.
-
- @interface EOAdaptorContext (EOTransactions)
-
- - (void)beginTransaction;
- // Attempts to begin a new transaction, nested within the current one if
- // nested transaction are supported. Raises an exception if an error is
- // encountered.
-
- - (void)commitTransaction;
- // Attempts to commit the last transaction begun. Raises an exception
- // if an error is encountered. This method will raise an exception if
- // any of the context's channels have a fetch in progress.
-
- - (void)rollbackTransaction;
- // Attempts to roll back the last transaction begun. Raises an exception
- // if an error is encountered. This method will raise an exception if any
- // of the context's channels have a fetch in progress.
-
- - (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. Superclass implements
- // this method.
-
- // 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. Also sends
- // an EOAdaptorContextBeginTransactionNotification. Superclass implements this
- // method.
-
- - (void)transactionDidCommit;
- // Informs the receiver that the server has committed a transaction. Also sends
- // an EOAdaptorContextCommitTransactionNotification. Superclass implements this
- // method.
-
- - (void)transactionDidRollback;
- // Informs the receiver that the server has rolled back a transaction. Also sends
- // an EOAdaptorContextRollbackTransactionNotification. Superclass implements this
- // method.
-
- + (void)setDebugEnabledDefault:(BOOL)yn;
- + (BOOL)debugEnabledDefault;
- // setting inherited by new instances. By default this comes from the user
- // default "EOAdaptorDebugEnabled"
-
- - (void)setDebugEnabled:(BOOL)debugEnabled;
- // sets debug enabled flag on self and all outstanding channels. Any new
- // channels that get created also have the debug flag set.
- - (BOOL)isDebugEnabled;
- @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)
-
- - (BOOL)adaptorContextShouldConnect:context;
- // Invoked before the adaptor attempts to connect. The delegate can return
- // NO if it wants to override the connect, YES if it wants the adaptor
- // to attempt to connect in the usual way. The delegate should raise an
- // exception if it fails to connect.
-
- - (BOOL)adaptorContextShouldBegin:context;
- // Invoked from -beginTransaction to ask the delegate whether or not to
- // begin a transaction.
-
- - (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.
-
- - (BOOL)adaptorContextShouldCommit:context;
- // Invoked from -beginTransaction to ask the delegate whether or not to
- // commit a transaction.
-
- - (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.
-
- - (BOOL)adaptorContextShouldRollback:context;
- // Invoked from -rollbackTransaction to ask the delegate whether or not to
- // rollback a transaction transaction.
-
- - (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
-
- //
- // Notifications
- //
- EOACCESS_EXTERN NSString *EOAdaptorContextBeginTransactionNotification;
- // Sent from -[EOAdaptorContext transactionDidBegin];
- EOACCESS_EXTERN NSString *EOAdaptorContextCommitTransactionNotification;
- // Sent from -[EOAdaptorContext transactionDidCommit];
- EOACCESS_EXTERN NSString *EOAdaptorContextRollbackTransactionNotification;
- // Sent from -[EOAdaptorContext transactionDidRollback];
-