Date: Wednesday, December 28, 2005 @ 18:14:57
  Author: gilles
    Path: /cvsroot/carob/carob

Modified: Makefile (1.29 -> 1.30) contrib/CPP/read_example.cpp (1.2 ->
          1.3) contrib/PHP/sample_carob_request.cpp (1.8 -> 1.9)
          include/Connection.hpp (1.38 -> 1.39) src/Connection.cpp (1.45
          -> 1.46) test/ConnectionSetup.cpp (1.3 -> 1.4)
          test/TestConnect.cpp (1.10 -> 1.11) test/TestConnect.hpp (1.6 ->
          1.7)
 Removed: include/ConnectionPool.hpp (1.5) src/ConnectionPool.cpp (1.5)

Connection pool removal: it has been finally decided that no connection pooling 
will be done in carob.
We let upper layers do the job the way they need to.
Implications:
- Connections to controller are now directly done in Connection constructor, 
given some connection parameters (as before).
- Connection empty contructor has been removed (put private) to avoid unknown 
state connections.


--------------------------------------+
 Makefile                             |    1 
 contrib/CPP/read_example.cpp         |   14 +---
 contrib/PHP/sample_carob_request.cpp |   24 +-----
 include/Connection.hpp               |   43 ++++++------
 include/ConnectionPool.hpp           |   68 -------------------
 src/Connection.cpp                   |  114 ++++++++++-----------------------
 src/ConnectionPool.cpp               |   38 -----------
 test/ConnectionSetup.cpp             |    4 -
 test/TestConnect.cpp                 |   10 +-
 test/TestConnect.hpp                 |    5 -
 10 files changed, 76 insertions(+), 245 deletions(-)


Index: carob/Makefile
diff -u carob/Makefile:1.29 carob/Makefile:1.30
--- carob/Makefile:1.29 Thu Dec 22 17:02:51 2005
+++ carob/Makefile      Wed Dec 28 18:14:57 2005
@@ -43,7 +43,6 @@
                                          ${SRCDIR}/CarobException.o\
                                          ${SRCDIR}/ConnectionParameters.o\
                                          ${SRCDIR}/Connection.o\
-                                         ${SRCDIR}/ConnectionPool.o\
                                          ${SRCDIR}/Request.o\
                                          
${SRCDIR}/RequestWithResultSetParameters.o\
                                          ${SRCDIR}/ResultSetMetaData.o\
Index: carob/contrib/CPP/read_example.cpp
diff -u carob/contrib/CPP/read_example.cpp:1.2 
carob/contrib/CPP/read_example.cpp:1.3
--- carob/contrib/CPP/read_example.cpp:1.2      Thu Dec 15 15:55:57 2005
+++ carob/contrib/CPP/read_example.cpp  Wed Dec 28 18:14:57 2005
@@ -29,7 +29,6 @@
 #include <iostream>
 
 #include "Connection.hpp"
-#include "ConnectionPool.hpp"
 #include "DriverResultSet.hpp"
 #include "ResultSetMetaData.hpp"
 #include "Statement.hpp"
