WebObjects 5.4.2

com.webobjects.eoaccess
Class EOModel

java.lang.Object
  extended by com.webobjects.eoaccess.EOModel
All Implemented Interfaces:
NSDisposable

public class EOModel
extends Object
implements NSDisposable

An EOModel represents a mapping between a database schema and a set of classes based on the entity-relationship model for an application. The model contains a number of EOEntity objects representing the tables (entities) of the database schema. Each EOEntity object has a number of EOAttribute and EORelationship objects representing the properties (columns or fields) of the table (entity) in the database schema.

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 can store information needed to connect to that server as well as the name of an adaptor framework to load so that the Enterprise Objects Framework can communicate with the database.

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

Creating an EOModel Programmatically

EOModel files are usually built using the EOModeler application, but it is possible to build an EOModel file programmatically if needed. 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.

Loading a Model File

EOModel files are typically stored in a project or a framework. To load an EOModel, provide a model file's path to the constructor. Note that loading an EOModel doesn't have the effect of loading all of its entities. EOModel files can be quite large, so to reduce start-up time, entity definitions are only loaded as needed. This incremental model loading is possible because an EOModel actually consists of one index file and two files for each entity. Models have an .eomodeld file wrapper ( which is actually a directory), and the individual entity files within the model are in ASCII format. The index file has the name index.eomodeld, and it contains the connection dictionary, the adaptor name, and a list of all of the entities in the model. This is the file that is loaded when you create a new model from a path.

The two entity files consist of a property list (.plist) file that describes the entity and a fetch specification (.fspec) file that describes any named fetch specifications for that entity.

Some of the EOModel methods contain the string "TableOfContents". An EOModel's table of contents corresponds to its index.eomodeld file, which is used to access the model's entities.

When an entity is loaded, EOModel posts an EntityLoadedNotification.

See Also:
EOModel.entityForObject(EOEnterpriseObject object)

Nested Class Summary
protected static class EOModel.EOModelFileNameFilter
          Used to filter out all the EOModel managed file and copy teh rest of the file over to the new model.
 
Field Summary
static String EntityLoadedNotification
          The notification posted after an EOEntity is loaded into memory.
 
Constructor Summary
  EOModel()
          Creates and returns a new EOModel.
protected EOModel(NSDictionary propertyList, String path)
           
protected EOModel(NSDictionary propertyList, URL url)
           
  EOModel(String path)
          Deprecated. use EOModel(URL url) instead.
  EOModel(URL url)
          Creates a new EOModel object by reading the contents of the model archive at url.
 
Method Summary
 String adaptorName()
          Returns the name of the adaptor for the receiver.
 void addEntity(EOEntity entity)
          Adds entity to the receiver.
 void addStoredProcedure(EOStoredProcedure storedProcedure)
          Adds storedProcedure to the receiver.
 NSArray availablePrototypeAttributeNames()
          Returns a list of names of all available prototypes.
 void beautifyNames()
          Makes all of the receiver's named components conform to a standard convention.
 NSDictionary connectionDictionary()
          Returns a dictionary containing information used to connect to the database server.
 void dispose()
          Conformance to NSDisposable.
 void encodeTableOfContentsIntoPropertyList(NSMutableDictionary result)
          Encodes the receiver into result.
 NSArray entities()
          Returns an array containing the receiver's entities.
 NSArray entitiesWithSharedObjects()
          Returns an array of entities that have objects to load into a shared editing context.
 EOEntity entityForObject(EOEnterpriseObject object)
          Returns the entity associated with object, whether object is an instance of an Enterprise Object class, an instance of EOGenericRecord, or a fault.
 EOEntity entityNamed(String name)
          Returns the entity named name, or null if no such entity exists in this model.
 NSArray entityNames()
          Returns an array containing the names of the receiver's entities.
static String entityPrototypeNameForAdaptor(EOAdaptor adaptor)
           
