SqlLogConnection Class Reference

#include <SqlLogConnection.h>

Inheritance diagram for SqlLogConnection:

Inheritance graph
[legend]
Collaboration diagram for SqlLogConnection:

Collaboration graph
[legend]

Public Member Functions

 SqlLogConnection ()
bool isTableCached (char *name)
ConnectiongetConnObject ()
DbRetVal connect (char *user, char *pass)
 opens connection to the sql engine
DbRetVal disconnect ()
 closes connection to the sql engine and releases all the resources
DbRetVal commit ()
 Commits active transaction.
DbRetVal rollback ()
 Aborts the active transaction.
DbRetVal beginTrans (IsolationLevel isoLevel, TransSyncMode mode)
 Starts a new transaction.
DbRetVal addPacket (BasePacket *pkt)
DbRetVal addPreparePacket (PacketPrepare *pkt)
DbRetVal removePreparePacket (int stmtid)
DbRetVal setSyncMode (TransSyncMode mode)
TransSyncMode getSyncMode ()
DbRetVal connectIfNotConnected ()
DbRetVal sendAndReceive (NetworkPacketType type, char *packet, int length)

Friends

class SqlFactory

Detailed Description

Definition at line 37 of file SqlLogConnection.h.


Constructor & Destructor Documentation

SqlLogConnection::SqlLogConnection (  )  [inline]

Definition at line 65 of file SqlLogConnection.h.

References ASYNC, and AbsSqlConnection::innerConn.

00065 {innerConn = NULL; syncMode = ASYNC;}


Member Function Documentation

DbRetVal SqlLogConnection::addPacket ( BasePacket pkt  ) 

Definition at line 27 of file SqlLogConnection.cxx.

References List::append(), and OK.

Referenced by SqlLogStatement::execute().

00028 {
00029     logStore.append(pkt);
00030     return OK;
00031 }

Here is the call graph for this function:

Here is the caller graph for this function:

DbRetVal SqlLogConnection::addPreparePacket ( PacketPrepare pkt  ) 

Definition at line 32 of file SqlLogConnection.cxx.

References List::append(), and OK.

Referenced by SqlLogStatement::prepare().

00033 {
00034     curPrepareStore.append(pkt);
00035     return OK;
00036 }

Here is the call graph for this function:

Here is the caller graph for this function:

DbRetVal SqlLogConnection::beginTrans ( IsolationLevel  isoLevel,
TransSyncMode  mode 
) [virtual]

Starts a new transaction.


The previous transaction should be either committed or rollback
before beginTrans is called.
Applications are required to start transaction before they attempt any
database operation.

Parameters:
isoLevel isolation level. Default is read committed.
Returns:
DbRetVal

Implements AbsSqlConnection.

Definition at line 83 of file SqlLogConnection.cxx.

References AbsSqlConnection::beginTrans(), AbsSqlConnection::innerConn, and OK.

00084 {
00085     DbRetVal rv = OK;
00086     if (innerConn) rv =  innerConn->beginTrans(isoLevel);
00087     if (rv != OK) return rv;
00088 
00089     syncMode = mode;
00090     return OK;
00091 }

Here is the call graph for this function:

DbRetVal SqlLogConnection::commit (  )  [virtual]

Commits active transaction.


It makes all the changes made in the current transaction permanent and
it also releases the locks held by the current transaction.
After a transaction commits, application is required to start another
transaction for further database operations.

Returns:
DbRetVal

Implements AbsSqlConnection.

Definition at line 92 of file SqlLogConnection.cxx.

References ASYNC, AbsSqlConnection::commit(), List::getIterator(), ListIterator::hasElement(), AbsSqlConnection::innerConn, ListIterator::nextElement(), OK, OSYNC, List::reset(), and List::size().

00093 {
00094     DbRetVal rv = OK;
00095     //printf("LOG: commit %d\n", syncMode);
00096     //if (innerConn) rv =  innerConn->commit();
00097     if (syncMode == OSYNC) {
00098         if (innerConn) rv = innerConn->commit();
00099         return rv;
00100     }
00101     if (logStore.size() == 0) 
00102     { 
00103         //This means no execution for any non select statements in 
00104         //this transaction
00105         //rollback so that subsequent beginTrans will not report that
00106         //transaction is already started
00107         if (innerConn) {
00108             rv =  innerConn->rollback(); 
00109             //if (rv != OK) return rv;
00110             //rv = innerConn->beginTrans(READ_COMMITTED, syncMode);
00111         }
00112         return rv; 
00113     }
00114     if (syncMode == ASYNC) {
00115     //TODO::put the packet in global log store
00116     /*
00117     PacketCommit *pkt = new PacketCommit();
00118     int tid = txnUID.getID();
00119     pkt->setExecPackets(tid, logStore);
00120     pkt->marshall();
00121     int *p = (int*) pkt->getMarshalledBuffer();
00122     NetworkClient *nwClient= nwTable.getNetworkClient();
00123     if (syncMode == ASYNC) {
00124         rv = nwClient->send(NW_PKT_COMMIT, pkt->getMarshalledBuffer(), 
00125                                           pkt->getBufferSize());    
00126         if (rv !=OK) 
00127         {
00128             printError(ErrOS, "Unable to send SQL Logs to peer site\n");
00129             return ErrOS;
00130         }
00131         rv = nwClient->receive();    
00132         if (rv !=OK) 
00133         {
00134           printError(ErrOS, "Could not get acknowledgement from peer site\n");
00135           return ErrPeerExecFailed;
00136         }
00137         //TODO::remove all sql logs nodes and the list which contains ptr to it
00138         */
00139     }
00140     
00141     ListIterator logStoreIter = logStore.getIterator();
00142     PacketExecute *execPkt = NULL;
00143     while (logStoreIter.hasElement())
00144     {
00145         execPkt = (PacketExecute*)logStoreIter.nextElement();
00146         delete execPkt;
00147     }
00148     logStore.reset();
00149     if (innerConn) rv = innerConn->commit();
00150     return rv;
00151 }

Here is the call graph for this function:

DbRetVal SqlLogConnection::connect ( char *  user,
char *  pass 
) [virtual]

opens connection to the sql engine

Parameters:
user username for authentication
pass password for authentication
Returns:
DbRetVal

Implements AbsSqlConnection.

Definition at line 59 of file SqlLogConnection.cxx.

References Conf::config, AbsSqlConnection::connect(), AbsSqlConnection::disconnect(), AbsSqlConnection::innerConn, OK, and List::size().

00060 {
00061     DbRetVal rv = OK;
00062     //printf("LOG: connect\n");
00063     if (innerConn) rv = innerConn->connect(user,pass);
00064     if (rv != OK) return rv;
00065     if (!Conf::config.useReplication() && !Conf::config.useCache()) return OK;
00066     if (rv !=OK) { innerConn->disconnect(); return rv; }
00067 
00068     //populate cacheList if not populated by another thread in same process
00069     //TODO::cacheList requires mutex guard
00070     if (0 == cacheList.size()) rv = populateCachedTableList(); 
00071     return rv;
00072     
00073 }

Here is the call graph for this function:

DbRetVal SqlLogConnection::connectIfNotConnected (  )  [inline]

Definition at line 89 of file SqlLogConnection.h.

References NetworkTable::connectIfNotConnected().

00089 { return nwTable.connectIfNotConnected(); }

Here is the call graph for this function:

DbRetVal SqlLogConnection::disconnect (  )  [virtual]

closes connection to the sql engine and releases all the resources

Returns:
DbRetVal

Implements AbsSqlConnection.

Definition at line 74 of file SqlLogConnection.cxx.

References Conf::config, AbsSqlConnection::disconnect(), AbsSqlConnection::innerConn, and OK.

00075 {
00076     DbRetVal rv = OK;
00077     //printf("LOG: disconnect\n");
00078     if (innerConn) rv =innerConn->disconnect();
00079     if (rv != OK) return rv;
00080     if (!Conf::config.useReplication() && !Conf::config.useCache()) return OK;
00081     return rv;
00082 }

Here is the call graph for this function:

Connection& SqlLogConnection::getConnObject (  )  [inline, virtual]

Implements AbsSqlConnection.

Definition at line 70 of file SqlLogConnection.h.

00070 {  return dummyConn; }

TransSyncMode SqlLogConnection::getSyncMode (  )  [inline]

Definition at line 88 of file SqlLogConnection.h.

Referenced by SqlLogStatement::execute(), SqlLogStatement::setByteIntParam(), SqlLogStatement::setDateParam(), SqlLogStatement::setDoubleParam(), SqlLogStatement::setFloatParam(), SqlLogStatement::setIntParam(), SqlLogStatement::setLongLongParam(), SqlLogStatement::setLongParam(), SqlLogStatement::setShortParam(), SqlLogStatement::setStringParam(), SqlLogStatement::setTimeParam(), and SqlLogStatement::setTimeStampParam().

00088 { return syncMode; }

Here is the caller graph for this function:

bool SqlLogConnection::isTableCached ( char *  name  ) 

Definition at line 189 of file SqlLogConnection.cxx.

References ErrBadArg, List::getIterator(), ListIterator::hasElement(), ListIterator::nextElement(), printError, and CachedTable::tableName.

Referenced by SqlLogStatement::prepare().

00190 {
00191     if (NULL == tblName)
00192     {
00193         printError(ErrBadArg, "tblName passed is NULL\n");
00194         return ErrBadArg;
00195     }
00196     ListIterator iter = cacheList.getIterator();
00197     CachedTable *node;
00198     while (iter.hasElement()) {
00199         node = (CachedTable*)iter.nextElement();
00200         if (strcmp(node->tableName, tblName) == 0)
00201         {
00202            return true;
00203         }
00204     }
00205     return false;
00206 }

