commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Olivier Grégoire (JIRA) <>
Subject [jira] Created: (DBUTILS-47) Add a StatementFiller to be able to provide a Bean for updates, instead of bean values.
Date Mon, 01 Dec 2008 21:41:44 GMT
Add a StatementFiller to be able to provide a Bean for updates, instead of bean values.

                 Key: DBUTILS-47
             Project: Commons DbUtils
          Issue Type: New Feature
    Affects Versions: 1.1
            Reporter: Olivier Grégoire
            Priority: Minor
             Fix For: 1.2

When using the QueryRunner, in conjunction with the ResultSetHandler interface, we got awesome
results. Everything seems to be easier... except when it comes to update an object to the

To solve this, what I request is adding a new interface that allows to easily fill a statement
with a bean, instead of a list of values (Object).

The interface should be something like this:

public interface StatementFiller {
  public void fillStatement (Statement stmt, Object bean) throws SQLException;

and can be called in an update() like this:

	public int update(Connection connection, String sql, StatementFiller filler, Object bean)
	        throws SQLException {
		PreparedStatement statement = null;
		try {
			statement = this.prepareStatement(connection, sql);
			filler.fillStatement(statement, bean);
			return statement.executeUpdate();
		} catch (SQLException e) {
			throw this.nestException(e, sql, bean);
		} finally {

What is clearly the advantage of this? Simply that we can use only one QueryRunner and any
amount of statement fillers, just like there exist a lot of ResultSetHandler. There is no
more need to override the QueryRunner's statementFiller.

To keep backward compatibility, QueryRunner may implement that interface and be provided as
the default Filler, so the current behavior is not lost.

(Sorry for not showing the actual sources of DButils: I don't have them right here, I used
my tweaked version instead).

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message