You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by dg...@apache.org on 2004/03/15 06:31:40 UTC
cvs commit: jakarta-commons/dbutils/xdocs index.xml
dgraham 2004/03/14 21:31:40
Modified: dbutils project.xml
dbutils/src/java/org/apache/commons/dbutils QueryRunner.java
dbutils/xdocs index.xml
Log:
Added QueryRunner.batch() methods. PreparedStatement.executeBatch()
is @since 1.3 so bump DbUtils' minimum Java version.
PR: 27530
Patch Submitted by: Adkins Kendall
Revision Changes Path
1.11 +9 -0 jakarta-commons/dbutils/project.xml
Index: project.xml
===================================================================
RCS file: /home/cvs/jakarta-commons/dbutils/project.xml,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- project.xml 9 Mar 2004 03:05:51 -0000 1.10
+++ project.xml 15 Mar 2004 05:31:40 -0000 1.11
@@ -87,6 +87,15 @@
</roles>
</contributor>
<contributor>
+ <name>Adkins Kendall</name>
+ <id></id>
+ <email></email>
+ <organization></organization>
+ <roles>
+ <role>Java Developer</role>
+ </roles>
+ </contributor>
+ <contributor>
<name>Corby Page</name>
<id></id>
<email></email>
1.10 +68 -7 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.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- QueryRunner.java 28 Feb 2004 00:12:23 -0000 1.9
+++ QueryRunner.java 15 Mar 2004 05:31:40 -0000 1.10
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.commons.dbutils;
import java.sql.Connection;
@@ -55,6 +56,64 @@
super();
this.ds = ds;
}
+
+ /**
+ * Execute a batch of SQL INSERT, UPDATE, or DELETE queries.
+ *
+ * @param conn The Connection to use to run the query. The caller is
+ * responsible for closing this Connection.
+ * @param sql The SQL to execute.
+ * @param params An array of query replacement parameters. Each row in
+ * this array is one set of batch replacement values.
+ * @return The number of rows updated per statement.
+ * @throws SQLException
+ * @since DbUtils 1.1
+ */
+ public int[] batch(Connection conn, String sql, Object[][] params)
+ throws SQLException {
+
+ PreparedStatement stmt = null;
+ int[] rows = null;
+ try {
+ stmt = this.prepareStatement(conn, sql);
+
+ for (int i = 0; i < params.length; i++) {
+ this.fillStatement(stmt, params[i]);
+ stmt.addBatch();
+ }
+ rows = stmt.executeBatch();
+
+ } catch (SQLException e) {
+ this.rethrow(e, sql, params);
+ } finally {
+ DbUtils.close(stmt);
+ }
+
+ return rows;
+ }
+
+ /**
+ * Execute a batch of SQL INSERT, UPDATE, or DELETE queries. The
+ * <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 update will not be saved.
+ *
+ * @param sql The SQL to execute.
+ * @param params An array of query replacement parameters. Each row in
+ * this array is one set of batch replacement values.
+ * @return The number of rows updated per statement.
+ * @throws SQLException
+ * @since DbUtils 1.1
+ */
+ public int[] batch(String sql, Object[][] params) throws SQLException {
+ Connection conn = this.ds.getConnection();
+
+ try {
+ return this.batch(conn, sql, params);
+ } finally {
+ DbUtils.close(conn);
+ }
+ }
/**
* Fill the <code>PreparedStatement</code> replacement parameters with
@@ -109,7 +168,7 @@
/**
* Execute an SQL SELECT query with a single replacement parameter. The
- * caller is responsible for connection cleanup.
+ * caller is responsible for closing the connection.
*
* @param conn The connection to execute the query in.
* @param sql The query to execute.
@@ -130,7 +189,7 @@
/**
* Execute an SQL SELECT query with replacement parameters. The
- * caller is responsible for connection cleanup.
+ * caller is responsible for closing the connection.
*
* @param conn The connection to execute the query in.
* @param sql The query to execute.
@@ -174,7 +233,7 @@
/**
* Execute an SQL SELECT query without any replacement parameters. The
- * caller is responsible for connection cleanup.
+ * caller is responsible for closing the connection.
*
* @param conn The connection to execute the query in.
* @param sql The query to execute.
@@ -360,7 +419,9 @@
/**
* Executes the given INSERT, UPDATE, or DELETE SQL statement without
* any replacement parameters. The <code>Connection</code> is retrieved
- * from the <code>DataSource</code> set in the constructor.
+ * from the <code>DataSource</code> set in the constructor. This
+ * <code>Connection</code> must be in auto-commit mode or the update will
+ * not be saved.
*
* @param sql The SQL statement to execute.
* @throws SQLException
@@ -374,6 +435,8 @@
* Executes the given INSERT, UPDATE, or DELETE SQL statement with
* a single replacement parameter. The <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
+ * update will not be saved.
*
* @param sql The SQL statement to execute.
* @param param The replacement parameter.
@@ -397,17 +460,15 @@
* @return The number of rows updated.
*/
public int update(String sql, Object[] params) throws SQLException {
-
Connection conn = this.ds.getConnection();
try {
return this.update(conn, sql, params);
-
} finally {
DbUtils.close(conn);
}
}
-
+
/**
* Wrap the <code>ResultSet</code> in a decorator before processing it.
* This implementation returns the <code>ResultSet</code> it is given
1.7 +1 -1 jakarta-commons/dbutils/xdocs/index.xml
Index: index.xml
===================================================================
RCS file: /home/cvs/jakarta-commons/dbutils/xdocs/index.xml,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- index.xml 14 Mar 2004 23:18:28 -0000 1.6
+++ index.xml 15 Mar 2004 05:31:40 -0000 1.7
@@ -106,7 +106,7 @@
<section name="Interaction With Other Packages">
<p>DbUtils relies on these packages:</p>
<ul>
- <li>Java 1.2 (or later)</li>
+ <li>Java 1.3 (or later)</li>
<li>JDBC 2.0 (or later)</li>
</ul>
</section>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org