home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.0 / NeXTSTEP3.0.iso / NextDeveloper / Headers / dbkit / DBRecordStream.h < prev    next >
Text File  |  1992-05-20  |  5KB  |  166 lines

  1. /*
  2. **      DBRecordStream.h
  3. **      Database Kit, Release 3.0
  4. **      Copyright (c) 1992, NeXT Computer, Inc.  All rights reserved. 
  5. */
  6.  
  7. #import <objc/Object.h>
  8. #import <dbkit/protocols.h>
  9. #import <dbkit/enums.h>
  10.  
  11. @class List;
  12. @class DBDatabase;
  13. @class DBQualifier;
  14. @class DBValue;
  15.  
  16. @interface DBRecordStream : Object
  17. {
  18. @public
  19.   id delegate;
  20.   id source;
  21.   id properties;
  22.   id database;
  23.  
  24. @private
  25.   id _keys;
  26.   id _sorts;
  27.   int _qualifierMark;
  28.  
  29. @protected
  30.   id _selectBinder;
  31.   id _modifyBinder;
  32.   id _private;
  33.   short    _status;
  34.   struct {
  35.     BOOL isModified:1;
  36.     BOOL newRecord:1;
  37.     BOOL freeSource:1;
  38.     BOOL freeQualifier:1;
  39.     int _RESERVED:12;
  40.   } _flags;
  41. }
  42.  
  43.  
  44. /*
  45. ** clear causes the entire RecordStream to be reset.  Empty will leave the
  46. **  orderings, keys, and properties intact.
  47. */
  48. - init;
  49. - empty;
  50. - clear;
  51. - free;
  52.  
  53. /*
  54. ** Any binders used by the recordStream will have the binderDelegate as 
  55. **  their delegate.
  56. */
  57. - delegate;
  58. - binderDelegate;
  59. - setDelegate:newDelegate;
  60. - setBinderDelegate:newDelegate;
  61.  
  62. /*
  63. ** setProperties: will reset the keys list to contain any properties that
  64. **  respond YES to isKey -- the keys can be read and modified after this
  65. **  by calling getKeys and/or setKeys:
  66. **
  67. ** The entity for every property in the list submitted must match the entity
  68. **  of the RecordList, otherwise the entire operation fails.
  69. */
  70.  
  71. - (List*)getProperties:(List*)returnList;
  72. - (List*)setProperties:(List*)aPropertyList ofSource:aSource;
  73. - (List*)getKeyProperties:(List*)returnList;
  74. - (List*)setKeyProperties:(List*)aPropertyL$    Q
  75.  
  76. - addRetrieveOrder:(DBRetrieveOrder)anOrder for:(id<DBProperties>)aProperty;
  77.  
  78. - fetchUsingQualifier:(DBQualifier*)aQualifier;
  79. - cancelFetch;
  80.  
  81. - (BOOL)isModified;
  82. - (BOOL)isNewRecord;
  83. - (BOOL)isReadOnly;
  84. - (DBRecordRetrieveStatus)currentRetrieveStatus;
  85.  
  86. /*
  87. ** saveModifications returns the number of records successfully modified and
  88. **  sent to the database.  For the RecordStream, this will always be either
  89. **  0, 1, or -1 on failure.
  90. */
  91. - (unsigned)saveModifications;
  92.  
  93. /*
  94. ** These methods are the only way to access the contents of the record
  95. */
  96. - getValue:(DBValue*)aValue forProperty:aProperty;
  97. - setValue:(DBValue*)aValue forProperty:aProperty;
  98.  
  99. - getRecordKeyValue:(DBValue*)aValue;
  100.  
  101. /*
  102. ** Record management --
  103. **  Both newRecord and deleteRecord will return nil if they failed (and that
  104. **  failure was not condoned or caught by the delegate).  If they return
  105. **  nil, then the cursor has NOT been advanced; it still points at the
  106. **  same record!!!  In the same way, setNext will return nil
  107. **  if the cursor has not advanced due to a failure.
  108. **
  109. ** The delegate has the option of "approving" a failure, by returning
  110. **  YES from recordStream:willFailForReason:  If YES is returned, the cursor
  111. **  will advance and the failure will be ignored.  In this event, if there
  112. **  is an active transaction context, its up to the application to deal with
  113. **  commit/abort.  Otherwise, the failed record will NOT have been committed
  114. **  to the database.
  115. **
  116. ** If there is no delegate, or the delegate returns NO from
  117. **  recordStream:willFailForReason:, then the cursor will not advance and
  118. **  whatever action is underway will not occur.
  119. **
  120. ** setNext returns self if there are more records, and nil if at end.
  121. */
  122. - newRecord;
  123. - deleteRecord;
  124. - setNext;
  125.  
  126. @end
  127.  
  128. @interface Object (DBRecordStreamDelegate)
  129.  
  130. /*
  131. ** The delegate of the RecordStream is given the opportunity to continue
  132. **  the transaction or abort.  If the delegate returns YES from its
  133. **  recordList:willFailAt:reason: method, the list will attempt to abort
  134. **  a local transaction.  If the transaction is not "owned" by the recordList,
  135. **  it is the responsibility of the app to either rollback or commit.
  136. **  If YES is returned, the list will attempt the rest of its modifications.
  137. **
  138. ** If the database being accessed supports transactions, they
  139. **  should always be enabled befo$    Raving modifications.  It is, in general,
  140. **  both safer for the integrity of the data involved and much more
  141. **  efficient to do this.
  142. */
  143. - (BOOL)recordStream:aRecordStream willFailForReason:(DBFailureCode)aCode;
  144.  
  145. /*
  146. ** The recordStream normally verifies that a record still exists and is
  147. **  unique before modifying or deleting it.  The default mechanism is to
  148. **  do a "confirming select" on the DBDatabase using the key value, and
  149. **  then to compare all properties to see that they haven't changed.  (The
  150. **  select is usually a locking select.)
  151. **
  152. ** This entire mechanism can be replaced by implementing the following
  153. **  delegate method.  In this case, verification and locking are up to the
  154. **  delegate object -- if YES is returned, the record is considered to
  155. **  be verified, and modification will proceed.  If NO is returned, the
  156. **  record will not be modified.  This may also cause the entire containing
  157. **  saveModifications: to fail, depending on the transaction model being
  158. **  used.
  159. **
  160. ** The only recordStream/recordList method that should be called during this
  161. **  delegate method is getValue:forProperty:
  162. */
  163. - (BOOL)recordStreamPrepareCurrentRecordForModification:aRecordStream;
  164.  
  165. @end
  166.