Documentation Archive Developer
Search
PATH  WebObjects 4.0 Documentation > WebObjects Programming Topics

Deleting with the Adaptor Level

Synopsis

Describes how to delete a row from the database using the adaptor level.

Description

The adaptor level is a server-independent interface for working with the relational database consisting of an EOAdaptor, an EOAdaptorContext and an EOAdaptorChannel. In this level, the database rows are represented as instances of NSDictionary.

The EOAdaptor manages the EOModel, a model that maps the tables and relationships in the database to EOF objects. The EOAdaptor is also responsible for instantiating the correct subclass for the database specific adaptor layer. The EOAdaptorContext manages the database transactions. The EOAdaptorChannel does all the inserts, updates, and deletes, as well as executing SQL. Before you send any SQL to the database, you need to:

To update the database at the adaptor level, you need to specify an EOQualifier which specifies the row to delete. The following code uses the adaptor level to delete a row from the database.

Figure 1. Objective-C Code
- (void) rawDelete:(EOEditingContext *)ec forModelNamed:(NSString *)
    modelName forEntityNamed:(NSString *)entityName withQualifierString:
    (NSString *)qualString
{
    EOModel *myModel;
    EOEntity *myEntity;
    EOQualifier *myQualifier;
    EOAdaptor *myAdaptor;
    EOAdaptorContext *myAdaptorContext;
    EOAdaptorChannel *myAdaptorChannel;
    // get the model, entity, and qualifier describing row to update
    myModel = [[ec modelGroup] modelNamed:modelName];
    myEntity = [ec entityNamed:entityName];
    myQualifier = [EOQualifier qualifierWithQualifierFormat:qualString];
    // get the adaptor, adaptor context, and adaptor channel
    myAdaptor = [EOAdaptor adaptorWithModel:myModel];
    myAdaptorContext = [myAdaptor createAdaptorContext];
    myAdaptorChannel = [myAdaptorContext createAdaptorChannel];
    // delete the row from the database
    [myAdaptorChannel openChannel];
    [myAdaptorChannel deleteRowDescribedByQualifier:myQualifier
        entity:myEntity];
    [myAdaptorChannel closeChannel];	
}

 

The deletion can fail for the following reasons:

    · The EOAdaptorChannel is not open.

    · The user logged on to the database does not have permission to update the row.

    · The EOAdaptorChannel is in an invalid state (for example, when a fetch is in progress).

    · The updated row fails to satisfy constraints defined in the database.

See Also

Questions

Keywords

Revision History

22 July, 1998. Seejo Pylappan. First Draft.
13 November, 1998. Clif Liu. Second Draft.