Documentation Archive Developer
Search
PATH  Documentation > WebObjects 4.5 > EOAccess Reference

Table of Contents

EOModel


Inherits from: NSObject
Conforms to: NSObject
(NSObject)
Declared in: EOAccess/EOModel.h




Class Description


An EOModel represents a mapping between a database schema and a set of classes based on the entity-relationship model. The model contains a number of EOEntity objects representing the entities (tables) of the database schema. Each EOEntity object has a number of EOAttribute and EORelationship objects representing the properties (columns or fields) of the entity in the database schema. For more information on attributes and relationships, see their respective class specifications.

An EOModel maintains a mapping between each of its EOEntity objects and a corresponding enterprise object class for use with the database level of the Enterprise Objects Framework. You can determine the EOEntity for a particular enterprise object with the entityForObject: method.

An EOModel is specific to a particular database server, and stores information needed to connect to that server. This includes the name of an adaptor framework to load so that the Enterprise Objects Framework can communicate with the database. Models are stored in the file system in a manner similar to adaptor framework. EOModel objects are usually loaded from model files built with the EOModeler application rather than built programmatically. If you need to programmatically load a model file, see the section "Loading a Model File" .

Models can have relationships that reference other models in the same model group. The other models may map to different databases and types of servers.

Models are organized into model groups; see the EOModelGroup class specification for more information.


Creating an EOModel Programmatically

The EOAdaptorChannel class declares methods for reading basic schema information from a relational database. You can use this information to build up an EOModel programmatically, and then enhance that model by defining extra relationships, flattening attributes, and so on. See the class description in the EOAdaptorChannel class specification for information on reading basic schema information, and see the other modeling classes' specifications for information on creating additional attributes and relationships.




Constants


In EOModel.h, EOModelEOAccess defines an NSString constant for the name of the notification it posts. For more information, see "Notifications" .



Method Types


Initializing an EOModel instance
- initWithContentsOfFile:
- initWithTableOfContentsPropertyList:path:
Saving a model
- encodeTableOfContentsIntoPropertyList:
- writeToFile:
Loading a model's objects
- loadAllModelObjects
Working with entities
- addEntity:
- removeEntity:
- removeEntityAndReferences:
- entityNames
- entityNamed:
- entities
- entitiesWithSharedObjects
Naming a model's components
- beautifyNames
Accessing the model's name
- setName:
- name
- path
Checking references
- referencesToProperty:
- externalModelsReferenced
Getting an object's entity
- entityForObject:
Accessing the adaptor bundle
- adaptorName
- setAdaptorName:
Accessing the connection dictionary
- setConnectionDictionary:
- connectionDictionary
Accessing the user dictionary
- setUserInfo:
- userInfo
Working with stored procedures
- addStoredProcedure:
- removeStoredProcedure:
- storedProcedureNames
- storedProcedureNamed:
- storedProcedures
Accessing the model's group
- setModelGroup:
- modelGroup
Accessing prototype attributes
- availablePrototypeAttributeNames
- prototypeAttributeNamed:


Instance Methods



adaptorName

- (NSString *)adaptorName

Returns the name of the adaptor for the receiver. This name can be used with EOAdaptor's adaptorWithName: class method to create an adaptor.

addEntity:

- (void)addEntity:(EOEntity *)anEntity

