home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / OpenStepConversion / 3.3Headers / eoaccess / EOQualifier.h < prev    next >
Encoding:
Text File  |  1994-12-06  |  5.7 KB  |  142 lines

  1. // EOQualifier.h
  2. // Copyright (c) 1994, NeXT Computer, Inc. All rights reserved.
  3.  
  4. #import <foundation/NSArray.h>
  5. #import <foundation/NSData.h>
  6. #import <foundation/NSDictionary.h>
  7. #import <foundation/NSObject.h>
  8. #import <foundation/NSString.h>
  9.  
  10. @class EOEntity;
  11. @class EOExpressionArray;
  12. @class EORelationship;
  13. @class EOAdaptor;
  14.  
  15. // An EOQualifier holds qualifications expressed in the target query language
  16. // and rooted in a single EOEntity.  You can build a qualifier with a
  17. // printf()-style format string or directly from an existing Enterprise Object
  18. // or row fetched from the database.
  19. //
  20. // CREATING A SQL QUALIFIER FROM A FORMAT STRING
  21. //
  22. // A qualifier string must contain only the internal names of properties
  23. // belonging to the qualifiers entity and relational operators (=, >, <, >=,
  24. // <=).  For example, if you have an Author entity with the properties
  25. // author_id, first_name, last_name, royalty, and toPublisher, and a Publisher
  26. // entity with properties pub_id, name, address, the following are valid
  27. // qualifier strings:
  28. //     last_name = "smith"
  29. //     royalty > 2.5
  30. //     toPublisher.name = "Eco Publishing House"
  31. //
  32. // An EOQualfier's format string can embed strings, numbers, and other objects
  33. // using the conversion specifications in the table below.  This allows
  34. // qualifiers to be built dynamically based on the return values of methods.
  35. //
  36. //    %s expects a (char *) argument, which is passed through 
  37. //         (and possibly quoted by the database)
  38. //    %A expects an (NSString) argument, which is resolved as a property
  39. //         name.
  40. //    %d expects an integer argument
  41. //    %f expects a float or double argument
  42. //    %@ expects an id argument -- valid objects are EOAttribute,
  43. //         NSString, or anything that responds reasonably to:
  44. //       expressionValueForContext:(id <EOExpressionContext>)context
  45. //    %% is a '%' passed through...
  46. //    % followed by any other character is ignored
  47. //
  48.  
  49. // The following code excerpts build qualifiers similar to the
  50. // qualifier strings mentioned above, but can take the particular values
  51. // to compare from an already-fetched Enterprise Object:
  52. //
  53. //     myQualifier = [[EOQualifier alloc] initWithEntity:authorEntity
  54. //         description:"%A = '%@'", @"last_name", [anAuthorObject lastName]];
  55. //     myQualifier = [[EOQualifier alloc] initWithEntity:authorEntity
  56. //         description:"%A > %f", @"royalty", [anAuthorObject salary]];
  57. //
  58. // The Enterprise Object classes here implement convenience methods for
  59. // directly accessing the given attributes: -lastName and -salary for author
  60. // Enterprise Objects, and -lastName for publisher Enterprise Objects. 
  61.  
  62. // The next example calls the method formatValue:forAttribute: on the adaptor.
  63. // This method looks at the attribute and returns a correctly formatted value
  64. // that is suitable for this specific adaptor. In this case, since the
  65. // attribute is a string type, the method will return a quoted copy of the
  66. // with any embedded quotes suitably escaped.
  67. //     myQualifier = [[EOQualifier alloc] initWithEntity:authorEntity
  68. //         description:"%A = %@", [attribute name],
  69. //       [adaptor formatValue:[aPublisherObject lastName]
  70. //        forAttribute:attribute]];
  71.  
  72.  
  73. @interface EOQualifier:NSObject <NSCopying>
  74. {
  75.     EOEntity *_entity;
  76.     EOExpressionArray *_contents;
  77.     EORelationship *_flattenedRelationship;
  78.     struct {
  79.     unsigned int usesDistinct:1;
  80.     unsigned int _RESERVED:31;
  81.     } _flags;
  82. }
  83.  
  84. + (EOQualifier *)qualifierForPrimaryKey:(NSDictionary *)key
  85.     entity:(EOEntity *)entity;
  86.     // Creates a qualifier for the entity based on the primary key dictionary 
  87.     // Such a qualifier will select only the row or object with the primary 
  88.     // key supplied.
  89.  
  90. + (EOQualifier *)qualifierForRow:(NSDictionary *)row 
  91.     relationship:(EORelationship *)relationship;
  92.     // Creates a qualifier for the destination of row's relationship.  This
  93.     // qualifier will select only the row whose primary key matches the given
  94.     // row's foreign key for the relationship.
  95.  
  96. + (EOQualifier *)qualifierForObject:sourceObject relationship:(EORelationship *)relationship;
  97.     // Creates a qualifier for the destination of eo's relationship.  This
  98.     // qualifier will select only the row whose primary key matches the eo's
  99.     // foreign key for the relationship.  The EO must store all of the necessary
  100.     // foreign keys as class properties.
  101.  
  102. - initWithEntity:(EOEntity *)entity 
  103.     qualifierFormat:(NSString *)qualifierFormat, ...;
  104.     // Initializes a newly allocated EOQualifier to be rooted in the given
  105.     // entity and to build itself from the format string.  The
  106.     // format string is a printf()-style format string as described at
  107.     // the top of this header file.
  108.  
  109. - (BOOL)isEmpty;
  110.     // Returns YES if the qualifier will select the entire table for its
  111.     // entity (that is, if has no qualifying information).
  112.  
  113. - (void)setUsesDistinct:(BOOL)yn;
  114. - (BOOL)usesDistinct;
  115.     // Sets/returns whether the qualifier eliminates duplicates from results.
  116.     // If a select would yield the same row many times, a qualifier that
  117.     // usesDistinct eliminates all duplicates after the first.
  118.  
  119. - (EOEntity *)entity;
  120.     // Returns the entity that roots data paths in the qualifier.  Any
  121.     // reference to an attribute or relationship in the qualifier must belong
  122.     // to the root entity.
  123.  
  124. @end
  125.  
  126.  
  127. @interface EOQualifier(EOQualifierEditing)
  128.  
  129. - (void)negate;
  130.     // Negates the entire qualifier.
  131.  
  132. - (void)conjoinWithQualifier:(EOQualifier *)qualifier;
  133.     // Replaces the contents of the qualifier with the conjunction (logical
  134.     // AND) of the existing contents and the argument.
  135.  
  136. - (void)disjoinWithQualifier:(EOQualifier *)qualifier;
  137.     // Replaces the contents of the qualifier with the disjunction (logical
  138.     // OR) of the existing contents and the argument.
  139.  
  140. @end
  141.  
  142.