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

  1. /**************************************************************************
  2.  * Source Id :
  3.  *
  4.  * $Id: dbobj.h,v 1.24 1993/11/04 14:59:41 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.  *
  23.  *        dbObject     : This is an object which handles low-level requests
  24.  *                     from the diamondBase.
  25.  *
  26.  *  Original Author :
  27.  *        Andy
  28.  *
  29.  *-------------------------------------------------------------------------
  30.  * Revision History:
  31.  *
  32.  * $Log: dbobj.h,v $
  33.  * Revision 1.24  1993/11/04  14:59:41  kevinl
  34.  * Fixed record locking
  35.  *
  36.  * Revision 1.23  1993/10/28  07:49:01  kevinl
  37.  * Added diaGRel dbString/dbData support
  38.  *
  39.  * Revision 1.22  1993/10/18  11:18:40  kevinl
  40.  * Added fieldName array
  41.  *
  42.  * Revision 1.21  1993/10/05  07:29:57  kevinl
  43.  * Added in dbObjData (previously in diaGRel)
  44.  *
  45.  * Revision 1.20  1993/06/23  05:21:22  kevinl
  46.  * Mallocs are now in angular brackets
  47.  *
  48.  * Revision 1.19  1993/06/20  13:39:23  kevinl
  49.  * theMemServer etc for String support
  50.  *
  51.  * Revision 1.18  1993/05/11  14:44:50  kevinl
  52.  * Added version number output
  53.  *
  54.  * Revision 1.17  1993/05/03  01:34:25  kevinl
  55.  * No more extern consts
  56.  *
  57.  * Revision 1.16  1993/05/01  14:38:08  kevinl
  58.  * Got rid of ints
  59.  * Reowrked inlie funcs to have 1 return
  60.  *
  61.  * Revision 1.15  1993/04/27  07:15:24  kevinl
  62.  * Added qWrite
  63.  * Fixed qId bounds checks on all query functions
  64.  *
  65.  * Revision 1.14  1993/04/25  13:19:57  kevinl
  66.  * Comments
  67.  *
  68.  * Revision 1.13  1993/04/15  07:58:55  kevinl
  69.  * Added del
  70.  *
  71.  * Revision 1.12  1993/04/15  04:28:17  kevinl
  72.  * Move malloc.h
  73.  *
  74.  * Revision 1.11  1993/04/11  05:49:02  kevinl
  75.  * Rationalised find/seek/peek methods etc
  76.  *
  77.  * Revision 1.10  1993/04/09  13:00:29  kevinl
  78.  * Stats can be called from diaRel now.
  79.  *
  80.  * Revision 1.9  1993/04/07  02:29:21  kevinl
  81.  * Changed qEnd to reset qId to -1
  82.  *
  83.  * Revision 1.8  1993/04/01  04:23:18  kevinl
  84.  * Fixed locking
  85.  * Added qFind, fixed the rest
  86.  *
  87.  * Revision 1.7  1993/03/30  07:15:19  davison
  88.  * Added the usage count stuff.
  89.  *
  90.  * Revision 1.6  1993/03/29  08:06:01  darrenp
  91.  * Nuked pathinfo
  92.  *
  93.  * Revision 1.5  1993/03/29  06:12:49  darrenp
  94.  * Nuked pathinfo structure
  95.  *
  96.  * Revision 1.4  1993/03/28  10:32:05  davison
  97.  * Modified for dbErr.
  98.  *
  99.  * Revision 1.3  1993/03/28  04:53:59  root
  100.  * more error code standardization.
  101.  *
  102.  * Revision 1.2  1993/03/26  06:16:38  darrenp
  103.  * standardized error codes.
  104.  *
  105.  * Revision 1.1  1993/03/25  22:29:25  davison
  106.  * Initial revision
  107.  *
  108.  **************************************************************************/
  109.  
  110. #ifndef __dbObject_h__
  111. #define __dbObject_h__
  112.  
  113. #include <idxinfo.h>
  114. #include <rserv.h>
  115. #include <btree.h>
  116. #include <object.h>
  117. #include <mserv.h>
  118. #include <iostream.h>
  119. #include <fstream.h>
  120.  
  121. const int NO_REC = -1;
  122.  
  123. class dbObject;
  124. class dbRegInfo;
  125. class diamondBase;
  126.  
  127. class dbQueryInfo
  128. {
  129.     long    queryId;
  130.     long    queryIdx;
  131.     long    queryRec;
  132.     bool    queryLock;
  133. public:
  134. //-----
  135. //    dbError status;
  136.  
  137. //    inline dberror(dbError err) { return status = err; };
  138.  
  139.     char* verStr(void) { return "$Id: dbobj.h,v 1.24 1993/11/04 14:59:41 kevinl Exp $"; }
  140.     dbQueryInfo(long id,long idx)
  141.     {
  142.         queryId = id;
  143.         queryIdx = idx;
  144.         queryRec = NO_REC;
  145.         queryLock = false;
  146.     }
  147.  
  148. #if 0
  149.     void pError(char *s)
  150.     {
  151.         cerr << ": ";
  152.         switch (status)
  153.         {    
  154.             case db_ok: cerr << "OK"; break;
  155.             case db_locked: cerr << "Query locked"; break;
  156.             case db_unlocked: cerr << "Query not locked"; break;
  157.             default: cerr << "GURGLE GURGLE SPLAT"; break;
  158.         }
  159.         cerr << endl;
  160.     }
  161. #endif
  162.  
  163.     // Lock the query. If it's already locked, tell them
  164.     dbError lock()
  165.     {
  166.         dbError err = db_locked;
  167.         if (queryLock == false)
  168.         {
  169.             queryLock = true;
  170.             err = db_ok;
  171.         }
  172.         return dbErr(err);
  173.     }
  174.  
  175.     // Unlock the query. If it's already unlocked, tell them
  176.     dbError unlock(void)
  177.     {
  178.         dbError err = db_unlocked;
  179.         if (queryLock == true)
  180.         {
  181.             queryLock = false;
  182.             err = db_ok;
  183.         }
  184.         return dbErr(err);
  185.     }
  186.  
  187.     // If the query is not locked, set the record this query used.
  188.     dbError setRec(long recIdx)
  189.     {
  190.         dbError err = db_locked;
  191.         if (queryLock == false)
  192.         {
  193.             queryRec = recIdx;
  194.             err = db_ok;
  195.         }
  196.         return dbErr(err);
  197.     }
  198.  
  199.     // We locked?
  200.     bool locked(void)
  201.     {
  202.         return queryLock;
  203.     }
  204.  
  205. friend dbObject;
  206.         
  207. };
  208.  
  209. #define MFII MAX_FIELDS_IN_INDEX
  210. class dbObjData
  211. {
  212. public:
  213.     // ----------------------------
  214.     // Data which is used to carry out the requested
  215.     // operations on the relation.
  216.     // ----------------------------
  217.     long        uniqOff;        // unique offset - -1 if not present 
  218.     long        numIndices;        // How many indices are there ?
  219.     long        numFields;        // How many fields are there ?
  220.     long        dataLength;        // What is the total length of the rec ?
  221.     long        stringCount;    // How many of the buggers we got?
  222.     long        *stringField;    // What are the numbers of the strings;
  223.     long        *theLongs;        // Array of offsets;
  224.     long        *containsUniq;    // Index contains a unique field.
  225.     long        *keyLength;        // Key lengths.
  226.     long        *fieldLength;    // How long each field is.
  227.     long        *fieldOffset;    // Where each field is.
  228.     char        *fieldType;        // What type each field is.
  229.     char        **fieldName;    // The field names.
  230.  
  231.     // These next two arrays are a real nightmare.
  232.     // They list which fields the indexes are compared
  233.     // on. There are two arrays, b/c they are compared in a
  234.     // different order to their packing order. C=comparison order
  235.     // P = packing order (during storage into btree)
  236.  
  237.     long        (*indexedOnC)[MFII];// Which fields are in each index.
  238.     long        (*indexedOnP)[MFII];// Which fields are in each index.
  239. };
  240.  
  241. class dbObject : public dbObjData
  242. {
  243. public:
  244. //-----
  245.  
  246. //    dbError status;
  247. //    inline dbError dboerror(dbError err) { return status = err; };
  248. //    void pError(char *s);
  249.  
  250. private:
  251. //------
  252.     char*        path;
  253.     char*        prefix;
  254.     fieldList    fldList;
  255.     indexList    idxList;
  256.     recServer*    theRecServer;
  257.     bTree**        theBTreeList;
  258.     memServer*    theMemServer;
  259.  
  260.     dbQueryInfo*    queryInfo[MAX_QUERY];
  261.  
  262.     long        usageCount;
  263.  
  264. public:
  265. //-----
  266.     dbObject(void)
  267.     {
  268.         idxList.numIndicies=0;
  269.         theBTreeList=0;
  270.         theRecServer=0;
  271.         theMemServer=0;
  272.         path=0;
  273.         prefix=0;
  274.     } // Use with care.
  275.     dbObject(char* path, char* name);
  276.     ~dbObject();
  277.     dbObjData* getObjData(void) { return (dbObjData*)this; }
  278.     char* verStr(void);
  279.     dbError checkRec(long qId, long recIdx, bool lockit = false);
  280.     dbError qBegin(long idxId, long& qId);
  281.     dbError qEnd(long& qId);
  282.     dbError qSeekFirst(long qId, object& theObject);
  283.     dbError qSeekLast(long qId, object& theObject);
  284.     dbError qNext(long qId, object& theObject, bool lock = false);
  285.     dbError qPeekNext(long qId, object& theObject);
  286.     dbError qPrev(long qId, object& theObject, bool lock = false);
  287.     dbError qPeekPrev(long qId, object& theObject);
  288.     dbError qSeek(long qId, object& theObject);
  289.     dbError qWrite(long qId, object& theObject);
  290.     dbError add(object& theObject);
  291.     dbError del(object& theObject);
  292.     void    stats(void);
  293.     dbError    getStrings(object& theObject);
  294.  
  295. friend class dbRegInfo;
  296. friend class diamondBase;
  297.  
  298. };
  299.  
  300. #endif
  301.