home *** CD-ROM | disk | FTP | other *** search
- // EOEntity.h
- // Copyright (c) 1994, NeXT Software, Inc. All rights reserved.
-
- #import <EOControl/EOControl.h>
- #import <EOAccess/EOPropertyListEncoding.h>
- #import <EOAccess/EODefines.h>
-
-
- @class EOAttribute;
- @class EOEntity;
- @class EORelationship;
- @class EOModel;
- @class EOQualifier;
- @class EOStoredProcedure;
-
- // An EOEntity describes a table, file or collection in a database, and
- // associates an internal name with an external name by which the table is
- // known to the database. An entity maintains an array of attributes and
- // another array of relationships.
- //
- // 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 are created.
-
-
- @interface EOEntity:NSObject <EOPropertyListEncoding>
- {
- NSString *_name;
- NSDictionary *_userInfo;
- EOModel *_model;
- NSString *_externalName;
- NSString *_externalQuery;
- EOQualifier *_restrictingQualifier;
- NSMutableArray *_attributes;
- NSMutableArray *_relationships;
- NSMutableDictionary *_storedProcedures;
- NSString *_className;
- NSMutableArray *_classProperties;
- NSMutableArray *_primaryKeyAttributes;
- NSMutableArray *_attributesUsedForLocking;
- NSMutableArray *_subEntities;
- EOEntity *_parent;
-
- NSArray *_classPropertyNames;
- NSArray *_primaryKeyAttributeNames;
- NSArray *_classPropertyAttributeNames;
- NSArray *_classPropertyToOneRelationshipNames;
- NSArray *_classPropertyToManyRelationshipNames;
- NSMutableArray *_attributesToFetch;
- NSMutableArray *_dbSnapshotKeys;
- NSMutableArray *_attributesToSave;
- NSMutableArray *_propertiesToFault;
- id _propertyDictionaryInitializer;
- id _primaryKeyDictionaryInitializer;
- id _snapshotDictionaryInitializer;
- id _adaptorDictionaryInitializer;
- id _snapshotToAdaptorRowSubsetMapping;
- NSMutableDictionary *_flattenedAttNameToSnapshotKeyMapping;
- EOClassDescription *_classDescription;
- NSMutableArray *_hiddenRelationships;
- unsigned int _batchCount;
- Class _classForInstances;
-
- struct {
- unsigned int attributesIsLazy:1;
- unsigned int relationshipsIsLazy:1;
- unsigned int classPropertiesIsLazy:1;
- unsigned int primaryKeyAttributesIsLazy:1;
- unsigned int attributesUsedForLockingIsLazy:1;
-
- unsigned int isReadOnly:1;
- unsigned int isAbstractEntity:1;
- unsigned int updating:1;
-
- unsigned int useBatchFaulting:1;
-
- unsigned int extraRefCount:23;
- } _flags;
- }
-
- - (NSString *)name;
- // Returns the internal name of the entity.
-
- - (EOModel *)model;
- // Returns the model that owns the entity.
-
- - (NSString *)externalName;
- // Returns the name of the entity as understood by the database server.
-
- - (NSString *)externalQuery;
- // Returns a query statement used for selecting rows from the entity. May
- // be nil.
-
- - (EOQualifier *)restrictingQualifier;
- // Returns the restricting qualifier used for restrict all queries made
- // against this entity. The restricting qualifier can be used to make an
- // entity map to a subset of the rows in a table.
-
- - (BOOL)isReadOnly;
- // Returns YES if the entity can't be modified, NO if it can.
-
- - (NSString *)className;
- // The name of the class that is bound to the entity. When a row is
- // fetched for the entity by a database-level object, it's returned as an
- // instance of this class.
-
- - (EOQualifier *)qualifierForPrimaryKey:(NSDictionary *)row;
- // Return a qualifier to fetch an instance of this entity with
- // the primary key extracted from the row
-
- - (BOOL)isQualifierForPrimaryKey:(EOQualifier *)qualifier;
- // Returns yes if qualifier describes primary key and nothing but the
- // primary key.
-
- - (EOAttribute *)attributeNamed: (NSString *)attributeName;
- // Returns the attribute with the given name.
-
- - (EOAttribute *)anyAttributeNamed:(NSString *)relationshipName;
- // Returns the user-created attribute with the given name, if none
- // exists, this method looks through the "hidden" attributes created
- // by EOF for one with the given name. If none is found, nil is returned.
- // The hidden attributes are used for such things as primary keys on
- // target entities of flattened attributes.
-
- - (NSArray *)attributes;
- // Returns all of the entity's attributes.
-
- - (EORelationship *)relationshipNamed: (NSString *)relationshipName;
- // Returns the relationship with the given name.
-
- - (EORelationship *)anyRelationshipNamed:(NSString *)relationshipName;
- // Returns the user created relationship with the given name, if none
- // exists, this method looks through the "hidden" relationships created
- // by EOF for one with the given name. If none is found, nil is returned.
-
- - (NSArray *)relationships;
- // Returns all of the entity's relationships.
-
- - (NSArray *)classProperties;
- // Returns an array containing the properties that are bound to the
- // entity's class (so that instances of the class will be passed values
- // corresponding to those properties). This is a subset of the entity's
- // attributes and relationships.
-
- - (NSArray *)classPropertyNames;
- // An array containing the names of all the properties returned by
- // -classProperties.
-
- - (NSArray *)primaryKeyAttributes;
- // Returns an array containing the attributes that make up the primary
- // key for the entity.
-
- - (NSArray *)primaryKeyAttributeNames;
- // Returns an array containing the names of the attributes returned by
- // -primaryKeyAttributes.
-
- - (NSArray *)attributesUsedForLocking;
- // Returns an array containing the properties whose values must not be
- // different from a snapshot any time a row is updated (with an update
- // strategy other than EOUpdateWithNoLocking).
-
- - (NSDictionary *)primaryKeyForRow:(NSDictionary *)row;
- // Returns the primary key in dictionary form for a row belonging to the
- // entity.
-
- - (BOOL)isValidAttributeUsedForLocking:(EOAttribute *)anAttribute;
- // Returns NO if the attribute isn't an EOAttribute, if the EOAttribute
- // doesn't belong to this entity, or if the EOAttribute is derived.
- // Otherwise returns YES.
-
- - (BOOL)isValidPrimaryKeyAttribute: (EOAttribute *)anAttribute;
- // Returns NO if the attribute isn't an EOAttribute, if the EOAttribute
- // doesn't belong to this entity, or if the EOAttribute is derived.
- // Otherwise returns YES.
-
- - (BOOL)isPrimaryKeyValidInObject:(id)object;
- // Returns YES if every key attribute is present in the object and has
- // a non-nil and non-EONULL value. Returns NO otherwise. This method
- // uses the key-value coding protocol so a dictionary may be substituted
- // for the actual object.
-
- - (BOOL)isValidClassProperty:aProp;
- // Returns NO if either the attribute isn't an EOAttribute or
- // EORelationship, or, if the property doesn't belong to this entity.
- // Otherwise returns YES.
-
- - (NSDictionary *)userInfo;
- // Returns a dictionary of user data. You can use this to store any
- // auxiliary information.
-
- - (NSArray *)subEntities;
- // Returns the entities which inherit from this entity.
-
- - (EOEntity *)parentEntity;
- // Returns the entity that this entity inherits from.
-
- - (BOOL)isAbstractEntity;
- // Indicates whether the objects map directly to this entity.
-
- - (EOGlobalID *)globalIDForRow:(NSDictionary *)row;
- // Constructs a globalID from a row for this entity.
-
- - (NSDictionary *)primaryKeyForGlobalID:(EOGlobalID *)gid;
- // Returns the primary key for the object identified by the global ID.
-
- - (unsigned int)maxNumberOfInstancesToBatchFetch;
- // Returns the max number of EOFaults from this entity to fire at one time.
-
- @end
-
-
- @interface EOEntity(EOEntityEditing)
-
- - (BOOL)setClassProperties: (NSArray *)properties;
- // Sets the entity's class properties to EOAttributes and EORelationships
- // in properties. Returns YES on success, NO if any of the objects in the
- // array don't return YES to isValidClassProperty:.
-
- - (BOOL)setPrimaryKeyAttributes: (NSArray *)keys;
- // Sets the primary key attributes to the attributes in keys. Returns YES
- // on success, or NO if any object in the array don't return YES to
- // isValidPrimaryKeyAttribute:.
-
- - (BOOL)setAttributesUsedForLocking: (NSArray *)attributes;
- // Takes an array of EOAttributes. Fails if any of the objects in the
- // array don't return YES to isValidAttributeUsedForLocking:.
-
- - (NSException *)validateName:(NSString *)name;
- // Returns error description string if name is not a legal entity name
- // and nil otherwise.
-
- - (void)setName:(NSString *)name;
- // Sets the entity's name
-
- - (void)setExternalName:(NSString *)name;
- // Sets the name of the entity as understood by the database server.
-
- - (void)setExternalQuery:(NSString *)query;
- // Sets the query statement used for selecting rows from the entity.
-
- - (void)setRestrictingQualifier:(EOQualifier *)qualifier;
- // Sets the restricting qualifier used for restrict all queries made
- // against this entity. The restricting qualifier can be used to make an
- // entity map to a subset of the rows in a table.
-
- - (void)setReadOnly:(BOOL)yn;
- // Sets whether the entity can be modified.
-
- - (void)addAttribute:(EOAttribute *)attribute;
- // Adds attribute to the entity.
-
- - (void)removeAttribute:(EOAttribute *)attribute;
- // Removes the attribute.
-
- - (void)addRelationship:(EORelationship *)relationship;
- // Adds relationship to the entity.
-
- - (void)removeRelationship:(EORelationship *)relationship;
- // Removes the relationship.
-
- - (void)setClassName:(NSString *)name;
- // Sets the class name.
-
- - (void)setUserInfo:(NSDictionary *)dictionary;
- // Sets the dictionary of auxiliary data, which your application can use
- // for whatever it needs.
-
- - (void)addSubEntity:(EOEntity *)child;
- // Causes the child entity to "inherit" from this entity. This is the first
- // step in setting up an inheritance hierarchy between entities.
-
- - (void)removeSubEntity:(EOEntity *)child;
- // Removes the child from this entity's list of subEntities.
-
- - (void)setIsAbstractEntity:(BOOL)f;
- // Sets whether the objects map directly to this entity.
-
- - (void)setMaxNumberOfInstancesToBatchFetch:(unsigned int)size;
- // Sets the max number of EOFaults from this entity to fire at one time.
-
- @end
-
- @interface EOEntity(EOModelReferentialIntegrity)
-
- - (BOOL)referencesProperty:property;
- // True if any of the entity's attributes or relationships reference
- // property.
-
- - (NSArray *)externalModelsReferenced;
- // returns a list of external models referenced by this entity
-
- @end
-
- @interface EOEntity(EOModelBeautifier)
- - (void)beautifyName;
- // Make the entity name and all of its components conform
- // to the Next naming style
- // NAME -> name, FIRST_NAME -> firstName
- @end
-
-
- EOACCESS_EXTERN NSString *EOFetchAllProcedureOperation;
- EOACCESS_EXTERN NSString *EOFetchWithPrimaryKeyProcedureOperation;
- EOACCESS_EXTERN NSString *EOInsertProcedureOperation;
- EOACCESS_EXTERN NSString *EODeleteProcedureOperation;
- EOACCESS_EXTERN NSString *EONextPrimaryKeyProcedureOperation;
-
- @interface EOEntity(EOStoredProcedures)
- - (EOStoredProcedure *)storedProcedureForOperation:(NSString *)operation;
- - (void)setStoredProcedure:(EOStoredProcedure *)storedProcedure forOperation:(NSString *)operation;
- @end
-
- @interface EOEntity(EOPrimaryKeyGeneration)
- - (NSString *)primaryKeyRootName;
- // If this entity inherits from another entity, the method is passed to it's parent.
- // The top level entity returns the externalName if it has one or the entity name
- // otherwise.
- @end
-
- @interface EOEntity(EOEntityClassDescription)
- - (EOClassDescription *)classDescriptionForInstances;
- @end
-
- // Entities register themselves as class descriptions for
- // their classes, thereby dynamically extending their behavior.
- @interface EOEntityClassDescription : EOClassDescription
- {
- EOEntity *_entity;
- }
- - initWithEntity:(EOEntity *)entity;
- - (EOEntity *)entity;
- @end
-
- @interface NSString(EODatabaseNameConversion)
- + (NSString *)nameForExternalName:(NSString *)externalName
- separatorString:(NSString *)separatorString initialCaps:(BOOL)initialCaps;
- // Name beautification uses this to convert database names to
- // nicer looking names
- // NAME -> name, FIRST_NAME -> firstName, MY_ENTITY -> MyEntity
-
- + (NSString *)externalNameForInternalName:(NSString *)internalName
- separatorString:(NSString *)separatorString useAllCaps:(BOOL)allCaps;
- // Database-style name from ObjC-style names.
- // With separatorString:@"_" and useAllCaps:YES :
- // name -> NAME, firstName -> FIRST_NAME, MyEntity -> MY_ENTITY
- // With separatorString:@"_" and useAllCaps:NO :
- // name -> name, firstName -> first_name, MyEntity -> my_entity
-
- @end
-