Date: Wednesday, June 28, 2006 @ 17:54:48
  Author: gilles
    Path: /cvsroot/carob/carob

Modified: include/Connection.hpp (1.68 -> 1.69)
          include/DriverResultSet.hpp (1.41 -> 1.42) src/Connection.cpp
          (1.77 -> 1.78) src/ControllerConnectPolicy.cpp (1.11 -> 1.12)
          src/DriverResultSet.cpp (1.55 -> 1.56)

.Update following new connection establishement process (protocol version 4->5)
.Update for SQLWarnings changes in sequoia (protocol version 5->6)


---------------------------------+
 include/Connection.hpp          |   23 +-----
 include/DriverResultSet.hpp     |   14 +++
 src/Connection.cpp              |  142 ++++++++++++++++++++------------------
 src/ControllerConnectPolicy.cpp |    2 
 src/DriverResultSet.cpp         |    3 
 5 files changed, 98 insertions(+), 86 deletions(-)


Index: carob/include/Connection.hpp
diff -u carob/include/Connection.hpp:1.68 carob/include/Connection.hpp:1.69
--- carob/include/Connection.hpp:1.68   Wed Jun 21 14:56:22 2006
+++ carob/include/Connection.hpp        Wed Jun 28 17:54:48 2006
@@ -32,7 +32,7 @@
 #include <list>
 
 namespace {
-const int32_t ProtocolVersion = (static_cast<int32_t>(4) /* major */ << 16)
+const int32_t ProtocolVersion = (static_cast<int32_t>(6) /* major */ << 16)
                                                     + 0 /* minor */;
 }
 
@@ -370,21 +370,19 @@
    *        IO exception occured during authentication (premature close of
    *        connection)
    */
-  bool                initConnection()
+  void                initConnection()
                           throw (DriverException, ConnectionException,
                           AuthenticationException, UnexpectedException);
   /**
    * Reads the controller acknowledgements and misc parameters that finish 
-   * connection. [EMAIL PROTECTED] #initConnection()} must be 
-   * called before this
-   * @return true upon successfull connection
+   * connection. [EMAIL PROTECTED] #initConnection()} must be called before 
this
    * @throw ConnectionException if the virtual database is not available on the
    *        controller
    * @throw AuthenticationException if the controller did not acknowledge or in
    *        case of i/o exception during finalization (premature close of
    *        connection)s
    */
-  bool                finalizeConnect() throw (ConnectionException,
+  void                finalizeConnect() throw (ConnectionException,
                           AuthenticationException, UnexpectedException);
 
   /**
@@ -586,24 +584,13 @@
                           BackendException, ControllerException,
                           ProtocolException, UnexpectedException);
   /**
-   * Checks if the given query already executed or not on the controller we are
-   * currently connected to.
-   *
-   * @param request the request to check
-   * @return ResultSet or null
-   */
-  DriverResultSet*    retrieveExecuteQueryResult(const Request &request)
-                          throw (SocketIOException, BackendException,
-                          ControllerException, ProtocolException,
-                          UnexpectedException);
-  /**
    * Check if the given query already executed or not on the controller we are
    * currently connected to.
    * 
    * @param request the request to check
    * @return int the number of updated rows or -1 if not found
    */
-  int                  retrieveExecuteUpdateResult(const Request &request)
+  ResultAndWarnings   retrieveExecuteUpdateResult(const Request &request)
                           throw (SocketIOException, BackendException,
                           ControllerException, ProtocolException,
                           UnexpectedException);
Index: carob/include/DriverResultSet.hpp
diff -u carob/include/DriverResultSet.hpp:1.41 
carob/include/DriverResultSet.hpp:1.42
--- carob/include/DriverResultSet.hpp:1.41      Wed Jun 21 14:56:22 2006
+++ carob/include/DriverResultSet.hpp   Wed Jun 28 17:54:48 2006
@@ -440,6 +440,18 @@
    * @return a SQL warning chain
    */
   SQLWarning*                 getWarnings() {return warningsPtr;}
+  /**
+   * Sets the owning statement warnings. Only fills statementWarnings field, 
+   * does *not* set the owningStatement->warnings
+   * @param stWarns the statement warnings to set
+   */
+  void                        setStatementWarnings(SQLWarning* stWarns)
+  { statement_warnings_ptr = stWarns; }
+  /**
+   * Retrieves the warnings linked to the owning statement
+   * @return warnings on owning statement
+   */
+  SQLWarning*                 getStatementWarnings() { return 
statement_warnings_ptr; }
 protected:
   /**
    * De-serialize only data rows, not any metadata.
@@ -503,6 +515,8 @@
 
   /** Warning chain */
   SQLWarning*                 warningsPtr;
+  /** Warnings on owning statement */
+  SQLWarning*                 statement_warnings_ptr;
   /** Statement corresponding to this ResultSet, if any (not for metadata) */
   Statement*                  owningStatementPtr;
   /** The driver connection we were received from. Useful for streaming */
Index: carob/src/Connection.cpp
diff -u carob/src/Connection.cpp:1.77 carob/src/Connection.cpp:1.78
--- carob/src/Connection.cpp:1.77       Wed Jun 21 14:56:22 2006
+++ carob/src/Connection.cpp    Wed Jun 28 17:54:48 2006
@@ -99,12 +99,12 @@
         throw DriverException(L"Connection policy error. Aborting.");
       connected_controller = connect_policy_ptr->getController();
   
-      //Do the authentication stuff, then receive ack and other params
-      if (initConnection() && finalizeConnect())
-      {
-        isClosed = false;
-        return;
-      }
+      // Do the authentication stuff
+      initConnection();
+      // receive ack and other params
+      finalizeConnect();
+      isClosed = false;
+      return;
     }
     // SocketIO and connection exceptions indicate dead controller => try to
     // connect to the next one in the controller list
