EOGenericRecord

Inherits From:
NSObject

Conforms To: NSObject (NSObject)

Declared in: EOAccess/EOGenericRecord.h

Class Description

EOGenericRecord is a generic enterprise object class that can be used in place of custom classes when you don't need custom behavior. An EOGenericRecord object has an EOClassDescription that provides metadata about the generic record, including the name of the entity that the generic record represents and the names of the record's attributes and relationships. A generic record stores its properties in an NSDictionary using its attribute and relationship names as keys.

In the typical case of applications that access a relational database, the access layer's modeling objects are an important part of how generic records map to database rows: If an EOModel doesn't have a custom enterprise object class defined for a particular entity, an EODatabaseChannel using that model creates EOGenericRecords when fetching objects for that entity from the database server. During this process, the EODatabaseChannel also sets each generic record's classDescription to an EOEntityClassDescription, providing the link to the record's associated modeling objects.

Creating an Instance of EOGenericRecord

The best way to create an instance of EOGenericRecord is using the EOClassDescription method createInstanceWithEditingContext:globalID:zone: as follows:

id newEO;

NSString *entityName;             // Assume this exists.

newEO = [[EOClassDescription descriptionForEntityName:entityName]

        createInstanceWithEditingContext:nil

        globalID:nil

        zone:nil];

createInstanceWithEditingContext:globalID:zone: is preferable to EOGenericRecord's init... method because the same code works if you later use a custom enterprise object class instead of EOGenericRecord. You can get an EOClassDescription for an entity name as shown above. Alternatively, you can get an EOClassDescription for a destination key of an existing enterprise object as follows:

id newEO;

id existingEO;              // Assume this exists.

NSString *relationshipName; // Assume this exists.

EOClassDescription *description = [existingEO classDescription];

newEO = [[description classDescriptionForDestinationKey:relationshipName]

        createInstanceWithEditingContext:editingContext

        globalID:nil

        zone:nil];

The technique in this example is useful for inserting a new destination object into an existing enterprise object-for creating a new Movie object to add to a Studio's array of Movies, for example.

Creating instances
- initWithEditingContext:classDescription:globalID:
Accessing properties
- takeValue:forKey:
- valueForKey:
- takeStoredValue:forKey:

Instance Methods

initWithEditingContext:classDescription:globalID:

- (id)initWithEditingContext: (EOEditingContext *)anEditingContext
classDescription: (EOClassDescription *)aClassDescription
globalID: (EOGlobalID *)globalID

The designated initializer, this method initializes a newly allocated EOGenericRecord to get its metadata from aClassDescription. You can pass nil for anEditingContext and globalID, because the arguments are optional: EOGenericRecord's implementation does nothing with them. Raises an NSInternalInconsistencyException if aClassDescription is nil . Returns self .

You shouldn't use this method to create new EOGenericRecords. Rather, use EOClassDescription's createInstanceWithEditingContext:globalID:zone: method. See the class description for more information.

takeStoredValue:forKey:

- (void)takeStoredValue:(id)value forKey:(NSString *)key

Overrides NSObject's takeStoredValue:forKey: method to invoke takeValue:forKey: For a description of how this method behaves for custom enterprise objects, see the "NSObject Additions" class specification.

takeValue:forKey:

- (void)takeValue: (id)value forKey: (NSString *)key

Invokes its willChange method, and sets the value for the property identified by key to value. If value is nil , this method removes the receiver's dictionary entry for key. EOGenericRecord overrides NSObject's implementation. If key is not one of the receiver's attribute or relationship names, EOGenericRecord's implementation does not invoke handleTakeValue:forUnboundKey: . Instead, EOGenericRecord's implementation does nothing.

See also: - valueForKey:

valueForKey:

- (id)valueForKey: (NSString *)key

Returns the value for the property identified by key. EOGenericRecord overrides NSObject's implementation. If key is not one of the receiver's attribute or relationship names, EOGenericRecord's implementation does not invoke handleTakeValue:forUnboundKey: . Instead, EOGenericRecord's implementation simply returns nil .

See also: - takeValue:forKey:

Copyright © 1997, Apple Computer, Inc. All rights reserved.