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

  

Deleting with the Adaptor Sublayer

Synopsis

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

Description

There are three ways to delete a row into the database with the adaptor sublayer. You can use raw SQL employing the adaptor channel's evaluateExpression method, the adaptor channel's deleteRowDescribedByQualifier method, or a stored procedure.

In this topic we describe how to delete a row using the deleteRowDescribedByQualifier method. This method eliminates the overhead associated with snapshots, uniquing, and fault creation. Furthermore, the source code does not depend on the particular database you use.

If you are working with an editing context and deleting using the adaptor sublayer at the same time, EOF does not realize that an objected has been deleted. You need to synchronize any enterprise objects with the changes to the database.

To delete a row using the adaptor channel's deleteRowDescribedByQualifier method, you need to provide

The following code deletes a row using the adaptor sublayer.

 
EOAdaptorChannel myAdaptorChannel; // assume exists 
String modelName = "movies"; 
String entityName = "Movie"; 
 
EOQualifier myQualifier = EOQualifier.qualifierWithQualifierFormat 
    ("title = 'EOF III: The Multithreading'"); 
 
EOModel myModel = EOModelGroup.defaultGroup().modelNamed(modelName) 
EOEntity myEntity = myModel.entityNamed(entityName); 
 
// delete row 
myAdaptorChannel.openChannel(); 
myAdaptorChannel.deleteRowsDescribedByQualifier(myQualifier,myEntity); 
myAdaptorChannel.closeChannel();	

The code first creates the qualifier that identifies the row you wish to delete.

The code then finds the EOModel corresponding to the model name in the default model group. The default model group, accessed using EOModelGroup.defaultGroup() is a collection of EOModel objects corresponding to the models in the project's Resources suitcase. If you already have the EOModel, you don't need this step. Next, the code determines the EOEntity corresponding to the given entity name from the EOModel.

Before performing deleteRowsDescribedByQualifier with the adaptor channel, the code establishes a connection to the database using the openChannel method. The closeChannel method invocation disconnects the channel from the database.

Deleting Multiple Rows

The deleteRowDescribedByQualifier method deletes a single row from the database. If the qualifier matches more than one row, the method deletes the matching rows and raises an exception. If you need to delete more than one row, use the deleteRowsDescribedByQualifier which will not raise an exception when multiple rows match the qualifier. This method also returns the number of rows that were deleted.

Deletion Failures

The deletion can fail for the following reasons:

  • The user logged on to the database does not have permission to delete the row.
  • The EOAdaptorChannel is in an invalid state for inserting, for example, a fetch is in progress. To test if a fetch is in progress, use the adaptor channel's isFetchInProgress method.

See Also

Questions

Keywords

Revision History

22 July, 1998. Seejo Pylappan. First Draft.

13 November, 1998. Clif Liu. Second Draft.

16 March, 1999. Clif Liu. Third Draft.

 

© 1999 Apple Computer, Inc.