Dashboard > iBATIS DataMapper > Home > Type Handler Callbacks > DateTimeTypeHandlerCallback.java
Added by Isidoro Treviño, last edited by Isidoro Treviño on Jul 17, 2007  (view change)

iBATIS DataMapper version

This TypeHandlerCallback class was build and tested using iBATIS DataMapper (Java) and requires the Joda Time http://joda-time.sf.net jars

package com.yourpackage.utils.service;
    import java.sql.SQLException;
    import org.joda.time.DateTime;
    import org.joda.time.format.DateTimeFormat;
    import org.joda.time.format.DateTimeFormatter;
    import com.ibatis.sqlmap.client.extensions.ParameterSetter;
    import com.ibatis.sqlmap.client.extensions.ResultGetter;
    import com.ibatis.sqlmap.client.extensions.TypeHandlerCallback;
    public class DateTimeTypeHandlerCallback implements TypeHandlerCallback {
    public Object getResult(ResultGetter getter) throws SQLException {
    DateTime date = new DateTime(getter.getDate());
    return date;
    public void setParameter(ParameterSetter setter, Object obj)
    throws SQLException {
    DateTimeFormatter format = DateTimeFormat.forPattern("yyyy-MM-dd");
    DateTime date;
    if(obj instanceof DateTime){
    date = (DateTime) obj;
    throw new IllegalArgumentException("Illegal Date object");
    public Object valueOf(String string) {
    DateTimeFormatter format = DateTimeFormat.forPattern("yyyy-mm-dd");
    DateTime date = format.parseDateTime(string);
    return date;

Site running on a free Atlassian Confluence Open Source Project License granted to OSS. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.5 Build:#811 Jul 25, 2007) - Bug/feature request - Contact Administrators