Here is the call graph for this function:

Here is the caller graph for this function:

DbRetVal SqlLogConnection::removePreparePacket ( int  stmtid  ) 

Definition at line 38 of file SqlLogConnection.cxx.

References ErrNotFound, List::getIterator(), ListIterator::hasElement(), ListIterator::nextElement(), OK, printError, List::remove(), and PacketPrepare::stmtID.

Referenced by SqlLogStatement::free().

00039 {
00040     ListIterator iter = prepareStore.getIterator();
00041     PacketPrepare *pkt = NULL, *dpkt=NULL;
00042     while (iter.hasElement())
00043     {
00044         pkt = (PacketPrepare*)iter.nextElement();
00045         if (pkt->stmtID == stmtid) dpkt = pkt;
00046     }
00047     if (dpkt == NULL) return OK;
00048     //TEMP:mask below error for now
00049     if (dpkt == NULL)
00050     {
00051         printError(ErrNotFound, "Prepare packet not found in list for %d\n", stmtid);
00052         return ErrNotFound;
00053     }
00054     delete dpkt;
00055     prepareStore.remove(dpkt);
00056     return OK;
00057 }

Here is the call graph for this function:

Here is the caller graph for this function:

DbRetVal SqlLogConnection::rollback (  )  [virtual]

Aborts the active transaction.


undo all the changes made in the current transaction and it also
releases the locks held by the current transaction.
After a transaction rollback, application is required to start another
transaction for further database operations.

Returns:
DbRetVal

Implements AbsSqlConnection.

Definition at line 152 of file SqlLogConnection.cxx.

References List::getIterator(), ListIterator::hasElement(), AbsSqlConnection::innerConn, ListIterator::nextElement(), OK, List::reset(), and AbsSqlConnection::rollback().

00153 {
00154     DbRetVal rv = OK;
00155     //printf("LOG: rollback \n");
00156     if (innerConn) rv =  innerConn->rollback();
00157     if (rv != OK) return rv;
00158     ListIterator logStoreIter = logStore.getIterator();
00159     PacketExecute *execPkt = NULL;
00160     while (logStoreIter.hasElement())
00161     {
00162         execPkt = (PacketExecute*)logStoreIter.nextElement();
00163         delete execPkt;
00164     }
00165     logStore.reset();
00166     return rv;
00167 }

Here is the call graph for this function:

DbRetVal SqlLogConnection::sendAndReceive ( NetworkPacketType  type,
char *  packet,
int  length 
)

Definition at line 209 of file SqlLogConnection.cxx.

References ErrOS, NetworkTable::getNetworkClient(), NetworkClient::getNetworkID(), NetworkClient::isCacheClient(), NetworkClient::isConnected(), OK, NetworkClient::receive(), NetworkClient::send(), and NetworkClient::setConnectFlag().

00210 {
00211     return OK;
00212     NetworkClient* nwClient = nwTable.getNetworkClient();
00213     DbRetVal rv = OK, retRV=OK;
00214     printf("isCacheClient %d\n", nwClient->isCacheClient());
00215     printf("isConnected %d\n", nwClient->isConnected());
00216 /*
00217     if (!nwClient->isConnected()) {
00218         if (nwClient->isCacheClient()) return ErrOS; 
00219         //TODO::put this packet in send buffer.
00220         return OK;
00221     }
00222 */
00223     rv = nwClient->send(type, packet, length);
00224     if (rv != OK) 
00225     {
00226        printf("Unable to send pkt to peer with nwid %d\n", nwClient->getNetworkID());
00227        //TODO:: put this packet in resend buffer, so that it will sent later by another thread for repl mode
00228         nwClient->setConnectFlag(false);
00229         if (nwClient->isCacheClient()) return ErrOS; else return OK;
00230     }
00231     rv = nwClient->receive();
00232     if (rv != OK)
00233     {
00234         printf("Unable to receive ack pkt from peer with nwid %d\n", nwClient->getNetworkID());
00235         nwClient->setConnectFlag(false);
00236         if (nwClient->isCacheClient()) return ErrOS;
00237         //TODO:: put this packet to resend buffer so that it can be sent later
00238         //and call continue;
00239     }
00240     return OK;
00241 }

Here is the call graph for this function:

DbRetVal SqlLogConnection::setSyncMode ( TransSyncMode  mode  ) 


Friends And Related Function Documentation

friend class SqlFactory [friend]

Definition at line 91 of file SqlLogConnection.h.


The documentation for this class was generated from the following files:
Generated on Mon Jun 9 22:51:49 2008 for csql by  doxygen 1.4.7