EOAdaptorChannel
Inherits from: NSObject
Conforms to: NSObject
(NSObject)
Declared in: EOAccess/EOAdaptorChannel.h
Class Description
EOAdaptorChannel is an abstract class that provides its concrete subclasses with a structure for performing database operations. It's associated with EOAdaptor and EOAdaptorContext, which, together with EOAdaptorChannel, form the adaptor level of Enterprise Objects Framework's access layer. See the EOAdaptor class specification for more information about accessing, creating, and using adaptor level objects.
A concrete subclass of EOAdaptorChannel provides database-specific method implementations and represents an independent communication channel to the database server to which its EOAdaptor object is connected. You never interact with instances of the EOAdaptorChannel class, rather your Enterprise Objects Framework applications use instances of concrete subclasses that are written to interact with a specific database or other persistent storage system.
You use an adaptor channel to manipulate rows (records) by selecting, fetching, inserting, deleting, and updating them. An adaptor channel also gives you access to some of the metadata on the server, such as what stored procedures exist, what tables exist, and what their basic attributes and relationships are.
All of an adaptor channel's operations take place within the context of transactions controlled or tracked by its EOAdaptorContext. An adaptor context may manage several channels (though not all can), but a channel is associated with only one context.
Notifying the Adaptor Channel's Delegate
You can assign a delegate to an adaptor channel. The EOAdaptorChannel sends certain messages directly to the delegate, and the delegate responds to these messages on the channel's behalf. Many of the adaptor channel methods notify the channel's delegate before and after an operation is performed. Some delegate methods, such as adaptorChannel:shouldEvaluateExpression:, let the delegate determine whether the channel should perform an operation. Others, such as adaptorChannel:didEvaluateExpression:, are simply notifications that an operation has occurred. The delegate has an opportunity to respond by implementing the delegate methods. If the delegate wants to intervene, it implements adaptorChannel:shouldEvaluateExpression:. If it simply wants notification when a transaction has begun, it implements adaptorChannel:didEvaluateExpression:.
The principal attributes of the EOAdaptorChannel class are:
- Adaptor context
- Delegate
To create an instance of a concrete EOAdaptorChannel subclass, you send a createAdaptorChannel message to an instance of the corresponding EOAdaptorContext subclass. You rarely create adaptor channels yourself. They are generally created automatically by other framework objects.
The following table lists EOAdaptorChannel's more commonly-used methods:
Method | Description |
openChannel | Opens the channel so it can perform database operations. |
closeChannel | Close the channel. |
selectAttributes:fetchSpecification:lock:entity: | Selects rows matching the specified qualifier. |
fetchRowWithZone: | Fetches a row resulting from the last selectAttributes:fetchSpecification:lock:entity:, executeStoredProcedure:withValues:, or evaluateExpression:. |
insertRow:forEntity: | Inserts the specified row. |
updateValues:inRowsDescribedByQualifier:entity: | Updates the row described by the specified qualifier. |
deleteRowDescribedByQualifier:entity: | Deletes the row described by the specified qualifier. |
executeStoredProcedure:withValues: | Performs the specified stored procedure. |
evaluateExpression: | Sends the specified expression to the database. |
Method | Description |
- openChannel | Opens the channel so it can perform database operations. |
- closeChannel | Close the channel. |
- selectAttributes:fetchSpecification:lock:entity: | Selects rows matching the specified qualifier. |
- fetchRowWithZone: | Fetches a row resulting from the last selectAttributes:fetchSpecification:lock:entity:, executeStoredProcedure:withValues:, or evaluateExpression:. |
- insertRow:forEntity: | Inserts the specified row. |
- updateValues:inRowDescribedByQualifier:entity: | Updates the row described by the specified qualifier. |
- deleteRowDescribedByQualifier:entity: | Deletes the row described by the specified qualifier. |
- executeStoredProcedure:withValues: | Performs the specified stored procedure. |
- evaluateExpression: | Sends the specified expression to the database. |
- performAdaptorOperation: | Performs an adaptor operation by invoking the EOAdaptorChannel method appropriate for performing the specified operation. |
For more information on subclassing EOAdaptorChannel, see "Creating an EOAdaptorChannel Subclass" .
Constants
EOAccess defines several NSString constants in EOAdaptorChannel.h for use as keys and values in an exception's userInfo dictionary (see performAdaptorOperations:).
Constant | Description |
EOAdaptorOperationsKey | A userInfo dictionary key. |
EOFailedAdaptorOperationKey | A userInfo dictionary key. |
EOAdaptorFailureKey | A userInfo dictionary key. |
EOAdaptorOptimisticLockingFailure | A userInfo dictionary value. |
Method Types
- Accessing the adaptor context
- - adaptorContext
- Opening and closing a channel
- - openChannel
- - closeChannel
- - isOpen
- Creating an EOAdaptorChannel
- - initWithAdaptorContext:
- Modifying rows
- - insertRow:forEntity:
- - updateValues:inRowDescribedByQualifier:entity:
- - updateValues:inRowsDescribedByQualifier:entity:
- - deleteRowDescribedByQualifier:entity:
- - deleteRowsDescribedByQualifier:entity:
- - lockRowComparingAttributes:entity:qualifier:snapshot:
- Fetching rows
- - selectAttributes:fetchSpecification:lock:entity:
- - describeResults
- - setAttributesToFetch:
- - attributesToFetch
- - fetchRowWithZone:
- - dictionaryWithObjects:forAttributes:zone:
- - cancelFetch
- - isFetchInProgress
- Invoking stored procedures
- - executeStoredProcedure:withValues:
- - returnValuesForLastStoredProcedureInvocation
- Assigning primary keys
- - primaryKeyForNewRowWithEntity:
- Sending SQL to the server
- - evaluateExpression:
- Batch processing operations
- - performAdaptorOperation:
- - performAdaptorOperations:
- Accessing schema information
- - describeTableNames
- - describeStoredProcedureNames
- - addStoredProceduresNamed:toModel:
- - describeModelWithTableNames:
- Debugging
- - setDebugEnabled:
- - isDebugEnabled
- Accessing the delegate
- - delegate
- - setDelegate:
Instance Methods
adaptorContext
- (EOAdaptorContext *)adaptorContext
See Also: - initWithAdaptorContext:
addStoredProceduresNamed:toModel:
- (void)addStoredProceduresNamed:(NSArray
*)storedProcedureNames
toModel:(EOModel *)model
attributesToFetch
- (NSArray *)attributesToFetch
cancelFetch
- (void)cancelFetch
An adaptor channel subclass should override this method without invoking EOAdaptorChannel's implementation.
closeChannel
- (void)closeChannel
An adaptor channel subclass should override this method without invoking EOAdaptorChannel's implementation.
See Also: - cancelFetch, - hasOpenTransaction (EOAdaptorContext)
delegate
- (id)delegate
deleteRowDescribedByQualifier:entity:
- (void)deleteRowDescribedByQualifier:(EOQualifier
*)qualifier
entity:(EOEntity *)entity
deleteRowsDescribedByQualifier:entity:
- (unsigned int)deleteRowsDescribedByQualifier:(EOQualifier
*)qualifier
entity:(EOEntity *)entity
- The adaptor channel isn't open.
- The adaptor channel is in an invalid state (for example, it's fetching).
- An error occurs in the database server.
An adaptor channel subclass should override this method without invoking EOAdaptorChannel's implementation.
See Also: - deleteRowDescribedByQualifier:entity:, - isOpen, - isFetchInProgress, - hasOpenTransaction (EOAdaptorContext)
describeModelWithTableNames:
- (EOModel *)describeModelWithTableNames:(NSArray
*)tableNames
EOAdaptorChannel's implementation does nothing. An adaptor channel subclass should override this method to create a default model from the database's metadata.
describeResults
- (NSArray *)describeResults
An adaptor channel subclass should override this method without invoking EOAdaptorChannel's implementation.
describeStoredProcedureNames
- (NSArray *)describeStoredProcedureNames
describeTableNames
- (NSArray *)describeTableNames
EOAdaptorChannel's implementation simply returns nil. An adaptor channel subclass should override this method to construct an array of table names from database metadata.
dictionaryWithObjects:forAttributes:zone:
- (NSMutableDictionary *)dictionaryWithObjects:(id
*)objects
forAttributes:(NSArray *)attributes
zone:(NSZone *)zone
A subclass of EOAdaptorChannel shouldn't override this method.
evaluateExpression:
- (void)evaluateExpression:(EOSQLExpression
*)expression
If expression results in a select operation being performed, you can fetch the results as you would if you had sent a selectAttributes:fetchSpecification:lock:entity:. You must use the method setAttributesToFetch: before you begin fetching. Also, if expression evaluates to multiple result sets, you must invoke setAttributesToFetch: before you begin fetching each subsequent set.
evaluateExpression: invokes the delegate methods adaptorChannel:shouldEvaluateExpression: and adaptorChannel:didEvaluateExpression:.
An adaptor channel subclass should override this method without invoking EOAdaptorChannel's implementation. Note, however, that the upper layers of the Framework never invoke evaluateExpression: directly. Thus, adaptors for data stores that don't naturally support an expression language (for example, flat file adaptors) don't need to implement this method to work with the Framework.
See Also: - fetchRowWithZone:
executeStoredProcedure:withValues:
- (void)executeStoredProcedure:(EOStoredProcedure
*)storedProcedure
withValues:(NSDictionary *)values
An adaptor channel subclass should override this method without invoking EOAdaptorChannel's implementation. Note, however, that the upper layers of the Framework never invoke executeStoredProcedure:withValues: directly. Thus, adaptors for data stores that don't support stored procedures (for example, flat file adaptors) don't need to implement this method to work with the Framework
fetchRowWithZone:
- (NSMutableDictionary *)fetchRowWithZone:(NSZone
*)zone
An adaptor channel subclass should override this method without invoking EOAdaptorChannel's implementation.
See Also: - setAttributesToFetch:
initWithAdaptorContext:
- initWithAdaptorContext:(EOAdaptorContext
*)adaptorContext
You never invoke this method directly unless you are implementing a concrete adaptor context. It is invoked automatically from createAdaptorChannel-the EOAdaptorContext method you use to create a new adaptor channel.
A subclass of EOAdaptorChannel doesn't need to override this method, but may override it to perform additional initialization. A subclass that does override this method must incorporate the superclass's version through a message to super.
See Also: - adaptorContext
insertRow:forEntity:
- (void)insertRow:(NSDictionary
*)row
forEntity:(EOEntity *)entity
- The user logged in to the database doesn't have permission to insert a new row.
- The adaptor channel is in an invalid state (for example, fetching).
- The row fails to satisfy a constraint defined in the database server.
An adaptor channel subclass should override this method without invoking EOAdaptorChannel's implementation.
isDebugEnabled
- (BOOL)isDebugEnabled
See Also: - setDebugEnabled: (EOAdaptorContext)
isFetchInProgress
- (BOOL)isFetchInProgress
- It's been sent a successful selectAttributes:fetchSpecification:lock:entity: message.
- A stored procedure that returns rows has been successfully executed using executeStoredProcedure:withValues:.
- An expression sent through evaluateExpression: resulted in a select operation being performed.
An adaptor channel stops fetching when there are no more records to fetch or when it's sent a cancelFetch message.
An adaptor channel subclass should override this method without invoking EOAdaptorChannel's implementation.
See Also: - fetchRowWithZone:
isOpen
- (BOOL)isOpen
See Also: - closeChannel
lockRowComparingAttributes:entity:qualifier:snapshot:
- (void)lockRowComparingAttributes:(NSArray
*)attributes
entity:(EOEntity *)entity
qualifier:(EOQualifier *)qualifier
snapshot:(NSDictionary *)snapshot
lockRowComparingAttributes:entity:qualifier:snapshot: invokes selectAttributes:fetchSpecification:lock:entity: with attributes as the attributes to select, a fetch specification built from qualifier, locking on, and entity as the entity. If the select returns no rows or more than one row, the method raises an EOGeneralAdaptorException. It also raises an EOGeneralAdaptorException if the values in the returned row don't match the corresponding values in snapshot.
The Framework uses this method whenever it needs to lock a row. When the Framework invokes it, qualifier specifies the primary key of the row to be locked and attributes used for locking to be compared in the database server. If any of the values specified in qualifier are different from the values in the database row, the select operation will not retrieve or lock the row. When this happens, the row to be locked has been updated in the database since it was last retrieved, and it isn't safe to update it.
Some attributes (such as BLOB types) can't be compared in the database. attributes should specify any such attributes. (If the row doesn't contain any such attributes, attributes can be nil.) If qualifier generates a select statement that returns and locks a single row, this method performs an in-memory comparison between the value in the retrieved row and the value in snapshot for each attribute in attributes. Therefore, snapshot must contain an entry for each attribute in attributes. In addition, it must contain an entry for the row's primary key.
A subclass of EOAdaptorChannel doesn't need to override this method.
openChannel
- (void)openChannel
See Also: - isOpen, - closeChannel
performAdaptorOperation:
- (void)performAdaptorOperation:(EOAdaptorOperation
*)adaptorOperation
A subclass of EOAdaptorChannel doesn't need to override this method.
See Also: - performAdaptorOperations:
performAdaptorOperations:
- (void)performAdaptorOperations:(NSArray
*)adaptorOperations
This method raises an exception if an error occurs. The exception's userInfo dictionary contains these keys:
Constant | The corresponding value in the exception's userInfo dictionary |
EOAdaptorOperationsKey |
An array of the EOAdaptorOperations being executed. |
EOFailedAdaptorOperationKey | The particular EOAdaptorOperation that failed. |
EOAdaptorFailureKey |
If present, offers additional information on the
type of error that occurred. Currently, the only possible value
for this key is EOAdaptorOptimisticLockingFailure ,
which indicates that an update or lock operation failed because the
row found in the database did not match the snapshot taken when
the row was last fetched into the application. |
A subclass of EOAdaptorChannel doesn't need to override the performAdaptorOperations: method.
primaryKeyForNewRowWithEntity:
- (NSDictionary *)primaryKeyForNewRowWithEntity:(EOEntity
*)entity
If information in entity specifies an adaptor-specific means to assign a new primary key (for example, a sequence name or stored procedure), then this method returns a new primary key. Otherwise, if the key is a simple integer, the method tries to fetch a new primary key from the database using an adaptor-specific scheme. Otherwise, the method returns nil.
EOAdaptorChannel's implementation simply returns nil. See your adaptor channel's documentation for information on how it generates primary keys.
A subclass of EOAdaptorChannel must override this method. For example, to return a value generated by a sequence, you'd create the proper SQL statement (using EOSQLExpression's expressionForString: method) and evaluate it (using the evaluateExpression: method).
returnValuesForLastStoredProcedureInvocation
- (NSDictionary *)returnValuesForLastStoredProcedureInvocation
An adaptor channel subclass should override this method without invoking EOAdaptorChannel's implementation.
selectAttributes:fetchSpecification:lock:entity:
- (void)selectAttributes:(NSArray
*)attributes
fetchSpecification:(EOFetchSpecification
*)fetchSpecification
lock:(BOOL)flag
entity:(EOEntity *)entity
- The adaptor channel is in an invalid state (for example, fetching).
- The database failed to lock the specified rows.
An adaptor channel subclass should override this method without invoking EOAdaptorChannel's implementation.
See Also: - setAttributesToFetch:
setAttributesToFetch:
- (EOAdaptorContext *)adaptorContext
An adaptor channel subclass should override this method without invoking EOAdaptorChannel's implementation.
See Also: - selectAttributes:fetchSpecification:lock:entity:
setDebugEnabled:
- (void)setDebugEnabled:(BOOL)flag
A subclass of EOAdaptorChannel doesn't need to override this method. A subclass that does override it must incorporate the superclass's version through a message to super.
See Also: - setDebugEnabled: (EOAdaptorContext)
setDelegate:
- (void)setDelegate:(id)delegate
updateValues:inRowDescribedByQualifier:entity:
- (void)updateValues:(NSDictionary
*)values
inRowDescribedByQualifier:(EOQualifier
*)qualifier
entity:(EOEntity *)entity
A subclass of EOAdaptorChannel doesn't need to override this method.
updateValues:inRowsDescribedByQualifier:entity:
- (unsigned int)updateValues:(NSDictionary
*)values
inRowsDescribedByQualifier:(EOQualifier
*)qualifier
entity:(EOEntity *)entity
- The user logged in to the database doesn't have permission to update.
- The adaptor channel is in an invalid state (for example, fetching).
- The new values fail to satisfy a constraint defined in the database server.
An adaptor channel subclass should override this method without invoking EOAdaptorChannel's implementation.
See Also: - updateValues:inRowDescribedByQualifier:entity: