[jira] Created: (DBUTILS-47) Add a StatementFiller to be able to provide a Bean for updates, instead of bean values.

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[jira] Created: (DBUTILS-47) Add a StatementFiller to be able to provide a Bean for updates, instead of bean values.

JIRA jira@apache.org
Add a StatementFiller to be able to provide a Bean for updates, instead of bean values.
---------------------------------------------------------------------------------------

                 Key: DBUTILS-47
                 URL: https://issues.apache.org/jira/browse/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 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).

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

Reply | Threaded
Open this post in threaded view
|

[jira] Closed: (DBUTILS-47) Add a StatementFiller to be able to provide a Bean for updates, instead of bean values.

JIRA jira@apache.org

     [ https://issues.apache.org/jira/browse/DBUTILS-47?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Yandell closed DBUTILS-47.
--------------------------------

    Resolution: Won't Fix

DBUTILS-29 has been applied and this is viewed as duplicated functionality.

> Add a StatementFiller to be able to provide a Bean for updates, instead of bean values.
> ---------------------------------------------------------------------------------------
>
>                 Key: DBUTILS-47
>                 URL: https://issues.apache.org/jira/browse/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 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).

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