static String entityPrototypePlugInNameForAdaptor(EOAdaptor adaptor)
           
 NSArray externalModelsReferenced()
          Returns an array containing those models that are referenced by the receiver.
 void loadAllModelObjects()
          Loads any of the receiver's entities, stored procedures, attributes, and relationships that have not yet been loaded.
 EOModelGroup modelGroup()
          Returns the model group to which the receiver belongs.
 String name()
          Returns the receiver's name.
 String path()
          Deprecated. use pathURL instead.
 URL pathURL()
          Returns the URL to the EOModel file used to create the receiver, or null if the model wasn't initialized from an URL.
 EOAttribute prototypeAttributeNamed(String name)
          Returns the prototype attribute identified by name.
 NSArray referencesToProperty(Object property)
          Returns an array of all properties in the receiver that reference property, whether derived attributes, relationships that reference property, and so on.
 void removeEntity(EOEntity entity)
          Removes entity from the receiver without performing any referential integrity checking.
 void removeEntityAndReferences(EOEntity entity)
          Removes entity from the receiver along with any attributes or relationships in other entities that reference entity.
 void removeStoredProcedure(EOStoredProcedure storedProcedure)
          Removes storedProcedure from the receiver without checking whether any entity uses it.
 void setAdaptorName(String adaptorName)
          Sets the name of the receiver's adaptor to adaptorName.
 void setConnectionDictionary(NSDictionary connectionDictionary)
          Sets the dictionary containing information used to connect to the database to connectionDictionary.
 void setModelGroup(EOModelGroup group)
          Sets the model group to which the receiver should belong.
 void setName(String newName)
          Sets the name of the receiver to newNname.
 void setUserInfo(NSDictionary dictionary)
          Sets the receiver's userInfo dictionary to dictionary.
 EOStoredProcedure storedProcedureNamed(String name)
          Returns the stored procedure named name, or null if the receiver doesn't contain a stored procedure with the given name.
 NSArray storedProcedureNames()
          Returns an array containing the names of all of the receiver's stored procedures sorted in alphabetical order.
 NSArray storedProcedures()
          Returns an array containing all of the receiver's stored procedures or an empty array if the receiver has no stored procedures.
 String toString()
          Returns a string representation of the receiver.
 NSDictionary userInfo()
          Returns a dictionary of user data.
 void writeToFile(String path)
          Writes out the model archive representation of the receiver in the location specified by path.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

EntityLoadedNotification

public static final String EntityLoadedNotification
The notification posted after an EOEntity is loaded into memory. This notification contains:
Notification Object The entity that was loaded. Userinfo None

See Also:
Constant Field Values
Constructor Detail

EOModel

public EOModel()
Creates and returns a new EOModel.


EOModel

@Deprecated
public EOModel(String path)
Deprecated. use EOModel(URL url) instead.

Creates a new EOModel object by reading the contents of the model archive identified by path. Sets the EOModel's name and path from the context of the model archive. Throws an IllegalArgumentException if path is null or if unable to read the file at path. Throws a runtime exception if unable for any other reason to initialize the model from the specified file path; the error text indicates the nature of the exception.

Parameters:
path - The path to a model archive.
Throws:
IllegalArgumentException - if path is null or if unable to read the file.
See Also:
EOModel.EOModel(URL url), EOModel.name(), EOModel.path(), (NSMutableDictionary propertyList)

EOModel

public EOModel(URL url)
Creates a new EOModel object by reading the contents of the model archive at url. Sets the EOModel's name and path from the context of the model archive. Throws an IllegalArgumentException if url is null or if unable to read content from url. Throws a runtime exception if unable for any other reason to initialize the model from the specified java.net.URL; the error text indicates the nature of the exception.

Parameters:
url - The java.net.URL to a model archive.
Throws:
IllegalArgumentException - if url is null or if unable to read the content.
Since:
5.2.2
See Also:
EOModel.EOModel(URL url), EOModel.name(), EOModel.pathURL(), (NSMutableDictionary propertyList)

EOModel

protected EOModel(NSDictionary propertyList,
                  String path)

EOModel

protected EOModel(NSDictionary propertyList,
                  URL url)
Method Detail

dispose

public void dispose()
Conformance to NSDisposable.

Specified by:
dispose in interface NSDisposable

toString

public String toString()
Returns a string representation of the receiver.

Overrides:
toString in class Object
Returns:
A string representation of the receiver.

name

public String name()
Returns the receiver's name.

Returns:
The receiver's name.
See Also:
EOModel.path(), EOModel.EOModel(String path), EOModel.EOModel(NSDictionary tableOfContents, String path)

path

@Deprecated
public String path()
Deprecated. use pathURL instead.

Returns:
The name of the EOModel file used to create the receiver, or null.
See Also:
EOModel.pathURL()

pathURL

public URL pathURL()
Returns the URL to the EOModel file used to create the receiver, or null if the model wasn't initialized from an URL.

Returns:
The name of the EOModel file used to create the receiver, or null.
Since:
5.2.2
See Also:
EOModel.name(), EOModel.EOModel(String path), EOModel.EOModel(NSDictionary tableOfContents, String path)

entityNames

public NSArray entityNames()
Returns an array containing the names of the receiver's entities.

Returns:
An array of the names of the receiver's entities.
See Also:
EOModel.entities(), EOModel.entityNamed(String name)

entityNamed

public EOEntity entityNamed(String name)
Returns the entity named name, or null if no such entity exists in this model. Posts an EntityLoadedNotification when the entity is loaded. Throws a runtime exception if an error occurs during loading; the error text indicates the nature of the exception.

