ibatis-user-cs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chad Humphries <chad.humphr...@gmail.com>
Subject Re: .NET 2.0 and Generics
Date Wed, 25 Jan 2006 02:44:19 GMT
Ok,  the patch is large, so I've uploaded it to my site
(http://tiredidea.com/files/ibatis-generics.zip).

This file contains:
-New build of Castle.DynamicProxy for .NET v2.0
-New Solution/Csproj files for dotnet2
-New conditional compilation symbol: dotnet2 for dotnet2 projects to
wrap v2 code from 1.1
-Modifications to support the new methods listed below, with copies of
certain test cases using generics

What it doesn't contain:
-Modifications to the build scripts (nant) to support building via
nant.  I'm not really clear on the build script structure, but it has
hardcoded paths to nant tasks that I don't have on my machine at the
moment.

-100% testing for this feature.  The generic tests works in testing on
my machine with the latest nunit/testdriven built for .net 2.0.

These modifications add the following additional methods when working
with .NET 2.0 for generics:

- void ExecuteQueryForList<T>(IDalSession session, object
parameterObject, IList<T> resultObject);
-IList<T> ExecuteQueryForList<T>(IDalSession session, object
parameterObject, int skipResults, int maxResults);
-IList<T> ExecuteQueryForList<T>(IDalSession session, object parameterObject);
-public IList<T> QueryForList<T>(string statementName, object parameterObject)
-public IList<T> QueryForList<T>(string statementName, object
parameterObject, int skipResults, int maxResults)
-public void QueryForList<T>(string statementName, object
parameterObject, IList<T> resultObject)

-T ExecuteQueryForObject<T>(IDalSession session, object parameterObject);
-T ExecuteQueryForObject<T>(IDalSession session, object
parameterObject, T resultObject);
-public T QueryForObject<T>(string statementName, object parameterObject)
-public T QueryForObject<T>(string statementName, object
parameterObject, T instanceObject)

Which allows for usages like:

public House GetOneHouse(int houseID)
{
  return QueryForObject<House>("House.GetOneByID", houseID);
}

public List<House> GetHouses()
{
  return QueryForList<House>("House.GetMany", null);
}

Ideas?  Theorys?  Questions? Comments?  Hopefully I didn't drive off
into crazy land but I think this makes sense.

-Chad

On 1/24/06, Chad Humphries <chad.humphries@gmail.com> wrote:
> I've started work on the .net 2.0 portion of the datamapper.  I'll be
> posting my code/patch as soon as I'm able.
>
> -Chad
>
> On 1/20/06, Michael Schall <mike.schall@gmail.com> wrote:
> > I would agree.  I want generic support.  These should help you get by
> > till then...
> >
> > Public Function Load(Of T As New)( _
> >    ByVal queryName As String, _
> >    ByVal parameters As IDictionary(Of String, Object)) As T
> >
> >         Dim mapper As SqlMapper = DatabaseManager.Instance()
> >         Dim rv As T
> >
> >         rv = DirectCast(mapper.QueryForObject(queryName,
> > DirectCast(parameters, Object))
> >
> >         Return rv
> >
> > End Function
> >
> > Public Function Enumerate(Of T As New)( _
> >    ByVal queryName As String, _
> >    ByVal parameters As IDictionary(Of String, Object)) As IEnumerable(Of T)
> >
> >         Dim mapper As SqlMapper = DatabaseManager.Instance()
> >
> >         Dim collector As TypedEnumerateCollector(Of T) = New
> > TypedEnumerateCollector(Of T)
> >
> >         mapper.QueryWithRowDelegate(queryName, parameters, New
> > SqlMapper.RowDelegate(AddressOf collector.Collect))
> >
> >         Return collector.Collected()
> >
> > End Function
> >
> > Private Class TypedEnumerateCollector(Of T)
> >
> >         Private _list As IList(Of T)
> >
> >         Public Sub New()
> >                 _list = New List(Of T)
> >         End Sub
> >
> >         Public Sub Collect(ByVal rowObject As Object, ByVal parameterObject
> > As Object, ByVal junkList As IList)
> >                 _list.Add(DirectCast(rowObject, T))
> >         End Sub
> >
> >         Public Function Collected() As IEnumerable(Of T)
> >                 Return _list
> >         End Function
> >
> > End Class
> >
> > Public Function Map(Of Tk, Tv As New)( _
> >  ByVal queryName As String, _
> >  ByVal parameters As IDictionary(Of String, Object), _
> >  ByVal keySel As KeySelector(Of Tk, Tv)) As IDictionary(Of Tk, Tv)
> >
> >         Dim mapper As SqlMapper = DatabaseManager.Instance()
> >         Dim collector As TypedMapCollector(Of Tk, Tv) = New
> > TypedMapCollector(Of Tk, Tv)(keySel)
> >
> >         mapper.QueryWithRowDelegate(queryName, parameters, New
> > SqlMapper.RowDelegate(AddressOf collector.Collect))
> >
> >         Return collector.Collected()
> >
> > End Function
> >
> > Public Delegate Function KeySelector(Of Tk, Tv)(ByVal v As Tv) As Tk
> >
> > Private Class TypedMapCollector(Of Tk, Tv)
> >
> >         Private _map As IDictionary(Of Tk, Tv)
> >         Private _keySelector As KeySelector(Of Tk, Tv)
> >
> >         Public Sub New(ByVal keySel As KeySelector(Of Tk, Tv))
> >                 _map = New Dictionary(Of Tk, Tv)
> >                 _keySelector = keySel
> >         End Sub
> >
> >         Public Sub Collect(ByVal rowObject As Object, ByVal parameterObject
> > As Object, ByVal junkList As IList)
> >                 Dim v As Tv = DirectCast(rowObject, Tv)
> >                 Dim k As Tk = _keySelector(v)
> >                 _map.Add(k, v)
> >         End Sub
> >
> >         Public Function Collected() As IDictionary(Of Tk, Tv)
> >                 Return _map
> >         End Function
> >
> > End Class
> >
>

Mime
View raw message