include/Transaction.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2007 by www.databasecache.com                           *
00003  *   Contact: praba_tuty@databasecache.com                                 *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015   ***************************************************************************/
00016 #ifndef TXN_H
00017 #define TXN_H
00018 #include<os.h>
00019 #include<Debug.h>
00020 #include<Session.h>
00021 class LockHashNode;
00022 
00023 enum TransStatus
00024 {
00025     TransNotUsed          =  0,
00026     TransCommitting       =  1,
00027     TransAborting         =  2,
00028     TransRunning          =  3,
00029     TransUnknown          =  4
00030 };
00031 class TransHasNode;
00032 class LockManager;
00033 class Database;
00034 
00035 enum OperationType
00036 {
00037     InsertOperation = 0,
00038     DeleteOperation = 1,
00039     UpdateOperation = 2,
00040     InsertHashIndexOperation = 3,
00041     UpdateHashIndexOperation = 4,
00042     DeleteHashIndexOperation = 5
00043 };
00044 class UndoLogInfo
00045 {
00046     public:
00047     int size_;
00048     OperationType opType_;
00049     void *ptrToTuple_;
00050     UndoLogInfo *next_;
00051     void print() {
00052        printf("<UndoLogInfo>\n");
00053        printf("  <Size> %d </Size>\n", size_);
00054        printf("  <OperationType> %d </OperationType>\n", opType_);
00055        printf("  <TuplePtr> %x </TuplePtr>\n", ptrToTuple_);
00056        printf("</UndoLogInfo>\n");
00057 
00058     }
00059 };
00060 
00061 class Transaction
00062 {
00063     public:
00064     int status_;
00065 
00066     IsolationLevel isoLevel_;
00067 
00068     TransHasNode *hasLockList_;
00069 
00070     UndoLogInfo *firstUndoLog_;
00071 
00072     LockHashNode *waitLock_;
00073 
00074     DbRetVal releaseAllLocks(LockManager *lockManager_);
00075 
00076     void updateWaitLock(LockHashNode *node) { waitLock_ = node; }
00077     void removeWaitLock() { waitLock_ = NULL; }
00078     DbRetVal insertIntoHasList(Database *sysdb, LockHashNode *node);
00079     DbRetVal removeFromHasList(Database *sysdb, void *tuple);
00080     bool findInHasList(Database *sysdb, LockHashNode *node);
00081 
00082     DbRetVal appendUndoLog(Database *sysdb, OperationType type, void *data, size_t size);
00083     DbRetVal appendLogicalUndoLog(Database *sysdb, OperationType type, void *data,
00084                        size_t size, void* indexPtr);
00085     UndoLogInfo* createUndoLog(Database *sysdb, OperationType type, void *data,
00086                        size_t size, DbRetVal *rv);
00087     void addAtBegin(UndoLogInfo* logInfo);
00088 
00089     UndoLogInfo* popUndoLog();
00090     DbRetVal removeUndoLogs(Database *sysdb);
00091     DbRetVal applyUndoLogs(Database *sysdb);
00092     int noOfUndoLogs();
00093     void printDebugInfo(Database *sysdb);
00094 };
00095 
00096 class TransactionManager
00097 {
00098     public:
00099     TransactionManager() {  }
00100     ~TransactionManager() {}
00101     //Transaction *trans;
00102 
00103     Transaction *firstTrans;
00104 
00105     void setFirstTrans(Transaction *trans);
00106     void printUsageStatistics();
00107     void printDebugInfo(Database *sysdb);
00108 
00109     DbRetVal startTransaction(LockManager *lManager, IsolationLevel level);
00110     DbRetVal commit(LockManager *lManager);
00111     DbRetVal rollback(LockManager *lManager, Transaction *t=NULL);
00112 
00113 };
00114 #endif

Generated on Mon Jun 9 22:37:14 2008 for csql by  doxygen 1.4.7