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

Graylin Kim updated DBUTILS-113:
--------------------------------

    Attachment: bean_enums3.diff

bq. 1. Line 94 and 95 can be collapsed

Sure, I was just trying to conform to the nested conditional structure above 
it. I've attached a diff with this change.

bq. 2. You do not need reflection because DbUtils 1.6 is set to Java 1.6, you 
simply could cast params\[0\] to Enum and call the static valueOf method. Catch 
blocks for NoSuchMethodException and SecurityException would be obsolete.

This was my original intention but I could not figure out how to do it. 
Class<?> can't be cast to an enum so I have to create a new instance of the 
Class<Enum>:

{{((Class<Enum>)params\[0\]).newInstance()}}

The Enum class forces us to use the {{valueOf(Class<T>, String)}} signature. I 
can't figure out how you would turn Class<?> into a valid Class<T> for the 
valueOf method.

I wouldn't call myself a Java expert, perhaps you know of a different way?

> Add support for conversion of ResultSet strings to enums in the BeanProcessor
> -----------------------------------------------------------------------------
>
>                 Key: DBUTILS-113
>                 URL: https://issues.apache.org/jira/browse/DBUTILS-113
>             Project: Commons DbUtils
>          Issue Type: Improvement
>            Reporter: Graylin Kim
>            Priority: Minor
>              Labels: patch
>         Attachments: bean_enums.diff, bean_enums2.diff, bean_enums3.diff
>
>
> When using commons-dbutils I frequently use enum values with corresponding 
> enum in the database. In this situation, using the BeanListHandler produces 
> the following exception causing me to write a custom bean handler for enum 
> conversion.
> {quote}
> Cannot set status: incompatible types, cannot convert java.lang.String to 
> gov.nysenate.openleg.util.Storage$Status Query: SELECT * FROM changelog WHERE 
> 1=1 AND time >= ? AND time <= ? Parameters: [2013-07-24 00:00:00, 2013-07-26 
> 23:59:59]
> java.sql.SQLException: Cannot set status: incompatible types, cannot convert 
> java.lang.String to gov.nysenate.openleg.util.Storage$Status Query: SELECT * 
> FROM changelog WHERE 1=1 AND time >= ? AND time <= ? Parameters: [2013-07-24 
> 00:00:00, 2013-07-26 23:59:59]
>       at 
> org.apache.commons.dbutils.AbstractQueryRunner.rethrow(AbstractQueryRunner.java:363)
>       at org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:350)
>       at org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:288)
> {quote}
> It seems to me that commons-dbutils should be able to handle this conversion.



--
This message was sent by Atlassian JIRA
(v6.1#6144)

Reply via email to