Wiki source code of EOF-Using EOF-Deleting
Last modified by Pascal Robert on 2010/09/11 23:51
Show last authors
| author | version | line-number | content |
|---|---|---|---|
| 1 | == Deleting in EOF == | ||
| 2 | |||
| 3 | Usually deleting is pretty easy: | ||
| 4 | |||
| 5 | {{code 0="java"}} | ||
| 6 | |||
| 7 | Person person; //Assume is an EO that exists | ||
| 8 | EOEditingContext ec = person.editingContext(); //Always make sure you are using the correct editing context | ||
| 9 | ec.deleteObject(person); //Mark the EO for deletion | ||
| 10 | ec.saveChanges(); //Commit | ||
| 11 | |||
| 12 | {{/code}} | ||
| 13 | |||
| 14 | A little more robust example: | ||
| 15 | |||
| 16 | {{code 0="java"}} | ||
| 17 | |||
| 18 | Person person; /Assume is an EO that exists | ||
| 19 | EOEditingContext ec = person.editingContext(); | ||
| 20 | ec.deleteObject(person); | ||
| 21 | |||
| 22 | try { | ||
| 23 | ec.saveChanges(); | ||
| 24 | } catch (Exception e) { | ||
| 25 | //something bad happened, the delete didn't occur | ||
| 26 | //well don't just stand there, do something about it! | ||
| 27 | ec.revert(); // clean up the mess | ||
| 28 | } | ||
| 29 | |||
| 30 | {{/code}} | ||
| 31 | |||
| 32 | //NOTE: These examples assume that correct EOEditingContext locking is occuring, ProjectWonder's ERXEC auto-locking is highly recommended.// |