You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ws...@apache.org on 2013/03/10 16:39:46 UTC

svn commit: r1454865 [2/2] - in /commons/proper/dbutils/branches/2_0: ./ src/changes/ src/main/java/org/apache/commons/dbutils2/ src/main/java/org/apache/commons/dbutils2/handlers/ src/main/java/org/apache/commons/dbutils2/wrappers/

Modified: commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils2/GenerousBeanProcessor.java
URL: http://svn.apache.org/viewvc/commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils2/GenerousBeanProcessor.java?rev=1454865&r1=1454864&r2=1454865&view=diff
==============================================================================
--- commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils2/GenerousBeanProcessor.java (original)
+++ commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils2/GenerousBeanProcessor.java Sun Mar 10 15:39:45 2013
@@ -28,17 +28,17 @@ import java.util.Arrays;
  * columns to Java Bean properties.
  */
 public class GenerousBeanProcessor extends BeanProcessor {
-    
+
     /**
      * Default constructor.
      */
     public GenerousBeanProcessor() {
         super();
     }
-    
+
     @Override
     protected int[] mapColumnsToProperties(final ResultSetMetaData rsmd,
-                                           final PropertyDescriptor[] props) throws SQLException {
+            final PropertyDescriptor[] props) throws SQLException {
 
         final int cols = rsmd.getColumnCount();
         final int[] columnToProperty = new int[cols + 1];
@@ -46,19 +46,19 @@ public class GenerousBeanProcessor exten
 
         for (int col = 1; col <= cols; col++) {
             String columnName = rsmd.getColumnLabel(col);
-            
+
             if (null == columnName || 0 == columnName.length()) {
                 columnName = rsmd.getColumnName(col);
             }
-            
-            final String generousColumnName = columnName.replace("_","");
+
+            final String generousColumnName = columnName.replace("_", "");
 
             for (int i = 0; i < props.length; i++) {
                 final String propName = props[i].getName();
-                
+
                 // see if either the column name, or the generous one matches
                 if (columnName.equalsIgnoreCase(propName) ||
-                    generousColumnName.equalsIgnoreCase(propName)) {
+                        generousColumnName.equalsIgnoreCase(propName)) {
                     columnToProperty[col] = i;
                     break;
                 }
@@ -67,5 +67,5 @@ public class GenerousBeanProcessor exten
 
         return columnToProperty;
     }
-    
+
 }

Modified: commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils2/InsertExecutor.java
URL: http://svn.apache.org/viewvc/commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils2/InsertExecutor.java?rev=1454865&r1=1454864&r2=1454865&view=diff
==============================================================================
--- commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils2/InsertExecutor.java (original)
+++ commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils2/InsertExecutor.java Sun Mar 10 15:39:45 2013
@@ -21,18 +21,32 @@ import java.sql.ResultSet;
 import java.sql.SQLException;
 
 
+/**
+ * Fluent class for executing inserts.
+ *
+ * @since 2.0
+ * @author William Speirs <ws...@apache.org>
+ */
 public class InsertExecutor extends AbstractExecutor<InsertExecutor> {
 
     private final boolean closeConn;
 
-    public InsertExecutor(final Connection conn, final String sql, final boolean closeConnection) throws SQLException {
+    /**
+     * Constructs an InsertExecutor given a connection and SQL statement.
+     * @param conn The connection to use during execution.
+     * @param sql The SQL statement.
+     * @param closeConnection If the connection should be closed or not.
+     * @throws SQLException thrown if there is an error during execution.
+     */
+    InsertExecutor(final Connection conn, final String sql, final boolean closeConnection) throws SQLException {
         super(conn, sql);
         this.closeConn = closeConnection;
     }
 
     /**
      * Executes the given INSERT SQL statement.
-     * 
+     *
+     * @param <T> the type returned by the ResultSetHandler.
      * @param handler The handler used to create the result object from
      * the <code>ResultSet</code> of auto-generated keys.
      *
@@ -54,10 +68,10 @@ public class InsertExecutor extends Abst
         try {
             // execute the update
             getStatement().executeUpdate();
-            
+
             // get the result set
             final ResultSet resultSet = getStatement().getGeneratedKeys();
-            
+
             // run the handler over the results and return them
             return handler.handle(resultSet);
         } catch (SQLException e) {
@@ -72,7 +86,7 @@ public class InsertExecutor extends Abst
         // we get here only if something is thrown
         return null;
     }
-    
+
     /**
      * Executes the given INSERT SQL statement.
      * @return the number of rows updated.
@@ -93,8 +107,8 @@ public class InsertExecutor extends Abst
                 close(getConnection());
             }
         }
-        
+
         return 0; // only get here on an error
     }
-    
+
 }

Modified: commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils2/QueryExecutor.java
URL: http://svn.apache.org/viewvc/commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils2/QueryExecutor.java?rev=1454865&r1=1454864&r2=1454865&view=diff
==============================================================================
--- commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils2/QueryExecutor.java (original)
+++ commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils2/QueryExecutor.java Sun Mar 10 15:39:45 2013
@@ -22,15 +22,22 @@ import java.sql.SQLException;
 
 /**
  * Fluent class for executing a query.
- * 
+ *
  * @since 2.0
  * @author William Speirs <ws...@apache.org>
  */
 class QueryExecutor extends AbstractExecutor<QueryExecutor> {
-    
+
     private final boolean closeConn;
 
-    public QueryExecutor(final Connection conn, final String sql, final boolean closeConnection) throws SQLException {
+    /**
+     * Constructs a QueryExecutor given a connection and SQL statement.
+     * @param conn The connection to use during execution.
+     * @param sql The SQL statement.
+     * @param closeConnection If the connection should be closed or not.
+     * @throws SQLException thrown if there is an error during execution.
+     */
+    QueryExecutor(final Connection conn, final String sql, final boolean closeConnection) throws SQLException {
         super(conn, sql);
         this.closeConn = closeConnection;
     }
@@ -46,7 +53,7 @@ class QueryExecutor extends AbstractExec
     public <T> T execute(ResultSetHandler<T> handler) throws SQLException {
         // throw an exception if there are unmapped parameters
         this.throwIfUnmappedParams();
-        
+
         // make sure our handler is not null
         if (handler == null) {
             if (closeConn) {

Modified: commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils2/QueryRunner.java
URL: http://svn.apache.org/viewvc/commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils2/QueryRunner.java?rev=1454865&r1=1454864&r2=1454865&view=diff
==============================================================================
--- commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils2/QueryRunner.java (original)
+++ commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils2/QueryRunner.java Sun Mar 10 15:39:45 2013
@@ -50,7 +50,7 @@ public class QueryRunner {
     public QueryRunner(final DataSource ds) {
         this.ds = ds;
     }
-    
+
     /**
      * Returns the <code>DataSource</code> this runner is using.
      * <code>QueryRunner</code> methods always call this method to get the
@@ -76,7 +76,7 @@ public class QueryRunner {
         if (this.getDataSource() == null) {
             throw new SQLException(
                     "QueryRunner requires a DataSource to be "
-                    + "invoked in this way, or a Connection should be passed in");
+                            + "invoked in this way, or a Connection should be passed in");
         }
         return this.getDataSource().getConnection();
     }
@@ -98,10 +98,10 @@ public class QueryRunner {
      * <code>Connection</code> is retrieved from the <code>DataSource</code>
      * set in the constructor.  This <code>Connection</code> must be in
      * auto-commit mode or the insert will not be saved. The <code>Connection</code> is
-     * closed after the call. 
-     * 
+     * closed after the call.
+     *
      * @param sql The SQL statement to execute.
-     * 
+     *
      * @return An {@link org.apache.commons.dbutils2.BatchExecutor} for this SQL statement.
      * @throws SQLException If there are database or parameter errors.
      */
@@ -115,7 +115,7 @@ public class QueryRunner {
      *
      * @param conn The connection to use for the batch call.
      * @param sql The SQL statement to execute.
-     * 
+     *
      * @return An {@link org.apache.commons.dbutils2.BatchExecutor} for this SQL statement.
      * @throws SQLException If there are database or parameter errors.
      */
@@ -125,11 +125,11 @@ public class QueryRunner {
 
     /**
      * Creates an {@link org.apache.commons.dbutils2.BatchExecutor} for the given SQL statement and connection.
-     * 
+     *
      * @param conn The connection to use for the batch call.
      * @param closeConn True if the connection should be closed, false otherwise.
      * @param sql The SQL statement to execute.
-     * 
+     *
      * @return An {@link org.apache.commons.dbutils2.BatchExecutor} for this SQL statement.
      * @throws SQLException If there are database or parameter errors.
      */
@@ -144,7 +144,7 @@ public class QueryRunner {
             }
             throw new SQLException("Null SQL statement");
         }
-        
+
         return new BatchExecutor(conn, sql, closeConn);
     }
 
@@ -153,10 +153,10 @@ public class QueryRunner {
      * <code>Connection</code> is retrieved from the <code>DataSource</code>
      * set in the constructor.  This <code>Connection</code> must be in
      * auto-commit mode or the insert will not be saved. The <code>Connection</code> is
-     * closed after the call. 
-     * 
+     * closed after the call.
+     *
      * @param sql The SQL statement to execute.
-     * 
+     *
      * @return An {@link org.apache.commons.dbutils2.QueryExecutor} for this SQL statement.
      * @throws SQLException If there are database or parameter errors.
      */
@@ -167,10 +167,10 @@ public class QueryRunner {
     /**
      * Creates an {@link org.apache.commons.dbutils2.QueryExecutor} for the given SQL statement and connection.
      * The connection is <b>NOT</b> closed after execution.
-     * 
+     *
      * @param conn The connection to use for the update call.
      * @param sql The SQL statement to execute.
-     * 
+     *
      * @return An {@link org.apache.commons.dbutils2.QueryExecutor} for this SQL statement.
      * @throws SQLException If there are database or parameter errors.
      */
@@ -180,11 +180,11 @@ public class QueryRunner {
 
     /**
      * Creates an {@link org.apache.commons.dbutils2.QueryExecutor} for the given SQL statement and connection.
-     * 
+     *
      * @param conn The connection to use for the query call.
      * @param closeConn True if the connection should be closed, false otherwise.
      * @param sql The SQL statement to execute.
-     * 
+     *
      * @return An {@link org.apache.commons.dbutils2.QueryExecutor} for this SQL statement.
      * @throws SQLException If there are database or parameter errors.
      */
@@ -199,7 +199,7 @@ public class QueryRunner {
             }
             throw new SQLException("Null SQL statement");
         }
-        
+
         return new QueryExecutor(conn, sql, closeConn);
     }
 
@@ -208,10 +208,10 @@ public class QueryRunner {
      * <code>Connection</code> is retrieved from the <code>DataSource</code>
      * set in the constructor.  This <code>Connection</code> must be in
      * auto-commit mode or the insert will not be saved. The <code>Connection</code> is
-     * closed after the call. 
+     * closed after the call.
      *
      * @param sql The SQL statement to execute.
-     * 
+     *
      * @return An {@link org.apache.commons.dbutils2.UpdateExecutor} for this SQL statement.
      * @throws SQLException if a database access error occurs
      */
@@ -222,10 +222,10 @@ public class QueryRunner {
     /**
      * Creates an {@link org.apache.commons.dbutils2.UpdateExecutor} for the given SQL statement and connection.
      * The connection is <b>NOT</b> closed after execution.
-     * 
+     *
      * @param conn The connection to use for the update call.
      * @param sql The SQL statement to execute.
-     * 
+     *
      * @return An {@link org.apache.commons.dbutils2.UpdateExecutor} for this SQL statement.
      * @throws SQLException If there are database or parameter errors.
      */
@@ -235,11 +235,11 @@ public class QueryRunner {
 
     /**
      * Creates an {@link org.apache.commons.dbutils2.UpdateExecutor} for the given SQL statement and connection.
-     * 
+     *
      * @param conn The connection to use for the update call.
      * @param closeConn True if the connection should be closed, false otherwise.
      * @param sql The SQL statement to execute.
-     * 
+     *
      * @return An {@link org.apache.commons.dbutils2.UpdateExecutor} for this SQL statement.
      * @throws SQLException If there are database or parameter errors.
      */
@@ -263,8 +263,8 @@ public class QueryRunner {
      * <code>Connection</code> is retrieved from the <code>DataSource</code>
      * set in the constructor.  This <code>Connection</code> must be in
      * auto-commit mode or the insert will not be saved. The <code>Connection</code> is
-     * closed after the call. 
-     * 
+     * closed after the call.
+     *
      * @param sql The SQL statement to execute.
      *
      * @return An {@link org.apache.commons.dbutils2.InsertExecutor} for this SQL statement.
@@ -277,7 +277,7 @@ public class QueryRunner {
     /**
      * Creates an {@link org.apache.commons.dbutils2.InsertExecutor} for the given SQL and connection
      * The connection is <b>NOT</b> closed after execution.
-     * 
+     *
      * @param conn The connection to use for the query call.
      * @param sql The SQL statement to execute.
      *
@@ -290,7 +290,7 @@ public class QueryRunner {
 
     /**
      * Creates an {@link org.apache.commons.dbutils2.InsertExecutor} for the given SQL and connection.
-     * 
+     *
      * @param conn The connection to use for the insert call.
      * @param closeConn True if the connection should be closed, false otherwise.
      * @param sql The SQL statement to execute.
@@ -309,7 +309,7 @@ public class QueryRunner {
             }
             throw new SQLException("Null SQL statement");
         }
-        
+
         return new InsertExecutor(conn, sql, closeConn);
     }
 }

Modified: commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils2/UpdateExecutor.java
URL: http://svn.apache.org/viewvc/commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils2/UpdateExecutor.java?rev=1454865&r1=1454864&r2=1454865&view=diff
==============================================================================
--- commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils2/UpdateExecutor.java (original)
+++ commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils2/UpdateExecutor.java Sun Mar 10 15:39:45 2013
@@ -19,12 +19,24 @@ package org.apache.commons.dbutils2;
 import java.sql.Connection;
 import java.sql.SQLException;
 
-
+/**
+ * Fluent class for executing updates.
+ *
+ * @since 2.0
+ * @author William Speirs <ws...@apache.org>
+ */
 public class UpdateExecutor extends AbstractExecutor<UpdateExecutor> {
 
     private final boolean closeConn;
-    
-    public UpdateExecutor(final Connection conn, final String sql, final boolean closeConnection) throws SQLException {
+
+    /**
+     * Constructs an UpdateExecutor given a connection and SQL statement.
+     * @param conn The connection to use during execution.
+     * @param sql The SQL statement.
+     * @param closeConnection If the connection should be closed or not.
+     * @throws SQLException thrown if there is an error during execution.
+     */
+    UpdateExecutor(final Connection conn, final String sql, final boolean closeConnection) throws SQLException {
         super(conn, sql);
         this.closeConn = closeConnection;
     }

Modified: commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils2/handlers/KeyedHandler.java
URL: http://svn.apache.org/viewvc/commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils2/handlers/KeyedHandler.java?rev=1454865&r1=1454864&r2=1454865&view=diff
==============================================================================
--- commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils2/handlers/KeyedHandler.java (original)
+++ commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils2/handlers/KeyedHandler.java Sun Mar 10 15:39:45 2013
@@ -55,18 +55,18 @@ public class KeyedHandler<K> extends Abs
      * The RowProcessor implementation to use when converting rows
      * into Objects.
      */
-    protected final RowProcessor convert;
+    private final RowProcessor convert;
 
     /**
      * The column index to retrieve key values from.  Defaults to 1.
      */
-    protected final int columnIndex;
+    private final int columnIndex;
 
     /**
      * The column name to retrieve key values from.  Either columnName or
      * columnIndex will be used but never both.
      */
-    protected final String columnName;
+    private final String columnName;
 
     /**
      * Creates a new instance of KeyedHandler.  The value of the first column
@@ -139,8 +139,8 @@ public class KeyedHandler<K> extends Abs
     @Override
     protected K createKey(ResultSet rs) throws SQLException {
         return (columnName == null) ?
-               (K) rs.getObject(columnIndex) :
-               (K) rs.getObject(columnName);
+                (K) rs.getObject(columnIndex) :
+                    (K) rs.getObject(columnName);
     }
 
     /**

Modified: commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils2/wrappers/SqlNullCheckedResultSet.java
URL: http://svn.apache.org/viewvc/commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils2/wrappers/SqlNullCheckedResultSet.java?rev=1454865&r1=1454864&r2=1454865&view=diff
==============================================================================
--- commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils2/wrappers/SqlNullCheckedResultSet.java (original)
+++ commons/proper/dbutils/branches/2_0/src/main/java/org/apache/commons/dbutils2/wrappers/SqlNullCheckedResultSet.java Sun Mar 10 15:39:45 2013
@@ -253,7 +253,7 @@ public class SqlNullCheckedResultSet imp
      * @return the value
      */
     public Date getNullDate() {
-        return this.nullDate;
+        return new Date(this.nullDate.getTime());
     }
 
     /**
@@ -353,7 +353,7 @@ public class SqlNullCheckedResultSet imp
      * @return the value
      */
     public Timestamp getNullTimestamp() {
-        return this.nullTimestamp;
+        return new Timestamp(this.nullTimestamp.getTime());
     }
 
     /**
@@ -380,7 +380,7 @@ public class SqlNullCheckedResultSet imp
      */
     @Override
     public Object invoke(Object proxy, Method method, Object[] args)
-        throws Throwable {
+            throws Throwable {
 
         Object result = method.invoke(this.rs, args);
 
@@ -389,8 +389,8 @@ public class SqlNullCheckedResultSet imp
         // Check nullMethod != null first so that we don't call wasNull()
         // before a true getter method was invoked on the ResultSet.
         return (nullMethod != null && this.rs.wasNull())
-            ? nullMethod.invoke(this, (Object[]) null)
-            : result;
+                ? nullMethod.invoke(this, (Object[]) null)
+                        : result;
     }
 
     /**
@@ -492,7 +492,7 @@ public class SqlNullCheckedResultSet imp
      * @param nullDate the value
      */
     public void setNullDate(Date nullDate) {
-        this.nullDate = nullDate;
+        this.nullDate = nullDate != null ? new Date(nullDate.getTime()) : null;
     }
 
     /**
@@ -592,7 +592,7 @@ public class SqlNullCheckedResultSet imp
      * @param nullTimestamp the value
      */
     public void setNullTimestamp(Timestamp nullTimestamp) {
-        this.nullTimestamp = nullTimestamp;
+        this.nullTimestamp = nullTimestamp != null ? new Timestamp(nullTimestamp.getTime()) : null;
     }
 
     /**