@@ -42,28 +41,23 @@
 {
   
   // 1- Connecting:
-  Connection* connectionPtr = NULL; //The connection we will use
-  
-  // 1.1 First step: get a reference to the connection pool
-  ConnectionPool& connectionPool = ConnectionPool::getInstance();
-
-  // 1.2 2nd step: fill in the parameters of the connection
+  // 1.1 Create the parameters of the connection
   ConnectionParameters connectionPrms(L"localhost",
                                       25322,
                                       L"myDB",
                                       L"user",
                                       L"",
-                                      DEBUG_LEVEL_DEBUG);  
+                                      DEBUG_LEVEL_DEBUG);
   try
   {
     // 1.3 3rd step: connect to controller
-    connectionPtr = connectionPool.connectToController(connectionPrms);
+    Connection connection(connectionPrms);
 
     // Now, we are connected to the controller
 
     // 2- Executing the request
     // 2.1 The easier way to create a request is to use a statement
-    Statement* statementPtr = connectionPtr->createStatement();
+    Statement* statementPtr = connection.createStatement();
     // statementPtr->setFetchSize(1);
     // 2.2 Execute the request and get a pointer to the result
     DriverResultSet* drsPtr = statementPtr->executeQuery(
Index: carob/contrib/PHP/sample_carob_request.cpp
diff -u carob/contrib/PHP/sample_carob_request.cpp:1.8 
carob/contrib/PHP/sample_carob_request.cpp:1.9
--- carob/contrib/PHP/sample_carob_request.cpp:1.8      Thu Dec 15 15:55:57 2005
+++ carob/contrib/PHP/sample_carob_request.cpp  Wed Dec 28 18:14:57 2005
@@ -26,8 +26,9 @@
 
 #include "php_carob.h"
 
-#include "../../include/ConnectionPool.hpp"
+#include "../../include/Connection.hpp"
 #include "../../include/DriverResultSet.hpp"
+#include "../../include/Statement.hpp"
 
 using namespace CarobNS;
 
@@ -98,11 +99,6 @@
   // uncomment to stop, attach & debug
   // kill(0, SIGTSTP);
 
-  Connection* connectionPtr = NULL;
-
-  ConnectionPool& connectionPool = ConnectionPool::getInstance();
-
-  
   ConnectionParameters connectionPrms(L"localhost",
                                       25322,
                                       L"myDB",
@@ -111,7 +107,6 @@
                                       DEBUG_LEVEL_DEBUG);  
   try
   {
-
     char *req;
     int req_len; // ignored: we just don't handle inline zeros.
        
@@ -129,16 +124,11 @@
 
 
     // Connect to controller
-    connectionPtr = connectionPool.connectToController(connectionPrms);
-
-    // Create request object
-    RequestWithResultSetParameters readReq(wreq);
-    readReq.setEscapeProcessing(false).setTimeoutInSeconds(2);
-       
-    // efree(req); // segfaults
+    Connection connection(connectionPrms);
 
-    // Execute request
-    DriverResultSet* drsPtr = connectionPtr->statementExecuteQuery(readReq);
+    // Create a statement
+    Statement* statementPtr = connection.createStatement();
+    DriverResultSet* drsPtr = statementPtr->executeQuery(wreq);
 
     if (!drsPtr)
       throw CarobException(L"null resultset");
@@ -188,8 +178,6 @@
     php_printf("Unknown exception at " __FILE__ ":" LINESTR  "\n");
     // RETURN_STRING("Unknown exception at " __FILE__ ":" LINESTR  "\n", 1);
   }
-  if (connectionPtr)
-    delete connectionPtr;
 }
 
 /*
Index: carob/include/Connection.hpp
diff -u carob/include/Connection.hpp:1.38 carob/include/Connection.hpp:1.39
--- carob/include/Connection.hpp:1.38   Thu Dec 22 17:02:51 2005
+++ carob/include/Connection.hpp        Wed Dec 28 18:14:57 2005
@@ -97,16 +97,28 @@
 class ParameterStatement;
 /**
  * This class implements the communication protocol to the Controller.
- * <p>
- * It must be accessed through connection pool.
  */
 class Connection
 {
-/** Connection pool must have access to at least constructor and destructor */
-friend class ConnectionPool;
 /** DriverResultSet must access getDriverSocketPtr() function */
 friend class DriverResultSet;
 public:
+  /**
+   * Creates a new connection and connects to a controller with the given
+   * parameters
+   * @param controller, base, user, etc. to use for connecting
+   * @throw ConnectionException if the requested controller could not be
+   *        reached
+   * @throw AuthenticationException if a login error occured, or if an 
+   *        IO exception occured during authentication (premature close of
+   *        connection)
+   */
+  Connection(const ConnectionParameters&) throw (ConnectionException,
+      AuthenticationException, UnexpectedException);
+
+  /**
+   * Closes the connection and destroys its socket
+   */
   virtual ~Connection();
 
        /**
@@ -262,17 +274,6 @@
                         UnexpectedException);
 
 protected:
-  /** 
-   * Protected constructor so that no one but the connection pool 
-   * can access it (the user MUST use the connection pool)
-   * @throw ConnectionException if the requested controller could not be
-   *        reached
-   * @throw AuthenticationException if a login error occured, or if an 
-   *        IO exception occured during authentication (premature close of
-   *        connection)
-   */
-  Connection(const ConnectionParameters&) throw (ConnectionException,
-      AuthenticationException, UnexpectedException);
   /**
    * Starts a connection by sending all connection/authentication informations.
    * Warning: this function only sends the connection infos, but there is no
@@ -306,9 +307,6 @@
    * If an error occurs while closing, just logs the error and returns false,
    * but does not throw any exception.
    * Called mainly by the connection destructor.
-   * TODO: In fact this should only mark the connection as "to be closed" and
-   * inform the connection pool about connection disposal for eventual further
-   * reuses
    * @return true if the connection has been closed without errors
    */
   bool                close();
@@ -336,8 +334,6 @@
    */
   const DriverSocket& getDriverSocket() { return *driverSocketPtr; }
 private:
-  /** true if transparent connection pooling must be used */
-  bool                connectionPooling;
   /** This connection socket pointer */
   DriverSocket*       driverSocketPtr;
   /** true if the controller needs SQL templates of PreparedStatements */
@@ -362,6 +358,13 @@
   bool                mustBeginTransaction;
 
   /**
+   * Forbids Connection creation that would lead to unexpected state.
+   * A connection is either created, ie. connected to a controller or destroyed
+   * @see #Connection(const ConnectionParameters&)
+   */
+  Connection();
+
+  /**
    * Begins a new transaction if needed (<code>mustBeginTransaction</code> is
    * set to <code>true</code>).
    */
Index: carob/include/ConnectionPool.hpp
diff -u carob/include/ConnectionPool.hpp:1.5 
carob/include/ConnectionPool.hpp:removed
--- carob/include/ConnectionPool.hpp:1.5        Fri Dec  2 15:53:07 2005
+++ carob/include/ConnectionPool.hpp    Wed Dec 28 18:14:57 2005
@@ -1,68 +0,0 @@
-/*
- * Sequoia: Database clustering technology.
- * Copyright (C) 2005 Emic Networks
- * Contact: [EMAIL PROTECTED]
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- * http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * Initial developer(s): Gilles Rayrat
- * Contributor(s): 
- */
-
-#ifndef CONNECTIONPOOL_H_
-#define CONNECTIONPOOL_H_
-
-#include "Connection.hpp"
-
-namespace CarobNS {
-
-/**
- * Singleton class to provide connections to controller.
- * TODO: implement real connection management. For now, connection are created
- * on demand and never reused...
- */
-class ConnectionPool
-{
-public:
-  /**
-   * Singleton-style function to retrieve the unique ConnectionPool 
-   * instance
-   * @return the connection pool
-   */
-  static ConnectionPool&  getInstance();
-  /**
-   * Retrieves a connection from the pool by connecting to a controller
-   * @param prms connection information to connect to a controller
-   * @throw ConnectionException if the requested controller could not be
-   *        reached
-   * @throw AuthenticationException if a login error occured, or if an 
-   *        IO exception occured during authentication (premature close of
-   *        connection)
-   */
-  Connection*             connectToController(const ConnectionParameters& prms)
-      throw (ConnectionException, AuthenticationException, 
UnexpectedException);
-
-private:
-  /**
-   * Non public empty constructor. Use getInstance to retrieve the connection
-   * pool
-   */
-  ConnectionPool() {};
-  /** private copy constructor to prevent copy of the instance */
-  ConnectionPool(const ConnectionPool&);
-  /** private = operator to prevent assignement of the instance */
-  ConnectionPool& operator= (const ConnectionPool&);
-};
-
-} //namespace CarobNS
-#endif /*CONNECTIONPOOL_H_*/
Index: carob/src/Connection.cpp
diff -u carob/src/Connection.cpp:1.45 carob/src/Connection.cpp:1.46
--- carob/src/Connection.cpp:1.45       Thu Dec 22 17:02:51 2005
+++ carob/src/Connection.cpp    Wed Dec 28 18:14:57 2005
@@ -27,27 +27,15 @@
 
 using namespace CarobNS;
 
-Connection::~Connection()
-{
-  close();
-  if (driverSocketPtr != NULL)
-  {
-    delete driverSocketPtr;
-    driverSocketPtr = NULL;
-  }
-}
-
 Connection::Connection(const ConnectionParameters& prms)
-    throw (ConnectionException, AuthenticationException, UnexpectedException):
-    connectionPooling(false),
-    isClosed(true),
-    autoCommit(true),
-    readOnly(false),
-    writeExecutedInTransaction(false),
-    mustBeginTransaction(false)
+    throw (ConnectionException, AuthenticationException, UnexpectedException) :
+  isClosed(true),
+  autoCommit(true),
+  readOnly(false),
+  writeExecutedInTransaction(false),
+  mustBeginTransaction(false)
 {
   wstring fctName(L"Connection::Connection");
-  isClosed = true;
   if (isInfoEnabled())
   {
     wstring msg = L"Authenticating with controller " + prms.getHostName() + 
@@ -64,6 +52,16 @@
   }
 }
 
+Connection::~Connection()
+{
+  close();
+  if (driverSocketPtr != NULL)
+  {
+    delete driverSocketPtr;
+    driverSocketPtr = NULL;
+  }
+}
+
 void Connection::sendCommand(const DriverSocket& socket, int command)
     throw (SocketIOException, ProtocolException, UnexpectedException)
 {
@@ -226,74 +224,34 @@
     return false;
   }
   
-  if (connectionPooling)
+  try
   {
-    //TODO: real connection pooling...
-    throw NotImplementedException(L"Connection pooling not implemented yet");
-    try
+    if (driverSocketPtr != NULL)
     {
       if (isDebugEnabled())
-        logDebug(fctName, L"Resetting connection and adding it to the pool");
-      autoCommit = true;
-      mustBeginTransaction = false;
-      readOnly = false;
-      sendCommand(*driverSocketPtr, Reset);
-      //TODO: Pool connection !!!
-    }
-    catch (SocketIOException sioe)
-    {
-      if (isErrorEnabled())
-        logError(fctName, L"I/O Error while closing the connection:"
-            + sioe.description());
+        logDebug(fctName, L"Closing connection");
+
+      sendCommand(*driverSocketPtr, Close);
+    
+      isClosed = true;
+      bool closeOK;
+      closeOK = receiveBoolOrException();
+    
+      //now close the socket itself
+      closeOK &= driverSocketPtr->closeSocket();
+
+      return closeOK;
     }
   }
-  else
+  //catch any exception, log an error and return false (no exception forward)
+  catch (...)
   {
-    try
-    {
-      if (driverSocketPtr != NULL)
-      {
-        if (isDebugEnabled())
-          logDebug(fctName, L"Closing connection");
-
-        sendCommand(*driverSocketPtr, Close);
-      
-        isClosed = true;
-        bool closeOK;
-        closeOK = receiveBoolOrException();
-      
-        //now close the socket itself
-        closeOK &= driverSocketPtr->closeSocket();
-
-        //TODO: Add connection to the pool
-        
-        return closeOK;
-      }
-    }
-    catch (SocketIOException sioe)
-    {
-      if (isErrorEnabled())
-      {
-        logError(fctName, L"Error while closing connection ("
-                          + sioe.description() + L")");
-      }
-      
-      //TODO: Do we have to throw the exception again ? reconnect ?
-      //good question, thank you. It is not mandatory to send an exception
-      //because we are at closing time... But for connection pooling purposes ?
-      //arg... to be decided later.
-      return false;
-    }
-    //catch any exception, log an error and return false (no exception forward)
-    catch (...)
+    if (isErrorEnabled())
     {
-      if (isErrorEnabled())
-      {
-        logError(fctName, L"Exception while closing connection");
-      }
-      //Don't re-throw = transparent closing
-      return false;
+      logError(fctName, L"Exception while closing connection");
     }
+    //Don't re-throw = transparent closing
+    return false;
   }
   return false;
 }
Index: carob/src/ConnectionPool.cpp
diff -u carob/src/ConnectionPool.cpp:1.5 carob/src/ConnectionPool.cpp:removed
--- carob/src/ConnectionPool.cpp:1.5    Fri Dec  2 15:53:07 2005
+++ carob/src/ConnectionPool.cpp        Wed Dec 28 18:14:57 2005
@@ -1,38 +0,0 @@
-/*
- * Sequoia: Database clustering technology.
- * Copyright (C) 2005 Emic Networks
- * Contact: [EMAIL PROTECTED]
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- * http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * Initial developer(s): Gilles Rayrat
- * Contributor(s): 
- */
-
-#include "ConnectionPool.hpp"
-
-using namespace CarobNS;
-
-ConnectionPool& ConnectionPool::getInstance()
-{
-  static ConnectionPool singleton;
-  return singleton;
-}
-
-Connection* ConnectionPool::connectToController(const ConnectionParameters& 
prms)
-    throw (ConnectionException, AuthenticationException, UnexpectedException)
-{
-  //TODO: Add connection reuse management !
-  Connection* newConnectionPtr = new Connection(prms);
-  return newConnectionPtr;
-}
Index: carob/test/ConnectionSetup.cpp
diff -u carob/test/ConnectionSetup.cpp:1.3 carob/test/ConnectionSetup.cpp:1.4
--- carob/test/ConnectionSetup.cpp:1.3  Fri Dec 16 18:20:01 2005
+++ carob/test/ConnectionSetup.cpp      Wed Dec 28 18:14:57 2005
@@ -21,7 +21,6 @@
 
 #include "Common.hpp"
 #include "ConnectionParameters.hpp"
-#include "ConnectionPool.hpp"
 #include "CarobException.hpp"
 #include "Statement.hpp"
 
@@ -34,14 +33,13 @@
 void ConnectionSetup::setUp()
 {
   wstring fctName(L"TestExecReadRequest::setUp");
-  ConnectionPool& connectionPool = ConnectionPool::getInstance();
   ConnectionParameters connectionPrms(L"localhost",
                                       25322,
                                       L"myDB",
                                       L"user",
                                       L"",
                                       DEBUG_LEVEL_DEBUG);  
-    connectionPtr = connectionPool.connectToController(connectionPrms);
+  connectionPtr = new Connection(connectionPrms);
 }
 
 void ConnectionSetup::tearDown()
Index: carob/test/TestConnect.cpp
diff -u carob/test/TestConnect.cpp:1.10 carob/test/TestConnect.cpp:1.11
--- carob/test/TestConnect.cpp:1.10     Thu Dec 15 17:43:53 2005
+++ carob/test/TestConnect.cpp  Wed Dec 28 18:14:57 2005
@@ -31,8 +31,6 @@
 
 void TestConnect::setUp()
 {
-  connectionPoolPtr = &ConnectionPool::getInstance();
-  connectionPtr = NULL;
 }
 
 void TestConnect::tearDown()
@@ -56,7 +54,7 @@
     {
       logDebug(fctName, L"Connecting to controller - should fail");
     }
-    connectionPtr = connectionPoolPtr->connectToController(connectionPrms);
+    connectionPtr = new Connection(connectionPrms);
     // We should receive an exception instead of coming here
     CPPUNIT_ASSERT(false);
   }
