Adding tests for composite keys
[csql.git] / include / Database.h
blob347a61fadee831e9e9ed6183116b820c29c5d78d
1 /***************************************************************************
2 * Copyright (C) 2007 by www.databasecache.com *
3 * Contact: praba_tuty@databasecache.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 ***************************************************************************/
16 #ifndef DATABASE_H
17 #define DATABASE_H
18 #include<os.h>
19 #include<Allocator.h>
20 #include<Debug.h>
23 class Bucket;
24 class Transaction;
25 class DatabaseMetaData
27 public:
28 int dbID_;
29 char dbName_[IDENTIFIER_LENGTH];
31 //TODO:: move this from here to system database
32 //as only sys db has the limit and user
33 //database does not have any limit for chunks
34 int noOfChunks_;
36 long maxSize_; //maximum size of database
37 long curSize_; //current size of database
39 //current page, this is used by the allocator to get new free page
40 Page *curPage_;
42 //first page, usually after this database meta data
43 //getFreePage function uses this to get the free page in this database
44 Page *firstPage_;
47 //This mutex is taken if pageInfo is accessed or modified for
48 //this database
49 Mutex dbAllocMutex_;
51 Mutex dbMutex_;
53 Mutex dbTransTableMutex_;
55 Mutex dbProcTableMutex_;
57 //This is where all hash index nodes are stored for all the
58 //indexes in this database
59 Chunk *hashIndexChunk_;
61 unsigned char reserved_[1024];
65 class DatabaseManagerImpl;
66 class Table;
67 class ProcInfo;
68 class ThreadInfo;
70 class Database
72 private:
73 //Only DatabaseManager creates this object
74 //initialization is done only in DatabaseManager during
75 //create, delete, open, close database methods
76 Database() { metaData_ = NULL; }
77 DatabaseMetaData *metaData_;
80 public:
82 DbRetVal createSystemDatabaseChunk(AllocType type = FixedSizeAllocator,
83 size_t size = 0, int chunkID=-1);
84 DbRetVal deleteSystemDatabaseChunk(int id);
86 Chunk* getSystemDatabaseChunk(int id);
87 Transaction* getSystemDatabaseTrans(int slot);
89 ThreadInfo* getThreadInfo(int slot);
90 //ThreadInfo* getThreadInfo(int pidSlot, int thrSlot);
91 bool isLastThread();
93 void createAllCatalogTables();
94 void createSystemTables();
95 void createMetaDataTables();
97 void* allocLockHashBuckets();
98 Bucket* getLockHashBuckets();
100 void incrementChunk() { (metaData_->noOfChunks_)++;}
101 void decrementChunk() { (metaData_->noOfChunks_)--;}
103 const char* getName();
104 int getDatabaseID();
105 long getMaxSize();
106 long getCurrentSize();
107 Page* getCurrentPage();
108 int getNoOfChunks();
109 DatabaseMetaData* getMetaDataPtr() { return metaData_; }
110 Page* getFirstPage();
111 Chunk* getHashIndexChunk();
113 void setDatabaseID(int id);
114 void setName(const char *name);
115 void setCurrentSize(long size);
116 void setCurrentPage(Page *page);
117 void setMaxSize(long size);
118 void setNoOfChunks(int maxChunks);
119 void setMetaDataPtr(DatabaseMetaData *ptr) {metaData_ = ptr; }
120 void setFirstPage(Page *ptr);
121 void setHashIndexChunk(Chunk* chunk);
124 // Gets the free page
125 // Each page is segmented by PAGE_SIZE, so it checks the pageInfo
126 // of each page to determine if the page is free
127 Page* getFreePage();
128 Page* getFreePage(size_t size);
130 void printStatistics();
132 int initAllocDatabaseMutex();
133 DbRetVal getAllocDatabaseMutex(bool procAccount = true);
134 DbRetVal releaseAllocDatabaseMutex(bool procAccount = true);
136 int initTransTableMutex();
137 DbRetVal getTransTableMutex();
138 DbRetVal releaseTransTableMutex();
140 int initDatabaseMutex();
141 DbRetVal getDatabaseMutex(bool procAccount = true);
142 DbRetVal releaseDatabaseMutex(bool procAccount = true);
144 int initProcessTableMutex();
145 DbRetVal getProcessTableMutex(bool procAccount = true);
146 DbRetVal releaseProcessTableMutex(bool procAccount = true);
148 int procSlot;
149 void setProcSlot(int slot) { procSlot =slot;}
150 //checks whether the ptr falls in the range of the database file size
151 bool isValidAddress(void *ptr);
152 friend class DatabaseManagerImpl;
153 friend class Table;
157 #endif