Date: Tuesday, December 13, 2005 @ 18:18:51
  Author: gilles
    Path: /cvsroot/carob/carob

Modified: include/CarobException.hpp (1.24 -> 1.25) include/Connection.hpp
          (1.33 -> 1.34) include/DriverResultSet.hpp (1.20 -> 1.21)
          include/ResultSetMetaData.hpp (1.5 -> 1.6) include/Statement.hpp
          (1.13 -> 1.14) src/Connection.cpp (1.38 -> 1.39)
          src/DriverResultSet.cpp (1.20 -> 1.21) src/ResultSetMetaData.cpp
          (1.5 -> 1.6)

Exception clean-up:
- removed unused SQLException and DriverSQLException
- throw ProtocolException when getting a wrong RequestID
- ProtocolException now inherits from CarobException (no more DriverException)
- ConnectionException and AuthenticationException now inherits from 
DriverException (no more from JavaSocketException)
- fixed javadocs
- fixed exception thrown


-------------------------------+
 include/CarobException.hpp    |   26 ++--------
 include/Connection.hpp        |   21 ++------
 include/DriverResultSet.hpp   |   96 ++++++++++++++++++++--------------------
 include/ResultSetMetaData.hpp |    1 
 include/Statement.hpp         |   11 ++--
 src/Connection.cpp            |   27 ++++++-----
 src/DriverResultSet.cpp       |   28 +++++------
 src/ResultSetMetaData.cpp     |    3 -
 8 files changed, 99 insertions(+), 114 deletions(-)


Index: carob/include/CarobException.hpp
diff -u carob/include/CarobException.hpp:1.24 
carob/include/CarobException.hpp:1.25
--- carob/include/CarobException.hpp:1.24       Tue Dec 13 16:08:30 2005
+++ carob/include/CarobException.hpp    Tue Dec 13 18:18:51 2005
@@ -177,14 +177,14 @@
 /**
  * Exception on connection. Send when connecting to a controller
  */
-class ConnectionException : public JavaSocketException
+class ConnectionException : public DriverException
 {
 public:
   /**
    * Constructs a ConnectionException with the given message
    * @param s error message of the exception
    */
-  ConnectionException(std::wstring s) : JavaSocketException(s) {};
+  ConnectionException(std::wstring s) : DriverException(s) {};
 };
 
 /**
@@ -203,27 +203,27 @@
 /**
  * Exception on authentication. Send on connection (user/pass)
  */
-class AuthenticationException : public JavaSocketException
+class AuthenticationException : public DriverException
 {
 public:
   /**
    * Constructs a AuthenticationException with the given message
    * @param s error message of the exception
    */
-  AuthenticationException(std::wstring s) : JavaSocketException(s) {};
+  AuthenticationException(std::wstring s) : DriverException(s) {};
 };
 
 /**
  * Exception on Protocol.
  */
-class ProtocolException : public DriverException
+class ProtocolException : public CarobException
 {
 public:
   /**
    * Constructs a ProtocolException with the given message
    * @param s error message of the exception
    */
-  ProtocolException(std::wstring s) : DriverException(s) {};
+  ProtocolException(std::wstring s) : CarobException(s) {};
 };
 
 /**
@@ -278,20 +278,6 @@
 };
 
 /**
- * Database access Exception
- */
-class SQLException : public CarobException
-{
-public:
-  /**
-   * Constructs a SQLException with the given message
-   * @param s error message of the exception
-   */
-  SQLException(std::wstring s) : CarobException(s) {};
-};
-
-
-/**
  * Map of the Java stack trace element contained in an exception
  * (actually a CarobException)
  */
Index: carob/include/Connection.hpp
diff -u carob/include/Connection.hpp:1.33 carob/include/Connection.hpp:1.34
--- carob/include/Connection.hpp:1.33   Tue Dec 13 16:08:30 2005
+++ carob/include/Connection.hpp        Tue Dec 13 18:18:51 2005
@@ -115,7 +115,7 @@
         * @param socket on which to read and write
         * @param command to send
         * @throws IOException on socket error
