home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / db02_src.zip / dbase.h < prev    next >
C/C++ Source or Header  |  1993-11-05  |  5KB  |  182 lines

  1. /**************************************************************************
  2.  * Source Id :
  3.  *
  4.  * $Id: dbase.h,v 1.15 1993/10/05 07:30:22 kevinl Exp $
  5.  *-------------------------------------------------------------------------
  6.  * Project Notes :
  7.  *
  8.  *  Diamond Base
  9.  *  ============
  10.  *      A solid database implementation, spurred on by the continuing
  11.  *  Metal (Lead) Base saga.
  12.  *
  13.  *  Project Team :
  14.  *        A. Davison
  15.  *        K. Lentin
  16.  *        D. Platt
  17.  *
  18.  *    Project Commenced : 05-02-1993
  19.  *
  20.  *-------------------------------------------------------------------------
  21.  *  Module Notes :
  22.  *      DiamondBase Object : This object is the main database which will
  23.  *  interact with client code via a transaction protocol
  24.  *
  25.  *  Original Author :
  26.  *        Andy
  27.  *
  28.  *-------------------------------------------------------------------------
  29.  * Revision History:
  30.  *
  31.  * $Log: dbase.h,v $
  32.  * Revision 1.15  1993/10/05  07:30:22  kevinl
  33.  * AAdded dbObjData to attach
  34.  *
  35.  * Revision 1.14  1993/06/23  05:21:22  kevinl
  36.  * Mallocs are now in angular brackets
  37.  *
  38.  * Revision 1.13  1993/05/11  15:14:41  kevinl
  39.  * Made constructor for diamondBase have an optional argument since
  40.  *      TNameServer can handle the null.
  41.  *
  42.  * Revision 1.12  1993/05/11  14:44:50  kevinl
  43.  * Added version number output
  44.  *
  45.  * Revision 1.11  1993/05/01  14:37:13  kevinl
  46.  * Got rid of ints
  47.  *
  48.  * Revision 1.10  1993/04/27  07:14:13  kevinl
  49.  * Added put and write
  50.  *
  51.  * Revision 1.9  1993/04/11  05:49:02  kevinl
  52.  * Rationalised find/seek/peek methods etc
  53.  *
  54.  * Revision 1.8  1993/04/09  13:00:29  kevinl
  55.  * Stats can be called from diaRel now.
  56.  *
  57.  * Revision 1.7  1993/04/04  23:57:47  kevinl
  58.  * Cache dbObj's
  59.  *
  60.  * Revision 1.6  1993/04/01  04:23:46  kevinl
  61.  * Modified/added transactions
  62.  * Now have get, extract, and find
  63.  *
  64.  * Revision 1.5  1993/03/30  07:13:52  davison
  65.  * Usage counter for dbObject implemented, thus burying the delete bug (this
  66.  * time Rocky, fur shur !)
  67.  *
  68.  * Revision 1.4  1993/03/29  08:05:26  darrenp
  69.  * Removed deletion of other peoples' data
  70.  *
  71.  * Revision 1.3  1993/03/26  06:16:38  darrenp
  72.  * standardized error codes.
  73.  *
  74.  * Revision 1.2  1993/03/25  23:25:36  davison
  75.  * Added the detach method.
  76.  *
  77.  * Revision 1.1  1993/03/25  22:28:50  davison
  78.  * Initial revision
  79.  *
  80.  **************************************************************************/
  81.  
  82. #ifndef __DiamondBaseObject_H__
  83. #define __DiamondBaseObject_H__
  84.  
  85. #define MAX_REG 20
  86. #define MAX_DB_INFO 20
  87.  
  88. #if (MAX_REG > MAX_DB_INFO)
  89. #error There must be at least as many dbObj slots as regInfo slots
  90. #endif
  91.  
  92. #include <nserver.h>
  93. #include <dbobj.h>
  94. #include <time.h>
  95.  
  96. class diamondBase;
  97. class dbObject;
  98.  
  99. // Who put this here?
  100. // extern diamondBase theDBase;
  101.  
  102. //------------------------------------------------------------------
  103. // dbInfo struct. This holds this dbObj. We use this so that dbObj's
  104. // can remain open, thus effecting good cacheing.
  105.  
  106. struct dbInfo {
  107.     dbObject    *theDbObject;
  108.     long        nameId;
  109.     time_t        detachTime;
  110. };
  111.  
  112. //------------------------------------------------
  113. // User Class Registration Information Structure.
  114. //
  115. //    Keeps track of the user classes currently attatched
  116. // to the database server. This information includes
  117. // a pointer to the buffer area, a pointer to the 
  118. // dbObject the user has requested access to, the
  119. // nameId for the relation and the current
  120. // query context.
  121.  
  122. class dbRegInfo
  123. {
  124.     object*     buffer;
  125.     long        dbListId;
  126.     long        queryId;
  127. public:
  128.     dbRegInfo(object* theObj, long listId)
  129.     {
  130.         buffer = theObj;
  131.         dbListId = listId;
  132.         queryId = -1;
  133.     }
  134.  
  135.     ~dbRegInfo()
  136.     {
  137.         // Repeat a thousand times, I shalt not delete other peoples data!
  138.         // delete buffer;
  139. //        if(!(--theDbObject->usageCount))
  140. //            delete theDbObject;
  141. //        nameId = -1;
  142.     }
  143.     char* verStr(void) { return "$Id: dbase.h,v 1.15 1993/10/05 07:30:22 kevinl Exp $"; }
  144. #if 0
  145.     void saveDbObject(void)
  146.     {
  147.         theDbObject = 0;
  148.     }
  149. #endif
  150.     friend class diamondBase;
  151. };
  152.  
  153. //---------------------------------------------
  154. //  The staticly linked database server.
  155.  
  156. class diamondBase  : public TNameServer
  157. {
  158.     private:
  159.         dbRegInfo*        regInfo[MAX_REG];    // The registration info.
  160.         dbInfo            dbList[MAX_DB_INFO]; // The open relations
  161. //        long            nameIds[MAX_RELATIONS][2];
  162.                         // The first element of this is the nameId for
  163.                         // some relation which has been registered. The second
  164.                         // is the number of user classes currently accessing
  165.                         // it. When User classes are detached, this array is
  166.                         // checked to determine whether or not to delete the
  167.                         // dbObject associated with the user class.
  168.     public:
  169.         enum transId {ti_add,ti_del,ti_begin,ti_end,ti_get,ti_put,ti_extract,
  170.             ti_seekFirst,ti_first,ti_next,ti_prev,ti_seekLast,ti_last,
  171.             ti_peekNext,ti_peekPrev,ti_seek,ti_find,ti_stats,ti_write};
  172.  
  173.         char* verStr(void);
  174.         char* version(bool full = false);
  175.         diamondBase(char* name = 0);
  176.         dbError attach(const char* name, object* resBuffer, long& refId, dbObjData* & objData);
  177.         dbError detach(long refId);
  178.         dbError trans(long refId,transId id,long idx=0);
  179.         ~diamondBase();
  180. };
  181. #endif
  182.