Table of Contents Previous Section

Using EOEditingContext to Archive Custom Objects

In an Enterprise Objects application, an EOEditingContext manages a graph of enterprise objects which represent records fetched from a database. You send messages to the EOEditingContext to fetch objects from the database, insert or delete objects, and save the data from the changed objects back to the database. (See the Enterprise Objects Framework Developer's Guide for more information.)

In WebObjects, applications that use the Enterprise Objects framework must enlist the help of the EOEditingContext to archive enterprise objects. The primary reason is so that the EOEditingContext can keep track, from one transaction to the next, of the objects it is designed to manage. But using an EOEditingContext for archiving also benefits your application in these other ways:

An enterprise object (like any other object that uses the OpenStep archiving scheme) makes itself available for archiving by declaring that it conforms to the NSCoding protocol and by implementing the protocol's two methods, encodeWithCoder: and initWithCoder:. It implements these methods like this:

- (void)encodeWithCoder:(NSCoder *)aCoder {
    [EOEditingContext encodeObject:self withCoder:aCoder];
}

- (id)initWithCoder:(NSCoder *)aDecoder {
    [EOEditingContext initObject:self withCoder:aDecoder];
    return self;
}

The enterprise object simply passes on responsibility for archiving and unarchiving itself to the EOEditingContext class, by invoking the encodeObject:withCoder: and initObject:withCoder: class methods and passing a reference to itself (self) as one of the arguments. The EOEditingContext takes care of the rest. (See the EOEditingContext class reference for more information.)

Table of Contents Next Section