Parameters:
name - The name of an entity.
Returns:
The entity identified by name, or null.
See Also:
EOModel.EntityLoadedNotification, EOModel.entityNames(), EOModel.entities()

entities

public 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.

Returns:
An array of all the receiver's entities.
See Also:
EOModel.entityNames()

entityForObject

public EOEntity entityForObject(EOEnterpriseObject object)
Returns the entity associated with object, whether object is an instance of an Enterprise Object class, an instance of EOGenericRecord, or a fault. Returns null if object has no associated entity.

Parameters:
object - An object.
Returns:
The entity associated with object, or null.

adaptorName

public String adaptorName()
Returns the name of the adaptor for the receiver. This name can be used with EOAdaptor's static method adaptorWithName to construct an adaptor.

Returns:
The name of the adaptor for the receiver.
See Also:
EOAdaptor.adaptorWithName(String name)

connectionDictionary

public 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 receiver as their model.

Returns:
The receiver's connection dictionary.
See Also:
EOAdaptor

userInfo

public NSDictionary userInfo()
Returns a dictionary of user data. You can use this to store any auxiliary information your application needs. Returns an empty dictionary if no user information has been set.

Returns:
A dictionary of arbitrary user data.
See Also:
EOModel.setUserInfo(NSDictionary dictionary)

entitiesWithSharedObjects

public NSArray entitiesWithSharedObjects()
Returns an array of entities that have objects to load into a shared editing context.

Returns:
An array of entities that load objects into a shared editing context.
See Also:
EOEditingContext

modelGroup

public EOModelGroup modelGroup()
Returns the model group to which the receiver belongs.

Returns:
The receiver's model group.
See Also:
EOModel.setModelGroup(EOModelGroup group), EOModelGroup

storedProcedureNames

public NSArray storedProcedureNames()
Returns an array containing the names of all of the receiver's stored procedures sorted in alphabetical order. Throws a runtime exception if an error occurs during processing; the error text indicates the nature of the exception.

Returns:
An alphabetically sorted array of the names of all of the receiver's stored procedures.
See Also:
EOModel.storedProcedures(), EOModel.storedProcedureNamed(String name), EOStoredProcedure

storedProcedureNamed

public EOStoredProcedure storedProcedureNamed(String name)
Returns the stored procedure named name, or null if the receiver doesn't contain a stored procedure with the given name. Throws a runtime exception if an error occurs during processing; the error text indicates the nature of the exception. Throws an IllegalArgumentException if the model's index file (table of contents) contains name but the associated stored procedure is not found in the model's .eomodeld directory.

Parameters:
name - The name of a stored procedure.
Returns:
The stored procedure identified by name, or null.
Throws:
IllegalArgumentException - if the model file is corrupted.
See Also:
EOModel.storedProcedureNames(), EOModel.storedProcedures(), EOStoredProcedure

storedProcedures

public NSArray storedProcedures()
Returns an array containing all of the receiver's stored procedures or an empty array if the receiver has no stored procedures. Note that this method loads each of the model's stored procedures, thus defeating the benefits of incremental model loading.

Returns:
An array of all of the model's stored procedures, or an empty array.
See Also:
EOModel.storedProcedureNames(), EOModel.storedProcedureNamed(String name), EOStoredProcedure

entityPrototypeNameForAdaptor

public static String entityPrototypeNameForAdaptor(EOAdaptor adaptor)

entityPrototypePlugInNameForAdaptor

public static String entityPrototypePlugInNameForAdaptor(EOAdaptor adaptor)

prototypeAttributeNamed

public EOAttribute prototypeAttributeNamed(String name)
Returns the prototype attribute identified by name. Looks first in the receiver, then in the model group to which the receiver belongs, and finally in the adaptor associated with the receiver.

Parameters:
name - An attribute name.
Returns:
The prototype attribute for the given name.
See Also:
EOModel.availablePrototypeAttributeNames()

availablePrototypeAttributeNames

public NSArray availablePrototypeAttributeNames()
Returns a list of names of all available prototypes.

Returns:
An array of available prototypes' names.
See Also:
EOModel.prototypeAttributeNamed(String attributeName)

writeToFile

public void writeToFile(String path)
Writes out the model archive representation of the receiver in the location specified by path. If the directory specified by path already exists, a backup copy is first created from the existing archive with a tilde (~) character appended to the archive name to distinguish it. As a side-effect, this method resets the current path for the receiver to path.

Throws a runtime exception if unable to write the archive; the error text indicates the nature of the exception.

Parameters:
path - The filesystem location at which to write the model archive.
See Also:
EOModel.path()

encodeTableOfContentsIntoPropertyList

