dgraham 2004/07/18 18:41:26 Modified: dbutils/src/java/org/apache/commons/dbutils QueryRunner.java dbutils/xdocs changes.xml Log: Added QueryRunner.prepareConnection(). PR: 30032 Revision Changes Path 1.12 +35 -20 jakarta-commons/dbutils/src/java/org/apache/commons/dbutils/QueryRunner.java Index: QueryRunner.java =================================================================== RCS file: /home/cvs/jakarta-commons/dbutils/src/java/org/apache/commons/dbutils/QueryRunner.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- QueryRunner.java 6 Jun 2004 14:35:39 -0000 1.11 +++ QueryRunner.java 19 Jul 2004 01:41:26 -0000 1.12 @@ -107,7 +107,7 @@ * @since DbUtils 1.1 */ public int[] batch(String sql, Object[][] params) throws SQLException { - Connection conn = this.ds.getConnection(); + Connection conn = this.prepareConnection(); try { return this.batch(conn, sql, params); @@ -166,24 +166,40 @@ return conn.prepareStatement(sql); } + + /** + * Factory method that creates and initializes a + * <code>Connection</code> object. <code>QueryRunner</code> methods + * always call this method to retrieve connections from its DataSource. + * Subclasses can override this method to provide + * special <code>Connection</code> configuration if needed. This + * implementation simply calls <code>ds.getConnection()</code>. + * + * @return An initialized <code>Connection</code>. + * @throws SQLException + * @since DbUtils 1.1 + */ + protected Connection prepareConnection() throws SQLException { + return this.ds.getConnection(); + } /** - * Execute an SQL SELECT query with a single replacement parameter. The + * Execute an SQL SELECT query with a single replacement parameter. The * caller is responsible for closing the connection. * - * @param conn The connection to execute the query in. - * @param sql The query to execute. - * @param param The replacement parameter. - * @param rsh The handler that converts the results into an object. + * @param conn + * The connection to execute the query in. + * @param sql + * The query to execute. + * @param param + * The replacement parameter. + * @param rsh + * The handler that converts the results into an object. * @return The object returned by the handler. * @throws SQLException */ - public Object query( - Connection conn, - String sql, - Object param, - ResultSetHandler rsh) - throws SQLException { + public Object query(Connection conn, String sql, Object param, + ResultSetHandler rsh) throws SQLException { return this.query(conn, sql, new Object[] { param }, rsh); } @@ -199,12 +215,8 @@ * @return The object returned by the handler. * @throws SQLException */ - public Object query( - Connection conn, - String sql, - Object[] params, - ResultSetHandler rsh) - throws SQLException { + public Object query(Connection conn, String sql, Object[] params, + ResultSetHandler rsh) throws SQLException { PreparedStatement stmt = null; ResultSet rs = null; @@ -285,7 +297,7 @@ public Object query(String sql, Object[] params, ResultSetHandler rsh) throws SQLException { - Connection conn = this.ds.getConnection(); + Connection conn = this.prepareConnection(); try { return this.query(conn, sql, params, rsh); @@ -461,7 +473,7 @@ * @return The number of rows updated. */ public int update(String sql, Object[] params) throws SQLException { - Connection conn = this.ds.getConnection(); + Connection conn = this.prepareConnection(); try { return this.update(conn, sql, params); @@ -499,6 +511,7 @@ * 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. + * @throws SQLException * @since DbUtils 1.1 */ protected void close(Connection conn) throws SQLException { @@ -509,6 +522,7 @@ * 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. + * @throws SQLException * @since DbUtils 1.1 */ protected void close(Statement stmt) throws SQLException { @@ -519,6 +533,7 @@ * 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. + * @throws SQLException * @since DbUtils 1.1 */ protected void close(ResultSet rs) throws SQLException { 1.2 +6 -0 jakarta-commons/dbutils/xdocs/changes.xml Index: changes.xml =================================================================== RCS file: /home/cvs/jakarta-commons/dbutils/xdocs/changes.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- changes.xml 3 Apr 2004 05:19:13 -0000 1.1 +++ changes.xml 19 Jul 2004 01:41:26 -0000 1.2 @@ -40,6 +40,12 @@ <release version="1.1-dev" date="in CVS"> <action dev="dgraham" type="add"> + Added a protected QueryRunner.prepareConnection() method to + allow subclasses to customize the Connections retrieved from + the DataSource before they're used. + PR# 30032 + </action> + <action dev="dgraham" type="add"> Refactored bean handling from BasicRowProcessor into new BeanProcessor class. This also fixes the common problem with Oracle NUMERIC fields not being set into bean properties.
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]