Documentation Archive Developer
Search
PATH Documentation > WebObjects

Table of Contents

EOAdaptorChannel


Inherits from: Object
Package: com.webobjects.eoaccess



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.


Note: EOAdaptorChannel is abstract. Never create instances of the EOAdaptorChannel class.

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 adaptorChannelShouldEvaluateExpression, let the delegate determine whether the channel should perform an operation. Others, such as adaptorChannelDidEvaluateExpression, 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 adaptorChannelShouldEvaluateExpression. If it simply wants notification when a transaction has begun, it implements adaptorChannelDidEvaluateExpression.

The principal attributes of the EOAdaptorChannel class are:

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 Selects rows matching the specified qualifier.
fetchRow Fetches a row resulting from the last selectAttributes, executeStoredProcedure, or evaluateExpression.
insertRow Inserts the specified row.
updateValuesInRowsDescribedByQualifier Updates the row described by the specified qualifier.
deleteRowDescribedByQualifier Deletes the row described by the specified qualifier.
executeStoredProcedure 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 Selects rows matching the specified qualifier.
fetchRow Fetches a row resulting from the last selectAttributes, executeStoredProcedure, or evaluateExpression.
insertRow Inserts the specified row.
updateValuesInRowDescribedByQualifier Updates the row described by the specified qualifier.
deleteRowDescribedByQualifier Deletes the row described by the specified qualifier.
executeStoredProcedure 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" (page 55).




Constants


EOAdaptorChannel defines several String constants for use as keys and values in an exception's userInfo dictionary (see performAdaptorOperations).


Constant Description
AdaptorOperationsKey A userInfo dictionary key.
FailedAdaptorOperationKey A userInfo dictionary key.
AdaptorFailureKey A userInfo dictionary key.
AdaptorOptimisticLockingFailure A userInfo dictionary value.



Method Types


Accessing the adaptor contextadaptorContextOpening and closing a channelopenChannelcloseChannelisOpenModifying rowsinsertRowupdateValuesInRowDescribedByQualifierupdateValuesInRowsDescribedByQualifierdeleteRowDescribedByQualifierdeleteRowsDescribedByQualifierlockRowComparingAttributesFetching rowsselectAttributesdescribeResultssetAttributesToFetchattributesToFetchfetchRowdictionaryWithObjectsForAttributescancelFetchisFetchInProgressInvoking stored proceduresexecuteStoredProcedurereturnValuesForLastStoredProcedureInvocationAssigning primary keysprimaryKeyForNewRowWithEntitySending SQL to the serverevaluateExpressionBatch processing operationsperformAdaptorOperationperformAdaptorOperationsAccessing schema informationdescribeTableNamesdescribeStoredProcedureNamesaddStoredProceduresNameddescribeModelWithTableNamesAccessing the delegatedelegatesetDelegate



Constructors



EOAdaptorChannel

public EOAdaptorChannel(EOAdaptorContext adaptorContext)

Creates and returns an EOAdaptorChannel, with adaptorContext. When you create an adaptor channel subclass, override this method.

Don't 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.

See Also: adaptorContext




Instance Methods



adaptorContext

public EOAdaptorContext adaptorContext()

Returns the receiver's EOAdaptorContext. A subclass of EOAdaptorChannel doesn't need to override this method.

See Also: EOAdaptorChannel constructor



addStoredProceduresNamed

public void addStoredProceduresNamed( NSArray storedProcedureNames, EOModel model)

Overridden by subclasses to create EOStoredProcedure objects for the stored procedures named in storedProcedureNames and then to add them to model. This method is used in conjunction with describeStoredProcedureNames to build a default model in EOModeler. Throws an exception if an error occurs.



attributesToFetch

public abstract NSArray attributesToFetch()

Implemented by subclasses to return the set of attributes to retrieve when fetchRow is next invoked. An adaptor channel subclass should override this method without invoking EOAdaptorChannel's implementation.



cancelFetch

public abstract void cancelFetch()

Implemented by subclasses to clear all result sets established by the last selectAttributes, executeStoredProcedure, or evaluateExpression message and terminate the current fetch, so that isFetchInProgress returns false.

An adaptor channel subclass should override this method without invoking EOAdaptorChannel's implementation.