@@ -161,7 +161,7 @@
   socket<<static_cast<int32_t>(command);
 }
 
-bool Connection::initConnection()
+void Connection::initConnection()
     throw (DriverException, ConnectionException, AuthenticationException,
         UnexpectedException)
 {
@@ -201,7 +201,6 @@
     if (isErrorEnabled())
       logError(fctName, msg);
     throw ConnectionException(msg);
-    return false;
   }
   catch (SocketIOException sockIOExcpt)
   {
@@ -257,12 +256,10 @@
       }
       throw AuthenticationException(msg);
     }
-    return false;
   }
-  return true;
 }
 
-bool Connection::finalizeConnect() throw (ConnectionException, 
AuthenticationException,
+void Connection::finalizeConnect() throw (ConnectionException, 
AuthenticationException,
     UnexpectedException)
 {
   wstring fctName(L"Connection::finalizeConnect");
@@ -297,7 +294,15 @@
     *driverSocketPtr << persistent_connection;
     persistentConnectionSent = true;
     if (persistent_connection)
-      *driverSocketPtr >> persistent_connection_id;
+    {
+      bool success = false;
+      *driverSocketPtr >> success;
+      if (success)
+        *driverSocketPtr >> persistent_connection_id;
+      else
+        throw AuthenticationException(fctName + 
+            L" No more connection available in the cluster");
+    }
     persistentConnectionRead = true;
     *driverSocketPtr << retrieve_sql_warnings;
   }
@@ -316,9 +321,7 @@
       msg += L"sending whether to retrieve SQL warnings";
     throw AuthenticationException(msg
                                   + L"(" + sockIOExcpt.description() + L")");
-    return false;
   }
-  return true;
 }
 
 void Connection::deleteStatement(Statement* stPtr) throw (DriverException, 
UnexpectedException)
@@ -654,14 +657,21 @@
   setConnectionParametersOnRequest(request);
 
   DriverResultSet* retVal = NULL;
-
+  SQLWarning* sqlwPtr = NULL;
   FO_TRY_NTIMES(RECONNECT_RETRIES)
     if (isDebugEnabled())
       logDebug(fctName, L"Sending read request " + 
static_cast<wstring>(request));
     sendCommand(*driverSocketPtr, StatementExecuteQuery);
     request.sendToStream(*driverSocketPtr);
-
+    // clean up (in case of failover)
+    if (retVal != NULL)
+      delete retVal;
+    if (sqlwPtr != NULL)
+      delete sqlwPtr;
+    SQLWarning* sqlwPtr = receiveSQLWarnings();
     retVal = receiveResultSet();
