You shouldn't have to modify IBatisNet's source code directly. The
version in SVN should allow these values to be set via the config file.
If you're using an ITypeHandlerCallback, it gets converted into an
ITypeHandler automatically:

 // TypeHandlerDeserializer.cs
 if (impl is ITypeHandlerCallback)
 {
  typeHandler = new CustomTypeHandler((ITypeHandlerCallback) impl);
 } 
 else if (impl is ITypeHandler) 
 {
  typeHandler = (ITypeHandler) impl;
 }

Are you able to test that this works correctly with the SVN build?

 <typeHandlers>
   <typeHandler 
    type="Int32?" 
    callback="NullableInt32TypeHandler" />
 </typeHandlers>

--- Okku Touronen <[EMAIL PROTECTED]> wrote:

> Thanks for the answers.
> 
> I have got things to work by implementing typeHandlers and
> registering them
> in typeHandlerFactory ctor like this:
> 
> ...
>       handler = new NullableInt32TypeHandler();
>       this.Register(typeof(Int32?), handler);
> ...
> 
> I had done this before, but I had not implemented the setParameter
> method
> correctly. I know this is a hack, but it works for now. 
> 
> So for now I don't need any custom TypeHandler callbacks, all my
> nullable
> types works by default which is nice.
> 
> I haven't tried the <typeHandler> syntax, but I suspect there will be
> some
> problems with the type names for generics.
> 
> I could paste my type handlers to the wiki, but it dosen't help those
> how
> run the binary version. I really would like some way to add those
> type
> handlers without modifying the source. Then I could create a package
> with
> source and a class library.
> 
> /Okku
> 
> 
> -----Original Message-----
> From: Ron Grabowski [mailto:[EMAIL PROTECTED] 
> Sent: den 18 oktober 2005 20:15
> To: user-cs@ibatis.apache.org
> Subject: Re: nullable types when querying the db
> 
> Thanks to some nagging on my part :-)
> 
> 
> http://www.mail-archive.com/user-cs%40ibatis.apache.org/msg00390.html
> 
> http://www.mail-archive.com/user-cs%40ibatis.apache.org/msg00405.html
>  http://issues.apache.org/jira/browse/IBATISNET-120
> 
> there is code in SVN allows for overriding the global typeHandlers.
> For
> example this code:
> 
>  <typeHandlers>
>   <typeHandler 
>    type="DateTime" 
>    callback="NullDateTimeTypeHandlerCallback" />
>  </typeHandlers>
> 
> automatically converts all DateTime objects with a value of
> DateTime.MinValue to DBNull.Value before sending them to the
> database.
> Likewise it ensures that all DBNull.Value values returned from the
> database get converted into DateTime.MinValue. When you use that
> syntax, you don't need to use parameterMaps and inline type handlers.
> 
> This is my implementation:
> 
>  public class NullDateTimeTypeHandlerCallback : ITypeHandlerCallback
>  {
>   public object ValueOf(string nullValue)
>   {
>    return 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;
>    }
>   }
>  }
> 
> I'm sure other people would enjoy seeing your .Net 2.0 nullable type
> handlers. You can't attach .zip files to the list but you could write
> up a simple article in the Wiki:
> 
>  http://opensource2.atlassian.com/confluence/oss/display/IBATIS/Home
> 
> Instead of having to re-specify each type handler for .NET 2.0
> nullable
> types, perhaps we could allow the type handler factory to be set:
> 
>  <!-- this doesn't exist yet... -->
>  <typeHandlers typeHandlerFactory="NullableTypeHandlerFactory" />
> 
> That would be equivalant to:
> 
>  <!-- this doesn't exist yet... -->
>  <typeHandlers>
>   <typeHandler 
>    type="DateTime" 
>    callback="NullableDateTimeTypeHandlerCallback" />
>   <typeHandler 
>    type="Int32" 
>    callback="NullableInt32TypeHandlerCallback" />  
>   ...
>  </typeHandlers>
> 
> --- Okku Touronen <[EMAIL PROTECTED]> wrote:
> 
> > I have a hard time with the new nullable types in .Net 2.0 when
> > querying the
> > db. (Yes I know IBatis is designed for 1.1)
> > 
> >  
> > 
> > I have got most things to work by using custom type handlers. To
> use
> > the
> > custom typehandlers I have to write a parameterMap and use the
> > typeHandler
> > attribute.
> > 
> >  
> > 
> > But sometimes I don't want to mess with parameter maps, for
> instance
> > when I
> > have dynamic sql.
> > 
> >  
> > 
> > For example if I have a nullable int (System.Nullable<Int32>)
> > property in a
> > parameterClass object,  I would like some way to tell the parameter
> > object
> > (System.Data.SqlClient.SqlParameter) that the "type=int" and
> > "IsNullable=true".
> > 
> >  
> > 
> > Is there a way? Or is this something I have to implement myself?
> > Where
> > should I start then?
> > 
> >  
> > 
> > Regards Okku Touronen
> > 
> > 
> 
> 
> 
> 
> 

Reply via email to