closeChannel

public abstract void closeChannel()

Implemented by subclasses to close the EOAdaptorChannel so that it can't perform operations with the server. Any fetch in progress is canceled. If the receiver is the last open channel in an adaptor context and if the channel's adaptor context has outstanding transactions, closing the channel has server-dependent results: some database servers roll back all outstanding transactions but others do nothing. Regardless of whether outstanding transactions are rolled back, this method has the side effect of closing the receiver's adaptor context's connection with the database if the receiver is its adaptor context's last open channel.

An adaptor channel subclass should override this method without invoking EOAdaptorChannel's implementation.

See Also: cancelFetch, hasOpenTransaction (EOAdaptorContext)



delegate

public Object delegate()

Returns the receiver's delegate, or null if the receiver doesn't have a delegate. A subclass of EOAdaptorChannel doesn't need to override this method.



deleteRowDescribedByQualifier

public void deleteRowDescribedByQualifier( com.webobjects.eocontrol.EOQualifier qualifier, EOEntity entity)

Deletes the row described by qualifier from the database table corresponding to entity. Invokes deleteRowsDescribedByQualifier and throws an exception unless exactly one row is deleted. A subclass of EOAdaptorChannel doesn't need to override this method.



deleteRowsDescribedByQualifier

public abstract int deleteRowsDescribedByQualifier( EOQualifier qualifier, EOEntity entity)

Implemented by subclasses to delete the rows described by qualifier from the database table corresponding to entity. Returns the number of rows deleted. Throws an exception on failure. Some possible reasons for failure are:

An adaptor channel subclass should override this method without invoking EOAdaptorChannel's implementation.

See Also: deleteRowDescribedByQualifier, isOpen, isFetchInProgress, hasOpenTransaction (EOAdaptorContext)



describeModelWithTableNames

public EOModel describeModelWithTableNames(NSArray tableNames)

Overridden by subclasses to create and return a default model containing entities for the tables specified in tableNames. Assigns the adaptor name and connection dictionary to the new model. This method is typically used in conjunction with describeTableNames and describeStoredProcedureNames.

EOAdaptorChannel's implementation does nothing. An adaptor channel subclass should override this method to create a default model from the database's metadata.



describeResults

public abstract NSArray describeResults()

Implemented by subclasses to return an array of EOAttributes describing the properties available in the current result set, as determined by selectAttributes, executeStoredProcedure, or a statement evaluated by evaluateExpression. Only invoke this method if a fetch is in progress as determined by isFetchInProgress.

An adaptor channel subclass should override this method without invoking EOAdaptorChannel's implementation.



describeStoredProcedureNames

public NSArray describeStoredProcedureNames()

Overridden by subclasses to read and return an array of stored procedure names from the database. This method is used in conjunction with addStoredProceduresNamed to build a default model in EOModeler. Throws an exception if an error occurs.



describeTableNames

public NSArray describeTableNames()

Overridden by subclasses to read and return an array of table names from the database. This method in conjunction with describeModelWithTableNames is used to build a default model.

EOAdaptorChannel's implementation simply returns null. An adaptor channel subclass should override this method to construct an array of table names from database metadata.



dictionaryWithObjectsForAttributes

public NSMutableDictionary dictionaryWithObjectsForAttributes( Object[] objects, NSArray attributes)

Used by EOAdaptorChannel subclasses to create dictionaries that can be returned from fetchRow. You don't ordinarily invoke this method unless you are writing your own concrete adaptor. If you are writing a concrete adaptor, use of this method is optional but strongly recommended because it enables performance optimizations. The objects in objects are the values for the row that correspond to the EOAttribute objects in attributes.

A subclass of EOAdaptorChannel shouldn't override this method.



evaluateExpression

public abstract void evaluateExpression(EOSQLExpression expression)

Implemented by subclasses to send expression to the database server for evaluation, beginning a transaction first and committing it after evaluation if a transaction isn't already in progress. Throws an exception if an error occurs. An EOAdaptorChannel uses this method to send SQL expressions to the database.

If expression results in a select operation being performed, you can fetch the results as you would if you had sent a selectAttributes. 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 adaptorChannelShouldEvaluateExpression and adaptorChannelDidEvaluateExpression.

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: fetchRow



