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 ***************************************************************************/
16 #ifndef DATABASE_MANAGER_IMPL_H
17 #define DATABASE_MANAGER_IMPL_H
19 #include<CatalogTables.h>
21 #include<DatabaseManager.h>
24 //Note::DatabaseManagerImpl is used to hide functionalites from normal database user.
25 //User is exposed to DatabaseManagerImpl, for our tools we shall type cast DatabaseManager
26 //to DatabaseManagerImpl to retreive internal information such as db statistics, etc
34 class TransactionManager
;
38 CSqlProcInfo() { sysDbAttachAddr
= userDbAttachAddr
= NULL
;}
39 void *sysDbAttachAddr
;
40 void *userDbAttachAddr
;
44 static CSqlProcInfo csqlProcInfo
;
46 class DllExport DatabaseManagerImpl
: public DatabaseManager
49 Database
* systemDatabase_
;
50 //pointer to system Database
57 TransactionManager
*tMgr_
;
60 ProcessManager
*pMgr_
;
63 //only SessionImpl creates object of this class
64 DatabaseManagerImpl() { systemDatabase_
= NULL
; tMgr_
= NULL
; lMgr_
= NULL
;
65 pMgr_
= NULL
; db_
= NULL
; }
66 ~DatabaseManagerImpl();
68 DbRetVal
openSystemDatabase();
69 DbRetVal
closeSystemDatabase();
70 ChunkIterator
getSystemTableIterator(CatalogTableID id
);
71 Chunk
* getSystemTableChunk(CatalogTableID id
);
73 void createLockManager();
74 void createTransactionManager();
76 Chunk
* createUserChunk(size_t size
= 0);
77 DbRetVal
deleteUserChunk(Chunk
*chunk
);
80 DbRetVal
createHashIndex(const char *indName
, const char *tableName
,
81 FieldNameList
&fldList
, int bucketSize
, bool isUnique
, bool isPrimary
= false);
82 DbRetVal
createTreeIndex(const char *indName
, const char *tableName
,
83 FieldNameList
&fldList
, int bucketSize
, bool isUnique
, bool isPrimary
= false);
84 DbRetVal
createTrieIndex(const char *indName
, const char *tableName
,
85 FieldNameList
&fldList
, bool isUnique
, bool isPrimary
= false);
86 void initHashBuckets(Bucket
*buck
, int bucketSize
);
88 DbRetVal
dropIndexInt(const char *name
, bool takeLock
);
89 DbRetVal
writeSchemaFile();
90 DbRetVal
updateIndexCatalogTables(const char *indName
,void *tptr
,
91 char **fptr
, FieldNameList
&fldList
, bool isUnique
,
92 Chunk
* chunkInfo
, Chunk
* hChunk
, void *&tupleptr
);
93 DbRetVal
validateIndex(const char *tblName
, FieldNameList
&fldList
,
94 void **tptr
, char ***fptr
, bool isPrimary
);
95 DbRetVal
removeIndexCatalogTables(const char *name
, void *&chunk
, void *&hchunk
, void *&tptr
);
96 DbRetVal
removeIndexChunks(void* chunk
, void* hchunk
, IndexType iType
);
97 DbRetVal
createIndexNodeForRecords(const char* tblName
, void* tupleptr
,
99 void initMutexes(Database
*db
);
100 size_t computeSysDbOffset();
104 Database
* db() { return db_
; }
105 Database
* sysDb() { return systemDatabase_
; }
106 void setSysDb(Database
*db
) { systemDatabase_
= db
; }
107 void setDb(Database
*db
) { db_
= db
; }
110 TransactionManager
* txnMgr() { return tMgr_
; }
111 LockManager
* lockMgr() { return lMgr_
; }
113 //for user database file there is no limit for the number
114 //of tables or chunks
115 DbRetVal
createDatabase(const char *name
, size_t size
);
116 DbRetVal
deleteDatabase(const char *name
);
118 DbRetVal
openDatabase(const char *name
);
119 DbRetVal
closeDatabase();
121 void setCanTakeCheckPoint(bool ctcp
);
122 bool getCanTakeCheckPoint();
124 DbRetVal
createTable(const char *name
, TableDef
&def
);
125 DbRetVal
dropTable(const char *name
);
126 DbRetVal
renameTable(const char *oldName
,const char *newName
);
127 DbRetVal
renameIndex(const char *oldName
,const char *newName
);
128 DbRetVal
renameField(const char *tableName
,const char *oldName
,const char *newName
);
129 Table
* openTable(const char *name
, bool checkpkfk
=true);
130 void closeTable(Table
*table
);
131 DbRetVal
createIndex(const char *indName
, IndexInitInfo
*info
);
132 DbRetVal
dropIndex(const char *name
);
133 DbRetVal
createForeignKey(char *kfName
,ForeignKeyInfo
*info
);
134 DbRetVal
dropForeignKey(void *ctptr
,bool trylock
);
135 List
getAllTableNames(int *rv
=NULL
);
136 void sendSignal(int signal
);
138 DbRetVal
registerThread();
139 DbRetVal
deregisterThread();
140 bool isAnyOneRegistered();
141 void printUsageStatistics();
142 void printDebugLockInfo();
143 void printDebugTransInfo();
144 void printDebugChunkInfo();
145 void printDebugProcInfo();
146 void printDebugMutexInfo();
147 int getNoOfPagesForTable(char *tblName
);
148 DbRetVal
loadRecords(char *tblName
, char *buffer
);
149 DbRetVal
pasteRecords(char *tblName
, void *buffer
);
150 DbRetVal
checkPoint();
152 DbRetVal
printIndexInfo(char *name
);
153 DbRetVal
printIndexDebugInfo(char *name
);
154 void printTreeIndexNodeInfo(char *name
,bool flag
);
155 friend class SessionImpl
;