-        * @throws DriverSQLException on protocol corruption
+        * @throws ProtocolException on protocol corruption
         */
        static void       sendCommand(const DriverSocket& socket, int command)
                         throw (SocketIOException, ProtocolException,
@@ -145,23 +145,21 @@
    * <code>autoCommit</code>== <code>true</code>, then we throw a
    * DriverException).
    * 
-   * @throws SQLException     if a database access error occurs
-   *         DriverException  if connection is in autocommit mode
+   * @throws DriverException  if connection is in autocommit mode
    * @see Connection#setAutoCommit(boolean)
    */
   void              commit() throw (SocketIOException, DriverException,
-                        UnexpectedException);
+                        ProtocolException, UnexpectedException);
   /**
    * Drops all changes made since the previous commit/rollback and releases any
    * database locks currently held by this connection. If the connection was in
    * autocommit mode, we throw a DriverException.
    * 
-   * @exception DriverException if a database access error occurs or the
-   *              connection is in autocommit mode
+   * @exception DriverException if the connection is in autocommit mode
    * @see Connection#commit()
    */
   void              rollback() throw (SocketIOException, DriverException,
-                        UnexpectedException);
+                        ProtocolException, UnexpectedException);
   /**
    * SQL statements without parameters are normally executed using
    * <code>Statement</code> objects. If the same SQL statement is executed
@@ -170,10 +168,9 @@
    * <code>TYPE_FORWARD_ONLY</code>/<code>CONCUR_READ_ONLY</code>.
    *
    * @return a new <code>Statement</code> object
-   * @throw DriverException passed through from the constructor
    */
   Statement*        createStatement() throw (SocketIOException,
-                        DriverException, UnexpectedException);
+                        UnexpectedException);
   /**
    * Performs a read request and returns the reply.
    * 
@@ -212,7 +209,6 @@
    * Closes the remote ResultSet given its cursor name.
    * 
    * @param cursorName cursor name of the ResultSet to close
-   * @throw DriverSQLException if an error occurs
    * @throw SocketIOException if an error occurs on the socket
    */
   void              closeRemoteResultSet(std::wstring cursorName)
@@ -236,7 +232,7 @@
    * 
    * @param readOnlyPrm  <code>true</code> enables read-only mode;
    *                  <code>false</code> disables it
-   * @exception DriverSQLException if a database access error occurs
+   * @throw DriverException if transaction executes write requests
    */
   void              setReadOnly(bool readOnlyPrm) throw (SocketIOException,
                         DriverException, UnexpectedException);
@@ -445,7 +441,6 @@
    *
    * @param request the request to check
    * @return ResultSet or null