Adds anEntity to the receiver. Raises an NSInvalidArgumentException if an error occurs (for example, if anEntity doesn't exist, if the entity belongs to another model, or if an entity of the same name is already in the receiver).

See Also: - entities, - removeEntity:, - removeEntityAndReferences:



addStoredProcedure:

- (void)addStoredProcedure:(EOStoredProcedure *)storedProcedure

Adds storedProcedure to the receiver. Raises an NSInvalidArgumentException if an error occurs (for example, if a stored procedure of the same name is already in the receiver).

See Also: - removeStoredProcedure:, - storedProcedures, - storedProcedureNamed:, - storedProcedureNames



availablePrototypeAttributeNames

- (NSArray *)availablePrototypeAttributeNames

Returns a list of available prototype names.

See Also: - prototypeAttributeNamed:



beautifyNames

- (void)beautifyNames

Makes all of the receiver's named components conform to a standard convention. Names that conform to this style are all lower-case except for the initial letter of each embedded word other than the first, which is upper case. Thus, "NAME" becomes "name", and "FIRST_NAME" becomes "firstName".

See Also: + externalNameForInternalName:separatorString:useAllCaps: (NSString Additions), - beautifyName ( EOEntity, EOAttribute, EORelationship, EOStoredProcedure), - name



connectionDictionary

- (NSDictionary *)connectionDictionary

Returns a dictionary containing information used to connect to the database server. The connection dictionary is the place to specify default login information for applications using the model. See the EOAdaptor class specification for more information.

encodeTableOfContentsIntoPropertyList:

- (void)encodeTableOfContentsIntoPropertyList:(NSMutableDictionary *)propertyList

Encodes the receiver into propertyList. This method is used to get an ASCII representation of an EOModel in property list format.

See Also: - initWithTableOfContentsPropertyList:path:



entities

- (NSArray *)entities

Returns an array containing the receiver's entities. Note that this method loads every entity, and thus defeats the benefits of incremental model loading.

See Also: - entityNames



entitiesWithSharedObjects

- (NSArray *)entitiesWithSharedObjects

Returns an array of entities that have objects to load into a shared editing context.

entityForObject:

- (EOEntity *)entityForObject:(id)anEO

Returns the entity associated with anEO, whether anEO is an instance of an enterprise object class, an instance of EOGenericRecord, or a fault (see the EOFault class specification for information on faults). Returns nil if anEO has no associated entity.

entityNamed:

- (EOEntity *)entityNamed:(NSString *)name

Returns the entity named name, or nil if no such entity exists. Posts an EOEntityLoadedNotification when the entity is loaded.

See Also: - entityNames, - entities



entityNames

- (NSArray *)entityNames

Returns an array containing the names of the EOModel's entities.

See Also: - entities, - entityNamed:



externalModelsReferenced

- (NSArray *)externalModelsReferenced

Returns an array containing those models that are referenced by this model.

See Also: - referencesToProperty:



initWithContentsOfFile:

- initWithContentsOfFile:(NSString *)path

Initializes a newly-allocated EOModel by reading the contents of the file named path as a model archive. The file specified by path can either be an old-style (.eomodel) or new-style (.eomodeld) model file. Sets the EOModel's name and path. initWithContentsOfFile: raises an NSInvalidArgumentException if for any reason it cannot initialize the model from the file specified by path.

See Also: - name, - path



initWithTableOfContentsPropertyList:path:

- initWithTableOfContentsPropertyList:(NSDictionary *)tableOfContents path:(NSString *)path

Uses tableOfContents (which is the property list representation of an EOModel) with the file name path to initialize the receiver.

See Also: - encodeTableOfContentsIntoPropertyList:



loadAllModelObjects

- (void)loadAllModelObjects

Loads any of the receiver's entities, stored procedures, attributes, and relationships that have not yet been loaded.

See Also: - attributes (EOEntity), - entities, - relationships (EOEntity), - storedProcedures



modelGroup

- (EOModelGroup *)modelGroup

Returns the model group of which the receiver is a part.

See Also: - setModelGroup:



name

- (NSString *)name

Returns the receiver's name.

See Also: - path, - initWithTableOfContentsPropertyList:path:



path

- (NSString *)path

Returns the name of the EOModel file used to create the receiver, or nil if the model wasn't initialized from a file.

See Also: - name - initWithContentsOfFile:



prototypeAttributeNamed:

- (EOAttribute *)prototypeAttributeNamed:(NSString *)attributeName

Returns the prototype attribute for the given attributeName. It first looks for the prototype in an entity named EOadaptorNamePrototypes (which can be in any model in the receiver's model group). If the prototype isn't found there or if the EOadaptorNamePrototypes entity doesn't exist, it then looks in an entity named EOPrototypes (in any model in the model group). If the search is still unsuccessful, this method finally looks for the prototype in the list of prototypes provided by the adaptor itself.

See Also: - availablePrototypeAttributeNames



referencesToProperty:

- (NSArray *)referencesToProperty:(id)aProperty

Returns an array of all properties in the receiver that reference aProperty, whether derived attributes, relationships that reference aProperty, and so on. Returns nil if aProperty isn't referenced by any of the properties in the model.

See Also: - externalModelsReferenced



removeEntity:

- (void)removeEntity:(EOEntity *)name

Removes the entity with the given name without performing any referential integrity checking.

See Also: - addEntity:, - removeEntityAndReferences:



removeEntityAndReferences:

- (void)removeEntityAndReferences:(EOEntity *)entity

Removes entity and any attributes or relationships in other entities that reference entity.

See Also: - removeEntity:, - addEntity:



removeStoredProcedure:

- (void)removeStoredProcedure:(EOStoredProcedure *)storedProcedure

Removes storedProcedure without checking to see if an entity uses it.

See Also: - addStoredProcedure:, - storedProcedures



setAdaptorName:

- (void)setAdaptorName:(NSString *)adaptorName

Sets the name of the receiver's adaptor to adaptorName.

See Also: + availableAdaptorNames (EOAdaptor)



setConnectionDictionary:

- (void)setConnectionDictionary:(NSDictionary *)connectionDictionary

Sets the dictionary containing information used to connect to the database to connectionDictionary. See the EOAdaptor class specification for more information on working with connection dictionaries.

See Also: adaptorWithModel: (EOAdaptor)



setModelGroup:

- (void)setModelGroup:(EOModelGroup *)group

Sets the model group of which the receiver should be a part. Note that you shouldn't change an EOModel's model group after it has been bound to other models in its group.

See Also: - modelGroup



setName:

- (void)setName:(NSString *)name

Sets the name of the receiver to name.

setUserInfo:

- (void)setUserInfo:(NSDictionary *)dictionary

Sets the dictionary of auxiliary data, which your application can use for whatever it needs. dictionary can only contain property list data types-that is, NSString, NSDictionary, NSArray, and NSData.

storedProcedureNamed:

- (EOStoredProcedure *)storedProcedureNamed:(NSString *)name

Returns the stored procedure named name, or nil if the model doesn't contain a stored procedure with the given name.

See Also: - storedProcedureNames, - storedProcedures



storedProcedureNames

- (NSArray *)storedProcedureNames

Returns an array containing the names of all of the model's stored procedures.

See Also: - storedProcedureNamed:, - storedProcedures



storedProcedures

- (NSArray *)storedProcedures

Returns an array containing all of the model's stored procedures. Note that this method loads each of the model's stored procedures, thus defeating the benefits of incremental model loading.

See Also: - storedProcedureNames, - storedProcedureNamed:



userInfo

- (NSDictionary *)userInfo

Returns a dictionary of user data. You can use this to store any auxiliary information it needs.

See Also: - setUserInfo:



writeToFile:

- (void)writeToFile:(NSString *)path

Saves the receiver in the directory specified by path. If the file specified by path already exists, a backup copy is first created (using path with a "~" character appended). As a side-effect, this method resets the current path.

Raises an NSInvalidArgumentException on any error which prevents the file from being written.

See Also: - path




Notifications


EOModel declares and posts the following notification.

EOEntityLoadedNotification

Posted after an EOEntity is loaded into memory. The notification contains:
Notification Object The entity that was loaded.
Userinfo None



Table of Contents