Uploaded image for project: 'Commons DbUtils'
  1. Commons DbUtils
  2. DBUTILS-47

Add a StatementFiller to be able to provide a Bean for updates, instead of bean values.

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Minor
    • Resolution: Won't Fix
    • 1.1
    • None
    • None

    Description

      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 database.

      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

      { close(statement); }

      }

      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).

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              ogregoire Olivier Grégoire
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: