1913337 when csql is down commit is called on csql
[csql.git] / src / gateway / SqlGwConnection.cxx
blobca3413a398651bd027b55c2f3b25df778f574541
1 /***************************************************************************
2 * Copyright (C) 2007 by Prabakaran Thirumalai *
3 * praba_tuty@yahoo.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 * 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 #include <SqlGwConnection.h>
21 #include <CSql.h>
22 #include <Network.h>
24 DbRetVal SqlGwConnection::connect (char *user, char * pass)
26 isCSqlConnected = false;
27 isAdapterConnected = false;
28 strcpy(username, user);
29 strcpy(password, pass);
30 DbRetVal rv = OK;
31 if (innerConn) rv = innerConn->connect(user,pass);
32 if (rv == OK) isCSqlConnected = true;
33 if (adapter) rv = adapter->connect(user,pass);
34 if (rv == OK) isAdapterConnected = true;
35 if (!isAdapterConnected && !isCSqlConnected) return ErrNoConnection;
36 return OK;
39 DbRetVal SqlGwConnection::disconnect()
41 DbRetVal rv = OK;
42 if (innerConn && isCSqlConnected) rv =innerConn->disconnect();
43 if (rv != OK) return rv;
44 if (adapter && isAdapterConnected) rv = adapter->disconnect();
45 isCSqlConnected = false;
46 isAdapterConnected = false;
47 return rv;
49 DbRetVal SqlGwConnection::beginTrans(IsolationLevel isoLevel, TransSyncMode smode)
51 DbRetVal rv = OK;
52 if (innerConn && isCSqlConnected) rv = innerConn->beginTrans(isoLevel);
53 if (rv != OK) return rv;
54 if (adapter && isAdapterConnected) rv = adapter->beginTrans(isoLevel);
55 if (!isAdapterConnected && !isCSqlConnected) return ErrNoConnection;
56 //printf("passed mode is %d\n", smode);
57 mode = smode;
58 txnHdlr = CSqlHandler;
59 return rv;
61 DbRetVal SqlGwConnection::commit()
63 DbRetVal rv = OK;
64 if (innerConn && isCSqlConnected)
65 //(txnHdlr == CSqlHandler || txnHdlr == CSqlAndAdapterHandler))
66 rv = innerConn->commit();
67 if (rv != OK) return rv;
68 if (adapter &&
69 (txnHdlr == AdapterHandler || txnHdlr == CSqlAndAdapterHandler))
70 rv = adapter->commit();
71 if (!isAdapterConnected && !isCSqlConnected) return ErrNoConnection;
72 return rv;
74 DbRetVal SqlGwConnection::rollback()
76 DbRetVal rv = OK;
77 if (innerConn && isCSqlConnected)
78 //(txnHdlr == CSqlHandler || txnHdlr == CSqlAndAdapterHandler))
79 rv = innerConn->rollback();
80 if (rv != OK) return rv;
81 if (adapter && isAdapterConnected &&
82 (txnHdlr == AdapterHandler || txnHdlr == CSqlAndAdapterHandler))
83 rv = adapter->rollback();
84 if (!isAdapterConnected && !isCSqlConnected) return ErrNoConnection;
85 return rv;
87 DbRetVal SqlGwConnection::connectCSqlIfNotConnected()
89 if (!isCSqlConnected) {
90 DbRetVal rv = innerConn->connect(username, password);
91 if (rv != OK) return rv;
92 isCSqlConnected = true;
94 return OK;
96 DbRetVal SqlGwConnection::connectAdapterIfNotConnected()
98 if (!isAdapterConnected) {
99 DbRetVal rv = adapter->connect(username, password);
100 if (rv != OK) return rv;
101 isAdapterConnected = true;
103 return OK;