include/CatalogTables.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2007 by www.databasecache.com                           *
00003  *   Contact: praba_tuty@databasecache.com                                 *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015   ***************************************************************************/
00016 
00017 #ifndef CATALOGTABLE_H
00018 #define CATALOGTABLE_H
00019 
00020 #include<DataType.h>
00021 #include<os.h>
00022 #include<Index.h>
00023 #include<Debug.h>
00024 #include<Util.h>
00025 
00026 class FieldList;
00027 class FieldNameList;
00028 class FieldIterator;
00029 class ChunkIterator;
00030 
00031 enum CatalogTableID
00032 {
00033     // chunk id 0 ->userChunkTable
00034     //
00035     // chunk id 10->DATABASE
00036     // chunk id 11->USER
00037     // chunk id 12->TABLE
00038     // chunk id 13->FIELD
00039     // chunk id 14->ACCESS
00040     // chunk id 15->INDEX
00041     // chunk id 16->INDEXFIELD
00042 
00043     UserChunkTableId      =  0,
00044     LockTableHashBucketId =  1,
00045     LockTableMutexId      =  2,
00046     LockTableId           =  3,
00047     TransHasTableId       =  4,
00048     UndoLogTableID        =  5,
00049 
00050 
00051     DatabaseTableId  = 10,
00052     UserTableId      = 11,
00053     TableTableId     = 12,
00054     FieldTableId     = 13,
00055     AccessTableId    = 14,
00056     IndexTableId     = 15,
00057     IndexFieldTableId= 16
00058 
00059 };
00060 
00061 
00062 class TABLE
00063 {
00064     public:
00065     char tblName_[IDENTIFIER_LENGTH];
00066     int tblID_;
00067     size_t length_; //length of the tuple
00068     int numFlds_;
00069     int numIndexes_;
00070     void* chunkPtr_;
00071 
00072 };
00073 
00074 class CatalogTableTABLE
00075 {
00076     Database *systemDatabase_;
00077     public:
00078     CatalogTableTABLE(Database *db) { systemDatabase_  = db; }
00079 
00080     //Last argument is OUT parameter which will contain the
00081     //pointer to the inserted tuple
00082     DbRetVal insert(const char *name, int id, size_t size,
00083                      int numFlds, void* chunk, void *&tptr);
00084 
00085     //Second argument is OUT parameter which will contain the
00086     //chunk pointer of this table
00087     //Third argument is OUT parameter which will contain the
00088     //pointer to the removed tuple
00089     DbRetVal remove(const char *name, void *&chunk, void *&tptr);
00090 
00091     DbRetVal getChunkAndTblPtr(const char *name, void *&chunk, void *&tptr);
00092 
00093     List getTableList();
00094 };
00095 
00096 
00097 class FIELD
00098 {
00099     public:
00100     char fldName_[IDENTIFIER_LENGTH];
00101     int tblID_;      //table id where this field resides
00102     void* tblPtr_;    //pointer to tuple in catalog table TABLE
00103     DataType type_;
00104     size_t length_;  //length of the field
00105     size_t offset_;  //offset (in bytes) into tuple
00106     //currently default value is supported for string and binary
00107     //less than length 32 bytes
00108     char defaultValueBuf_[DEFAULT_VALUE_BUF_LENGTH];
00109     bool isNull_;
00110     bool isPrimary_;
00111     bool isUnique_;
00112     bool isDefault_;
00113     int width_;
00114     int scale_;
00115 };
00116 
00117 class CatalogTableFIELD
00118 {
00119     Database *systemDatabase_;
00120     public:
00121     CatalogTableFIELD(Database *db) { systemDatabase_  = db; }
00122 
00123     //returns -1 on error
00124     DbRetVal insert(FieldIterator &iter, int tblID, void *tblPtr);
00125 
00126     DbRetVal remove(void *tblPtr);
00127 
00128     //II argument is OUT parameter
00129     //field list is populated from the catalog table for
00130     // the table pointed by tblPtr
00131     void getFieldInfo( void* tblPtr, FieldList &list);
00132 
00133     //array is OUT param
00134     //returns the pointer to fields for the corresponding name
00135     //in field name list as an array
00136     DbRetVal getFieldPtrs(FieldNameList &fldList,void *tptr, char **&array);
00137 };
00138 
00139 class USER
00140 {
00141     public:
00142     char userName_[IDENTIFIER_LENGTH];
00143     char password_[IDENTIFIER_LENGTH];
00144 };
00145 
00146 class CatalogTableUSER
00147 {
00148     Database *systemDatabase_;
00149     public:
00150     CatalogTableUSER(Database *db) { systemDatabase_  = db; }
00151 
00152     //returns -1 on error
00153     DbRetVal insert(const char *name, const char *pass);
00154     DbRetVal authenticate(const char *name, const char *pass,
00155                      bool &isAuthenticated, bool &isDba);
00156     DbRetVal remove(const char *name);
00157     DbRetVal changePass(const char *name, const char *pass);
00158 
00159 };
00160 
00161 class ACCESS
00162 {
00163     public:
00164     char userName_[IDENTIFIER_LENGTH];
00165     char dbName_[IDENTIFIER_LENGTH];
00166 };
00167 
00168 class DATABASEFILE
00169 {
00170     public:
00171     int dbID_;
00172     char dbName_[IDENTIFIER_LENGTH];
00173     int maxChunks_;
00174     size_t maxSize_;  //maximum size of database
00175     caddr_t dbStart_; //address where the database is mapped
00176 };
00177 
00178 
00179 class INDEX
00180 {
00181     public:
00182     char indName_[IDENTIFIER_LENGTH];
00183     int tblID_;      //table id of the table
00184     void* tblPtr_;    //pointer to tuple in catalog table TABLE
00185     IndexType indexType_;
00186     void* chunkPtr_; //pointer to the index chunk
00187     int numFlds_;
00188     int noOfBuckets_;
00189     bool isUnique_;
00190     void *hashNodeChunk_;
00191 
00192 };
00193 
00194 class CatalogTableINDEX
00195 {
00196     Database *systemDatabase_;
00197     public:
00198     CatalogTableINDEX(Database *db) { systemDatabase_  = db; }
00199 
00200 
00201     //last arg is OUT parameter which will give the pointer to
00202     //the index tuple
00203     DbRetVal insert(const char *name, void *tblPtr, int numFlds, bool isUnique,
00204                      void* chunk, int bucketSize, void *hChunk, void *&tupleptr);
00205 
00206     //Second argument is OUT parameter which will contain the
00207     //chunk pointer of this table
00208     //Third argument is OUT parameter which will contain the
00209     //pointer to the removed tuple
00210     DbRetVal remove(const char *name, void *&chunk, void *&hchunk, void *&iptr);
00211     DbRetVal get(const char *name, void *&chunk, void *&hchunk, void *&iptr);
00212 
00213     //get the number of indexes on table pointed by tblPtr
00214     int getNumIndexes(void *tblPtr);
00215 
00216     char* getIndexName(void *tblPtr, int pos);
00217 
00218     //gets all the index ptrs as array for the table pointed by tblPtr
00219     void getIndexPtrs(void *tblPtr, char **&array);
00220 
00221     static ChunkIterator getIterator(void *iptr);
00222     static int getNoOfBuckets(void *iptr);
00223     static int getUnique(void *iptr);
00224     static char* getName(void *iptr);
00225 };
00226 
00227 
00228 class INDEXFIELD
00229 {
00230     public:
00231     void* indexPtr; //pointer to tuple in catalog table INDEX
00232     void* tablePtr; //pointer to tuple in catalog table TABLE
00233     void* fieldPtr; //pointer to tuple in catalog table FIELD
00234 
00235 };
00236 
00237 class CatalogTableINDEXFIELD
00238 {
00239     Database *systemDatabase_;
00240     public:
00241     CatalogTableINDEXFIELD(Database *db) { systemDatabase_  = db; }
00242 
00243     DbRetVal insert(FieldNameList &fldList, void *indexPtr,
00244                                void *tblPtr, char **&fptr);
00245 
00246     DbRetVal remove(void *iptr);
00247 
00248     DbRetVal getFieldNameAndType(void *iptr, char *&name, DataType &type);
00249 
00250 };
00251 #endif

Generated on Mon Jun 9 22:37:14 2008 for csql by  doxygen 1.4.7