[jira] [Created] (DBUTILS-91) Enhance BasicRowProcessor to have row mapping easier to configure

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

[jira] [Created] (DBUTILS-91) Enhance BasicRowProcessor to have row mapping easier to configure

Gary D. Gregory (Jira)
Stevo Slavic created DBUTILS-91:
-----------------------------------

             Summary: Enhance BasicRowProcessor to have row mapping easier to configure
                 Key: DBUTILS-91
                 URL: https://issues.apache.org/jira/browse/DBUTILS-91
             Project: Commons DbUtils
          Issue Type: Improvement
    Affects Versions: 1.4
            Reporter: Stevo Slavic


{{BasicRowProcessor}} by default makes use of {{BeanProcessor}} for mapping result set row columns to bean property names. {{BeanProcessor}} uses bean property names, and performs case-insensitive matching of those names to column names.

Currently {{BasicRowProcessor}} can be configured with custom {{BeanProcessor}} extension to customize the row mapping, but it gets rather ugly.

It would be great if {{BeanProcessor}} was configurable with column name to bean property name strategy. Besides current strategy, DbUtils should also bundle strategy implementation configurable with a property name to column name (or other way around) map.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (DBUTILS-91) Enhance BasicRowProcessor to have row mapping easier to configure

Gary D. Gregory (Jira)

    [ https://issues.apache.org/jira/browse/DBUTILS-91?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13407882#comment-13407882 ]

Stevo Slavic commented on DBUTILS-91:
-------------------------------------

Here is sample code that I currently (commons-dbutils:commons-dbutils:1.4:jar) have to use to override column to property name mapping:

{code}
final Map<String, String> columnToPropertyOverrides = new HashMap<>();
columnToPropertyOverrides.put("foo", "bar");
ResultSetHandler<List<Acme>> rsh = new BeanListHandler<Acme>(Acme.class, new BasicRowProcessor(new BeanProcessor() {
        @Override
        protected int[] mapColumnsToProperties(ResultSetMetaData rsmd,
                        PropertyDescriptor[] props) throws SQLException {
                int cols = rsmd.getColumnCount();
                int[] columnToProperty = new int[cols + 1];
                Arrays.fill(columnToProperty, PROPERTY_NOT_FOUND);

                for (int col = 1; col <= cols; col++) {
                        String columnName = rsmd.getColumnLabel(col);
                        if (null == columnName || 0 == columnName.length()) {
                          columnName = rsmd.getColumnName(col);
                        }
                        for (int i = 0; i < props.length; i++) {

                                String propertyName = columnToPropertyOverrides.get(columnName);
                                if (propertyName == null) {
                                        propertyName = columnName;
                                }
                                if (propertyName.equalsIgnoreCase(props[i].getName())) {
                                        columnToProperty[col] = i;
                                        break;
                                }
                        }
                }

                return columnToProperty;
        }
}));
{code}
               

> Enhance BasicRowProcessor to have row mapping easier to configure
> -----------------------------------------------------------------
>
>                 Key: DBUTILS-91
>                 URL: https://issues.apache.org/jira/browse/DBUTILS-91
>             Project: Commons DbUtils
>          Issue Type: Improvement
>    Affects Versions: 1.4
>            Reporter: Stevo Slavic
>
> {{BasicRowProcessor}} by default makes use of {{BeanProcessor}} for mapping result set row columns to bean property names. {{BeanProcessor}} uses bean property names, and performs case-insensitive matching of those names to column names.
> Currently {{BasicRowProcessor}} can be configured with custom {{BeanProcessor}} extension to customize the row mapping, but it gets rather ugly.
> It would be great if {{BeanProcessor}} was configurable with column name to bean property name strategy. Besides current strategy, DbUtils should also bundle strategy implementation configurable with a property name to column name (or other way around) map.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Comment Edited] (DBUTILS-91) Enhance BasicRowProcessor to have row mapping easier to configure

