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
;
70 //Only DatabaseManager creates this object
71 //initialization is done only in DatabaseManager during
72 //create, delete, open, close database methods
73 Database() { metaData_
= NULL
; }
74 DatabaseMetaData
*metaData_
;
79 DbRetVal
createSystemDatabaseChunk(AllocType type
= FixedSizeAllocator
,
80 size_t size
= 0, int chunkID
=-1);
81 DbRetVal
deleteSystemDatabaseChunk(int id
);
83 Chunk
* getSystemDatabaseChunk(int id
);
84 Transaction
* getSystemDatabaseTrans(int slot
);
86 void createAllCatalogTables();
88 void* allocLockHashBuckets();
89 Bucket
* getLockHashBuckets();
92 int getNoOfChunks(){ return 0;}
94 const char* getName();
97 size_t getCurrentSize();
98 Page
* getCurrentPage();
100 DatabaseMetaData
* getMetaDataPtr() { return metaData_
; }
101 Page
* getFirstPage();
102 Chunk
* getHashIndexChunk();
104 void setDatabaseID(int id
);
105 void setName(const char *name
);
106 void setCurrentSize(size_t size
);
107 void setCurrentPage(Page
*page
);
108 void setMaxSize(size_t size
);
109 void setMaxChunks(int maxChunks
);
110 void setMetaDataPtr(DatabaseMetaData
*ptr
) {metaData_
= ptr
; }
111 void setFirstPage(Page
*ptr
);
112 void setHashIndexChunk(Chunk
* chunk
);
115 // Gets the free page
116 // Each page is segmented by PAGE_SIZE, so it checks the pageInfo
117 // of each page to determine if the page is free
119 Page
* getFreePage(size_t size
);
121 int initAllocDatabaseMutex();
122 DbRetVal
getAllocDatabaseMutex();
123 DbRetVal
releaseAllocDatabaseMutex();
125 int initTransTableMutex();
126 DbRetVal
getTransTableMutex();
127 DbRetVal
releaseTransTableMutex();
129 int initDatabaseMutex();
130 DbRetVal
getDatabaseMutex();
131 DbRetVal
releaseDatabaseMutex();
133 int initProcessTableMutex();
134 DbRetVal
getProcessTableMutex();
135 DbRetVal
releaseProcessTableMutex();
137 //checks whether the ptr falls in the range of the database file size
138 bool isValidAddress(void *ptr
);
139 friend class DatabaseManagerImpl
;