You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by bu...@apache.org on 2004/07/11 10:12:28 UTC

DO NOT REPLY [Bug 30032] New: - [PATCH][DbUtils] protected prepareConnection()

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=30032>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=30032

[PATCH][DbUtils] protected prepareConnection()

           Summary: [PATCH][DbUtils] protected prepareConnection()
           Product: Commons
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Enhancement
          Priority: Other
         Component: DbUtils
        AssignedTo: commons-dev@jakarta.apache.org
        ReportedBy: info@mikkri.com


This patch contains protected prepareConnection() method for the QueryRunner.
Also all this.ds.getConnection() calls were replaced with prepareConnection() 
calls.

Additionaly I added a few missed JavaDocs. Look at the patch for details.
===================================================================

Index: QueryRunner.java
===================================================================
RCS file: /home/cvspublic/jakarta-
commons/dbutils/src/java/org/apache/commons/dbutils/QueryRunner.java,v
retrieving revision 1.11
diff -u -r1.11 QueryRunner.java
--- QueryRunner.java	6 Jun 2004 14:35:39 -0000	1.11
+++ QueryRunner.java	11 Jul 2004 08:09:58 -0000
@@ -107,7 +107,7 @@
      * @since DbUtils 1.1
      */
     public int[] batch(String sql, Object[][] params) throws SQLException {
-        Connection conn = this.ds.getConnection();
+        Connection conn = prepareConnection();
 
         try {
             return this.batch(conn, sql, params);
@@ -142,6 +142,7 @@
 
     /**
      * Returns the <code>DataSource</code> this runner is using.
+     * @return <code>DataSource</code> this runner is using.
      */
     public DataSource getDataSource() {
         return this.ds;
@@ -166,6 +167,20 @@
             
         return conn.prepareStatement(sql);
     }
+    
+    /**
+     * Factory method that retrieves a <code>Connection</code> object.
+     * It called from all methods that don't receive <code>Connection</code> 
as one
+     * of parameters.
+     * This implementation uses <code>DataSource</code> to get a connection.
+     * @return retrieved <code>Connection</code>.
+     * @throws SQLException
+     * @since DbUtils 1.1
+     */
+    protected Connection prepareConnection()
+    		throws SQLException {
+      	return ds.getConnection();
+    }
 
     /**
      * Execute an SQL SELECT query with a single replacement parameter.  The
@@ -285,7 +300,7 @@
     public Object query(String sql, Object[] params, ResultSetHandler rsh)
         throws SQLException {
 
-        Connection conn = this.ds.getConnection();
+        Connection conn = prepareConnection();
 
         try {
             return this.query(conn, sql, params, rsh);
@@ -461,7 +476,7 @@
      * @return The number of rows updated.
      */
     public int update(String sql, Object[] params) throws SQLException {
-        Connection conn = this.ds.getConnection();
+        Connection conn = prepareConnection();
 
         try {
             return this.update(conn, sql, params);
@@ -499,6 +514,8 @@
      * Close a <code>Connection</code>.  This implementation avoids closing if 
      * null and does <strong>not</strong> suppress any exceptions.  Subclasses
      * can override to provide special handling like logging.
+     * @param conn <code>Connection</code> to close.
+     * @throws SQLException
      * @since DbUtils 1.1
      */
     protected void close(Connection conn) throws SQLException {
@@ -509,6 +526,8 @@
      * Close a <code>Statement</code>.  This implementation avoids closing if 
      * null and does <strong>not</strong> suppress any exceptions.  Subclasses
      * can override to provide special handling like logging.
+     * @param stmt <code>Statement</code> to close.
+     * @throws SQLException
      * @since DbUtils 1.1
      */
     protected void close(Statement stmt) throws SQLException {
@@ -519,6 +538,8 @@
      * Close a <code>ResultSet</code>.  This implementation avoids closing if 
      * null and does <strong>not</strong> suppress any exceptions.  Subclasses
      * can override to provide special handling like logging.
+     * @param rs <code>ResultSet</code> to close.
+     * @throws SQLException
      * @since DbUtils 1.1
      */
     protected void close(ResultSet rs) throws SQLException {

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org