include/Database.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 #ifndef DATABASE_H
00017 #define DATABASE_H
00018 #include<os.h>
00019 #include<Allocator.h>
00020 #include<Debug.h>
00021 
00022 
00023 class Bucket;
00024 class Transaction;
00025 class DatabaseMetaData
00026 {
00027     public:
00028     int dbID_;
00029     char dbName_[IDENTIFIER_LENGTH];
00030 
00031     //TODO:: move this from here to system database
00032     //as only sys db has the limit and user
00033     //database does not have any limit for chunks
00034     int noOfChunks_;
00035 
00036     long maxSize_; //maximum size of database
00037     long curSize_; //current size of database
00038 
00039     //current page, this is used by the allocator to get new free page
00040     Page *curPage_;
00041 
00042     //first page, usually after this database meta data
00043     //getFreePage function uses this to get the free page in this database
00044     Page *firstPage_;
00045 
00046 
00047     //This mutex is taken if pageInfo is accessed or modified for
00048     //this database
00049     Mutex dbAllocMutex_;
00050 
00051     Mutex dbMutex_;
00052 
00053     Mutex dbTransTableMutex_;
00054 
00055     Mutex dbProcTableMutex_;
00056 
00057     //This is where all hash index nodes are stored for all the
00058     //indexes in this database
00059     Chunk *hashIndexChunk_;
00060 
00061     unsigned char reserved_[1024];
00062 };
00063 
00064 
00065 class DatabaseManagerImpl;
00066 class Table;
00067 class ProcInfo;
00068 class ThreadInfo;
00069 
00070 class Database
00071 {
00072     private:
00073     //Only DatabaseManager creates this object
00074     //initialization is done only in DatabaseManager during
00075     //create, delete, open, close database methods
00076     Database() { metaData_ = NULL; }
00077     DatabaseMetaData *metaData_;
00078 
00079 
00080     public:
00081 
00082     DbRetVal createSystemDatabaseChunk(AllocType type = FixedSizeAllocator,
00083                                       size_t size = 0, int chunkID=-1);
00084     DbRetVal deleteSystemDatabaseChunk(int id);
00085 
00086     Chunk* getSystemDatabaseChunk(int id);
00087     Transaction* getSystemDatabaseTrans(int slot);
00088 
00089     ThreadInfo* getThreadInfo(int slot);
00090     //ThreadInfo* getThreadInfo(int pidSlot, int thrSlot);
00091     bool isLastThread();
00092 
00093     void createAllCatalogTables();
00094     void createSystemTables();
00095     void createMetaDataTables();
00096 
00097     void* allocLockHashBuckets();
00098     Bucket* getLockHashBuckets();
00099 
00100     void incrementChunk() { (metaData_->noOfChunks_)++;}
00101     void decrementChunk() { (metaData_->noOfChunks_)--;}
00102 
00103     const char* getName();
00104     int getDatabaseID();
00105     long getMaxSize();
00106     long getCurrentSize();
00107     Page* getCurrentPage();
00108     int getNoOfChunks();
00109     DatabaseMetaData* getMetaDataPtr() { return metaData_; }
00110     Page* getFirstPage();
00111     Chunk* getHashIndexChunk();
00112 
00113     void setDatabaseID(int id);
00114     void setName(const char *name);
00115     void setCurrentSize(long size);
00116     void setCurrentPage(Page *page);
00117     void setMaxSize(long size);
00118     void setNoOfChunks(int maxChunks);
00119     void setMetaDataPtr(DatabaseMetaData *ptr) {metaData_ = ptr; }
00120     void setFirstPage(Page *ptr);
00121     void setHashIndexChunk(Chunk* chunk);
00122 
00123 
00124     // Gets the free page
00125     // Each page is segmented by PAGE_SIZE, so it checks the pageInfo
00126     // of each page to determine if the page is free
00127     Page* getFreePage();
00128     Page* getFreePage(size_t size);
00129 
00130     void printStatistics();
00131 
00132     int initAllocDatabaseMutex();
00133     DbRetVal getAllocDatabaseMutex(bool procAccount = true);
00134     DbRetVal releaseAllocDatabaseMutex(bool procAccount = true);
00135 
00136     int initTransTableMutex();
00137     DbRetVal getTransTableMutex();
00138     DbRetVal releaseTransTableMutex();
00139 
00140     int initDatabaseMutex();
00141     DbRetVal getDatabaseMutex(bool procAccount = true);
00142     DbRetVal releaseDatabaseMutex(bool procAccount = true);
00143 
00144     int initProcessTableMutex();
00145     DbRetVal getProcessTableMutex(bool procAccount = true);
00146     DbRetVal releaseProcessTableMutex(bool procAccount = true);
00147 
00148     int procSlot;
00149     void setProcSlot(int slot) { procSlot =slot;}
00150     //checks whether the ptr falls in the range of the database file size
00151     bool isValidAddress(void *ptr);
00152     friend class DatabaseManagerImpl;
00153     friend class Table;
00154 
00155 };
00156 
00157 #endif

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