home *** CD-ROM | disk | FTP | other *** search
- // EOAdaptor.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 EOModel;
- @class EOAttribute;
- @class EOAdaptorContext;
- @class EOAdaptorChannel;
-
-
- // An EOAdaptor represents a single connection to a database server. It's
- // responsible for keeping login and model information, performing server-
- // specific formatting of SQL expressions, and reporting errors. The EOAdaptor
- // class also defines the methods that find and load adaptor bundles.
- //
- // An EOAdaptor can manage several EOAdaptorContexts, each of which represents
- // a transaction scope on the database server. An EOAdaptorContext can in
- // turn manage several EOAdaptorChannels, each of which handles actual access
- // to the data on the server. An EOAdaptor by default has no
- // EOAdaptorContexts; to create a new EOAdaptorContext, send your EOAdaptor a
- // -createAdaptorContext message. See EOAdaptorContext.h and
- // EOAdaptorChannel.h for more information.
- //
- // Not all adaptors support multiple contexts.
- //
- // 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.
- //
- // CONNECTING TO THE SERVER
- //
- // An EOAdaptor uses a connection dictionary to connect to the database
- // server. The keys of this dictionary identify the information the server
- // expects, and the values of those keys are the values that the adaptor will
- // try when connecting. For ORACLE databases the required keys are
- // hostMachine, serverId, userName, and password. For Sybase databases the
- // required keys are hostName, databaseName, userName, and password.
- //
- // A connection to the database server isn't actually formed until an adaptor
- // channel is opened. When you ask an adaptor to validate its connection
- // dictionary it only confirms with the server that it will accept the values
- // in the dictionary when a connection is requested.
-
-
- @interface EOAdaptor:NSObject
- {
- NSString *_name;
- EOModel *_model;
- NSDictionary *_connectionDictionary;
- id _delegate;
- struct {
- unsigned willReportError:1;
- unsigned int _RESERVED:31;
- } _delegateRespondsTo;
- }
-
- + adaptorWithName:(NSString *)name;
- // Searches the app's main bundle, ~/Library/Adaptors,
- // /LocalLibrary/Adaptors, and /NextLibrary/Adaptors (in that order) for
- // the first adaptor whose base filename matches name. It then loads
- // that adaptor if needed and inits it.
-
- + adaptorWithModel:(EOModel *)model;
- // The EOAdaptor implementation of this method extracts the adaptor name
- // from the model, sends +adaptorWithName: to self, and assigns to the
- // adaptor the model and the connection dictionary of that model.
-
- - initWithName:(NSString *)name;
- // This is the designated initializer for adaptors to be overridden by
- // subclasses. You MUST use +adaptorWithName: or +adaptorWithModel: to
- // create a new adaptor.
-
- - (NSString *)name;
- // Returns the base filename for the bundle the adaptor came from.
-
- - (void)setModel:(EOModel *)model;
- // Sets the model used by the adaptor. The model may also provide a
- // default connection dictionary.
-
- - (EOModel *)model;
- // Returns the model that describes the adaptor's database. This may be
- // nil; an adaptor must have a model to work with higher layers of the
- // Framework, though.
-
- - (EOAdaptorContext *)createAdaptorContext;
- // Returns a new EOAdaptorContext, or nil if a new context cannot be
- // created. EOAdaptors by default have no contexts at all. The newly
- // created context retains its adaptor.
-
- - (Class)expressionClass;
- // Returns the subclass of EOSQLExpression used by this adaptor for query
- // language expressions. You directly invoke this method, but an
- // adaptor subclass must properly implement this method.
-
- - formatAttribute:(EOAttribute *)attribute;
- // Returns an expression formatting the attribute for a SQL select
- // statement. You never directly invoke this method, but an adaptor
- // subclass must properly implement this method.
-
- - formatValue:value forAttribute:(EOAttribute *)attribute;
- // Returns an expression formatting the value for the given attribute for
- // a SQL select statement. You never directly invoke this method, but an
- // adaptor subclass must properly implement this method.
-
- - (BOOL)isValidQualifierType:(NSString *)typeName;
- // Returns YES if an attribute of type typeName can be used in a
- // qualifier, otherwise returns NO. typeName is the name of a type as
- // determined by the database server, such as a Sybase "varchar" or an
- // Oracle "NUMBER".
-
- - (BOOL)hasOpenChannels;
- // Returns YES if the adaptor has any open channels, NO otherwise. See
- // -openChannel in EOAdaptorChannel.h.
-
- - (BOOL)runLoginPanelAndValidateConnectionDictionary;
- // Runs a login panel until the user enters a valid login or clicks
- // Cancel. Valid login information entered in the panel is stored in the
- // adaptor's connection dictionary. Returns YES if the connection
- // dictionary is validated, NO if the user cancels the login panel.
-
- - (NSDictionary *)runLoginPanel;
- // This method runs the adaptor's login panel but does not affect the
- // adaptor's connection dictionary. The returned dictionary contains the
- // values of the fields entered by the user (which aren't validated), or
- // is nil if the user clicked cancel.
-
- - (BOOL)hasValidConnectionDictionary;
- // Returns YES if the adaptor can connect with the current connection
- // dictionary, NO otherwise. An actual connection is made when the first
- // adaptor channel is sent an -openChannel message.
-
- - (NSDictionary *)connectionDictionary;
- // Returns the adaptor's connection dictionary.
-
- - (void)setConnectionDictionary:(NSDictionary *)dictionary;
- // Gives the adaptor a dictionary with information about how and where to
- // open connections to a database server; see CONNECTING TO THE SERVER for
- // more information. Raises NSInvalidArgumentException if there are open
- // channels--you can't reset the connection information while the adaptor
- // is connected.
-
- - delegate;
- - (void)setDelegate:delegate;
- // These methods return/set the delegate of the adaptor context.
-
- - (void)reportError:(NSString *)error;
- // The adaptor components send this message to their EOAdaptor to have
- // errors reported to the user. The EOAdaptor first checks its delegate
- // with -adaptor:willReportError:. If the delegate returns NO then
- // EOAdaptor does nothing. If the delegate returns YES or is not present,
- // the EOAdaptor tries to open an alert panel, or if there is no
- // Application instance, it logs the error to the console.
-
- @end
-
-
- @interface NSObject(EOAdaptorDelegate)
-
- - (BOOL)adaptor:(EOAdaptor *)adaptor willReportError:(NSString *)error;
- // An adaptor sends this message to its delegate when an error has
- // occurred. If the delegate returns NO, the adaptor doesn't open an
- // alert panel (or log the error to the console if it isn't in an
- // application).
-
- @end
-