submitting patch from enterprise version
[csql.git] / include / Transaction.h
blobf68048d0d29814dd00b14840014518c73cd5cc2b
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 TXN_H
17 #define TXN_H
18 #include<os.h>
19 #include<Debug.h>
20 #include<Session.h>
21 class LockHashNode;
23 enum TransStatus
25 TransNotUsed = 0,
26 TransCommitting = 1,
27 TransAborting = 2,
28 TransRunning = 3,
29 TransUnknown = 4
31 class TransHasNode;
32 class LockManager;
33 class Database;
35 enum OperationType
37 InsertOperation = 0,
38 DeleteOperation = 1,
39 UpdateOperation = 2,
40 InsertHashIndexOperation = 3,
41 UpdateHashIndexOperation = 4,
42 DeleteHashIndexOperation = 5
44 class UndoLogInfo
46 public:
47 int size_;
48 OperationType opType_;
49 void *ptrToTuple_;
50 UndoLogInfo *next_;
51 void print() {
52 printf("<UndoLogInfo>\n");
53 printf(" <Size> %d </Size>\n", size_);
54 printf(" <OperationType> %d </OperationType>\n", opType_);
55 printf(" <TuplePtr> %x </TuplePtr>\n", ptrToTuple_);
56 printf("</UndoLogInfo>\n");
61 class HashUndoLogInfo
63 public:
64 void *metaData_;
65 void *tuple_;
66 void *keyPtr_;
67 void *hChunk_;
68 void *bucket_;
69 HashUndoLogInfo()
70 { metaData_ = tuple_ = keyPtr_ = hChunk_ = bucket_ = NULL; }
73 class Transaction
75 public:
76 int status_;
78 IsolationLevel isoLevel_;
80 TransHasNode *hasLockList_;
82 UndoLogInfo *firstUndoLog_;
84 LockHashNode *waitLock_;
86 DbRetVal releaseAllLocks(LockManager *lockManager_);
88 void updateWaitLock(LockHashNode *node) { waitLock_ = node; }
89 void removeWaitLock() { waitLock_ = NULL; }
90 DbRetVal insertIntoHasList(Database *sysdb, LockHashNode *node);
91 DbRetVal removeFromHasList(Database *sysdb, void *tuple);
92 bool findInHasList(Database *sysdb, LockHashNode *node);
94 DbRetVal appendUndoLog(Database *sysdb, OperationType type, void *data, size_t size);
95 DbRetVal appendLogicalUndoLog(Database *sysdb, OperationType type, void *data, size_t size, void *indexPtr);
96 DbRetVal appendLogicalHashUndoLog(Database *sysdb, OperationType type, void *data, size_t size);
97 UndoLogInfo* createUndoLog(Database *sysdb, OperationType type, void *data,
98 size_t size, DbRetVal *rv);
99 void addAtBegin(UndoLogInfo* logInfo);
101 UndoLogInfo* popUndoLog();
102 DbRetVal removeUndoLogs(Database *sysdb);
103 DbRetVal applyUndoLogs(Database *sysdb);
104 int noOfUndoLogs();
105 void printDebugInfo(Database *sysdb);
108 class TransactionManager
110 public:
111 TransactionManager() { }
112 ~TransactionManager() {}
113 //Transaction *trans;
115 Transaction *firstTrans;
117 void setFirstTrans(Transaction *trans);
118 void printUsageStatistics();
119 void printDebugInfo(Database *sysdb);
121 DbRetVal startTransaction(LockManager *lManager, IsolationLevel level);
122 DbRetVal commit(LockManager *lManager);
123 DbRetVal rollback(LockManager *lManager, Transaction *t=NULL);
126 #endif