Inherits From:
EOAdaptorChannel : NSObject
Declared in: SybaseEOAdaptor/SybaseChannel.h
The feature SybaseChannel adds to EOAdaptorChannel is processing for compute rows and stored procedures.
Processing Compute Rows and Stored Procedures
The delegate methods used for processing compute rows and stored procedures give you access to the three types of non-regular rows supported by Sybase: compute rows, return parameters (from a stored procedure), and status from a stored procedure. Because the access layer can only handle regular table rows, the Sybase adaptor channel normally skips non-regular rows. However, you can use the delegate methods to intercept non-regular rows before they are skipped. These delegate methods are sybaseChannel:willFetchAttributes:forRowOfType:
withComputeRowId: and sybaseChannel:willReturnRow:ofType:withComputeRowId: The method sybaseChannel:willFetchAttributes:... is invoked when a row is fetched, while sybaseChannel:willReturnRow:... is invoked when a row is about to be returned. Based on the type of the row, the delegate can specify the appropriate behavior. This enables you to use data in one of the three non-regular row types and either extract the data from them or use the method describeResults
to return an array of attributes that describe the properties available in the current result set. Using describeResults
is appropriate if you're not concerned with format-for example, if you're just writing raw data to a report.
Note: The regular rows in the results from a stored procedure must map to the attributes in the corresponding entity, and must be in alphabetical order.
Generating Primary Keys
Each adaptor provides a database-specific implementation of the method primaryKeyForNewRowWithEntity: for generating primary keys. The SybaseChannel's implementation uses a table named eo_sequence_table to keep track of the next available primary key value for a given table. The table contains a row for each table for which the adaptor provides primary key values. The statement used to create the eo_sequence_table is:
create table eo_sequence_table (
table_name varchar(32),
counter int null
)
SybaseChannel uses a stored procedure named eo_pk_for_table to access and maintain the primary key counter in eo_sequence_table. The stored procedure is defined as follows:
create procedure
eo_pk_for_table @tname varchar(32) as
begin
define @max int
update eo_sequence_table
set counter = counter + 1
where table_name = @tname
select counter
from eo_sequence_table
where table_name = @tname
end
The stored procedure increments the counter in the eo_sequence_table row for the specified table, selects th counter value, and returns it. SybaseChannel executes this eo_pk_for_table stored procedure from primaryKeyForNewRowWithEntity: and returns the stored procedure's return value.
To use SybaseChannel's database-specific primary key generation mechanism, be sure that your database accommodates the adaptor's scheme. To modify your database so that it supports the adaptor's mechanism for generating primary keys, use EOModeler. For more information on this topic, see Enterprise Objects Framework Developer's Guide.
Methods Implemented By the Delegate
sybaseChannel:willFetchAttributes:forRowOfType:withComputeRowId:
- (NSArray *)sybaseChannel:
(SybaseChannel *)channelwillFetchAttributes:
(NSArray *)attributesforRowOfType:
(SybaseRowType)rowTypewithComputeRowId:
(int)computeRowId
Invoked whenever a row is fetched. The delegate can return nil, which causes the row to be skipped, or can return a substitute set of attributes that is appropriate for the type of row being fetched. Delegates can have the channel fabricate a set of attributes for the current non-regular row by calling describeResults.
For example, the following implementation checks the row type; if it's a regular row, it simply returns the attributes. If it's not a regular row type, describeResults
is used to return an array of attributes that describe the properties available in the current result set. Note that describeResults
always describes the current row type.
- (NSArray *)sybaseChannel:(SybaseChannel *)channel
willFetchAttributes:(NSArray *)attributes
forRowOfType:(SybaseRowType)rowType
withComputeRowId:(int)computeRowId
{
if (rowType == SybaseRegularRow)
return attributes;
attributes = [(EOAdaptorChannel *) channel describeResults];
return attributes;
}
sybaseChannel:willReturnRow:ofType:withComputeRowId:
- (BOOL)sybaseChannel:
(SybaseChannel *)channel willReturnRow:
(NSDictionary *)row ofType:
(SybaseRowType)rowType withComputeRowId:
(int)computeRowId
Invoked once a row has been read from the database and packaged into the dictionary. Delegates can return YES to cause the row to be returned from fetchAttributes:WithZone:, or they can return NO to cause the row to be skipped.
For example, the following implementation checks each row type and uses NSLog()
to output a message describing the row's type. In this example all rows are returned, but you could use this template to selectively return or not return rows based on type.
- (BOOL)sybaseChannel:(SybaseChannel *)channel
willReturnRow:(NSDictionary *)row ofType:(SybaseRowType)rowType
withComputeRowId:(int)computeRowId
{
switch (rowType) {
case SybaseRegularRow:
break;
case SybaseComputeRow:
NSLog(@"Returning compute row");
break;
case SybaseReturnParameterRow:
NSLog(@"Returning return parameter row");
break;
case SybaseReturnStatusRow:
NSLog(@"Returning return status row");
break;
}
return YES;
}
Copyright © 1997, Apple Computer, Inc. All rights reserved.