Documentation Archive Developer
Search
PATH Documentation > WebObjects

Up Previous Next

Updating with the Adaptor Sublayer

Synopsis

Describes how to update a row of the database using the adaptor channel's updateValuesInRowDescribedByQualifier method.

Description

There are three ways to update a row into the database with the adaptor sublayer. You can update using raw SQL using the adaptor channel's evaluateExpression method, the adaptor channel's updateValuesInRowDescribedByQualifier method, or a stored procedure.

In this topic we describe how to update a row using the updateValuesInRowDescribedByQualifier 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. However, you have to work with raw row dictionaries.

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

To update a row using the adaptor channel's updateValuesInRowDescribedByQualifier method, you need to provide

The following code updates a row using the adaptor sublayer.

 
EOAdaptorChannel myAdaptorChannel; // assume exists 
String modelName = "movies"; 
String entityName = "Movie"; 
 
NSMutableDictionary dict = new NSMutableDictionary(); 
dict.setObjectForKey (new Integer(95000000),"revenue"); 
 
EOQualifier myQualifier = EOQualifier.qualifierWithQualifierFormat 
    ("title = 'EOF III: The Multithreading'"); 
 
EOModel myModel = EOModelGroup.defaultGroup().modelNamed(modelName); 
EOEntity myEntity = myModel.entityNamed(entityName); 
 
// update row 
myAdaptorChannel.openChannel(); 
myAdaptorChannel.updateValuesInRowDescribedByQualifier 
    (dict,myQualifier,myEntity); 
myAdaptorChannel.closeChannel();	

The code first allocates and initializes a raw row dictionary for the changed values of the database row and creates the qualifier that identifies the row.

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

Update Failures

The update can fail for the following reasons:

  • The user logged on to the database does not have permission to update the row.
  • The EOAdaptorChannel is in an invalid state, for example, a fetch is in progress. To check if a fetch is in progress, use the adaptor channels isFetchInProgress method
  • The updated row fails to satisfy constraints defined in the database, for example, the primary key has been modified with an improper value.

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.

Up Previous Next[an error occurred while processing this directive]