You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-cs@ibatis.apache.org by Okku Touronen <ok...@stendahls.net> on 2006/04/20 22:31:03 UTC
Lazy loading and generics
Hello I searched the issue tracker and found
IBATISNET-105: Lazy load support for Strong typed collections and single
Items
I have a similar problem (I think) that lazy loading of a generic list
doesn't work.
It seems to me that the proxy that is generated is not correct. So I get a
casting exception.
The following code works, so the EmitPropertyAccessor.Set method should work
only if the proxy was correct.
ProxyGenerator gen = new ProxyGenerator();
object proxy = gen.CreateClassProxy(typeof(List<T>), new Interceptor());
IList<T> ilist = (IList<T>)proxy;
I can't see any code in the LazyLoadList.NewInstance that is creating a
proxy of such kind.
Another question: How do I signal that the "connection" is over do not lazy
load anything more, for example if I want to serialize an object.
Regards Okku Touronen
Exception:
Unable to cast object of type
'ProxyInterfaceCollectionsArrayList_IList_ISerializable' to type
'System.Collections.Generic.List`1[lejistest.ACL]'. at
MemberAccessorForlejistest.GroupaccessControlList.Set(Object , Object )
at
IBatisNet.Common.Utilities.Objects.Members.EmitPropertyAccessor.Set(Object
target, Object value) in
C:\dev\misc\Ibatis\IBatisNet.Common\Utilities\Objects\Members\EmitPropertyAc
cessor.cs:line 130
at
IBatisNet.DataMapper.MappedStatements.MappedStatement.SetObjectProperty(Requ
estScope request, ResultMap resultMap, ResultProperty mapping, Object&
target, IDataReader reader) in
C:\dev\misc\Ibatis\IBatisNet.DataMapper\MappedStatements\MappedStatement.cs:
line 1360
at
IBatisNet.DataMapper.MappedStatements.MappedStatement.ApplyResultMap(Request
Scope request, IDataReader reader, Object resultObject) in
C:\dev\misc\Ibatis\IBatisNet.DataMapper\MappedStatements\MappedStatement.cs:
line 264
at
IBatisNet.DataMapper.MappedStatements.MappedStatement.ExecuteQueryForList[T]
(IDalSession session, Object parameterObject, IList`1 resultObject, Boolean
forceLazyLoad) in
C:\dev\misc\Ibatis\IBatisNet.DataMapper\MappedStatements\MappedStatement.cs:
line 945
at IBatisNet.DataMapper.SqlMapper.QueryForList[T](String statementName,
Object parameterObject, IList`1 resultObject, Boolean forceLazyLoad) in
C:\dev\misc\Ibatis\IBatisNet.DataMapper\SqlMapper.cs:line 1150
at DataAccess.GroupDataAccess.GetAllGroups(SqlMapper sql, Boolean
forceLazyLoad) in
C:\dev\LejisTest\Test1\Test1\DataAccess\groupDataAccess.cs:line 34
at Test1.Form1.LoadGroups() in C:\dev\LejisTest\Test1\Test1\Form1.cs:line
81
RE: Lazy loading and generics
Posted by Okku Touronen <ok...@stendahls.net>.
First I have solved this by myself, but I really don't know if you
understand what I mean.
> You have to start the lazy loading by accessing an IList property as
"Count"
Yes I understand that. (That is what I tried to illustrate with the method
"Do_some_logic_wich_lazy_loades_some_of_the_lists" below)
But the question is if I don't want the lazy load to occur when I access a
property of the list.
Another example:
Let's say I have a class A with two lazy loaded lists L1 and L2.
I fetch an A object from the database and then loades the L1 list by
accessing some property in L1.
After that I decide that I want to print the content of A.
Like this:
foreach(object o in a.L1)
print(o.ToSting());
foreach(object o in a.L2)
print(o.ToSting());
Since L2 is lazy loaded it will load from the database and will be printed.
That could be what I wanted to do.
BUT in some cases I would like to not lazy load the L2 list, just let it be
empty and not be printed.
As I said I have solved this by modifying the SVN version.
Just added some checks to see if the sqlMap had a session started if not I
just create an empty arraylist.
So I signal that the lazy load should not occur if the session is not
started.
Regards Okku Touronen
_____
From: Gilles Bayon [mailto:ibatis.net@gmail.com]
Sent: den 25 april 2006 19:00
To: user-cs@ibatis.apache.org
Subject: Re: Lazy loading and generics
On 4/21/06, Okku Touronen <ok...@stendahls.net> wrote:
How do you tell Ibatis that you don't want to lazy load anything more.
You have to start the lazy loading by accessing an IList property as "Count"
For instance if you want send the objects through soap.
Example:
SqlMapper sqlMap = Mapper.Get();
List<ClassWithLazyLoadedList> list = GetListFromDB(sqlMap)
Do_some_logic_wich_lazy_loades_some_of_the_lists(sqlMap,list);
Signal_IBatis_to_not_lazy_load_anyting_more(sqlMap);
string serializedObjects = Serialize(list);
/Okku
_____
From: Gilles Bayon [mailto: ibatis.net@gmail.com]
Sent: den 20 april 2006 22:48
To: user-cs@ibatis.apache.org
Subject: Re: Lazy loading and generics
The code in SVN doesn't support lazy loading for generic list as it is not
finish.
I don't understand the 2nd question.
-Gilles
On 4/20/06, Okku Touronen < okku@stendahls.net <ma...@stendahls.net> >
wrote:
Hello I searched the issue tracker and found
IBATISNET-105: Lazy load support for Strong typed collections and single
Items
I have a similar problem (I think) that lazy loading of a generic list
doesn't work.
It seems to me that the proxy that is generated is not correct. So I get a
casting exception.
The following code works, so the EmitPropertyAccessor.Set method should work
only if the proxy was correct.
ProxyGenerator gen = new ProxyGenerator();
object proxy = gen.CreateClassProxy(typeof(List<T>), new Interceptor());
IList<T> ilist = (IList<T>)proxy;
I can't see any code in the LazyLoadList.NewInstance that is creating a
proxy of such kind.
Another question: How do I signal that the "connection" is over do not lazy
load anything more, for example if I want to serialize an object.
Regards Okku Touronen
Exception:
Unable to cast object of type
'ProxyInterfaceCollectionsArrayList_IList_ISerializable' to type
'System.Collections.Generic.List`1[lejistest.ACL ]'. at
MemberAccessorForlejistest.GroupaccessControlList.Set(Object , Object )
at
IBatisNet.Common.Utilities.Objects.Members.EmitPropertyAccessor.Set(Object
target, Object value) in
C:\dev\misc\Ibatis\IBatisNet.Common\Utilities\Objects\Members\EmitPropertyAc
cessor.cs:line 130
at
IBatisNet.DataMapper.MappedStatements.MappedStatement.SetObjectProperty(Requ
estScope request, ResultMap resultMap, ResultProperty mapping, Object&
target, IDataReader reader) in
C:\dev\misc\Ibatis\IBatisNet.DataMapper\MappedStatements\MappedStatement.cs:
line 1360
at
IBatisNet.DataMapper.MappedStatements.MappedStatement.ApplyResultMap(Request
Scope request, IDataReader reader, Object resultObject) in
C:\dev\misc\Ibatis\IBatisNet.DataMapper\MappedStatements\MappedStatement.cs:
line 264
at
IBatisNet.DataMapper.MappedStatements.MappedStatement.ExecuteQueryForList[T]
(IDalSession session, Object parameterObject, IList`1 resultObject, Boolean
forceLazyLoad) in
C:\dev\misc\Ibatis\IBatisNet.DataMapper\MappedStatements\MappedStatement.cs:
line 945
at IBatisNet.DataMapper.SqlMapper.QueryForList[T](String statementName,
Object parameterObject, IList`1 resultObject, Boolean forceLazyLoad) in
C:\dev\misc\Ibatis\IBatisNet.DataMapper\SqlMapper.cs:line 1150
at DataAccess.GroupDataAccess.GetAllGroups(SqlMapper sql, Boolean
forceLazyLoad) in
C:\dev\LejisTest\Test1\Test1\DataAccess\groupDataAccess.cs:line 34
at Test1.Form1.LoadGroups() in C:\dev\LejisTest\Test1\Test1\Form1.cs:line
81
Re: Lazy loading and generics
Posted by Gilles Bayon <ib...@gmail.com>.
On 4/21/06, Okku Touronen <ok...@stendahls.net> wrote:
>
> How do you tell Ibatis that you don't want to lazy load anything more.
>
You have to start the lazy loading by accessing an IList property as "Count"
>
> For instance if you want send the objects through soap.
>
>
>
> Example:
>
> SqlMapper sqlMap = Mapper.Get();
>
>
>
> List<ClassWithLazyLoadedList> list = GetListFromDB(sqlMap)
>
>
>
> Do_some_logic_wich_lazy_loades_some_of_the_lists(sqlMap,list);
>
>
>
> Signal_IBatis_to_not_lazy_load_anyting_more(sqlMap);
>
>
>
> string serializedObjects = Serialize(list);
>
>
>
>
>
> /Okku
>
>
> ------------------------------
>
> *From:* Gilles Bayon [mailto:ibatis.net@gmail.com]
> *Sent:* den 20 april 2006 22:48
> *To:* user-cs@ibatis.apache.org
> *Subject:* Re: Lazy loading and generics
>
>
>
> The code in SVN doesn't support lazy loading for generic list as it is not
> finish.
>
>
> I don't understand the 2nd question.
>
>
>
> -Gilles
>
>
> On 4/20/06, *Okku Touronen* <ok...@stendahls.net> wrote:
>
> Hello I searched the issue tracker and found
>
> IBATISNET-105: Lazy load support for Strong typed collections and single
> Items
>
>
>
> I have a similar problem (I think) that lazy loading of a generic list
> doesn't work.
>
>
>
> It seems to me that the proxy that is generated is not correct. So I get a
> casting exception.
>
> The following code works, so the EmitPropertyAccessor.Set method should
> work only if the proxy was correct.
>
>
>
> ProxyGenerator gen = new ProxyGenerator();
>
> object proxy = gen.CreateClassProxy(typeof(List<T>), new Interceptor());
>
> IList<T> ilist = (IList<T>)proxy;
>
>
>
> I can't see any code in the LazyLoadList.NewInstance that is creating a
> proxy of such kind.
>
>
>
> Another question: How do I signal that the "connection" is over do not
> lazy load anything more, for example if I want to serialize an object.
>
>
>
> Regards Okku Touronen
>
>
>
>
>
>
>
> Exception:
>
>
>
> Unable to cast object of type
> 'ProxyInterfaceCollectionsArrayList_IList_ISerializable' to type '
> System.Collections.Generic.List`1[lejistest.ACL ]'. at
> MemberAccessorForlejistest.GroupaccessControlList.Set(Object , Object )
>
> at IBatisNet.Common.Utilities.Objects.Members.EmitPropertyAccessor.Set(Object
> target, Object value) in
> C:\dev\misc\Ibatis\IBatisNet.Common\Utilities\Objects\Members\EmitPropertyAccessor.cs:line
> 130
>
> at
> IBatisNet.DataMapper.MappedStatements.MappedStatement.SetObjectProperty(RequestScope
> request, ResultMap resultMap, ResultProperty mapping, Object& target,
> IDataReader reader) in
> C:\dev\misc\Ibatis\IBatisNet.DataMapper\MappedStatements\MappedStatement.cs:line
> 1360
>
> at IBatisNet.DataMapper.MappedStatements.MappedStatement.ApplyResultMap(RequestScope
> request, IDataReader reader, Object resultObject) in
> C:\dev\misc\Ibatis\IBatisNet.DataMapper\MappedStatements\MappedStatement.cs:line
> 264
>
> at
> IBatisNet.DataMapper.MappedStatements.MappedStatement.ExecuteQueryForList[T](IDalSession
> session, Object parameterObject, IList`1 resultObject, Boolean
> forceLazyLoad) in
> C:\dev\misc\Ibatis\IBatisNet.DataMapper\MappedStatements\MappedStatement.cs:line
> 945
>
> at IBatisNet.DataMapper.SqlMapper.QueryForList[T](String statementName,
> Object parameterObject, IList`1 resultObject, Boolean forceLazyLoad) in
> C:\dev\misc\Ibatis\IBatisNet.DataMapper\SqlMapper.cs:line 1150
>
> at DataAccess.GroupDataAccess.GetAllGroups(SqlMapper sql, Boolean
> forceLazyLoad) in
> C:\dev\LejisTest\Test1\Test1\DataAccess\groupDataAccess.cs:line 34
>
> at Test1.Form1.LoadGroups() in
> C:\dev\LejisTest\Test1\Test1\Form1.cs:line 81
>
>
>
RE: Lazy loading and generics
Posted by Okku Touronen <ok...@stendahls.net>.
How do you tell Ibatis that you don't want to lazy load anything more.
For instance if you want send the objects through soap.
Example:
SqlMapper sqlMap = Mapper.Get();
List<ClassWithLazyLoadedList> list = GetListFromDB(sqlMap)
Do_some_logic_wich_lazy_loades_some_of_the_lists(sqlMap,list);
Signal_IBatis_to_not_lazy_load_anyting_more(sqlMap);
string serializedObjects = Serialize(list);
/Okku
_____
From: Gilles Bayon [mailto:ibatis.net@gmail.com]
Sent: den 20 april 2006 22:48
To: user-cs@ibatis.apache.org
Subject: Re: Lazy loading and generics
The code in SVN doesn't support lazy loading for generic list as it is not
finish.
I don't understand the 2nd question.
-Gilles
On 4/20/06, Okku Touronen <ok...@stendahls.net> wrote:
Hello I searched the issue tracker and found
IBATISNET-105: Lazy load support for Strong typed collections and single
Items
I have a similar problem (I think) that lazy loading of a generic list
doesn't work.
It seems to me that the proxy that is generated is not correct. So I get a
casting exception.
The following code works, so the EmitPropertyAccessor.Set method should work
only if the proxy was correct.
ProxyGenerator gen = new ProxyGenerator();
object proxy = gen.CreateClassProxy(typeof(List<T>), new Interceptor());
IList<T> ilist = (IList<T>)proxy;
I can't see any code in the LazyLoadList.NewInstance that is creating a
proxy of such kind.
Another question: How do I signal that the "connection" is over do not lazy
load anything more, for example if I want to serialize an object.
Regards Okku Touronen
Exception:
Unable to cast object of type
'ProxyInterfaceCollectionsArrayList_IList_ISerializable' to type
'System.Collections.Generic.List`1[lejistest.ACL ]'. at
MemberAccessorForlejistest.GroupaccessControlList.Set(Object , Object )
at
IBatisNet.Common.Utilities.Objects.Members.EmitPropertyAccessor.Set(Object
target, Object value) in
C:\dev\misc\Ibatis\IBatisNet.Common\Utilities\Objects\Members\EmitPropertyAc
cessor.cs:line 130
at
IBatisNet.DataMapper.MappedStatements.MappedStatement.SetObjectProperty(Requ
estScope request, ResultMap resultMap, ResultProperty mapping, Object&
target, IDataReader reader) in
C:\dev\misc\Ibatis\IBatisNet.DataMapper\MappedStatements\MappedStatement.cs:
line 1360
at
IBatisNet.DataMapper.MappedStatements.MappedStatement.ApplyResultMap(Request
Scope request, IDataReader reader, Object resultObject) in
C:\dev\misc\Ibatis\IBatisNet.DataMapper\MappedStatements\MappedStatement.cs:
line 264
at
IBatisNet.DataMapper.MappedStatements.MappedStatement.ExecuteQueryForList[T]
(IDalSession session, Object parameterObject, IList`1 resultObject, Boolean
forceLazyLoad) in
C:\dev\misc\Ibatis\IBatisNet.DataMapper\MappedStatements\MappedStatement.cs:
line 945
at IBatisNet.DataMapper.SqlMapper.QueryForList[T](String statementName,
Object parameterObject, IList`1 resultObject, Boolean forceLazyLoad) in
C:\dev\misc\Ibatis\IBatisNet.DataMapper\SqlMapper.cs:line 1150
at DataAccess.GroupDataAccess.GetAllGroups(SqlMapper sql, Boolean
forceLazyLoad) in
C:\dev\LejisTest\Test1\Test1\DataAccess\groupDataAccess.cs:line 34
at Test1.Form1.LoadGroups() in C:\dev\LejisTest\Test1\Test1\Form1.cs:line
81
Re: Lazy loading and generics
Posted by Gilles Bayon <ib...@gmail.com>.
The code in SVN doesn't support lazy loading for generic list as it is not
finish.
I don't understand the 2nd question.
-Gilles
On 4/20/06, Okku Touronen <ok...@stendahls.net> wrote:
>
> Hello I searched the issue tracker and found
>
> IBATISNET-105: Lazy load support for Strong typed collections and single
> Items
>
>
>
> I have a similar problem (I think) that lazy loading of a generic list
> doesn't work.
>
>
>
> It seems to me that the proxy that is generated is not correct. So I get a
> casting exception.
>
> The following code works, so the EmitPropertyAccessor.Set method should
> work only if the proxy was correct.
>
>
>
> ProxyGenerator gen = new ProxyGenerator();
>
> object proxy = gen.CreateClassProxy(typeof(List<T>), new Interceptor());
>
> IList<T> ilist = (IList<T>)proxy;
>
>
>
> I can't see any code in the LazyLoadList.NewInstance that is creating a
> proxy of such kind.
>
>
>
> Another question: How do I signal that the "connection" is over do not
> lazy load anything more, for example if I want to serialize an object.
>
>
>
> Regards Okku Touronen
>
>
>
>
>
>
>
> Exception:
>
>
>
> Unable to cast object of type
> 'ProxyInterfaceCollectionsArrayList_IList_ISerializable' to type '
> System.Collections.Generic.List`1[lejistest.ACL]'. at
> MemberAccessorForlejistest.GroupaccessControlList.Set(Object , Object )
>
> at IBatisNet.Common.Utilities.Objects.Members.EmitPropertyAccessor.Set(Object
> target, Object value) in
> C:\dev\misc\Ibatis\IBatisNet.Common\Utilities\Objects\Members\EmitPropertyAccessor.cs:line
> 130
>
> at
> IBatisNet.DataMapper.MappedStatements.MappedStatement.SetObjectProperty(RequestScope
> request, ResultMap resultMap, ResultProperty mapping, Object& target,
> IDataReader reader) in
> C:\dev\misc\Ibatis\IBatisNet.DataMapper\MappedStatements\MappedStatement.cs:line
> 1360
>
> at IBatisNet.DataMapper.MappedStatements.MappedStatement.ApplyResultMap(RequestScope
> request, IDataReader reader, Object resultObject) in
> C:\dev\misc\Ibatis\IBatisNet.DataMapper\MappedStatements\MappedStatement.cs:line
> 264
>
> at
> IBatisNet.DataMapper.MappedStatements.MappedStatement.ExecuteQueryForList[T](IDalSession
> session, Object parameterObject, IList`1 resultObject, Boolean
> forceLazyLoad) in
> C:\dev\misc\Ibatis\IBatisNet.DataMapper\MappedStatements\MappedStatement.cs:line
> 945
>
> at IBatisNet.DataMapper.SqlMapper.QueryForList[T](String statementName,
> Object parameterObject, IList`1 resultObject, Boolean forceLazyLoad) in
> C:\dev\misc\Ibatis\IBatisNet.DataMapper\SqlMapper.cs:line 1150
>
> at DataAccess.GroupDataAccess.GetAllGroups(SqlMapper sql, Boolean
> forceLazyLoad) in
> C:\dev\LejisTest\Test1\Test1\DataAccess\groupDataAccess.cs:line 34
>
> at Test1.Form1.LoadGroups() in
> C:\dev\LejisTest\Test1\Test1\Form1.cs:line 81
>