ibatis-user-cs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alexandre Grenier" <Alexandre.Gren...@markettools.com>
Subject RE: Problem with Generic IList as return type.
Date Thu, 31 Aug 2006 17:37:17 GMT

You stated:

"the problem is my BaseSQLMapDao ... this class does not know which
custom object's list it will return ..."

You must then refactor your BaseSqlMapDao to give it knowledge of the
type.

class BaseSqlMapDao<T>
{
}

class EmployeeSqlMapDao : BaseSqlMapDao<Employee>
{
}

Then you can then refactor BaseSqlMapDao.ExecuteQueryForList as IList<T>
ExecuteQueryForList which in turn calls QueryForList<T>.

You can further refactor and eliminate the inheritance structure in
favor of a generic SqlMapDao. From there you can easily implement the
Repository pattern. This will prevent the concept of data access and sql
from seeping into higher layers.

Write unit tests for what you'd like the calls to look like in the
application layer before you write the code. Then the code will be very
obvious to write.

Alex


-----Original Message-----
From: Alexandre Grenier [mailto:Alexandre.Grenier@markettools.com] 
Sent: Wednesday, August 30, 2006 12:09 PM
To: user-cs@ibatis.apache.org
Subject: RE: Problem with Generic IList as return type.


Make BaseSQLMapDao generic.

-----Original Message-----
From: Nikhil Vaghela [mailto:nikhil.vaghela@in.v2solutions.com] 
Sent: Monday, August 28, 2006 9:13 PM
To: user-cs@ibatis.apache.org
Subject: RE: Problem with Generic IList as return type.

Hi You are right I can use ExecuteQueryForList<Employee> but the problem
is my BaseSQLMapDao which is a wrapper class from where I am firing
sqlMapper's functions like executeQueryForList , now this class does not
know which custom object's list it will return because that is based on
the parameters I passed to the functions that are statementname and
parameterobject.

One way is as I earlier said is I have my return type as IList<object> ,
object being the base class of all class but in that case i will endup
casting object list to my custom class object's list which is even
worst...

:-? Any help ?

Thanks,
Nikhil

-----Original Message-----
From: Arjen Smits [mailto:arjen@ProPlanet.nl] 
Sent: Monday, August 28, 2006 7:14 PM
To: user-cs@ibatis.apache.org
Subject: RE: Problem with Generic IList as return type.

If u use the latest release of iBatis data Mapper (1.5.1).
Then u can use the generics variant of QueryForList.
e.g

instead of 
> return ExecuteQueryForList("GetEmployeesForDepartment",DepartmentID);


U can do:

> return ExecuteQueryForList<Employee>("GetEmployeesForDepartment",
> DepartmentID);   

That way iBatis already returned an strong typed list for u ;).

Hope this helps,

- Arjen

-----Oorspronkelijk bericht-----
Van: Matt Grande [mailto:matt.grande@fluidmedia.com] 
Verzonden: maandag 28 augustus 2006 15:39
Aan: user-cs@ibatis.apache.org
Onderwerp: Re: Problem with Generic IList as return type.

Hi Nikhil,

I played around generics a couple weeks ago and, as far as I can tell,
there's no way to do what you're asking.

The only way to do it is to loop through each list item, and assign it
to the new (generic) list.

Sorry I couldn't be more helpful,

- Matt.

On Mon, 2006-28-08 at 10:26 +0530, Nikhil Vaghela wrote:
> Hi,
> 
>  
> 
> Problem overview
> 
> I am going to use iBatis.Net latest version which supports .NET 2.0.
> 
>  
> 
> I have a wrapper class as given in the old example NPetShop that is
> BaseSQLMapDao in my Persistance layer which is having methods like
> "ExecuteQueryForList" which actually calls sqlMapper's QueryForList
> method of iBatisNet.DataMapper
> 
> Now .NET 2.0 supports generic IList and iBatis also supports this
> feature.
> 
>  
> 
> Actual problem
> 
>  
> 
> I will be calling ExecuteQueryForList method from my BuisnessObject's
> sqlMapDao say for example "EmployeeSqlMapDao.cs" or
> "DepartmentSqlMapDao.cs" in my persistence layer.
> 
>  
> 
> Now the problem is if I use genericsList my BaseSqlMapDao doest not
> know which type of IList it is returning !!!!
> 
> e.g
> 
> publicIList GetEmployeeListForDepartment(string DepartmentID)
> 
> {
> 
> return ExecuteQueryForList("GetEmployeesForDepartment",
> DepartmentID);   
> 
> //above given is a method of BaseSqlMapDao class
> 
> }
> 
>  
> 
> this works fine 
> 
> but if I use generic IList like as follows
> 
>  
> 
> publicIList<Employee> GetEmployeeListForDepartment(string
> DepartmentID)
> 
> {
> 
> return ExecuteQueryForList("GetEmployeesForDepartment",
> DepartmentID);   
> 
> }
> 
> Now what will i be having as return type in this case for
> ExecuteQueryForList as that method does not know which type of Objects
> are stored in the Ilist!!!! And if I make its return type
> IList<Object> i will have to cast it each and every item in
> IList<Object> to my custome object's Ilist<MyCustomObject> which I
> don't want as its not good method 
> 
>  
> 
> So how can I solve the problem ???? I hope I could describe my
> question properly.
> 
>  
> 
> Any help will be greatly appreciated.
> 
> Thanks.
> 
> Nikhil.
> 
>  
> 
>  
> 
> 




Mime
View raw message