Inherits from: NSObject
Implements: EOPropertyListEncoding
Package: com.apple.yellow.eoaccess
An EOEntity describes a table in a database and associates a name internal to the Framework with an external name by which the table is known to the database. An EOEntity maintains a group of attributes and relationships, which are collectively called properties. These are represented by the EOAttribute and EORelationship classes, respectively; see their specifications for more information.
You usually define entities in a model with the EOModeler application, which is documented in Enterprise Objects Tools and Techniques. EOEntity objects are primarily used by the Enterprise Objects Framework for mapping tables in the database to enterprise objects; your code will probably make limited use of them unless you're specifically working with models.
An EOEntity is associated with a specific class whose instances are used to represent records (rows) from the database in applications using layers at or above the database layer of the Enterprise Objects Framework. If an EOEntity doesn't have a specific class associated with it, instances of EOGenericRecord (defined in EOControl) are created.
An EOEntity may be marked as read-only, in which case any changes to rows or objects for that entity made by the database level objects are denied.
You can define an external query for an EOEntity to be used when a selection is attempted with an unrestricted qualifier (one that would select all rows in the entity's table). An external query is sent unaltered to the database server and so can use database-specific features such as stored procedures; external queries are thus useful for hiding records or invoking database-specific features. You can also assign stored procedures to be invoked upon particular database operations through the use of EOEntity's setStoredProcedure method.
Like the other major modeling classes, EOEntity provides a user dictionary for your application to store any application-specific information related to the entity.
For more information on programmatically creating EOEntity objects, see "Creating an Entity" .
EOEntity defines the following String constants:
Constant | Description |
FetchAllProcedureOperation | A stored procedure to fetch all records |
FetchWithPrimaryKeyProcedureOperation | A stored procedure to fetch by primary key |
InsertProcedureOperation | A stored procedure to insert a row |
DeleteProcedureOperation | A stored procedure to delete a row |
NextPrimaryKeyProcedureOperation | A stored procedure to generate a new primary key |
EOPropertyListEncodingawakeWithPropertyList encodeIntoPropertyList
- Constructors
- EOEntity
- Accessing the name
- setName
- name
- validateName
- beautifyName
- Accessing the model
- model
- Specifying fetching behavior for the entity
- setExternalQuery
- externalQuery
- setRestrictingQualifier
- restrictingQualifier
- Accessing primary key qualifiers
- qualifierForPrimaryKey
- isQualifierForPrimaryKey
- Accessing a schema-based qualifier from a qualifier for in-memory evaluation
- schemaBasedQualifier
- Accessing attributes
- addAttribute
- anyAttributeNamed
- attributeNamed
- attributes
- removeAttribute
- attributesToFetch
- Accessing relationships
- addRelationship
- anyRelationshipNamed
- relationships
- relationshipNamed
- removeRelationship
- Checking referential integrity
- externalModelsReferenced
- referencesProperty
- Accessing primary keys
- globalIDForRow
- isPrimaryKeyValidInObject
- primaryKeyForGlobalID
- primaryKeyForRow
- Accessing primary key attributes
- setPrimaryKeyAttributes
- primaryKeyAttributes
- primaryKeyAttributeNames
- primaryKeyRootName
- isValidPrimaryKeyAttribute
- Accessing class properties
- setClassProperties
- classProperties
- classPropertyNames
- isValidClassProperty
- Accessing the enterprise object class
- classDescriptionForInstances
- setClassName
- className
- Accessing locking attributes
- setAttributesUsedForLocking
- attributesUsedForLocking
- isValidAttributeUsedForLocking
- Accessing external name
- setExternalName
- externalName
- externalNameForInternalName
- nameForExternalName
- Accessing whether an entity is read only
- setReadOnly
- isReadOnly
- Accessing the user dictionary
- setUserInfo
- userInfo
- Working with stored procedures
- setStoredProcedure
- storedProcedureForOperation
- Working with fetch specifications
- addFetchSpecification
- fetchSpecificationNamed
- fetchSpecificationNames
- removeFetchSpecificationNamed
- addSharedObjectFetchSpecificationByName
- sharedObjectFetchSpecificationNames
- setSharedObjectFetchSpecificationsByName
- removeSharedObjectFetchSpecificationByName
- Working with entity inheritance hierarchies
- parentEntity
- subEntities
- addSubEntity
- removeSubEntity
- setIsAbstractEntity
- isAbstractEntity
- Specifying fault behavior
- setMaxNumberOfInstancesToBatchFetch
- maxNumberOfInstancesToBatchFetch
- Caching objects
- setCachesObjects
- cachesObjects
public EOEntity(
NSDictionary propertyList,
Object owner)
See Also: encodeIntoPropertyList (EOPropertyListEncoding)
public static String externalNameForInternalName(
String name,
String separatorString,
boolean useAllCaps)
separatorString is a character that is used to separate words. The Framework uses "_" by default as in the examples above. useAllCaps indicates whether to capitalize the name. For example, providing false converts "firstName" to "first_name".
public static String nameForExternalName(
String name,
String separatorString,
boolean initialCaps)
separatorString is a character that is used to separate words. The Framework uses "_" by default as in the examples above. initialCaps indicates whether to capitalize the first letter of the first word. By default, the Framework uses true for entities and false for everything else.
See Also: beautifyNames (EOModel), beautifyName, - beautifyName ( EOAttribute, EORelationship, EOStoredProcedure)
public void addAttribute(EOAttribute anAttribute)
See Also: removeAttribute, attributes, attributeNamed
public void addFetchSpecification(
com.apple.yellow.eocontrol.EOFetchSpecification fetchSpec,
String fetchSpecName)
See Also: fetchSpecificationNamed, fetchSpecificationNames, removeFetchSpecificationNamed
public void addRelationship(EORelationship aRelationship)
See Also: removeRelationship, relationships, relationshipNamed
public void addSharedObjectFetchSpecificationByName(String name)
public void addSubEntity(EOEntity child)
See Also: subEntities, removeSubEntity
public EOAttribute anyAttributeNamed(String attributeName)
See Also: attributeNamed, attributes
public EORelationship anyRelationshipNamed(String relationshipName)
See Also: relationshipNamed, relationships
public EOAttribute attributeNamed(String attributeName)
See Also: anyAttributeNamed, attributes, relationshipNamed
public NSArray attributes()
See Also: anyAttributeNamed, attributeNamed
public NSArray attributesToFetch()
public NSArray attributesUsedForLocking()
Attributes used for locking are those whose values are compared when a database-level object performs an update. When the database-level classes fetch an enterprise object, they cache these attributes' values in a snapshot. Later, when the enterprise object is updated, the values of these attributes in the object are checked with those in the snapshot-if they differ, the update fails. See the EODatabaseContext class specification for more information.
public void beautifyName()
See Also: setName, validateName, beautifyNames (EOModel)
public boolean cachesObjects()
See Also: setCachesObjects
public com.apple.yellow.eocontrol.EOClassDescription classDescriptionForInstances()
public String className()
An enterprise object class other than EOGenericRecord can be mapped to only one entity.
public NSArray classProperties()
See Also: classPropertyNames
public NSArray classPropertyNames()
See Also: classProperties
public NSArray externalModelsReferenced()
See Also: referencesProperty
public String externalName()
public String externalQuery()
External queries are useful for hiding records or invoking database-specific features such as stored procedures when an application attempts to select all records for an entity. You can also use the EOStoredProcedure class to work with stored procedures; for more information see the EOStoredProcedure class specification.
See Also: setExternalQuery
public com.apple.yellow.eocontrol.EOFetchSpecification fetchSpecificationNamed(String fetchSpecName)
See Also: addFetchSpecification, fetchSpecificationNames, removeFetchSpecificationNamed
public NSArray fetchSpecificationNames()
See Also: addFetchSpecification, fetchSpecificationNamed, removeFetchSpecificationNamed
public com.apple.yellow.eocontrol.EOGlobalID globalIDForRow(NSDictionary row)
See Also: primaryKeyForGlobalID
public boolean isAbstractEntity()
See Also: setIsAbstractEntity
public boolean isPrimaryKeyValidInObject(Object anObject)
See Also: primaryKeyForRow
public boolean isQualifierForPrimaryKey(com.apple.yellow.eocontrol.EOQualifier aQualifier)
public boolean isReadOnly()
public boolean isValidAttributeUsedForLocking(EOAttribute anAttribute)
See Also: attributesUsedForLocking
public boolean isValidClassProperty(Object aProperty)
public boolean isValidPrimaryKeyAttribute(EOAttribute anAttribute)
See Also: setPrimaryKeyAttributes
public int maxNumberOfInstancesToBatchFetch()
public EOModel model()
See Also: addEntity (EOModel)
public String name()
public EOEntity parentEntity()
See Also: subEntities
public NSArray primaryKeyAttributeNames()
See Also: primaryKeyAttributes
public NSArray primaryKeyAttributes()
See Also: primaryKeyAttributeNames
public NSDictionary primaryKeyForGlobalID(com.apple.yellow.eocontrol.EOKeyGlobalID globalID)
See Also: globalIDForRow
public NSDictionary primaryKeyForRow(NSDictionary aRow)
See Also: primaryKeyForGlobalID
public String primaryKeyRootName()
See Also: externalName, name, parentEntity
public com.apple.yellow.eocontrol.EOQualifier qualifierForPrimaryKey(NSDictionary aRow)
See Also: isQualifierForPrimaryKey, restrictingQualifier
public boolean referencesProperty(Object aProperty)
If an entity has any outstanding references to a property, you shouldn't remove the property.
See Also: removeAttribute, removeRelationship
public EORelationship relationshipNamed(String name)
See Also: anyRelationshipNamed, attributeNamed, relationships
public NSArray relationships()
See Also: attributes
public void removeAttribute(EOAttribute name)
See Also: addAttribute, attributes
public void removeFetchSpecificationNamed(String fetchSpecName)
See Also: addFetchSpecification, fetchSpecificationNamed, fetchSpecificationNames
public void removeRelationship(EORelationship name)
See Also: addRelationship, relationships
public void removeSharedObjectFetchSpecificationByName(String name)
public void removeSubEntity(EOEntity child)
See Also: addSubEntity, subEntities
public com.apple.yellow.eocontrol.EOQualifier restrictingQualifier()
For example, if you're using the "one table" inheritance model in which parent and child data is contained in the same table, you'd use a restricting qualifier to fetch objects of the appropriate type. To give a non-inheritance example, for an Employees table you might create a "Sales" entity that has a restricting qualifier that only fetches employees who are in the Sales department.
See Also: setRestrictingQualifier
public com.apple.yellow.eocontrol.EOQualifier schemaBasedQualifier(com.apple.yellow.eocontrol.EOQualifier aQualifier)
Whereas in-memory qualifier evaluation uses object instance variables to resolve relationships, a database qualifier must use foreign keys. For example, consider a qualifier that is used to fetch all employees who work in a specified department:
Department dept; // Assume this exists. EOQualifier qualifier; NSMutableArray qualArgs = new NSMutableArray(); qualArgs.addObject(dept); qualifier = EOQualifier.qualifierWithQualifierFormat("department = %@", qualArgs);
For an in-memory search, the Framework queries employee objects for their department object and includes an employee in the result list if its department object is equal to dept. (See EOControl's EOQualifierEvaluation interface description for more information on in-memory searching.)
For a database search, the Framework needs to qualify the fetch by specifying a foreign key value for dept. The Framework sends the EOEntity class a schemaBasedQualifier message that creates a new EOQualifier object from qualifier. Assume that the entity for employee objects has an attribute named departmentID and that the primary key value for dept is 459, the resulting qualifier specifies the search conditions as:
department.departmentID = 459
See Also: selectObjectsWithFetchSpecification (EODatabaseChannel)
public boolean setAttributesUsedForLocking(NSArray attributes)
public void setCachesObjects(boolean flag)
See Also: cachesObjects
public void setClassName(String name)
An enterprise object class other than EOGenericRecord can be mapped to only one entity.
See Also: className
public boolean setClassProperties(NSArray properties)
public void setExternalName(String name)
public void setExternalQuery(String aQuery)
External queries are useful for hiding records or invoking database-specific features such as stored procedures when an application attempts to select all records for an entity. You can also use the EOStoredProcedure class to work with stored procedures; for more information see the EOStoredProcedure class specification.
An external query is sent unaltered to the database server, and so must contain the external (column) names instead of the names of EOAttributes. However, to work properly with the adaptor the external query must use the columns in alphabetical order by their corresponding EOAttributes' names.
See Also: columnName (EOAttribute), externalQuery
public void setIsAbstractEntity(boolean flag)
public void setMaxNumberOfInstancesToBatchFetch(int size)
See Also: maxNumberOfInstancesToBatchFetch
public void setName(String name)
See Also: beautifyName, validateName
public boolean setPrimaryKeyAttributes(NSArray keys)
You should exercise care in choosing primary key attributes. Floating-point numbers, for example, can't be reliably compared for equality, and are thus unsuitable for use in primary keys. Integer and string types are the safest choice for primary keys. BigDecimal objects will work, but they'll entail more overhead than integers.
See Also: isValidPrimaryKeyAttribute
public void setReadOnly(boolean flag)
See Also: isReadOnly
public void setRestrictingQualifier(com.apple.yellow.eocontrol.EOQualifier aQualifier)
public void setSharedObjectFetchSpecificationsByName(NSArray names)
public void setStoredProcedure(
EOStoredProcedure storedProcedure,
String operation)
This information is used when changes from the object graph have been transformed into EODatabaseOperations that are being used to construct EOAdaptorOperations. At this point, Enterprise Objects Framework checks the entities associated with the changed objects to see if the entities have any stored procedures defined for the operation being performed.
See Also: storedProcedureForOperation
public void setUserInfo(NSDictionary dictionary)
public NSArray sharedObjectFetchSpecificationNames()
public EOStoredProcedure storedProcedureForOperation(String operation)
See Also: setStoredProcedure, parameterDirection (EOAttribute), storedProcedure (EOAttribute)
public NSArray subEntities()
See Also: addSubEntity, parentEntity, removeSubEntity
public NSDictionary userInfo()
See Also: setUserInfo
public Throwable validateName(String name)
setName uses this method to validate its argument.