Main Menu
Lecture 1
Lecture 2
Lecture 3
Lecture 4
Lecture 6
Lecture 7
 

 

 

Inserting a new Enterprise Object

//get the editing context 
EOEditingContext ec = session().defaultEditingContext();
//create the instance
Student student = new Student();
//insert in the editing context
ec.insertObject(student);
//will become a new row in database at next save

      

Updating and Deleting an EO

object is registered with ec by either fetching or inserting

send message to object and the ec observes

//To update
student.setFirstName("Owen");
//To delete
//find the editing context the object is registered with
EOEditingContext ec = student.editingContext();
ec.deleteObject(student);

      

Saving, reverting, refetching and undoing

//get the editing context 
EOEditingContext ec = session().defaultEditingContext(); 
// Look up the API on what the follwoing functions do. 
//When shoudl you revert and when shoudlyou refetch ?
ec.saveChanges();
ec.revert();
ec.refetch();
ec.undo();
ec.redo();