Gary D. Gregory (Jira)
In reply to this post by Gary D. Gregory (Jira)

    [ https://issues.apache.org/jira/browse/DBUTILS-91?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13407882#comment-13407882 ]

Stevo Slavic edited comment on DBUTILS-91 at 7/6/12 11:08 AM:
--------------------------------------------------------------

Here is sample code that I currently (commons-dbutils:commons-dbutils:1.4:jar) have to use to override column to property name mapping:

{code}
final Map<String, String> columnToPropertyOverrides = new HashMap<>();
columnToPropertyOverrides.put("foo", "bar");
ResultSetHandler<List<Acme>> rsh = new BeanListHandler<Acme>(Acme.class, new BasicRowProcessor(new BeanProcessor() {
        @Override
        protected int[] mapColumnsToProperties(ResultSetMetaData rsmd,
                        PropertyDescriptor[] props) throws SQLException {
                int cols = rsmd.getColumnCount();
                int[] columnToProperty = new int[cols + 1];
                Arrays.fill(columnToProperty, PROPERTY_NOT_FOUND);

                for (int col = 1; col <= cols; col++) {
                        String columnName = rsmd.getColumnLabel(col);
                        if (null == columnName || 0 == columnName.length()) {
                          columnName = rsmd.getColumnName(col);
                        }
                        String propertyName = columnToPropertyOverrides.get(columnName);
                        if (propertyName == null) {
                                propertyName = columnName;
                        }
                        for (int i = 0; i < props.length; i++) {
                                if (propertyName.equalsIgnoreCase(props[i].getName())) {
                                        columnToProperty[col] = i;
                                        break;
                                }
                        }
                }

                return columnToProperty;
        }
}));
{code}
               
      was (Author: sslavic):
    Here is sample code that I currently (commons-dbutils:commons-dbutils:1.4:jar) have to use to override column to property name mapping:

{code}
final Map<String, String> columnToPropertyOverrides = new HashMap<>();
columnToPropertyOverrides.put("foo", "bar");
ResultSetHandler<List<Acme>> rsh = new BeanListHandler<Acme>(Acme.class, new BasicRowProcessor(new BeanProcessor() {
        @Override
        protected int[] mapColumnsToProperties(ResultSetMetaData rsmd,
                        PropertyDescriptor[] props) throws SQLException {
                int cols = rsmd.getColumnCount();
                int[] columnToProperty = new int[cols + 1];
                Arrays.fill(columnToProperty, PROPERTY_NOT_FOUND);

                for (int col = 1; col <= cols; col++) {
                        String columnName = rsmd.getColumnLabel(col);
                        if (null == columnName || 0 == columnName.length()) {
                          columnName = rsmd.getColumnName(col);
                        }
                        for (int i = 0; i < props.length; i++) {

                                String propertyName = columnToPropertyOverrides.get(columnName);
                                if (propertyName == null) {
                                        propertyName = columnName;
                                }
                                if (propertyName.equalsIgnoreCase(props[i].getName())) {
                                        columnToProperty[col] = i;
                                        break;
                                }
                        }
                }

                return columnToProperty;
        }
}));
{code}
                 

> Enhance BasicRowProcessor to have row mapping easier to configure
> -----------------------------------------------------------------
>
>                 Key: DBUTILS-91
>                 URL: https://issues.apache.org/jira/browse/DBUTILS-91
>             Project: Commons DbUtils
>          Issue Type: Improvement
>    Affects Versions: 1.4
>            Reporter: Stevo Slavic
>
> {{BasicRowProcessor}} by default makes use of {{BeanProcessor}} for mapping result set row columns to bean property names. {{BeanProcessor}} uses bean property names, and performs case-insensitive matching of those names to column names.
> Currently {{BasicRowProcessor}} can be configured with custom {{BeanProcessor}} extension to customize the row mapping, but it gets rather ugly.
> It would be great if {{BeanProcessor}} was configurable with column name to bean property name strategy. Besides current strategy, DbUtils should also bundle strategy implementation configurable with a property name to column name (or other way around) map.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Updated] (DBUTILS-91) Enhance BasicRowProcessor to have row mapping easier to configure

Gary D. Gregory (Jira)
In reply to this post by Gary D. Gregory (Jira)

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

Stevo Slavic updated DBUTILS-91:
--------------------------------

    Attachment: DBUTILS-91.patch

Here's a rather simple patch ( [^DBUTILS-91.patch] ) which makes overriding mapping defaults a bit cleaner.

{code}
final Map<String, String> columnToPropertyOverrides = new HashMap<>();
columnToPropertyOverrides.put("foo", "bar");
ResultSetHandler<List<Acme>> rsh = new BeanListHandler<Acme>(Acme.class, new BasicRowProcessor(new BeanProcessor(columnToPropertyOverrides)));
{code}
               

> Enhance BasicRowProcessor to have row mapping easier to configure
> -----------------------------------------------------------------
>
>                 Key: DBUTILS-91
>                 URL: https://issues.apache.org/jira/browse/DBUTILS-91
>             Project: Commons DbUtils
>          Issue Type: Improvement
>    Affects Versions: 1.4
>            Reporter: Stevo Slavic
>         Attachments: DBUTILS-91.patch
>
>
> {{BasicRowProcessor}} by default makes use of {{BeanProcessor}} for mapping result set row columns to bean property names. {{BeanProcessor}} uses bean property names, and performs case-insensitive matching of those names to column names.
> Currently {{BasicRowProcessor}} can be configured with custom {{BeanProcessor}} extension to customize the row mapping, but it gets rather ugly.
> It would be great if {{BeanProcessor}} was configurable with column name to bean property name strategy. Besides current strategy, DbUtils should also bundle strategy implementation configurable with a property name to column name (or other way around) map.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Resolved] (DBUTILS-91) Enhance BasicRowProcessor to have row mapping easier to configure

Gary D. Gregory (Jira)
In reply to this post by Gary D. Gregory (Jira)

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