public void encodeTableOfContentsIntoPropertyList(NSMutableDictionary result)
Encodes the receiver into result. This method is used to create an ASCII representation of an EOModel in property list format.

Parameters:
result - The dictionary into which to encode the receiver.
See Also:
EOModel.EOModel(), EOModel.EOModel(String path), EOModel.EOModel(NSDictionary tableOfContents, String path)

setName

public void setName(String newName)
Sets the name of the receiver to newNname.

Parameters:
newName - A new name for the receiver.

setAdaptorName

public void setAdaptorName(String adaptorName)
Sets the name of the receiver's adaptor to adaptorName.

Parameters:
adaptorName - The name of the receiver's adaptor.

setConnectionDictionary

public void setConnectionDictionary(NSDictionary connectionDictionary)
Sets the dictionary containing information used to connect to the database to connectionDictionary.

Parameters:
connectionDictionary - The information used to connect to the database.
See Also:
EOAdaptor, EOAdaptor.adaptorWithModel(EOModel model)

setUserInfo

public void setUserInfo(NSDictionary dictionary)
Sets the receiver's userInfo dictionary to dictionary. User information is arbitrary auxiliary data which the application can use for whatever it needs. dictionary can only contain property list data types, which are String, NSDictionary, NSArray, and NSData.

Parameters:
dictionary - A dictionary of auxiliary data for the application to use as it needs.

addEntity

public void addEntity(EOEntity entity)
Adds entity to the receiver. Throws an exception if:

Parameters:
entity - An EOEntity object to add to the receiver.
Throws:
IllegalArgumentException - if entity is null, has a different EOModel, or has the same name as another entity registered with the receiver.
See Also:
EOModel.entities(), EOModel.removeEntity(EOEntity name), EOModel.removeEntityAndReferences(EOEntity entity)

removeEntity

public void removeEntity(EOEntity entity)
Removes entity from the receiver without performing any referential integrity checking.

Parameters:
entity - An EOEntity object to remove from the receiver.
See Also:
EOModel.addEntity(EOEntity anEntity), EOModel.removeEntityAndReferences(EOEntity entity)

removeEntityAndReferences

public void removeEntityAndReferences(EOEntity entity)
Removes entity from the receiver along with any attributes or relationships in other entities that reference entity.

Parameters:
entity - An EOEntity object to remove from the receiver.
See Also:
EOModel.addEntity(EOEntity anEntity), EOModel.removeEntity(EOEntity entity)

addStoredProcedure

public void addStoredProcedure(EOStoredProcedure storedProcedure)
Adds storedProcedure to the receiver. Throws an exception if:

Parameters:
storedProcedure - An EOStoredProcedure object to add to the receiver.
Throws:
IllegalArgumentException - if storedProcedure is null, has a different EOModel, has an invalid name, or has the same name as another stored procedure registered with the receiver.
See Also:
EOModel.removeStoredProcedure(EOStoredProcedure storedProcedure), EOModel.storedProcedures(), EOModel.storedProcedureNamed(String name)

removeStoredProcedure

public void removeStoredProcedure(EOStoredProcedure storedProcedure)
Removes storedProcedure from the receiver without checking whether any entity uses it.

Parameters:
storedProcedure - The stored procedure to remove from the receiver.
See Also:
EOModel.addStoredProcedure(EOStoredProcedure storedProcedure), EOModel.storedProcedures()

setModelGroup

public void setModelGroup(EOModelGroup group)
Sets the model group to which the receiver should belong. Note that you shouldn't change an EOModel's model group after it has been bound to other models in its group.

Parameters:
group - The model group to which the receiver should belong.
See Also:
EOModel.modelGroup()

loadAllModelObjects

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

See Also:
EOModel.entities(), EOModel.storedProcedures(), EOEntity.attributes(), EOEntity.relationships()

referencesToProperty

public NSArray referencesToProperty(Object property)
Returns an array of all properties in the receiver that reference property, whether derived attributes, relationships that reference property, and so on. Returns null if property isn't referenced by any of the properties in the model.

Parameters:
property - The name of a property.
Returns:
An array of all properties in the receiver that reference property.
See Also:
EOModel.externalModelsReferenced()

externalModelsReferenced

public NSArray externalModelsReferenced()
Returns an array containing those models that are referenced by the receiver.

Returns:
An array of models referenced by the receiver.
See Also:
EOModel.referencesToProperty(Object aProperty)

beautifyNames

public 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:
EOEntity.nameForExternalName(String name, String separatorString , boolean initialCaps), EOModel.name(), EOEntity.beautifyName(), EOAttribute.beautifyName(), EORelationship.beautifyName(), EOStoredProcedure.beautifyName()

Last updated June 2008

Copyright © 2000-2008 Apple Inc.