+    if (retVal != NULL)
+      retVal->setStatementWarnings(sqlwPtr);
   FO_CATCH_NTIMES
   return retVal;
 }
@@ -681,35 +691,40 @@
   SQLWarning* sqlwPtr = NULL;
   int controllerResponse = -1;
 
-  FO_TRY_NTIMES(RECONNECT_RETRIES)
-    if (isDebugEnabled())
-      logDebug(fctName, L"Sending write request " + 
static_cast<wstring>(request));
-    sendCommand(*driverSocketPtr, StatementExecuteUpdate);
-    writeRequestOnStream(request);
-    request.setId(receiveLongOrException());
-  FO_CATCH_NTIMES
-
-  // At this point, the request id has been received, let's retrieve the
-  // update count
-  try
-  {
-    sqlwPtr = receiveSQLWarnings();    
-    controllerResponse = static_cast<int>(receiveIntOrException());
-  }
-  catch (SocketIOException sioe)
+  // this for-loop is in the case we were disconnected and the controller did
+  // not get the update request
+  for (int failuresCnt=0; failuresCnt<RECONNECT_RETRIES; failuresCnt++)
   {
+    ResultAndWarnings ret;
     FO_TRY_NTIMES(RECONNECT_RETRIES)
-    controllerResponse = retrieveExecuteUpdateResult(request);
-    if (controllerResponse != -1)
+      if (isDebugEnabled())
+        logDebug(fctName, L"Sending write request " + 
static_cast<wstring>(request));
+      sendCommand(*driverSocketPtr, StatementExecuteUpdate);
+      writeRequestOnStream(request);
+      request.setId(receiveLongOrException());
+    FO_CATCH_NTIMES
+  
+    // At this point, the request id has been received, let's retrieve the
+    // update count
+    try
     {
-      if (sqlwPtr != NULL)
-        delete sqlwPtr;
-      sqlwPtr = new SQLWarning(L"Failover happened while executing request "
-          + static_cast<std::wstring>(request)
-              + L". SQLWarnings, if any, were lost");
-      return ResultAndWarnings(controllerResponse, sqlwPtr);
+      sqlwPtr = receiveSQLWarnings();    
+      controllerResponse = static_cast<int>(receiveIntOrException());
+      break; // get out of the big for-loop
+    }
+    catch (SocketIOException sioe)
+    {
+      FO_TRY_NTIMES(RECONNECT_RETRIES)
+        ret = retrieveExecuteUpdateResult(request);
+      FO_CATCH_NTIMES
+      if (ret.getUpdateCount() != -1)
+      {
+        return ret;
+      }
+      // otherwise, the update was not done on the controller, we go back at
+      // the beginning of the function, cleaning up results
+      delete ret.getWarnings();
     }
-    FO_CATCH_NTIMES
   }
 
   return ResultAndWarnings(controllerResponse, sqlwPtr);
@@ -789,9 +804,11 @@
 
   SQLWarning* sqlwPtr = NULL;
   std::list<ResultSetOrUpdateCount> result;
+
+  // this for-loop is in the case we were disconnected and the controller did
+  // not get the update request
   for (int failuresCnt=0; failuresCnt<RECONNECT_RETRIES; failuresCnt++)
