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

 

 

Editing EOs

EOF provides an abstraction of common database operations - removes you from SQL perculiarities

1. To edit a row in database you edit the analogous object

2. To create a new row in database you create a new object

3. Editing context tracks the changes

4. Notify editing context when you want to committ these changes to the database

You should save after significant operations to keep database up to date

NOTE: saving is an expensive operation, so do it as little as possible

 

SQL
EOF
Example Code
UPDATE edit EO directly

editing context observes

customer.setName("Joe");
INSERT create EO object

tell editing context

customer = new Customer();

ec.insertObject(customer);

DELETE tell editing context ec.deleteObject(customer);
COMMIT tell editing context ec.saveChanges();

 

To find which editing context a object belongs to if you have more than 1

customer.editingcontext();

Editing Context

Observes changes in enterprise objects

Tracks inserts and deletes

Maintains pending edits without accessing the database

Supports undo and redo logic

Changes only exist in editing context untill you explicitly save to the database - allows a number of changes to be made before accessing the database

How does the ec know when an object is changed?

The accessor method tells it

....StoredValueFor Key() Methods store and retrieve values from the EOGenericRecord's built-in dictionary and notify the ec that the object has changes

    public String posterName() {
        return (String)storedValueForKey("posterName");
    }

    public void setPosterName(String value) {
//access dictionary elements directly
        takeStoredValueForKey(value, "posterName");
    }

Stored Value Encoding

Looks for getname(), name(), methods then for name variable in sequence until it finds a key