executeStoredProcedure

public abstract void executeStoredProcedure( EOStoredProcedure storedProcedure, NSDictionary values)

Implemented by subclasses to execute storedProcedure. Any arguments to the stored procedure are in values, a dictionary whose keys are the argument names. Use fetchRow to get result rows and returnValuesForLastStoredProcedureInvocation to get return arguments and result status, if any. Throws an exception if an error occurs.

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 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



fetchRow

public abstract NSMutableDictionary fetchRow()

Implemented by subclasses to fetch the next row from the result set of the last selectAttributes, executeStoredProcedure, or evaluateExpression message sent to the receiver. Returns values for the receiver's attributesToFetch in a dictionary whose keys are the attribute names. When there are no more rows in the current result set, this method returns null, and invokes the delegate method adaptorChannelDidChangeResultSet if there are more results sets. When there are no more rows or result sets, this method returns null, ends the fetch, and invokes adaptorChannelDidFinishFetching. isFetchInProgress returns true until the fetch is canceled or until this method exhausts all result sets and returns null. This method also invoke the delegate methods adaptorChannelWillFetchRow and adaptorChannelDidFetchRow. Throws an exception if an error occurs.

An adaptor channel subclass should override this method without invoking EOAdaptorChannel's implementation.

See Also: setAttributesToFetch



insertRow

public abstract void insertRow( NSDictionary row, EOEntity entity)

Implemented by subclasses to insert the values of row into the table in the database that corresponds to entity. row is a dictionary whose keys are attribute names and whose values are the values to insert. Throws an exception on failure. Some possible reasons for failure are:

An adaptor channel subclass should override this method without invoking EOAdaptorChannel's implementation.



isFetchInProgress

public abstract boolean isFetchInProgress()

Implemented by subclasses to return true if the receiver is fetching, false otherwise. An adaptor channel is fetching if:

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: fetchRow



isOpen

public abstract boolean isOpen()

Implemented by subclasses to return true if the channel has been opened with openChannel, false if not. An adaptor channel subclass should override this method without invoking EOAdaptorChannel's implementation.

See Also: closeChannel



lockRowComparingAttributes

public void lockRowComparingAttributes( NSArray attributes, EOEntity entity, com.webobjects.eocontrol.EOQualifier qualifier, NSDictionary snapshot)

Attempts to lock a row in the database by selecting it with locking on. The lock operation succeeds if a select statement generated with qualifier retrieves exactly one row and the values in the row match the values in snapshot, a dictionary whose keys are attribute names and whose values are the values that were last fetched from the database.

lockRowComparingAttributes invokes selectAttributes 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 throws an exception. It also throws an exception 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 null.) 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

public abstract void openChannel()

Implemented by subclasses to put the channel and both its context and adaptor into a state where they are ready to perform database operations. Throws an exception if an error occurs. An adaptor channel subclass should override this method without invoking EOAdaptorChannel's implementation.

See Also: isOpen, closeChannel



performAdaptorOperation

public void performAdaptorOperation(EOAdaptorOperation adaptorOperation)

Performs adaptorOperation by invoking the adaptor channel method appropriate for performing the specified operation. For example, if the adaptor operator for adaptorOperation is EOAdaptorInsertOperator, this method invokes insertRow using information in adaptorOperation to supply the arguments. Throws an exception if an error occurs.

A subclass of EOAdaptorChannel doesn't need to override this method.

See Also: performAdaptorOperations



performAdaptorOperations

public void performAdaptorOperations(NSArray adaptorOperations)

Performs adaptor operations by invoking performAdaptorOperation with each EOAdaptorOperation object in the array adaptorOperations. An adaptor channel subclass may be able to override this method to take advantage of database-specific batch processing capabilities. Invokes the delegate methods adaptorChannelWillPerformOperations and adaptorChannelDidPerformOperations.

This method throws an exception if an error occurs. The exception's userInfo dictionary contains these keys:


Constant The corresponding value in the exception's userInfo dictionary
AdaptorOperationsKey An array of the EOAdaptorOperations being executed.
FailedAdaptorOperationKey The particular EOAdaptorOperation that failed.
AdaptorFailureKey If present, offers additional information on the type of error that occurred. Currently, the only possible value for this key is AdaptorOptimisticLockingFailure, 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

