1 /***************************************************************************
2 * Copyright (C) 2007 by Prabakaran Thirumalai *
3 * praba_tuty@yahoo.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 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20 #ifndef SQLLOGCONNECTION_H
21 #define SQLLOGCONNECTION_H
23 #include<SqlFactory.h>
28 * @class SqlLogConnection
35 virtual DbRetVal
prepare(int txnId
, int stmtId
, int len
, char *stmt
)=0;
36 virtual DbRetVal
commit(int len
, void *data
)=0;
37 virtual DbRetVal
free(int txnId
, int stmtId
)=0;
40 class FileSend
: public AbsSqlLogSend
45 DbRetVal
prepare(int txnId
, int stmtId
, int len
, char *stmt
);
46 DbRetVal
commit(int len
, void *data
);
47 DbRetVal
free(int txnId
, int stmtId
);
59 ExecLogInfo() : pos(0), len(0) {}
68 class SqlLogConnection
: public AbsSqlConnection
72 //stores all the sql log packets to be shipped to peers
78 //stores all the prepare log packets to be shipped to peers
79 //as soon as connection is reestablished to cache server
82 //stores all the prepare log packets to be shipped between two
83 //consecutive commits. Commit() call sends first all the stmts
84 //prepared during the course and then sends the exec pkts
87 //sync mode of the current transaction
88 TransSyncMode syncMode
;
90 //stores client objects in it for peer
92 AbsSqlLogSend
*fileSend
;
94 static GlobalUniqueID txnUID
;
95 static List cacheList
;
97 DbRetVal
populateCachedTableList();
100 innerConn
= NULL
; syncMode
= ASYNC
;
101 if (Conf::config
.useDurability()) { fileSend
= new FileSend(); }
104 bool isTableCached(char *name
);
106 //Note::forced to implement this as it is pure virtual in base class
107 Connection
& getConnObject(){ return dummyConn
; }
109 DbRetVal
connect (char *user
, char * pass
);
111 DbRetVal
disconnect();
117 DbRetVal
beginTrans (IsolationLevel isoLevel
, TransSyncMode mode
);
119 DbRetVal
fileLogPrepare(int txnId
, int stmtId
, int len
, char *stmt
)
121 return fileSend
->prepare(txnId
, stmtId
, len
, stmt
);
123 DbRetVal
commitLogs(int logSize
, void *data
)
125 int txnId
= getTxnID();
126 if (Conf::config
.useDurability()) fileSend
->commit(logSize
, data
);
129 DbRetVal
freeLogs(int stmtId
)
131 int txnId
= getTxnID();
132 if (Conf::config
.useDurability()) fileSend
->free(txnId
, stmtId
);
135 void addExecLog(ExecLogInfo
*info
) { execLogStore
.append(info
); }
136 void addToExecLogSize(int size
){ execLogStoreSize
+= size
; }
137 int getExecLogStoreSize() { return execLogStoreSize
; }
138 List
getExecLogList() { return execLogStore
; }
139 DbRetVal
addPacket(BasePacket
*pkt
);
140 DbRetVal
addPreparePacket(PacketPrepare
*pkt
);
141 DbRetVal
removePreparePacket(int stmtid
);
143 DbRetVal
setSyncMode(TransSyncMode mode
);
144 TransSyncMode
getSyncMode() { return syncMode
; }
145 int getTxnID() { return txnID
; }
146 DbRetVal
connectIfNotConnected() { return nwTable
.connectIfNotConnected(); }
147 DbRetVal
sendAndReceive(NetworkPacketType type
, char *packet
, int length
);
148 friend class SqlFactory
;