On May 1, 2010, at 10:01 AM, Farrukh Ijaz wrote:

Is it legal to perform saveChanges/revert on EOEditingContext in a traditional JDBC transaction commit/rollback style?

EOEditingContext ec = // Got EOEditingContext from Somewhere...
// ec is not locked...

Find gun.
Shoot self in head.
Don't worry about rest of code.

This is so very not safe.  An unlocked editing  context is a bomb.


// did a lot of fetches...
// modified some objects fetched using this ec...
try {
        ec.lock();
        ec.saveChanges();
} catch(Exception ex) {
        throw ex;
} finally {
        ec.revert();
        ec.unlock();
}

What can be the potential problem in the above approach? Sorry if I sound stupid here but this is quite a good practice in JDBC style coding :)


This is not JDBC. :-) An editing context is not a database transaction.

One of these two patterns is the usual practice:

// ec is locked and has been before fetching, or inspecting or modifying objects

try {
        ec.saveChanges();
} catch(EOGeneralAdaptorException e) {
        // Deal with exception
        // prepare to present exception to user
}
} catch(EOValidationException e) {
        // Deal with exception
        // prepare to present exception to user
}


If you really want to reverse all changes rather than try to correct the problem:
try {
        ec.saveChanges();
} finally {
        ec.revert();
}


Chuck



--
Chuck Hill             Senior Consultant / VP Development

Practical WebObjects - for developers who want to increase their overall knowledge of WebObjects or who are trying to solve specific problems.
http://www.global-village.net/products/practical_webobjects







_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to