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>
29 * @class SqlLogConnection
33 typedef struct my_msgbuffer
{
38 class DllExport AbsSqlLogSend
41 virtual DbRetVal
prepare(int tId
, int sId
, int len
, char *st
, char *tn
,
43 virtual DbRetVal
commit(int len
, void *data
)=0;
44 virtual DbRetVal
free(int txnId
, int stmtId
, bool hasParam
)=0;
47 class DllExport MsgQueueSend
: public AbsSqlLogSend
51 MsgQueueSend() { msgQId
= os::msgget(Conf::config
.getMsgKey(), 0666); }
52 DbRetVal
prepare(int tId
, int sId
, int len
, char *stmt
, char *tn
,
54 DbRetVal
commit(int len
, void *data
);
55 DbRetVal
free(int txnId
, int stmtId
, bool hasParam
);
58 class DllExport FileSend
: public AbsSqlLogSend
65 DbRetVal
openRedoFile();
66 DbRetVal
prepare(int txnId
, int stmtId
, int len
, char *stmt
, char*tn
,
68 DbRetVal
commit(int len
, void *data
);
69 DbRetVal
free(int txnId
, int stmtId
, bool hasParam
);
73 class DllExport OfflineLog
: public AbsSqlLogSend
78 DbRetVal
createMetadataFile();
79 void *openMetadataFile();
83 DbRetVal
openOfflineLogFile();
84 DbRetVal
prepare(int txnId
, int stmtId
, int len
, char *stmt
, char*tn
,
86 DbRetVal
commit(int len
, void *data
);
87 DbRetVal
free(int txnId
, int stmtId
, bool hasParam
);
100 ExecLogInfo() : pos(0), len(0), isNull(0) {}
107 void *value
; //Extendible value as per parameter type size
110 class DllExport SqlLogConnection
: public AbsSqlConnection
112 Connection dummyConn
;
115 int execLogStoreSize
;
117 //sync mode of the current transaction
118 TransSyncMode syncMode
;
120 AbsSqlLogSend
*msgQSend
;
121 AbsSqlLogSend
*fileSend
;
122 AbsSqlLogSend
*offlineLog
;
124 GlobalUniqueID txnUID
;
125 static List cacheList
;
127 DbRetVal
populateCachedTableList();
133 innerConn
= NULL
; syncMode
= ASYNC
;
134 msgQSend
= NULL
; fileSend
= NULL
; offlineLog
= NULL
;
136 if (Conf::config
.useCache() && Conf::config
.getCacheMode()==ASYNC_MODE
)
137 msgQSend
= new MsgQueueSend();
138 if (Conf::config
.useCache() &&
139 Conf::config
.getCacheMode() == OFFLINE_MODE
)
140 offlineLog
= new OfflineLog
;
142 if (Conf::config
.useDurability()) { fileSend
= new FileSend(); }
146 noOfflineLog
= false;
150 bool isTableCached(char *name
);
152 inline bool isNoLogRequired()
154 if (!msgQSend
&& !fileSend
&& !offlineLog
) return true;
157 inline bool isMsgQReqd()
159 if (msgQSend
) return true; else return false;
161 inline bool isFileLogReqd()
163 if (fileSend
) return true; else return false;
165 inline bool isOfflineLogReqd()
167 if (offlineLog
) return true; else return false;
169 //Note::forced to implement this as it is pure virtual in base class
170 Connection
& getConnObject(){ return dummyConn
; }
172 DbRetVal
connect (char *user
, char * pass
);
174 DbRetVal
disconnect();
180 DbRetVal
beginTrans (IsolationLevel isoLevel
, TransSyncMode mode
);
182 DbRetVal
msgPrepare(int tId
, int sId
, int len
, char *stmt
, char *tname
,
185 return msgQSend
->prepare(tId
, sId
, len
, stmt
, tname
, hasParam
);
187 DbRetVal
fileLogPrepare(int tId
, int sId
, int len
, char *stmt
, char *tname
,
190 return fileSend
->prepare(tId
, sId
, len
, stmt
, tname
, hasParam
);
192 DbRetVal
offlineLogPrepare(int tId
, int sId
, int len
, char *stmt
,
193 char *tname
, bool hasParam
)
195 return offlineLog
->prepare(tId
, sId
, len
, stmt
, tname
, hasParam
);
197 DbRetVal
commitLogs(int logSize
, void *data
)
199 int txnId
= getTxnID();
200 if (msgQSend
&& !noMsgLog
) msgQSend
->commit(logSize
, data
);
201 if (fileSend
) fileSend
->commit(logSize
, data
);
202 if (offlineLog
&& !noOfflineLog
) offlineLog
->commit(logSize
, data
);
205 DbRetVal
freeLogs(int stmtId
, bool hasParam
)
207 int txnId
= getTxnID();
208 if (msgQSend
&& !noMsgLog
) msgQSend
->free(txnId
, stmtId
, hasParam
);
209 if (fileSend
) fileSend
->free(txnId
, stmtId
, hasParam
);
210 if (offlineLog
&& !noOfflineLog
)
211 offlineLog
->free(txnId
, stmtId
, hasParam
);
215 inline void addExecLog(ExecLogInfo
*info
) { execLogStore
.append(info
); }
216 inline void addToExecLogSize(int size
) { execLogStoreSize
+= size
; }
217 inline int getExecLogStoreSize() { return execLogStoreSize
; }
218 List
getExecLogList() { return execLogStore
; }
220 DbRetVal
setSyncMode(TransSyncMode mode
);
221 inline void setNoMsgLog(bool nmlog
) { noMsgLog
= nmlog
; }
222 inline void setNoOfflineLog(bool nolog
) { noOfflineLog
= nolog
; }
223 inline TransSyncMode
getSyncMode() { return syncMode
; }
224 inline int getTxnID() { return txnID
; }
225 friend class SqlFactory
;