dgraham 2003/07/22 17:12:28
Modified: mapper/src/share/org/apache/commons/mapper/jdbc
JdbcHelper.java
Log:
Added executeUpdate() method that takes no replacement
parameters for executing things like DELETE FROM table_x.
Revision Changes Path
1.7 +76 -52
jakarta-commons-sandbox/mapper/src/share/org/apache/commons/mapper/jdbc/JdbcHelper.java
Index: JdbcHelper.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/mapper/src/share/org/apache/commons/mapper/jdbc/JdbcHelper.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- JdbcHelper.java 13 Jul 2003 05:54:55 -0000 1.6
+++ JdbcHelper.java 23 Jul 2003 00:12:28 -0000 1.7
@@ -81,8 +81,8 @@
public class JdbcHelper {
/**
- * An implementation of StatementPreparer that does nothing. Useful when there
- * are no replacement parameters to be set on the PreparedStatement.
+ * An implementation of StatementPreparer that does nothing. Useful when
+ * there are no replacement parameters to be set on the PreparedStatement.
*/
private static final StatementPreparer NULL_PREPARER = new StatementPreparer() {
public void prepareStatement(PreparedStatement stmt, Object obj)
@@ -107,6 +107,9 @@
}
};
+ /**
+ * The DataSource to use for queries.
+ */
protected DataSource ds = null;
/**
@@ -120,10 +123,11 @@
/**
* Executes the given INSERT, UPDATE, or DELETE SQL statement. The
- * statement is executed in it's own transaction that will be committed or
rolled
- * back depending on any SQLExceptions thrown.
+ * statement is executed in it's own transaction that will be committed or
+ * rolled back depending on any SQLExceptions thrown.
* @param sql The SQL statement to execute.
- * @param preparer Initializes the PreparedStatement's IN (ie. '?') parameters.
+ * @param preparer Initializes the PreparedStatement's IN (ie. '?')
+ * parameters.
* @param prepareObject An object to pass to the preparer to setup the
* PreparedStatement.
* @throws MapperException
@@ -165,8 +169,8 @@
/**
* Executes the given INSERT, UPDATE, or DELETE SQL statement. The
- * statement is executed in it's own transaction that will be committed or
rolled
- * back depending on any SQLExceptions thrown.
+ * statement is executed in it's own transaction that will be committed or
+ * rolled back depending on any SQLExceptions thrown.
* @param sql The SQL statement to execute.
* @param params An array of values to fill the sql '?' markers with.
* @throws MapperException
@@ -178,10 +182,10 @@
/**
* Executes the given INSERT, UPDATE, or DELETE SQL statement. The
- * statement is executed in it's own transaction that will be committed or
rolled
- * back depending on any SQLExceptions thrown. This is
- * useful for queries with only one replacement parameter and is the equivalent
of
- * calling executeUpdate(sql, new Object[] { param }).
+ * statement is executed in it's own transaction that will be committed or
+ * rolled back depending on any SQLExceptions thrown. This is
+ * useful for queries with only one replacement parameter and is the
+ * equivalent of calling executeUpdate(sql, new Object[] { param }).
* @param sql The SQL statement to execute.
* @param param An object to fill one sql '?' marker with.
* @throws MapperException
@@ -190,6 +194,19 @@
public int executeUpdate(String sql, Object param) throws MapperException {
return this.executeUpdate(sql, ARRAY_PREPARER, new Object[] { param });
}
+
+ /**
+ * Executes the given INSERT, UPDATE, or DELETE SQL statement. The
+ * statement is executed in it's own transaction that will be committed or
+ * rolled back depending on any SQLExceptions thrown. This is
+ * useful for queries without any replacement parameters.
+ * @param sql The SQL statement to execute.
+ * @throws MapperException
+ * @return The number of rows updated.
+ */
+ public int executeUpdate(String sql) throws MapperException {
+ return this.executeUpdate(sql, NULL_PREPARER, null);
+ }
/**
* Executes the given SELECT SQL query and returns a List of results.
@@ -197,8 +214,8 @@
* @param preparer Initializes the PreparedStatement's IN parameters.
* @param prepareObject An object to pass to the preparer to setup the
* PreparedStatement.
- * @param processor The processor used to create the result objects from the
- * ResultSet.
+ * @param processor The processor used to create the result objects from
+ * the ResultSet.
* @return A list of objects generated by the processor.
* @throws MapperException
*/
@@ -254,9 +271,10 @@
}
/**
- * Executes the given SELECT SQL query and returns a List of results. This is
- * useful for queries with only one replacement parameter and is the equivalent
of
- * calling executeQuery(sql, new Object[] { param }, factory).
+ * Executes the given SELECT SQL query and returns a List of results.
+ * This is useful for queries with only one replacement parameter and is
+ * the equivalent of calling
+ * <code>executeQuery(sql, new Object[] { param }, factory)</code>.
* @param sql The SQL statement to execute.
* @param param An object to fill one sql '?' marker with.
* @param processor The processor to generate objects with.
@@ -289,8 +307,8 @@
}
/**
- * Performs just like the other getField method except that this one gets its
own
- * Connection.
+ * Performs just like the other getField method except that this one
+ * gets its own Connection.
* @param query
* @param column
* @return The value of the selected field.
@@ -314,14 +332,14 @@
}
/**
- * Executes the query and returns the column's value from the first returned
row.
- * This is helpful when finding the last generated ID in a table but can be
used to
- * return any column value.
+ * Executes the query and returns the column's value from the first
+ * returned row. This is helpful when finding the last generated ID in
+ * a table but can be used to return any column value.
* @param query A valid SQL SELECT query.
* @param column The column whose value should be returned.
* @param conn A Connection to run the query on.
- * @throws SQLException if a database access error occurs or the given query
- * returned 0 rows.
+ * @throws SQLException if a database access error occurs or the given
+ * query returned 0 rows.
*/
public String getField(String query, String column, Connection conn)
throws SQLException {
@@ -365,17 +383,17 @@
}
/**
- * Convenience method to reset autoCommit on a connection to its previous value
- * while wrapping any SQLException in a MapperException.
+ * Convenience method to reset autoCommit on a connection to its previous
+ * value while wrapping any SQLException in a MapperException.
* We restore autoCommit after using the connection
* for a create, delete, update, or find because other code might be using
* the same DataSource object to get connections and might depend on the
- * autoCommit flag being set a certain way. We set it to false and then
restore
- * it when we're done with the connection.
+ * autoCommit flag being set a certain way. We set it to false and then
+ * restore it when we're done with the connection.
* @param autoCommit The autoCommit value to set on the Connection.
* @param conn The Connection to set autoCommit on.
- * @throws MapperException if an SQLException occurred setting the autoCommit
- * status.
+ * @throws MapperException if an SQLException occurred setting the
+ * autoCommit status.
*/
public void setAutoCommit(boolean autoCommit, Connection conn)
throws MapperException {
@@ -389,14 +407,16 @@
}
/**
- * Attempts to close the given connection wrapping any SQLExceptions that occur
- * in a MapperException. Typically, a mapper's methods throw MapperException
- * rather than SQLException so this simplifies Connection cleanup. Connection
- * objects should <strong>always</strong> be closed in
- * case the DataSource is performing Connection pooling so the Connection can
- * be returned to the pool.
- * @param conn The Connection to close. A null value for this argument is
legal.
- * @throws MapperException if an SQLException is thrown closing the Connection.
+ * Attempts to close the given connection wrapping any SQLExceptions that
+ * occur in a MapperException. Typically, a mapper's methods throw
+ * MapperException rather than SQLException so this simplifies Connection
+ * cleanup. Connection objects should <strong>always</strong> be closed in
+ * case the DataSource is performing Connection pooling so the Connection
+ * can be returned to the pool.
+ * @param conn The Connection to close. A null value for this argument
+ * is legal.
+ * @throws MapperException if an SQLException is thrown closing the
+ * Connection.
*/
public void closeConnection(Connection conn) throws MapperException {
try {
@@ -409,14 +429,16 @@
}
/**
- * Attempts to close the given Statement wrapping any SQLExceptions that occur
- * in a MapperException. Typically, a mapper's methods throw MapperException
- * rather than SQLException so this simplifies Statement cleanup. Statement
- * objects (especially PreparedStatements) should <strong>always</strong> be
- * closed in case the DataSource is performing Statement pooling so the
- * Statement can be returned to the pool.
- * @param stmt The Statment to close. A null value for this argument is legal.
- * @throws MapperException if an SQLException is thrown closing the Statement.
+ * Attempts to close the given Statement wrapping any SQLExceptions that
+ * occur in a MapperException. Typically, a mapper's methods throw
+ * MapperException rather than SQLException so this simplifies Statement
+ * cleanup. Statement objects (especially PreparedStatements) should
+ * <strong>always</strong> be closed in case the DataSource is performing
+ * Statement pooling so the Statement can be returned to the pool.
+ * @param stmt The Statment to close. A null value for this argument is
+ * legal.
+ * @throws MapperException if an SQLException is thrown closing the
+ * Statement.
*/
public void closeStatement(Statement stmt) throws MapperException {
try {
@@ -429,10 +451,12 @@
}
/**
- * Attempts to close the given ResultSet wrapping any SQLExceptions that occur
- * in a MapperException.
- * @param rs The ResultSet to close. A null value for this argument is legal.
- * @throws MapperException if an SQLException is thrown closing the ResultSet.
+ * Attempts to close the given ResultSet wrapping any SQLExceptions that
+ * occur in a MapperException.
+ * @param rs The ResultSet to close. A null value for this argument is
+ * legal.
+ * @throws MapperException if an SQLException is thrown closing the
+ * ResultSet.
*/
public void closeResultSet(ResultSet rs) throws MapperException {
try {
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]