-   * @throws DriverSQLException if an error occurs
    */
   DriverResultSet*    retrieveExecuteQueryResult(const Request &request)
                           throw (SocketIOException, BackendException,
@@ -457,7 +452,6 @@
    * 
    * @param request the request to check
    * @return int the number of updated rows or -1 if not found
-   * @throws DriverSQLException if an error occurs
    */
   int                 retrieveExecuteUpdateResult(const Request &request)
                           throw (SocketIOException, BackendException,
@@ -469,7 +463,6 @@
    * 
    * @param request the request to check
    * @return a <code>List</code> of ResultSetOrUpdateCount
-   * @throws DriverSQLException if an error occurs
    */
   std::list<ResultSetOrUpdateCount> retrieveExecuteResult(const Request 
&request)
                           throw (SocketIOException, BackendException,
Index: carob/include/DriverResultSet.hpp
diff -u carob/include/DriverResultSet.hpp:1.20 
carob/include/DriverResultSet.hpp:1.21
--- carob/include/DriverResultSet.hpp:1.20      Tue Dec 13 16:08:30 2005
+++ carob/include/DriverResultSet.hpp   Tue Dec 13 18:18:51 2005
@@ -127,9 +127,8 @@
    * 
    * @return <code>true</code> if the new current is valid; <code>false</code>
    *         if there are no more rows
-   * @throw SQLException if an error occurs on the stream
    */
-   bool                       next() throw (SocketIOException,
+  bool                        next() throw (SocketIOException,
                                   ControllerException, ProtocolException,
                                   BackendException, UnexpectedException);
 
@@ -138,24 +137,24 @@
    * 
    * @param columnIndex the first column is 1, the second is 2...
    * @return the column value, null for SQL NULL
-   * @throw SQLException if a database access error occurs
+   * @exception DriverException if the ResultSet is closed or the cursor is
+   *            out of bounds
    */
-  std::wstring                getString(int columnIndex)
-                                  throw (SQLException, UnexpectedException);
+  std::wstring                getString(int columnIndex) throw 
(DriverException,
+                                  NotImplementedException, 
UnexpectedException);
   /**
    * Get the value of a column in the current row as an int.
    * 
    * @param columnIndex the first column is 1, the second is 2,...
    * @return the column value; NULL if SQL NULL
-   * @throw SQLException if a database access error occurs
+   * @exception DriverException if the ResultSet is closed or the cursor is
+   *            out of bounds
    */
-  int32_t                     getInt(int columnIndex) throw (SQLException,
-                                  UnexpectedException);
+  int32_t                     getInt(int columnIndex) throw (DriverException,
+                                  NotImplementedException, 
UnexpectedException);
   /**
    * Closes the remote ResultSet if the ResultSet was streamed else just closes
    * the ResultSet locally.
-   * 
-   * @exception DriverSQLException if a database access error occurs
    */
   void                        close() throw (SocketIOException,
                                   BackendException, ControllerException,
@@ -164,37 +163,37 @@
    * Gets the number of column in this resultSet
    * @return number of columns value
    */
-   int                        getNumberOfColumns() { return nbOfColumns; }
-   /**
-    * Gets the number of rows that have been fetched yet.
-    * Note: this is not the number of rows of the ResultSet, but the current
-    * number of rows in memory !
-    * @return number of rows fetched until now
-    */
-   int                        getNumberOfRowsInMemory() { return nbOfRows; }
-    /**
-     * A column may have the value of SQL NULL; wasNull() reports whether the
-     * last column read had this special value.
-     * Note that you must first call getXXX on a column to try to read its 
value
-     * and then call wasNull() to find if the value was SQL NULL
-     * If you need to know if a value is NULL beforehand, use isNull(int)
-     * 
-     * @return <code>true</code> if the last column read was SQL NULL
-     * @see #isNull(int) const
-     */
-    bool                      wasNull() const { return wasNullFlag; }
-    /**
-     * A column may have the value of SQL NULL; isNull(int) reports whether
-     * the value at the given column and current row is NULL.
-     * 
-     * @param columnIndex the first column is 1, the second is 2,...
-     * @return <code>true</code> if the current row's value for the given 
column
-     *         is SQL NULL
-     * @exception SQLException if the ResultSet is closed or the cursor is out
-     *            of bounds
-     */
-    bool                      isNull(int columnIndex) const
-                                  throw (SQLException, UnexpectedException);
+  int                         getNumberOfColumns() { return nbOfColumns; }
+  /**
+   * Gets the number of rows that have been fetched yet.
+   * Note: this is not the number of rows of the ResultSet, but the current
+   * number of rows in memory !
+   * @return number of rows fetched until now
+   */
+  int                         getNumberOfRowsInMemory() { return nbOfRows; }
+  /**
+   * A column may have the value of SQL NULL; wasNull() reports whether the
+   * last column read had this special value.
+   * Note that you must first call getXXX on a column to try to read its value
+   * and then call wasNull() to find if the value was SQL NULL
+   * If you need to know if a value is NULL beforehand, use isNull(int)
+   * 
+   * @return <code>true</code> if the last column read was SQL NULL
+   * @see #isNull(int) const
+   */
+  bool                        wasNull() const { return wasNullFlag; }
+  /**
+   * A column may have the value of SQL NULL; isNull(int) reports whether
+   * the value at the given column and current row is NULL.
+   * 
+   * @param columnIndex the first column is 1, the second is 2,...
+   * @return <code>true</code> if the current row's value for the given column
+   *         is SQL NULL
+   * @exception DriverException if the ResultSet is closed or the cursor is
+   *            out of bounds
+   */
+  bool                        isNull(int columnIndex) const
+                                  throw (DriverException, UnexpectedException);
 protected:
   /**
    * De-serialize only data rows, not any metadata.
@@ -266,24 +265,25 @@
 
   /**
    * Checks that the cursor is on row in the ResultSet
-   * @throw SQLException if the cursor is out of bounds
+   * @throw DriverException if the cursor is out of bounds
    */
-  void                        checkRowPos() const throw (SQLException,
+  void                        checkRowPos() const throw (DriverException,
                                   UnexpectedException);
   /**
-   * Check if the ResultSet if closed and throws a SQLException if so.
-   * @throw SQLException if the ResultSet is closed
+   * Check if the ResultSet if closed and throws a DriverException if so.
+   * @throw DriverException if the ResultSet is closed
    */
-  void                        checkIfClosed() const throw (SQLException,
+  void                        checkIfClosed() const throw (DriverException,
                                   UnexpectedException);
   /**
    * Sanity checks for result parsing
    * 
    * @param columnIndex the column to check
-   * @throws SQLException if an error occurs
+   * @exception DriverException if the ResultSet is closed or the cursor is
+   *            out of bounds
    */
   void                        checkRowAndColPosAndSetNullFlag(int columnIndex)
-                                  throw (SQLException, UnexpectedException);
+                                  throw (DriverException, UnexpectedException);
   /** Clear/delete data, nulls and typeTags vectors */
   void                        clearAllData();
 };
Index: carob/include/ResultSetMetaData.hpp
diff -u carob/include/ResultSetMetaData.hpp:1.5 
carob/include/ResultSetMetaData.hpp:1.6
--- carob/include/ResultSetMetaData.hpp:1.5     Tue Dec 13 16:08:30 2005
+++ carob/include/ResultSetMetaData.hpp Tue Dec 13 18:18:51 2005
@@ -281,6 +281,7 @@
   /**
    * Utility function: checks that the given column number is between 1 and 
    * ResultSet's <code>nbOfColumns</code> and throws and exception if not.
+   * @exception DriverException if a the given column number is out of range
    */
   void ResultSetMetaData::checkColumnIndex(int column) throw (DriverException,
     UnexpectedException);
Index: carob/include/Statement.hpp
diff -u carob/include/Statement.hpp:1.13 carob/include/Statement.hpp:1.14
--- carob/include/Statement.hpp:1.13    Thu Dec  8 15:18:37 2005
+++ carob/include/Statement.hpp Tue Dec 13 18:18:51 2005
@@ -81,6 +81,7 @@
    * Execute a SQL statement that may return multiple results.
    * @param sql any SQL statement
    * @return true if the result is a ResultSet or false if it is an integer
+   * @throw DriverException if the statement is closed
    */
   bool                    execute(std::wstring sql) throw (DriverException,
                               SocketIOException, BackendException,
@@ -91,6 +92,7 @@
    * Executes a SQL statement that returns a single ResultSet
    * @param sql typically a static SQL <code>SELECT</code> statement
    * @return a ResulSet pointer that contains the data produced by the query
+   * @throw DriverException if the statement is closed
    */
   DriverResultSet*        executeQuery(std::wstring sql)
                               throw (DriverException, SocketIOException,
@@ -117,7 +119,6 @@
    * Any open ResultSet is implicitly closed.
    * 
    * @return true for a ResultSet, false for an updateCount or no more results
-   * @exception DriverException if an error occurs
    */
   bool                    getMoreResults() throw (DriverException,
                               SocketIOException, BackendException,
@@ -141,7 +142,6 @@
    * @return <code>true</code> if the next result is a <code>ResultSet</code>
    *         object; <code>false</code> if it is an update count or there are
    *         no more results
-   * @exception SQLException if a database access error occurs
    * @see #execute(std::wstring)
    */
   bool                    getMoreResults(int current) throw (DriverException,
@@ -169,8 +169,7 @@
    * <code>Statement</code> object to execute.
    * 
    * @param seconds the new query timeout limit in seconds; 0 means no timeout
-   * @throw DriverException if the condition
-   *              seconds >= 0 is not satisfied
+   * @throw DriverException if the condition seconds >= 0 is not satisfied
    */
   void                    setQueryTimeout(int seconds)
                               throw (DriverException, UnexpectedException);
@@ -180,8 +179,8 @@
    * Sets the default fetch size for the produced ResultSet.
    * 
    * @param rows number of rows that should be fetched from the database
-   * @throw DriverException if the condition 0 <= size <= getMaxRows()
-   *        is not satisfied
+   * @throw DriverException if the condition 0 <= size <= getMaxRows() is not
+   *        satisfied
    */
   void                    setFetchSize(int rows)
                               throw (DriverException, UnexpectedException);
Index: carob/src/Connection.cpp
diff -u carob/src/Connection.cpp:1.38 carob/src/Connection.cpp:1.39
--- carob/src/Connection.cpp:1.38       Tue Dec 13 16:08:30 2005
+++ carob/src/Connection.cpp    Tue Dec 13 18:18:51 2005
@@ -385,7 +385,7 @@
 }
 
 void Connection::commit() throw (SocketIOException, DriverException,
-    UnexpectedException)
+    ProtocolException, UnexpectedException)
 {
   wstring fctName(L"Connection::commit");
   
@@ -403,9 +403,11 @@
     int64_t acknowledgedTransactionId = receiveLongOrException();
     if (acknowledgedTransactionId != transactionId)
     {
-      throw (DriverException(L"Protocol error during commit (acknowledge 
transaction ID = "
-              + toWString(acknowledgedTransactionId) + L", expected 
transaction ID = "
-              + toWString(transactionId) + L")"));
+      throw (ProtocolException(
+          L"Protocol error during commit (acknowledge transaction ID = "
+          + toWString(acknowledgedTransactionId)
+          + L", expected transaction ID = "
+          + toWString(transactionId) + L")"));
     }
     // Commit must be followed by a BEGIN
     mustBeginTransaction = true;
@@ -428,7 +430,7 @@
 }
 
 void Connection::rollback() throw (SocketIOException, DriverException,
-    UnexpectedException)
+    ProtocolException, UnexpectedException)
 {
   wstring fctName(L"Connection::rollback");
   
@@ -447,9 +449,11 @@
     int64_t acknowledgedTransactionId = receiveLongOrException();
     if (acknowledgedTransactionId != transactionId)
     {
-      throw (DriverException(L"Protocol error during rollback (acknowledge 
transaction ID = "
-              + toWString(acknowledgedTransactionId) + L", expected 
transaction ID = "
-              + toWString(transactionId) + L")"));
+      throw (ProtocolException(
+          L"Protocol error during rollback (acknowledge transaction ID = "
+            + toWString(acknowledgedTransactionId)
+            + L", expected transaction ID = "
+            + toWString(transactionId) + L")"));
     }
     // Rollback is followed by a BEGIN
     mustBeginTransaction = true;
@@ -471,8 +475,8 @@
   }
 }
 
-Statement* Connection::createStatement() throw (DriverException, 
-    SocketIOException, UnexpectedException)
+Statement* Connection::createStatement() throw (SocketIOException,
+    UnexpectedException)
 {
   checkIfConnected();
   return new Statement(this);
@@ -482,7 +486,8 @@
     UnexpectedException)
 {
   if (driverSocketPtr == NULL || !driverSocketPtr->isConnected())
-    throw SocketIOException(L"Request cannot be processed : connection is 
closed!");
+    throw SocketIOException(
+        L"Request cannot be processed : connection is closed!");
 }
 
 void Connection::setConnectionParametersOnRequest(Request &request)
Index: carob/src/DriverResultSet.cpp
diff -u carob/src/DriverResultSet.cpp:1.20 carob/src/DriverResultSet.cpp:1.21
--- carob/src/DriverResultSet.cpp:1.20  Tue Dec 13 16:08:30 2005
+++ carob/src/DriverResultSet.cpp       Tue Dec 13 18:18:51 2005
@@ -172,7 +172,7 @@
     {
       // TODO: what happens if user closed this connection? What says JDBC?
       connectionPtr->tryFetchNext(cursorName, fetchSize);
-      // no SQLException from controller, so let's receive our new rows
+      // no exception from controller, so let's receive our new rows
       receiveRows();
       currentRow = 0;
       if (dataIsNull)
@@ -197,8 +197,8 @@
   return true;
 }
 
-wstring DriverResultSet::getString(int columnIndex) throw (SQLException,
-    UnexpectedException)
+wstring DriverResultSet::getString(int columnIndex) throw (DriverException,
+    NotImplementedException, UnexpectedException)
 {
   checkRowAndColPosAndSetNullFlag(columnIndex);
   if (wasNullFlag)
@@ -259,8 +259,8 @@
   return buffer.str();
 }
 
-int32_t DriverResultSet::getInt(int columnIndex) throw (SQLException, 
-    UnexpectedException)
+int32_t DriverResultSet::getInt(int columnIndex) throw (DriverException,
+    NotImplementedException, UnexpectedException)
 {
   checkRowAndColPosAndSetNullFlag(columnIndex);
 
@@ -333,24 +333,24 @@
   socket>>hasMoreData;
 }
 
-void DriverResultSet::checkRowPos() const throw (SQLException,
+void DriverResultSet::checkRowPos() const throw (DriverException,
     UnexpectedException)
 {
   if (currentRow < 0)
-    throw SQLException(L"Before start of result set");
+    throw DriverException(L"Before start of result set");
 
   if (currentRow == nbOfRows)
-    throw SQLException(L"After end of result set");
+    throw DriverException(L"After end of result set");
 }
 
-void DriverResultSet::checkIfClosed() const throw (SQLException, 
+void DriverResultSet::checkIfClosed() const throw (DriverException, 
     UnexpectedException)
 {
   if (isClosed)
-    throw SQLException(L"Trying to access a closed ResultSet");
+    throw DriverException(L"Trying to access a closed ResultSet");
 }
 
-bool DriverResultSet::isNull(int columnIndex) const throw (SQLException,
+bool DriverResultSet::isNull(int columnIndex) const throw (DriverException,
     UnexpectedException)
 {
   bool answer = false;
@@ -360,10 +360,10 @@
   checkRowPos();
 
   if (fields.size() == 0)
-    throw SQLException(L"Query generated no fields for ResultSet");
+    throw DriverException(L"Query generated no fields for ResultSet");
 
   if (columnIndex < 1 || columnIndex > nbOfColumns)
-    throw SQLException(L"Column Index out of range ( "
+    throw DriverException(L"Column Index out of range ( "
         + toWString(columnIndex) + L" > " + toWString(nbOfColumns) + L").");
 
   if ((int)data[currentRow].size()<columnIndex-1)
@@ -374,7 +374,7 @@
 }
 
 void DriverResultSet::checkRowAndColPosAndSetNullFlag(int columnIndex)
-    throw (SQLException, UnexpectedException)
+    throw (DriverException, UnexpectedException)
 {
     wasNullFlag = isNull(columnIndex);
 }
Index: carob/src/ResultSetMetaData.cpp
diff -u carob/src/ResultSetMetaData.cpp:1.5 carob/src/ResultSetMetaData.cpp:1.6
--- carob/src/ResultSetMetaData.cpp:1.5 Fri Dec  2 15:53:07 2005
+++ carob/src/ResultSetMetaData.cpp     Tue Dec 13 18:18:51 2005
@@ -36,7 +36,8 @@
     UnexpectedException)
 {
   if ((column < 1) || (column > resultSetPtr->nbOfColumns))
-    throw DriverException(L"Invalid column index " + toWString(column));
+    throw DriverException(L"Invalid column index " + toWString(column)
+        + L" is not between 1 and " + toWString(resultSetPtr->nbOfColumns));
 }
 bool ResultSetMetaData::isAutoIncrement(int column) throw (DriverException,
     UnexpectedException)

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

Reply via email to