Simone Tripodi resolved DBUTILS-91.
-----------------------------------

       Resolution: Fixed
    Fix Version/s: 1.5
         Assignee: Simone Tripodi

Patch applied, see r1358253, thanks for contributing.

Please, for future patches, remind the following:

 * respect the original file format - no tabs;
 * javadoc was not complete (the new constructor didn't have the argument documented);
 * when adding new methods/constructors, add the {{@since}} tag

thanks
               

> Enhance BasicRowProcessor to have row mapping easier to configure
> -----------------------------------------------------------------
>
>                 Key: DBUTILS-91
>                 URL: https://issues.apache.org/jira/browse/DBUTILS-91
>             Project: Commons DbUtils
>          Issue Type: Improvement
>    Affects Versions: 1.4
>            Reporter: Stevo Slavic
>            Assignee: Simone Tripodi
>             Fix For: 1.5
>
>         Attachments: DBUTILS-91.patch
>
>
> {{BasicRowProcessor}} by default makes use of {{BeanProcessor}} for mapping result set row columns to bean property names. {{BeanProcessor}} uses bean property names, and performs case-insensitive matching of those names to column names.
> Currently {{BasicRowProcessor}} can be configured with custom {{BeanProcessor}} extension to customize the row mapping, but it gets rather ugly.
> It would be great if {{BeanProcessor}} was configurable with column name to bean property name strategy. Besides current strategy, DbUtils should also bundle strategy implementation configurable with a property name to column name (or other way around) map.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Comment Edited] (DBUTILS-91) Enhance BasicRowProcessor to have row mapping easier to configure

Gary D. Gregory (Jira)
In reply to this post by Gary D. Gregory (Jira)

    [ https://issues.apache.org/jira/browse/DBUTILS-91?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13408051#comment-13408051 ]

Simone Tripodi edited comment on DBUTILS-91 at 7/6/12 3:10 PM:
---------------------------------------------------------------

Patch applied, see r1358253, thanks for contributing.

Please, for future patches, remind the following:

 * respect the original file format - no tabs;
 * javadoc was not complete (the new constructor didn't have the argument documented);
 * when adding new methods/constructors, add the {{@since}} tag;
 * the constructor didn't shield the class from potential {{null}} maps, which could have caused NPEs at runtime.

thanks
               
      was (Author: simone.tripodi):
    Patch applied, see r1358253, thanks for contributing.

Please, for future patches, remind the following:

 * respect the original file format - no tabs;
 * javadoc was not complete (the new constructor didn't have the argument documented);
 * when adding new methods/constructors, add the {{@since}} tag

thanks
                 

> Enhance BasicRowProcessor to have row mapping easier to configure
> -----------------------------------------------------------------
>
>                 Key: DBUTILS-91
>                 URL: https://issues.apache.org/jira/browse/DBUTILS-91
>             Project: Commons DbUtils
>          Issue Type: Improvement
>    Affects Versions: 1.4
>            Reporter: Stevo Slavic
>            Assignee: Simone Tripodi
>             Fix For: 1.5
>
>         Attachments: DBUTILS-91.patch
>
>
> {{BasicRowProcessor}} by default makes use of {{BeanProcessor}} for mapping result set row columns to bean property names. {{BeanProcessor}} uses bean property names, and performs case-insensitive matching of those names to column names.
> Currently {{BasicRowProcessor}} can be configured with custom {{BeanProcessor}} extension to customize the row mapping, but it gets rather ugly.
> It would be great if {{BeanProcessor}} was configurable with column name to bean property name strategy. Besides current strategy, DbUtils should also bundle strategy implementation configurable with a property name to column name (or other way around) map.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Closed] (DBUTILS-91) Enhance BasicRowProcessor to have row mapping easier to configure

Gary D. Gregory (Jira)
In reply to this post by Gary D. Gregory (Jira)

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

Simone Tripodi closed DBUTILS-91.
---------------------------------


1.5-RC released
               

> Enhance BasicRowProcessor to have row mapping easier to configure
> -----------------------------------------------------------------
>
>                 Key: DBUTILS-91
>                 URL: https://issues.apache.org/jira/browse/DBUTILS-91
>             Project: Commons DbUtils
>          Issue Type: Improvement
>    Affects Versions: 1.4
>            Reporter: Stevo Slavic
>            Assignee: Simone Tripodi
>             Fix For: 1.5
>
>         Attachments: DBUTILS-91.patch
>
>
> {{BasicRowProcessor}} by default makes use of {{BeanProcessor}} for mapping result set row columns to bean property names. {{BeanProcessor}} uses bean property names, and performs case-insensitive matching of those names to column names.
> Currently {{BasicRowProcessor}} can be configured with custom {{BeanProcessor}} extension to customize the row mapping, but it gets rather ugly.
> It would be great if {{BeanProcessor}} was configurable with column name to bean property name strategy. Besides current strategy, DbUtils should also bundle strategy implementation configurable with a property name to column name (or other way around) map.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira