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