-  { // this for is in the case we were disconnected and the controller did not
-    // get the update request
+  {
     ResultAndWarnings ret;
     FO_TRY_NTIMES(RECONNECT_RETRIES)
       if (isDebugEnabled())
@@ -814,6 +831,7 @@
       rs.isResultSet = true;
       rs.resultSetPtr = receiveResultSet();
       result.push_back(rs);
+      break; //no exception, get out of the big for-loop
     }
     catch (SocketIOException sioe)
     {
@@ -872,8 +890,7 @@
   *driverSocketPtr<<cursorName;
   *driverSocketPtr<<fetchSize;
   if (isDebugEnabled())
-    logDebug(fctName, L"Fetching next " + toWString(fetchSize) + L" from "
-        + cursorName);
+    logDebug(fctName, L"Fetching next " + toWString(fetchSize) + L" rows.");
   TypeTag tag(*driverSocketPtr);
 
   if (tag == TT_EXCEPTION)
@@ -1065,22 +1082,15 @@
   return receiveLongOrException();
 }
 
-DriverResultSet* Connection::retrieveExecuteQueryResult(const Request &request)
-    throw (SocketIOException, BackendException, ControllerException,
-    ProtocolException, UnexpectedException)
-{
-  sendCommand(*driverSocketPtr, RetrieveExecuteQueryResult);
-  *driverSocketPtr << request.getId();
-  return receiveResultSet();
-}
-
-int Connection::retrieveExecuteUpdateResult(const Request &request)
+ResultAndWarnings Connection::retrieveExecuteUpdateResult(const Request 
&request)
     throw (SocketIOException, BackendException, ControllerException,
     ProtocolException, UnexpectedException)
 {
   sendCommand(*driverSocketPtr, RetrieveExecuteUpdateResult);
   *driverSocketPtr << request.getId();
-  return static_cast<int>(receiveIntOrException());
+  SQLWarning* sqlwPtr = receiveSQLWarnings();
+  int result = static_cast<int>(receiveIntOrException());
+  return ResultAndWarnings(result, sqlwPtr);
 }
 
 ResultAndWarnings Connection::retrieveExecuteResult(
@@ -1207,13 +1217,12 @@
     {
       if (isDebugEnabled())
         logDebug(fctName, L"Trying to reconnect to the same controller...");
-      if (initConnection() && finalizeConnect())
-      {
-        isClosed = false;
-      }
+      initConnection();
+      finalizeConnect();
+      isClosed = false;
     }
     catch (...)
-    { //ignore but detroy socket if created
+    { //ignore but destroy socket if created
       delete driverSocketPtr; driverSocketPtr = NULL;
     }
   }
@@ -1228,12 +1237,11 @@
       if (isDebugEnabled())
         logDebug(fctName, L"Getting a new controller from the list...");
       connected_controller = connect_policy_ptr->getController();
-      if (initConnection() && finalizeConnect())
-      {
-        if (isInfoEnabled())
-          logInfo(fctName, L"Connection succeded");
-        isClosed = false;
-      }
+      initConnection();
+      finalizeConnect();
+      if (isInfoEnabled())
+        logInfo(fctName, L"Connection succeded");
+      isClosed = false;
     }
     catch (AuthenticationException ae)
     {
Index: carob/src/ControllerConnectPolicy.cpp
diff -u carob/src/ControllerConnectPolicy.cpp:1.11 
carob/src/ControllerConnectPolicy.cpp:1.12
--- carob/src/ControllerConnectPolicy.cpp:1.11  Fri Feb 24 12:56:41 2006
+++ carob/src/ControllerConnectPolicy.cpp       Wed Jun 28 17:54:48 2006
@@ -185,7 +185,7 @@
       SuspectController newSuspect;
       newSuspect.controllerInfo = controllerInfo;
       if (isDebugEnabled())
-        logDebug(fctName, L"Creating ping socket to suspect controller...");
+        logDebug(fctName, L"Creating ping socket to suspected controller...");
       // creates and prepares a new socket for pinging the controller
       newSuspect.pingSocketPtr = new JavaSocket();
       newSuspect.pingSocketPtr->create(false); //create non blocking
Index: carob/src/DriverResultSet.cpp
diff -u carob/src/DriverResultSet.cpp:1.55 carob/src/DriverResultSet.cpp:1.56
--- carob/src/DriverResultSet.cpp:1.55  Wed Jun 21 14:56:22 2006
+++ carob/src/DriverResultSet.cpp       Wed Jun 28 17:54:48 2006
@@ -125,6 +125,8 @@
       nulls[cnt].clear();
     nulls.clear();
     delete warningsPtr;
+    warningsPtr = NULL;
+    // Don't delete statementWarnings, it will be done by the statement itself
   }  
 }
 DriverResultSet::DriverResultSet(Connection* conPtr) throw (ProtocolException,
@@ -138,6 +140,7 @@
 resultSetType(0),
 resultSetConcurrency(0),
 warningsPtr(NULL),
+statement_warnings_ptr(NULL),
 owningStatementPtr(NULL),
 isClosed(true)
 {

_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits

Reply via email to