windows porting changesw
[csql.git] / include / DatabaseManagerImpl.h
blob1a4d91f195308b4e96b70cc9c46742bf9ea86868
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_MANAGER_IMPL_H
17 #define DATABASE_MANAGER_IMPL_H
18 #include<os.h>
19 #include<CatalogTables.h>
20 #include<Lock.h>
21 #include<DatabaseManager.h>
22 #include<Process.h>
23 #include<Util.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
27 class Database;
28 class SessionImpl;
29 class TableDef;
30 class Table;
31 class FieldNameList;
32 class ChunkIterator;
33 class Chunk;
34 class TransactionManager;
35 class CSqlProcInfo
37 public:
38 CSqlProcInfo() { sysDbAttachAddr = userDbAttachAddr = NULL;}
39 void *sysDbAttachAddr;
40 void *userDbAttachAddr;
43 //Global object
44 static CSqlProcInfo csqlProcInfo;
46 class DllExport DatabaseManagerImpl : public DatabaseManager
48 private:
49 Database* systemDatabase_;
50 //pointer to system Database
52 Database* db_;
53 //pointer to database
55 LockManager *lMgr_;
57 TransactionManager *tMgr_;
60 ProcessManager *pMgr_;
61 int procSlot;
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 void initHashBuckets(Bucket *buck, int bucketSize);
86 DbRetVal dropIndexInt(const char *name, bool takeLock);
87 DbRetVal writeSchemaFile();
88 public:
90 Database* db() { return db_; }
91 Database* sysDb() { return systemDatabase_; }
92 void setSysDb(Database *db) { systemDatabase_ = db; }
93 void setDb(Database *db) { db_ = db; }
95 void setProcSlot();
96 TransactionManager* txnMgr() { return tMgr_; }
97 LockManager* lockMgr() { return lMgr_; }
99 //for user database file there is no limit for the number
100 //of tables or chunks
101 DbRetVal createDatabase(const char *name, size_t size);
102 DbRetVal deleteDatabase(const char *name);
104 DbRetVal openDatabase(const char *name);
105 DbRetVal closeDatabase();
107 void setCanTakeCheckPoint(bool ctcp);
108 bool getCanTakeCheckPoint();
110 DbRetVal createTable(const char *name, TableDef &def);
111 DbRetVal dropTable(const char *name);
112 DbRetVal renameTable(const char *oldName,const char *newName);
113 DbRetVal renameIndex(const char *oldName,const char *newName);
114 DbRetVal renameField(const char *tableName,const char *oldName,const char *newName);
115 Table* openTable(const char *name, bool checkpkfk=true);
116 void closeTable(Table *table);
117 DbRetVal createIndex(const char *indName, IndexInitInfo *info);
118 DbRetVal dropIndex(const char *name);
119 DbRetVal createForeignKey(char *kfName,ForeignKeyInfo *info);
120 DbRetVal dropForeignKey(void *ctptr,bool trylock);
121 List getAllTableNames(int *rv=NULL);
122 void sendSignal(int signal);
124 DbRetVal registerThread();
125 DbRetVal deregisterThread();
126 bool isAnyOneRegistered();
127 void printUsageStatistics();
128 void printDebugLockInfo();
129 void printDebugTransInfo();
130 void printDebugChunkInfo();
131 void printDebugProcInfo();
132 int getNoOfPagesForTable(char *tblName);
133 DbRetVal loadRecords(char *tblName, char *buffer);
134 DbRetVal pasteRecords(char *tblName, void *buffer);
135 DbRetVal checkPoint();
136 DbRetVal recover();
137 DbRetVal printIndexInfo(char *name);
138 void printTreeIndexNodeInfo(char *name,bool flag);
139 friend class SessionImpl;
141 #endif