Documentation Archive Developer
Search
PATH  WebObjects 4.5 Documentation > EOControl Reference

Table of Contents

EOEnterpriseObject



Initialization

Enterprise objects are initialized using initWithEditingContext:classDescription:globalID:, which by default simply invokes init. You can place your custom initialization code in init, or you can override initWithEditingContext:classDescription:globalID: to take advantage of the extra information available with this method.

After an enterprise object is created, it receives an awake... message. The particular message depends on whether the object has been fetched from a database or created anew in the application. In the former case, it receives an awakeFromFetchInEditingContext: message. In the latter, it receives an awakeFromInsertionInEditingContext: message. The receiver can override either method to perform extra initialization-such as setting default values-based on how it was created.


Change Notification

For the Framework to keep all areas of an application synchronized, enterprise objects must notify their observers when their state changes. Objects do this by invoking willChange before altering any instance variable or other kind of state. This method informs all observers that the invoker is about to change. See the EOObserverCenter class specification for more information on change notification.

The primary observer of changes in an object is the object's EOEditingContext. EOEditingContext is a subclass of EOObjectStore that manages collections of objects in memory, tracking inserts, deletes, and updates, and propagating changes to the persistent store as needed. You can get the EOEditingContext that contains an object by sending the object an editingContext message.


Object and Class Metadata Access

One of the larger groups of methods in the EOEnterpriseObject interface provides information about an object's properties. Most of these methods consult an EOClassDescription to provide their answers. An object's classDescription method returns it's class description. See the EOClassDescription class specification for the methods it implements. Methods you can send directly to an enterprise object include entityName, which provides the name of the entity mapped to the receiver's class; allPropertyKeys, which returns the names of all the receiver's class properties, attributes and relationships alike; and attributeKeys, which returns just the names of the attributes.

Some methods return information about relationships. toOneRelationshipKeys and toManyRelationshipKeys return the names of the receiver's relationships, while isToManyKey: tells which kind a particular relationship is. deleteRuleForRelationshipKey: indicates what should happen to the receiver's relationships when it's deleted. Similarly, ownsDestinationObjectsForRelationshipKey: indicates what should happen when another object is added to or removed from the receiver's relationship. Another method, classDescriptionForDestinationKey:, returns the EOClassDescription for the objects at the destination of a relationship.


Snapshots

The key-value coding methods define a general mechanism for accessing an object's properties, but you first have to know what those properties are. Sometimes, however, the Framework needs to preserve an object's entire state for later use, whether to undo changes to the object, compare the values that have changed, or just keep a record of the changes. The snapshotting methods provide this service, extracting or setting all properties at once and performing the necessary conversions for proper behavior. snapshot returns a dictionary containing all the receiver's properties, and updateFromSnapshot: sets properties of the receiver to the values in a snapshot.

A special kind of snapshot is also used to merge an object's uncommitted changes with changes that have been committed to the external store since the object was fetched. These methods are changesFromSnapshot and reapplyChangesFromDictionary:.


Writing an Enterprise Object Class

Some of the EOEnterpriseObject methods are for enterprise objects to implement or override, and some are meant to be used as defined by the Framework. Many methods are used internally by the Framework and rarely invoked by application code. The tables in this section highlight the methods that you typically override or implement in a custom enterprise object.


Creation
- initDesignated initializer.
- initWithEditingContext:classDescription:globalID:Optional initializer.
- awakeFromFetchInEditingContext:Performs additional initialization after the object is fetched.
- awakeFromInsertionInEditingContext:Performs additional initialization after the object is created in memory.


Key-Value Coding: Accessing Properties and Relationships
- setKey:Sets the value for the property named key.
- keyRetrieves the value for the property named key.
- addToKey:Adds an object to a relationship property named key.
- removeFromKey:Removes an object from the property named key.
- handleTakeValue:forUnboundKey:Handles a failure of takeValue:forKey: to find a property.
- handleQueryWithUnboundKey:Handles a failure of valueForKey: to find a property.
- unableToSetNullForKey:Handles an attempt to set a non-object property's value to nil.


Validation
- validateKey:Validates a value for the property named key.
- validateForDeleteValidates all properties before deleting the receiver.
- validateForInsertValidates all properties before inserting the receiver.
- validateForSaveValidates all properties before saving the receiver.
- validateForUpdateValidates all properties before updating the receiver.


Table of Contents