home *** CD-ROM | disk | FTP | other *** search
- // EOAdaptor.h
- // Copyright (c) 1994, NeXT Software, Inc. All rights reserved.
-
- #import <EOControl/EOControl.h>
- #import <EOAccess/EODefines.h>
-
- @class EOModel;
- @class EOEntity;
- @class EOAttribute;
- @class EOAdaptorContext;
- @class EOAdaptorChannel;
- @class EOLoginPanel;
-
- // Exceptions raised by adaptors when errors occur during DBMS interactions.
- EOACCESS_EXTERN NSString *EOGeneralAdaptorException;
-
- // 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 informix the required keys are dbName, userName,
- // and password. 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;
- NSDictionary *_connectionDictionary;
- NSStringEncoding _encoding;
- NSMutableArray *_contexts;
- NSString *_expressionClassName;
- Class _expressionClass;
- id _delegate;
- struct {
- unsigned processValue: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.
-
- + (void)setExpressionClassName:(NSString *)sqlExpressionClassName
- adaptorClassName:(NSString *)adaptorClassName;
- // Overrides the defaultExpressionClass provided by the adaptor. This allows
- // programmers to subclass the SQLExpression class used by the adaptor with
- // subclassing the entire adaptor. The expression class can be reset to the
- // default by passing nil as the sqlExpressionClassName;
-
- + (EOLoginPanel *)sharedLoginPanelInstance;
- // For applications (when [NSApp sharedApplication] is non-nil, this will
- // return an instance of the login panel for this adaptor. The default
- // implementation looks for "LoginPanel.bundle" in the resources for the
- // adaptor framework, loads this bundle, and returns the result of alloc
- // and initing its principalClass. The framework uses the returned object
- // to implement runLoginPanel and runLoginPanelAndValidateConnectionDictionary.
-
- - 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.
-
- - (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.
-
- - (NSArray *)contexts;
-
- - (Class)expressionClass;
- // Returns the subclass of EOSQLExpression used by this adaptor for query
- // language expressions. The EOAdaptor superclass provides a default
- // implementation of this method which looks to see if the programmer has
- // set a new sqlExpressionClass for this adaptor type by invoking
- // setExpressionClassName:adaptorClassName: If no class has been set,
- // the defaultExpressionClass method is invoked on the individual adaptor.
-
- - (Class)defaultExpressionClass;
- // This method should never be invoked by the programmer. It is implemented
- // by the adaptor subclass and invoked by the framework when determining which
- // sqlExpression class should be used.
-
- - (BOOL)isValidQualifierType:(NSString *)typeName model:(EOModel *)model;
- // 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.
-
- - (void)assertConnectionDictionaryIsValid;
- // Raises an exception if any error occurs. 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.
-
- - (BOOL)canServiceModel:(EOModel *)model;
- // Returns YES if this adaptor instance can service access requests
- // for this model, NO otherwise. Default implementation checks if
- // this model has an identical connection dictionary to the current
- // connectionDicionaries. Subclasses may want to override to be
- // more permissive of unimportant differences in the connection
- // dictionaries.
-
- - (NSStringEncoding)databaseEncoding;
- // Looks in the connection dictionary for an entry entitled
- // "databaseEncoding". If it finds one it returns the corresponding
- // NSStringEncoding value. If it doesn't find one it returns the
- // default encoding. This method can raise if an entry exists in the
- // dictionary that doesn't map to one of the legal NSStringEncoding
- // values. (e.g. if the value is misspelled)
-
- - (id)fetchedValueForValue:(id)value attribute:(EOAttribute *)attribute;
- // Called for each value that is inserted or updated so that the adaptor
- // may perform database specific transformations before they are assigned
- // back to the object and snapshots. For example, say the object holds an
- // NSDecimalNumber with value 5.24. The precision and scale of the attribute
- // and corresponding database column is 2 and 1 respectively. When the value
- // gets stored in the database it's value will be truncated to 5.4. At this
- // point, the value in the database is different than the one in the snapshot.
- // In order to avoid the problems that can occur in such situations, this
- // method gives the adaptor a chance to adjust any values that have been sent
- // to the database in a DBMS specific manner before they are placed in the
- // snapshot.
- // Subclassers may override this method as well as the next 4 methods which
- // used to perform the conversion for each of the possible adaptor types.
- // This method doesn't do any conversion of custom classes. Programs that need
- // to process custom classes must implement the processValue:attribute:adaptor:
- // delegate on the adaptor.
-
- - (NSString *)fetchedValueForStringValue:(NSString *)value attribute:(EOAttribute *)attribute;
- // Superclass implementation returns value. Adaptors should override to mimic specific
- // DBMS behavior.
-
- - (NSNumber *)fetchedValueForNumberValue:(NSNumber *)value attribute:(EOAttribute *)attribute;
- // Superclass implementation returns value. Adaptors should override to mimic specific
- // DBMS behavior.
-
- - (NSCalendarDate *)fetchedValueForDateValue:(NSCalendarDate *)value attribute:(EOAttribute *)attribute;
- // Superclass implementation returns value. Adaptors should override to mimic specific
- // DBMS behavior.
-
- - (NSData *)fetchedValueForDataValue:(NSData *)value attribute:(EOAttribute *)attribute;
- // Superclass implementation returns value. Adaptors should override to mimic specific
- // DBMS behavior.
-
- - delegate;
- - (void)setDelegate:delegate;
- // These methods return/set the delegate of the adaptor context.
-
- @end
-
- @interface EOAdaptor (EOAdaptorLoginPanel)
- - (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 user enters correct
- // connection information and NO otherwise.
-
- - (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.
- @end
-
- @interface EOAdaptor (EOExternalTypeMapping)
- + (NSString *)internalTypeForExternalType:(NSString *)extType model:(EOModel *)model;
- + (NSArray *)externalTypesWithModel:(EOModel *)model;
- + (void)assignExternalInfoForAttribute:(EOAttribute *)attribute;
- // should convert the columnName and external type based on the
- // internalType, precision, and length info.
- // Default implementation creates columnName from name:
- // e.g. "firstName" -> "FIRST_NAME"
- // Adaptor subclasses should override to assign external types.
- + (void)assignExternalInfoForEntity:(EOEntity *)entity;
- // Creates external name based on internal name. Default implementation
- // will covert name of style "EmpPhoto" to "EMP_PHOTO".
- // This does not recurse over the attributes.
- + (void)assignExternalInfoForEntireModel:(EOModel *)model;
- // Recurses through entities and their attributes calling the
- // conversion methods above
-
- @end
-
- @interface EOLoginPanel : NSObject
- - (NSDictionary *)runPanelForAdaptor:(EOAdaptor *)adaptor validate:(BOOL)yn;
- // Adaptor subclasses should implement a subclass that implements
- // this method. If validate==YES, the panel should call
- // [adaptor setConnectionDictionary:connDict], and return only if
- // [adaptor assertConnectionDictionaryIsValid] does not raise or the user
- // cancels the operation. This method returns a nil dictionary if the user
- // does cancel the operation.
- @end
-
- @interface EOAdaptor (EOAdaptorDelegation)
- - (id)adaptor:(EOAdaptor *)adaptor fetchedValueForValue:(id)value attribute:(EOAttribute *)attribute;
- // Allows the adaptor delegate to handle attribute processing when saving
- // eos to the database. When this method is implemented, it must return the
- // processed value. Returning nil as the new value is OK.
- @end
-
-