@@ -84,7 +82,7 @@
     {
       logDebug(fctName, L"Connecting to controller - sould fail");
     }
-    connectionPtr = connectionPoolPtr->connectToController(connectionPrms);
+    connectionPtr = new Connection(connectionPrms);
     // We should receive an exception instead of coming here
     CPPUNIT_ASSERT(false);
   }
@@ -107,7 +105,7 @@
                                       DEBUG_LEVEL_DEBUG);  
   try
   {
-    connectionPtr = connectionPoolPtr->connectToController(connectionPrms);
+    connectionPtr = new Connection(connectionPrms);
     if (isDebugEnabled())
     {
       logDebug(fctName, L"Connecting to controller - sould fail");
@@ -140,7 +138,7 @@
   {
     logDebug(fctName, L"Connecting to controller - this should succeed");
   }
-    connectionPtr = connectionPoolPtr->connectToController(connectionPrms);
+    connectionPtr = new Connection(connectionPrms);
   if (isDebugEnabled())
   {
     logDebug(fctName, L"Connection succeeded");
Index: carob/test/TestConnect.hpp
diff -u carob/test/TestConnect.hpp:1.6 carob/test/TestConnect.hpp:1.7
--- carob/test/TestConnect.hpp:1.6      Mon Dec 12 14:30:10 2005
+++ carob/test/TestConnect.hpp  Wed Dec 28 18:14:57 2005
@@ -28,7 +28,7 @@
 #include <cppunit/TestSuite.h>
 #include <cppunit/TestCaller.h>
 
-#include "ConnectionPool.hpp"
+#include "Connection.hpp"
 
 /**
  * Test class for connection establishement.
@@ -42,7 +42,7 @@
   /** Suite of tests to be run */
   static CppUnit::Test* suite();
 
-  /** Gets the connection pool pointer. */
+  /** Nothing to setup */
   void setUp();
   /** Destroys connection pointer if applicable */
   void tearDown();
@@ -68,7 +68,6 @@
   void testConnectGood();
 
 private:
-  CarobNS::ConnectionPool*   connectionPoolPtr;
   CarobNS::Connection*       connectionPtr;
 };
 

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

Reply via email to