home *** CD-ROM | disk | FTP | other *** search
/ OpenStep (Enterprise) / OpenStepENTCD.toast / OEDEV / EODEV.Z / EORelationship.h < prev    next >
Encoding:
Text File  |  1996-09-09  |  7.8 KB  |  212 lines

  1. // EORelationship.h
  2. // Copyright (c) 1994, NeXT Software, Inc. All rights reserved. 
  3.  
  4. #import <EOControl/EOControl.h>
  5. #import <EOAccess/EOJoin.h>
  6. #import <EOAccess/EOPropertyListEncoding.h>
  7.  
  8. @class EOEntity;
  9. @class EOAttribute;
  10. @class EOExpressionArray;
  11.  
  12. // An EORelationship describes an association between two entities. The two
  13. // entities can be in the same model or two different models as long as they
  14. // are in the same model group. The assocation can be to-one or to-many, and
  15. // is directional: no inverse is implied, however an inverse relationship may
  16. // exist. A relationship maintains an array of joins identifying
  17. // attributes from the related entities.  See EOJoin.h for more information.
  18.  
  19. typedef enum {
  20.     EOInnerJoin = 0, EOFullOuterJoin,
  21.     EOLeftOuterJoin, EORightOuterJoin
  22. } EOJoinSemantic;
  23.     // EOJoinSemantic specifies the manner in which a join should be made.
  24.     // An inner join (also known as an equijoin) produces results only for
  25.     // destinations of the join relationship that have non-null values.  A
  26.     // full outer join produces results for all source records, regardless of
  27.     // the values of the relationships.  A left outer join preserves rows in
  28.     // the left (source) table (keeps them even if there's no corresponding
  29.     // row in the right table), while a right outer join preserves rows in the
  30.     // right (destination) table.  Not all join semantics are supported by all
  31.     // database servers.
  32.  
  33.  
  34. @interface EORelationship:NSObject <EOPropertyListEncoding>
  35. {
  36.     NSString *_name;
  37.     EOEntity *_entity;
  38.     EOEntity *_destination;
  39.     EOQualifier *_qualifier;
  40.     EOExpressionArray *_definitionArray;
  41.     NSMutableArray *_joins;
  42.     NSMutableDictionary *_sourceNames;
  43.     NSMutableDictionary *_destinationNames;
  44.     NSDictionary *_userInfo;
  45.     EOExpressionArray *_expressionArray;
  46.     NSDictionary *_sourceToDestinationKeyMap;
  47.     unsigned int _batchCount;
  48.     EOJoinSemantic _joinSemantic;
  49.  
  50.     struct {
  51.     unsigned int isToMany:1;
  52.         unsigned int useBatchFaulting:1;
  53.         unsigned int deleteRule:2;
  54.         unsigned int isMandatory:1;
  55.         unsigned int ownsDestination:1;
  56.         unsigned int propagatesPrimaryKey:1;
  57.     unsigned int extraRefCount:25;
  58.     } _flags;
  59.     id _sourceRowToForeignKeyMapping;
  60.     EORelationship *_inverseRelationship;
  61.     EORelationship *_hiddenInverseRelationship;
  62. }
  63.  
  64. - (NSString *)name;
  65.      // Returns the internal name of the relationship.
  66.  
  67. - (EOEntity *)entity;
  68.     // Returns the source entity of the relationship.
  69.  
  70. - (EOEntity *)destinationEntity;
  71.     // Returns the destination entity of the relationship
  72.  
  73. - (NSString *)definition;
  74.     // A path containing relationships that defines a flattened relationship.
  75.     // This may be something like "toAuthor.toPublisher". 
  76.  
  77. - (BOOL)isFlattened;
  78.     // Returns YES if the relationship has a definition; that is, if the
  79.     // relationship traverses more than two entities. 
  80.  
  81. - (BOOL)isToMany;
  82.     // Returns YES if this is a to-many relationship, NO if it's a
  83.     // to-one relationship.
  84.  
  85. - (BOOL)isCompound;
  86.     // Returns YES if this joins more than one pair of attributes, NO if it
  87.     // joins only one.
  88.  
  89. - (NSArray *)sourceAttributes;
  90.     // Returns the source attributes of the relationship.
  91.  
  92. - (NSArray *)destinationAttributes;
  93.     // Returns the destination attributes of the relationship.
  94.  
  95. - (NSArray *)joins;
  96.     // Returns all joins used by relationship.
  97.  
  98. - (EOJoinSemantic)joinSemantic;
  99.     // Returns the semantic used to create sql expressions for this relationship.    
  100.  
  101. - (NSArray *)componentRelationships;
  102.     // Returns an array of base relationships making up a flattened
  103.     // relationship.  Returns nil if the relationship is not flattened.
  104.  
  105. - (NSDictionary *)userInfo;
  106.     // Returns a dictionary of user data.  Your application can use this data
  107.     // for whatever it needs.
  108.  
  109. - (BOOL)referencesProperty:(id)property;
  110.     // Returns YES if property is in the relationship's data path or is a join
  111.     // attribute of the relationship, NO otherwise.
  112.  
  113. - (EODeleteRule)deleteRule;
  114.     // Returns rule describing the action to take when object is being deleted.
  115.  
  116. - (BOOL)isMandatory;
  117.     // Return value indicating if the target of the relationship can be nil.
  118.  
  119. - (BOOL)propagatesPrimaryKey;
  120.     // Returns yes if objects should propagate their primary key to related objects
  121.     // through this relationship. Only propagates the value if the corresponding
  122.     // keys don't have a value in the destination object.
  123.  
  124. - (EORelationship *)inverseRelationship;
  125.     // Searches destinationEntity for a user-created, back-pointing relationship
  126.     // joining on the same keys. Returns nil if none found.
  127.  
  128. - (EORelationship *)anyInverseRelationship;
  129.     // Searches the destination for a user-created, back-pointing relationship
  130.     // joining on the same keys. If none is found, is looks for a "hidden" inverse
  131.     // relationship that was manufactured by EOF. If none is found, EOF creates
  132.     // a "hidden" inverse relationship and returns that. These hidden relationships
  133.     // are used internally by the framework.
  134.  
  135. - (unsigned int)numberOfToManyFaultsToBatchFetch;
  136.     // Returns the number of toMany faults that are fired at one time.    
  137.  
  138. - (BOOL)ownsDestination;
  139.     // returns YES if the relationship should insert or delete the target object when
  140.     // added or removed
  141.  
  142. - (EOQualifier *)qualifierWithSourceRow:(NSDictionary *)sourceRow;
  143.     // Returns the qualifier needed to fetch the destination
  144.     // of the receiving relationship.
  145.  
  146. @end
  147.  
  148.  
  149. @interface EORelationship(EORelationshipEditing)
  150.  
  151.  
  152. - (NSException *)validateName:(NSString *)name;
  153.     // Returns nil if name is a valid relationship name
  154.  
  155. - (void)setName:(NSString *)name;
  156.     // Sets the relationship's name.  This method raises if the name is
  157.     // not a valid name or if the relationship's entity already has a
  158.     // property with this name.
  159.  
  160. - (void)setDefinition:(NSString *)definition;
  161.     // Sets the definition of the relationship. This method will release 
  162.     // any joins and source/destination attributes that may be associated
  163.     // with the relationship. This method will not function correctly if
  164.     // the relationship's entity has not been set.
  165.     
  166. - (void)setEntity:(EOEntity *)entity;
  167.     // Sets the entity of the relationship. If the relationship is currently
  168.     // owned by a different entity, this method will remove the relationship
  169.     // from that entity. This method does not add the attribute to the new
  170.     // entity. EOEntity's addRelationship: method invokes this method.
  171.  
  172. - (void)setToMany:(BOOL)yn;
  173.     // Sets whether the relationship is one-to-many or one-to-one.
  174.  
  175. - (void)setPropagatesPrimaryKey:(BOOL)yn;
  176.     // Sets whether the object propagates its primary key to its destination
  177.     // object.
  178.  
  179. - (void)setOwnsDestination:(BOOL)yn;
  180.     // Sets whether the relationship should insert or delete the target object when
  181.     // added or removed.
  182.  
  183. - (void)addJoin:(EOJoin *)join;
  184.     // Adds a source/destination attribute pair to the relationship. This could raise
  185.     // if the join is invalid.
  186.  
  187. - (void)removeJoin:(EOJoin *)join;
  188.     // Deletes a source/destination attribute pair from the relationship.
  189.  
  190. - (void)setJoinSemantic:(EOJoinSemantic)joinSemantic;
  191.     // Sets the semantic used to create sql expressions for this relationship.    
  192.  
  193. - (void)setUserInfo:(NSDictionary *)dictionary;
  194.     // Sets the dictionary of auxiliary data, which your application can use
  195.     // for whatever it needs.
  196.  
  197. - (void)beautifyName;
  198.     // Make the name conform to the Next naming style
  199.     // NAME -> name, FIRST_NAME -> firstName
  200.  
  201. - (void)setNumberOfToManyFaultsToBatchFetch:(unsigned int)size;
  202.     // Sets the number of toMany faults that are fired at one time.    
  203.  
  204. - (void)setDeleteRule:(EODeleteRule)deleteRule;
  205.     // Set rule describing the action to take when object is being deleted.
  206.  
  207. - (void)setIsMandatory:(BOOL)isMandatory;
  208.     // Set value indicating if the target of the relationship can be nil.
  209.  
  210. @end
  211.  
  212.