00001 /*************************************************************************** 00002 * Copyright (C) 2007 by Prabakaran Thirumalai * 00003 * praba_tuty@yahoo.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 * You should have received a copy of the GNU General Public License * 00016 * along with this program; if not, write to the * 00017 * Free Software Foundation, Inc., * 00018 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00019 ***************************************************************************/ 00020 #include <SqlGwConnection.h> 00021 #include <CSql.h> 00022 #include <Network.h> 00023 00024 DbRetVal SqlGwConnection::connect (char *user, char * pass) 00025 { 00026 isCSqlConnected = false; 00027 isAdapterConnected = false; 00028 strcpy(username, user); 00029 strcpy(password, pass); 00030 DbRetVal rv = OK; 00031 if (innerConn) rv = innerConn->connect(user,pass); 00032 if (rv == OK) isCSqlConnected = true; 00033 if (adapter) rv = adapter->connect(user,pass); 00034 if (rv == OK) isAdapterConnected = true; 00035 if (!isAdapterConnected && !isCSqlConnected) return ErrNoConnection; 00036 return OK; 00037 00038 } 00039 DbRetVal SqlGwConnection::disconnect() 00040 { 00041 DbRetVal rv = OK; 00042 if (innerConn && isCSqlConnected) rv =innerConn->disconnect(); 00043 if (rv != OK) return rv; 00044 if (adapter && isAdapterConnected) rv = adapter->disconnect(); 00045 isCSqlConnected = false; 00046 isAdapterConnected = false; 00047 return rv; 00048 } 00049 DbRetVal SqlGwConnection::beginTrans(IsolationLevel isoLevel, TransSyncMode smode) 00050 { 00051 DbRetVal rv = OK; 00052 if (!isAdapterConnected && !isCSqlConnected) return ErrNoConnection; 00053 if (innerConn && isCSqlConnected) rv = innerConn->beginTrans(isoLevel, smode); 00054 if (rv != OK) return rv; 00055 if (adapter && isAdapterConnected) rv = adapter->beginTrans(isoLevel); 00056 //mode = smode; 00057 txnHdlr = CSqlHandler; 00058 return rv; 00059 } 00060 DbRetVal SqlGwConnection::commit() 00061 { 00062 DbRetVal rv = OK; 00063 if (innerConn && isCSqlConnected) 00064 //(txnHdlr == CSqlHandler || txnHdlr == CSqlAndAdapterHandler)) 00065 rv = innerConn->commit(); 00066 if (rv != OK) return rv; 00067 if (adapter && 00068 (txnHdlr == AdapterHandler || txnHdlr == CSqlAndAdapterHandler)) 00069 rv = adapter->commit(); 00070 if (!isAdapterConnected && !isCSqlConnected) return ErrNoConnection; 00071 return rv; 00072 } 00073 DbRetVal SqlGwConnection::rollback() 00074 { 00075 DbRetVal rv = OK; 00076 if (innerConn && isCSqlConnected) 00077 //(txnHdlr == CSqlHandler || txnHdlr == CSqlAndAdapterHandler)) 00078 rv = innerConn->rollback(); 00079 if (rv != OK) return rv; 00080 if (adapter && isAdapterConnected && 00081 (txnHdlr == AdapterHandler || txnHdlr == CSqlAndAdapterHandler)) 00082 rv = adapter->rollback(); 00083 if (!isAdapterConnected && !isCSqlConnected) return ErrNoConnection; 00084 return rv; 00085 } 00086 DbRetVal SqlGwConnection::connectCSqlIfNotConnected() 00087 { 00088 if (!isCSqlConnected) { 00089 DbRetVal rv = innerConn->connect(username, password); 00090 if (rv != OK) return rv; 00091 isCSqlConnected = true; 00092 } 00093 return OK; 00094 } 00095 DbRetVal SqlGwConnection::connectAdapterIfNotConnected() 00096 { 00097 if (!isAdapterConnected) { 00098 DbRetVal rv = adapter->connect(username, password); 00099 if (rv != OK) return rv; 00100 isAdapterConnected = true; 00101 } 00102 return OK; 00103 }