ibatis-user-cs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ron Grabowski <rongrabow...@yahoo.com>
Subject Re: Custom DateTime type handler that overrides IBatisNet's DateTimeTypeHandler
Date Mon, 03 Oct 2005 14:22:03 GMT
I still haven't found a solution to this. If I'm working with a legacy
database that stores 'Y' for boolean true and 'N' for boolean false can
I have override IBatisNet.DataMapper.TypeHandlers.BooleanTypeHandler
with my own type handler so its used globally for all resultMaps and
parameterMaps?

--- Ron Grabowski <rongrabowski@yahoo.com> wrote:

> I want to implement a typeHandler for DateTime objects that overrides
> the default DateTimeTypeHandler. I've added this text to my
> sqlMap.config file:
> 
>  <typeHandlers>
>   <typeHandler
>    type="DateTime"
>    callback="Company.Project.DataMapper.MyDateTimeTypeHandler" />
>  </typeHandlers>
> 
> This is the implementation:
> 
> public class MyDateTimeTypeHandler : ITypeHandlerCallback
> {
>  public object ValueOf(string nullValue)
>  {
>   // ???
>   return Convert.ToDateTime(nullValue);
>  }
> 
>  public object GetResult(IResultGetter getter)
>  {
>   if (getter.Value.Equals(System.DBNull.Value))
>   {
>    return DateTime.MinValue;
>   }
>   else
>   {
>    return getter.Value;
>   }
>  }
> 
>  public void SetParameter(IParameterSetter setter, object parameter)
>  {
>   if (parameter.Equals(DateTime.MinValue))
>   {
>    setter.Value = System.DBNull.Value;
>   }
>   else
>   {
>    setter.Value = parameter;
>   }
>  }
> }
> 
> The MyDateTimeTypeHandler class is ignored if I don't specify a
> dbType
> attribute. If I do supply one:
> 
>  dbType="System.Data.OleDb.OleDbType"
> 
> I get a NullReferenceException on line 200 of TypeHanlderFactory.cs:
> 
> public void Register(Type type, string dbType, ITypeHandler handler) 
> {
>  HybridDictionary map = (HybridDictionary)_typeHandlerMap[type];
>  if (map == null) 
>  {
>   map = new HybridDictionary();
>   _typeHandlerMap.Add(type, map);
>  }
>  if (dbType==null)
>  {
>   map.Add(NULL, handler); // line 200
>  }
>  else
>  {
>   map.Add(dbType, handler);
>  }
> }
> 
> Yes, I've seen the TestCustomTypeHandler test case. That requires me
> to
> specify a typeHandler attribute on the result and parameter nodes:
> 
>  <result
>   property="Bool2" 
>   column="Other_String" 
>   typeHandler="OuiNonBool" />
> 
> I don't want to do that. I want MyDateTimeTypeHandler to replace the
> DateTimeTypeHandler in all cases automatically.
> 
> Ideas?
> 
> Thanks,
> Ron
> 


Mime
View raw message