00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 #ifndef DATABASE_MANAGER_IMPL_H
00017 #define DATABASE_MANAGER_IMPL_H
00018 #include<os.h>
00019 #include<CatalogTables.h>
00020 #include<Lock.h>
00021 #include<DatabaseManager.h>
00022 #include<Process.h>
00023 
00024 
00025 
00026 class Database;
00027 class SessionImpl;
00028 class TableDef;
00029 class Table;
00030 class FieldNameList;
00031 class ChunkIterator;
00032 class Chunk;
00033 class TransactionManager;
00034 class CSqlProcInfo
00035 {
00036     public:
00037     CSqlProcInfo() { sysDbAttachAddr = userDbAttachAddr = NULL;}
00038     void *sysDbAttachAddr;
00039     void *userDbAttachAddr;
00040 };
00041 
00042 
00043 static CSqlProcInfo csqlProcInfo;
00044 
00045 class DatabaseManagerImpl : public DatabaseManager
00046 {
00047     private:
00048     Database* systemDatabase_;
00049     
00050 
00051     Database* db_;
00052     
00053 
00054     LockManager *lMgr_;
00055 
00056     TransactionManager *tMgr_;
00057 
00058 
00059     ProcessManager *pMgr_;
00060     int procSlot;
00061 
00062     
00063     DatabaseManagerImpl() { systemDatabase_ = NULL; tMgr_ = NULL; lMgr_ =  NULL; 
00064                             pMgr_ = NULL; db_ = NULL; }
00065     ~DatabaseManagerImpl();
00066 
00067     DbRetVal openSystemDatabase();
00068     DbRetVal closeSystemDatabase();
00069     ChunkIterator getSystemTableIterator(CatalogTableID id);
00070     Chunk* getSystemTableChunk(CatalogTableID id);
00071 
00072     void createLockManager();
00073     void createTransactionManager();
00074 
00075     Chunk* createUserChunk(size_t size = 0);
00076     DbRetVal deleteUserChunk(Chunk *chunk);
00077 
00078 
00079     DbRetVal createHashIndex(const char *indName, const char *tableName,
00080                         FieldNameList &fldList, int bucketSize, bool isUnique, bool isPrimary = false);
00081     void initHashBuckets(Bucket *buck, int bucketSize);
00082 
00083     DbRetVal dropIndexInt(const char *name, bool takeLock);
00084 
00085     public:
00086 
00087     Database* db() { return db_; }
00088     Database* sysDb() { return systemDatabase_; }
00089     void setSysDb(Database *db) { systemDatabase_ = db; }
00090     void setDb(Database *db) { db_ = db; }
00091 
00092     void setProcSlot();
00093     TransactionManager* txnMgr() { return tMgr_; }
00094     LockManager* lockMgr() { return lMgr_; }
00095 
00096     
00097     
00098     DbRetVal createDatabase(const char *name, size_t size);
00099     DbRetVal deleteDatabase(const char *name);
00100 
00101     DbRetVal openDatabase(const char *name);
00102     DbRetVal closeDatabase();
00103 
00104 
00105 
00106     DbRetVal createTable(const char *name, TableDef &def);
00107     DbRetVal dropTable(const char *name);
00108     Table* openTable(const char *name);
00109     void closeTable(Table *table);
00110     DbRetVal createIndex(const char *indName, IndexInitInfo *info);
00111     DbRetVal dropIndex(const char *name);
00112     List getAllTableNames();
00113 
00114     DbRetVal registerThread();
00115     DbRetVal deregisterThread();
00116     bool isAnyOneRegistered();
00117     void printUsageStatistics();
00118     void printDebugLockInfo();
00119     void printDebugTransInfo();
00120     void printDebugChunkInfo();
00121     void printDebugProcInfo();
00122     DbRetVal printIndexInfo(char *name);
00123     friend class SessionImpl;
00124 };
00125 #endif