1 /***************************************************************************
2 * Copyright (C) 2007 by www.databasecache.com *
3 * Contact: praba_tuty@databasecache.com *
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. *
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. *
15 ***************************************************************************/
25 class DatabaseMetaData
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
36 size_t maxSize_
; //maximum size of database
37 size_t curSize_
; //current size of database
39 //current page, this is used by the allocator to get new free page
42 //first page, usually after this database meta data
43 //getFreePage function uses this to get the free page in this database
47 //This mutex is taken if pageInfo is accessed or modified for
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
;
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_
;
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 ProcInfo
* getProcInfo(int pidSlot
);
90 ThreadInfo
* getThreadInfo(int pidSlot
, int thrSlot
);
93 void createAllCatalogTables();
95 void* allocLockHashBuckets();
96 Bucket
* getLockHashBuckets();
99 int getNoOfChunks(){ return 0;}
101 const char* getName();
104 size_t getCurrentSize();
105 Page
* getCurrentPage();
107 DatabaseMetaData
* getMetaDataPtr() { return metaData_
; }
108 Page
* getFirstPage();
109 Chunk
* getHashIndexChunk();
111 void setDatabaseID(int id
);
112 void setName(const char *name
);
113 void setCurrentSize(size_t size
);
114 void setCurrentPage(Page
*page
);
115 void setMaxSize(size_t size
);
116 void setMaxChunks(int maxChunks
);
117 void setMetaDataPtr(DatabaseMetaData
*ptr
) {metaData_
= ptr
; }
118 void setFirstPage(Page
*ptr
);
119 void setHashIndexChunk(Chunk
* chunk
);
122 // Gets the free page
123 // Each page is segmented by PAGE_SIZE, so it checks the pageInfo
124 // of each page to determine if the page is free
126 Page
* getFreePage(size_t size
);
128 int initAllocDatabaseMutex();
129 DbRetVal
getAllocDatabaseMutex();
130 DbRetVal
releaseAllocDatabaseMutex();
132 int initTransTableMutex();
133 DbRetVal
getTransTableMutex();
134 DbRetVal
releaseTransTableMutex();
136 int initDatabaseMutex();
137 DbRetVal
getDatabaseMutex();
138 DbRetVal
releaseDatabaseMutex();
140 int initProcessTableMutex();
141 DbRetVal
getProcessTableMutex();
142 DbRetVal
releaseProcessTableMutex();
144 //checks whether the ptr falls in the range of the database file size
145 bool isValidAddress(void *ptr
);
146 friend class DatabaseManagerImpl
;