public NSDictionary primaryKeyForNewRowWithEntity(EOEntity entity)

Overridden by subclasses to return a primary key for a new row in the database table that corresponds to entity. The primary key returned from this method is a dictionary whose keys are the primary key attribute names. For example, suppose you've got a table MOVIE with primary key MOVIE_ID, and the corresponding Movie entity's primary key attribute is movieID. In this scenario, the dictionary returned from primaryKeyForNewRowWithEntity has one entry whose key is movieID and whose value is the unique value to assign. If the primary key is compound (made up of more than one attribute), the dictionary should contain an entry for each primary key attribute. Note, however, that the Enterprise Objects Frameworks adaptors don't handle compound primary keys; they return null from primaryKeyForNewRowWithEntity if the primary key is compound.

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 null.

EOAdaptorChannel's implementation simply returns null. 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).



primaryKeysForNewRowsWithEntity

public NSArray primaryKeysForNewRowsWithEntity( int numRows, EOEntity anEntity)

Description forthcoming.



returnValuesForLastStoredProcedureInvocation

public abstract NSDictionary returnValuesForLastStoredProcedureInvocation()

Implemented by subclasses to return stored procedure parameter and return values. Used in conjunction with executeStoredProcedure. The dictionary returned by this method has entries whose keys are stored procedure parameter names and whose values are the parameter values. The dictionary also contains a special entry for the stored procedures return value with the key "returnValue". Returns an empty dictionary for stored procedures that have void return types. Returns null if the stored procedure has results to fetch. In this case, you must use fetchRow until there are no more results to fetch before the return value will be available.

An adaptor channel subclass should override this method without invoking EOAdaptorChannel's implementation.



selectAttributes

public abstract void selectAttributes( NSArray attributes, EOFetchSpecification fetchSpecification, boolean flag, EOEntity entity)

Implemented by subclasses to select attributes in rows matching the qualifier in fetchSpecification and set the receiver's attributes to fetch. The selected rows compose one or more result sets, each row of which will be returned by subsequent fetchRow messages according to fetchSpecification's sort orderings. If flag is true, the rows are locked if possible so that no other user can modify them (the lock specification in fetchSpecification is ignored). Throws an exception if an error occurs. Some possible reasons for failure are:

An adaptor channel subclass should override this method without invoking EOAdaptorChannel's implementation.

See Also: setAttributesToFetch



setAttributesToFetch

public abstract void setAttributesToFetch(NSArray attributes)

Implemented by subclasses to specify the set of attributes used to describe fetch data from a corresponding select. attributes is an array of the attributes to fetch. This method is invoked after evaluateExpression but before the first call to fetchRow. This method throws an exception if invoked when there is no fetch in progress.

An adaptor channel subclass should override this method without invoking EOAdaptorChannel's implementation.

See Also: selectAttributes



setDelegate

public void setDelegate(Object delegate)

Sets the receiver's delegate to delegate, or removes its delegate if delegate is null. 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.



updateValuesInRowDescribedByQualifier

public void updateValuesInRowDescribedByQualifier( NSDictionary values, com.webobjects.eocontrol.EOQualifier qualifier, EOEntity entity)

Updates the row described by qualifier. Invokes updateValuesInRowsDescribedByQualifier and raises an exception unless exactly one row is updated.

A subclass of EOAdaptorChannel doesn't need to override this method.



updateValuesInRowsDescribedByQualifier

public abstract int updateValuesInRowsDescribedByQualifier( NSDictionary values, EOQualifier qualifier, EOEntity entity)

Implemented by subclasses to update the rows described by qualifier with the values in values. values is a dictionary whose keys are attribute names and whose values are the new values for those attributes (the dictionary need only contain entries for the attributes being changed). Returns the number of updated rows. Throws an exception if an error occurs. Some possible reasons for failure are:

An adaptor channel subclass should override this method without invoking EOAdaptorChannel's implementation.

See Also: updateValuesInRowDescribedByQualifier



© 2001 Apple Computer, Inc. (Last Published April 13, 2001)


Table of Contents