Details
-
Improvement
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
None
-
None
-
Operating System: All
Platform: All
-
30032
Description
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); }+
{ + return ds.getConnection(); + }
+ /**
+ * 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
/**
- 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 {