commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Carl Hall (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (DBUTILS-115) Enhance BeanProcessor to support Joda DateTime
Date Mon, 20 Apr 2015 06:41:58 GMT

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

Carl Hall commented on DBUTILS-115:
-----------------------------------

I've committed DBUTILS-124 which should enable adding a handler for setting Joda DateTime
properties using a custom property handler.

{code}
public DateTimePropertyHandler implements PropertyHandler {
    public boolean match(Class<?> parameter, Object value) {
        if (value instanceof java.util.Timestamp) {  // use java.util.Date to get Date, Time,
and Timestamp
            final String targetType = parameter.getName();
            if ("org.joda.date.DateTime".equals(targetType)) {
                return true;
            }
        }
    }

    public Object apply(Class<?> parameter, Object value) {
        return DateTime.parse(((Date) value).getTime());
    }
}
{code}

> Enhance BeanProcessor to support Joda DateTime
> ----------------------------------------------
>
>                 Key: DBUTILS-115
>                 URL: https://issues.apache.org/jira/browse/DBUTILS-115
>             Project: Commons DbUtils
>          Issue Type: Improvement
>    Affects Versions: 1.5
>            Reporter: Bill Comer
>              Labels: features
>
> We use the popular org.joda.time.DateTime to map all our Date fields in our POJOs.
> Could this be added to BeanProcessor.callSetter(....)
> I have done this local change that appears to work for me.
>             if (value instanceof java.util.Date) {
>                 final String targetType = params[0].getName();
>                 if ("java.sql.Date".equals(targetType)) {
>                     value = new java.sql.Date(((java.util.Date) value).getTime());
>                 } else
>                 if ("java.sql.Time".equals(targetType)) {
>                     value = new java.sql.Time(((java.util.Date) value).getTime());
>                 } else
>                 if ("java.sql.Timestamp".equals(targetType)) {
>                     value = new java.sql.Timestamp(((java.util.Date) value).getTime());
>                 } else
>                 if ("org.joda.time.DateTime".equals(targetType)) {
>                     if (value instanceof java.sql.Timestamp) {                      
>                       value = new DateTime((java.sql.Timestamp)value);
>                     }
>                 }
>             }



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message