stevencaswell 2003/03/12 14:29:06
Modified: dbutils/src/java/org/apache/commons/dbutils DbUtils.java
Added: dbutils/src/java/org/apache/commons/dbutils
ResultSetMetaDataHandler.java
Log:
added support for passing ResultSetMetaDataHandler into DbUtils execute and
executeQuery methods
Revision Changes Path
1.16 +35 -8
jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/DbUtils.java
Index: DbUtils.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/DbUtils.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- DbUtils.java 12 Mar 2003 01:54:25 -0000 1.15
+++ DbUtils.java 12 Mar 2003 22:29:05 -0000 1.16
@@ -81,7 +81,7 @@
- public static boolean execute(Connection connection, String query,Object[]
vals, ResultSetHandler rsh, Object userObject)
+ public static boolean execute(Connection connection, String query,Object[]
vals, ResultSetHandler rsh, ResultSetMetaDataHandler rsmdh, Object userObject)
throws SQLException {
PreparedStatement stmt = null;
@@ -97,6 +97,11 @@
do{
rs = stmt.getResultSet();
+ if(rs != null) {
+ if(rsmdh != null) {
+ rsmdh.handle(rs.getMetaData());
+ }
+ }
rsh.handle(rs,vals,userObject);
}while(stmt.getMoreResults());
@@ -123,12 +128,12 @@
}
public static Object executeQuery(Connection connection, String query,
- Object[] vals, ResultSetHandler rsh) throws SQLException{
- return executeQuery(connection,query, vals, rsh, null );
+ Object[] vals, ResultSetHandler rsh, ResultSetMetaDataHandler
rsmdh) throws SQLException{
+ return executeQuery(connection,query, vals, rsh, rsmdh, null );
}
public static Object executeQuery(Connection connection, String query,
- Object[] vals, ResultSetHandler rsh,Object userObject)
+ Object[] vals, ResultSetHandler rsh, ResultSetMetaDataHandler
rsmdh, Object userObject)
throws SQLException {
PreparedStatement stmt = null;
@@ -144,7 +149,16 @@
}catch(SQLException sqle){
rethrow( sqle, query, vals);
}
-
+ if(rs != null){
+ if(rsmdh != null) {
+ try{
+ rsmdh.handle(rs.getMetaData());
+ }
+ catch(SQLException sqle){
+ rethrow( sqle, query, vals);
+ }
+ }
+ }
return rsh.handle(rs,vals,userObject);
} finally {
@@ -209,6 +223,12 @@
}
+ public static List executeListQuery(Connection connection,
+ String query, Object[] vals, Object userObject )
+ throws SQLException {
+ return executeListQuery(connection, query, vals, null, userObject);
+ }
+
/**
* Creates a PreparedStatement using the String and Object array,
* executes this using the Connection, and returns the results
@@ -216,7 +236,7 @@
* Null values in the Object array will be passed to the driver.
*/
public static List executeListQuery(Connection connection,
- String query, Object[] vals, Object userObject )
+ String query, Object[] vals, ResultSetMetaDataHandler rsmdh, Object
userObject )
throws SQLException {
return (List)executeQuery(connection,query,vals,
@@ -227,13 +247,20 @@
}
}
-
+
+ , rsmdh
, userObject );
}
+ public static Iterator executeQuery(Connection connection, String query,
Object[] vals, ResultSetMetaDataHandler rsmdh )
+ throws SQLException {
+ return executeListQuery(connection, query, vals, rsmdh, null ).iterator();
+
+ }
+
/**
* Creates a PreparedStatement using the String and Object array,
* executes this using the Connection, and returns the results
@@ -242,7 +269,7 @@
*/
public static Iterator executeQuery(Connection connection, String query,
Object[] vals )
throws SQLException {
- return executeListQuery(connection, query, vals, null ).iterator();
+ return executeListQuery(connection, query, vals, null, null ).iterator();
}
1.1
jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/ResultSetMetaDataHandler.java
Index: ResultSetMetaDataHandler.java
===================================================================
/*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.dbutils;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
/**
*
* @author <a href="mailto:[EMAIL PROTECTED]">Steven Caswell</a>
* @version $Id: ResultSetMetaDataHandler.java,v 1.1 2003/03/12 22:29:05
stevencaswell Exp $
*/
public interface ResultSetMetaDataHandler
{
public void handle(ResultSetMetaData rsmd) throws SQLException;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]