home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.2 (Developer) / NS_dev_3.2.iso / NextDeveloper / Headers / dbkit / DBDatabase.h < prev    next >
Text File  |  1993-08-06  |  6KB  |  209 lines

  1. /*
  2. **      DBDatabase.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 <ansi/stdarg.h>
  9. #import <dbkit/protocols.h>
  10. #import <mach/cthreads.h>
  11.  
  12. @class List;
  13. @class DBBinder;
  14.  
  15. /*
  16. ** A Database represents a (potential) connection to an external source of
  17. **  data.  It also represents structural information about that source of
  18. **  data.  This structural information is represented as a list of properties.
  19. **  (See the protocols header for a description of a property.)
  20. **
  21. ** Properties can either be built from scratch by a tool or by a program, or
  22. **  they can be provided by the DBDatabase.  In the latter case, the complexity
  23. **  and completeness of the data dictionary is totally dependant upon the
  24. **  database; most will produce a very simple model which reflects their 
  25. **  structure.
  26. **
  27. ** Given an expressive enough query language, properties can also be built
  28. **  by using DBExpressions -- aggregate and compound properties can be built
  29. **  this way.
  30. */
  31.  
  32. @interface DBDatabase : Object
  33. {
  34. @public
  35.   id delegate;
  36.  
  37. @private
  38.   id _adaptor;
  39.   mutex_t _adaptorLock;
  40.  
  41.   id _entityList;
  42.   id _bundle;
  43.   id _strings;
  44.  
  45.   id _databaseNameString;
  46.   char *_namebuf;
  47.   id _identityProperty;
  48.  
  49.   id _private;
  50.   struct {
  51. #if    __BIG_ENDIAN__
  52.     BOOL connected:1;
  53.     BOOL panelsEnabled:1;
  54.     BOOL delegateDoesTrace:1;
  55.     BOOL delegateChecksQuery:1;
  56.     BOOL transactionInProgress:1;
  57.     BOOL useOuterJoins:1;
  58.     BOOL isAsciiFormat:1;
  59.     int _RESERVED:9;
  60. #else    __BIG_ENDIAN__
  61.     int _RESERVED:9;
  62.     BOOL isAsciiFormat:1;
  63.     BOOL useOuterJoins:1;
  64.     BOOL transactionInProgress:1;
  65.     BOOL delegateChecksQuery:1;
  66.     BOOL delegateDoesTrace:1;
  67.     BOOL panelsEnabled:1;
  68.     BOOL connected:1;
  69. #endif    __BIG_ENDIAN__
  70.   } _flags;
  71.   NXZone *_garbageZone;
  72. }
  73.  
  74. + initialize;
  75.  
  76. /*
  77. ** If there is an open db with this name, it is returned.  If there is a
  78. **  database file in the search path with this name, it is opened and a
  79. **  connection is attempted.  If the connection attempt fails, the 
  80. **  database is freed, so subsequent calls will attempt to connect again,
  81. **  possibly using new information...
  82. **
  83. ** Databases found using this method should not be freed!
  84. */
  85. + findDatabaseNamed:(const char*)aName connect:(BOOL)yn;
  86.  
  87. /*
  88. ** Databases can use database "bundles" that reside in the filesystem to
  89. **  initialize themselves with user and schema information.  The documents are
  90. **  directories (with a file extension of .db) that contain at least two
  91. **  files: db.strings and db.archive.
  92. **
  93. ** Within the bundle, db.strings is a stringTable that can contain a string
  94. **  with the key "AdaptorName".  It can also contain multiple initStrings,
  95. **  indexed by username.  A key of "LoginString" will be used as a default
  96. **  loginString.
  97. */
  98. + (const char**)databaseNamesForAdaptor:(const char*)anAdaptorName;
  99. + (const char**)adaptorNames;
  100.  
  101. - initFromFile:(const char*)aPath;
  102. - (const char*)directory;
  103.  
  104. - (const char*)name;
  105. - (BOOL)setName:(const char*)aName;
  106.  
  107. - adaptor;
  108.  
  109. - (BOOL)connect;
  110. - (BOOL)disconnect;
  111. - (BOOL)connectUsingString:(const unsigned char*)aString;
  112. - (BOOL)disconnectUsingString:(const unsigned char*)aString;
  113.  
  114. - (BOOL)isConnected;
  115. - (const unsigned char*)connectionName;
  116.  
  117. - (BOOL)beginTransaction;
  118. - (BOOL)commitTransaction;
  119. - (BOOL)rollbackTransaction;
  120.  
  121. - (BOOL)isTransactionInProgress;
  122. - (BOOL)enableTransactions:(BOOL)yn;
  123. - (BOOL)areTransactionsEnabled;
  124.  
  125. - (BOOL)evaluateString:(const unsigned char*)aString, ...;
  126.  
  127. - (List*)getEntities:(List*)aList;
  128. - (id<DBEntities>)entityNamed:(const char*)aName;
  129.  
  130. /*
  131. ** These can be used to find information specific to the current db bundle.
  132. */
  133. - (const char*)currentAdaptorName;
  134. - (const char*)defaultAdaptorName;
  135. - (const unsigned char*)currentLoginString;
  136. - (const unsigned char*)defaultLoginString;
  137. - (const unsigned char*)loginStringForUser:(const char*)aUser;
  138.  
  139. /*
  140. ** This can be used to launch a login panel, or to use a specific adaptor
  141. **  in the context of a database.  The init string can be NULL.
  142. */
  143. - (BOOL)connectUsingAdaptor:(const char*)aClassname
  144.     andString:(const unsigned char*)aLoginString;
  145.  
  146. /*
  147. ** -emptyDataDictionary will free up the currently loaded data dictionary
  148. **  so that another can be opened for the db.  -loadDefaultDataDictionary
  149. **  will attempt to load a data dictionary from the adaptor if one is
  150. **  not already loaded.
  151. */
  152. - emptyDataDictionary;
  153. - loadDefaultDataDictionary;
  154.  
  155. /*
  156. ** Delegate can act as trace of execution, log all query expressions, or
  157. **  verify query expressions. It can also override commits and aborts.
  158. */
  159. - setDelegate:aDelegate;
  160. - delegate;
  161.  
  162. @end
  163.  
  164. @interface Object (DatabaseDelegate)
  165.  
  166. /*
  167. ** Commit/abort verification -- no cancelling allowed!
  168. */
  169. - dbWillCommitTransaction:aDatabase;
  170. - dbDidCommitTransaction:aDatabase;
  171. - dbWillRollbackTransaction:aDatabase;
  172. - dbDidRollbackTransaction:aDatabase;
  173.  
  174. /*
  175. ** Query interposition -- before evaluating an expression, the delegate can
  176. **  be given the chance to override a query expression, to examine it, or
  177. **  to replace it.
  178. */
  179. - (BOOL)db:aDb willEvaluateString:(const unsigned char*)aString
  180.      usingBinder:aBinder;
  181.  
  182. /*
  183. ** Logging -- the delegate receives a printf style format string and
  184. **  arguments, to be used with vsprintf().
  185. */
  186. - db:aDatabase log:(const char*)fmt, ...;
  187.  
  188. /*
  189. ** Notification -- an object being used by the database has encountered
  190. **  an exceptional situation.
  191. **
  192. ** By providing a delegate that responds to this method, the default alert
  193. **  panels can be squelched.
  194. */
  195. - (BOOL)db:aDb notificationFrom:anObject
  196.      message:(const unsigned char*)msg code:(int)n;
  197.  
  198. /*
  199. ** setPanelsEnabled:NO must be called if you plan to use the DBDatabase
  200. **  without panels or windows, or in a program without an Application object.
  201. */
  202. - (BOOL)arePanelsEnabled;
  203. - setPanelsEnabled:(BOOL)yn;
  204.  
  205. - read:(NXTypedStream*)ts;
  206. - write:(NXTypedStream*)ts;
  207.  
  208. @end
  209.