dgraham     2003/10/22 17:28:38

  Modified:    dbutils/src/java/org/apache/commons/dbutils QueryRunner.java
  Log:
  javadoc fixes, cast null parameters to make sure we call the
  correct method, always call DbUtils.closeQuietly()
  instead of DbUtils.close() in finally blocks so we don't
  lose a more interesting exception that occurred in the
  try block.
  
  Revision  Changes    Path
  1.10      +28 -19    
jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/QueryRunner.java
  
  Index: QueryRunner.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/QueryRunner.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- QueryRunner.java  22 Oct 2003 23:33:25 -0000      1.9
  +++ QueryRunner.java  23 Oct 2003 00:28:38 -0000      1.10
  @@ -214,7 +214,7 @@
        public Object query(Connection conn, String sql, ResultSetHandler rsh)
                throws SQLException {
   
  -             return this.query(conn, sql, null, rsh);
  +             return this.query(conn, sql, (Object[]) null, rsh);
        }
   
        /**
  @@ -223,9 +223,10 @@
         * <code>DataSource</code> set in the constructor.
         * 
         * @param sql The SQL statement to execute.
  +      * @param param The replacement parameter.
         * @param rsh The handler used to create the result object from 
         * the <code>ResultSet</code>.
  -      * @param param The replacement parameter.
  +      * 
         * @return An object generated by the handler.
         * @throws SQLException
         */
  @@ -241,10 +242,12 @@
         * <code>DataSource</code> set in the constructor.
         * 
         * @param sql The SQL statement to execute.
  -      * @param params Initialize the PreparedStatement's IN parameters with this
  -      * array.
  +      * @param params Initialize the PreparedStatement's IN parameters with 
  +      * this array.
  +      * 
         * @param rsh The handler used to create the result object from 
         * the <code>ResultSet</code>.
  +      * 
         * @return An object generated by the handler.
         * @throws SQLException
         */
  @@ -259,7 +262,7 @@
                        result = this.query(conn, sql, params, rsh);
   
                } finally {
  -                     DbUtils.close(conn);
  +                     DbUtils.closeQuietly(conn);
                }
   
                return result;
  @@ -273,20 +276,24 @@
         * @param sql The SQL statement to execute.
         * @param rsh The handler used to create the result object from 
         * the <code>ResultSet</code>.
  +      * 
         * @return An object generated by the handler.
         * @throws SQLException
         */
        public Object query(String sql, ResultSetHandler rsh) throws SQLException {
  -             return this.query(sql, null, rsh);
  +             return this.query(sql, (Object[]) null, rsh);
        }
   
        /**
         * Throws a new exception with a more informative error message.
  +      * 
         * @param cause The original exception that will be chained to the new 
         * exception when it's rethrown. 
  +      * 
         * @param sql The query that was executing when the exception happened.
         * @param params The query replacement paramaters; <code>null</code> is a 
         * valid value to pass in.
  +      * 
         * @throws SQLException
         */
        protected void rethrow(SQLException cause, String sql, Object[] params)
  @@ -309,6 +316,7 @@
         * database connections from.  This should be called after creating a
         * runner with the default constructor if you intend to use the
         * execute methods without passing in a <code>Connection</code>.
  +      * 
         * @param dataSource The DataSource to use.
         */
        public void setDataSource(DataSource dataSource) {
  @@ -325,7 +333,7 @@
         * @throws SQLException
         */
        public int update(Connection conn, String sql) throws SQLException {
  -             return this.update(conn, sql, null);
  +             return this.update(conn, sql, (Object[]) null);
        }
   
        /**
  @@ -346,6 +354,7 @@
   
        /**
         * Execute an SQL INSERT, UPDATE, or DELETE query.
  +      * 
         * @param conn The connection to use to run the query.
         * @param sql The SQL to execute.
         * @param params The query replacement parameters.
  @@ -355,12 +364,13 @@
        public int update(Connection conn, String sql, Object[] params)
                throws SQLException {
   
  -             PreparedStatement stmt = conn.prepareStatement(sql);
  -             this.fillStatement(stmt, params);
  -
  +             PreparedStatement stmt = null;
                int rows = 0;
   
                try {
  +                     stmt = conn.prepareStatement(sql);
  +                     this.fillStatement(stmt, params);
  +
                        rows = stmt.executeUpdate();
   
                } catch (SQLException e) {
  @@ -375,7 +385,7 @@
   
        /**
         * Executes the given INSERT, UPDATE, or DELETE SQL statement without
  -      * any replacement parameters.  The statement is executed in it's own 
  +      * any replacement parameters.  The statement is executed in its own 
         * transaction that will be committed or rolled back depending on any 
         * SQLExceptions thrown.  The <code>Connection</code> is retrieved from the
         * <code>DataSource</code> set in the constructor.
  @@ -385,12 +395,12 @@
         * @return The number of rows updated.
         */
        public int update(String sql) throws SQLException {
  -             return this.update(sql, null);
  +             return this.update(sql, (Object[]) null);
        }
   
        /**
         * Executes the given INSERT, UPDATE, or DELETE SQL statement with
  -      * a single replacement parameter.  The statement is executed in it's own 
  +      * a single replacement parameter.  The statement is executed in its own 
         * transaction that will be committed or rolled back depending on any 
         * SQLExceptions thrown.  The <code>Connection</code> is retrieved from the
         * <code>DataSource</code> set in the constructor.
  @@ -406,7 +416,7 @@
   
        /**
         * Executes the given INSERT, UPDATE, or DELETE SQL statement.  The 
  -      * statement is executed in it's own transaction that will be committed or 
  +      * statement is executed in its own transaction that will be committed or 
         * rolled back depending on any SQLExceptions thrown.  The 
         * <code>Connection</code> is retrieved from the <code>DataSource</code> 
         * set in the constructor.
  @@ -420,7 +430,6 @@
        public int update(String sql, Object[] params) throws SQLException {
   
                Connection conn = this.ds.getConnection();
  -
                int rows = 0;
   
                try {
  @@ -433,7 +442,7 @@
                        throw e;
   
                } finally {
  -                     DbUtils.close(conn);
  +                     DbUtils.closeQuietly(conn);
                }
   
                return rows;
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to