You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by zeppelin <sh...@gmail.com> on 2008/09/04 16:41:52 UTC

using java SortedSet instead of List for the resultMap

I have seen a similar question on this forum but it's not answered.

My scenario :
* I'd like to use the iBATIS cache. It's working fine.
* My requirement is to use TreeSet cos I specifically want to use the
subset(...) method.

It appears there's just no way in iBATIS to return a Set instead of a List.
I can't understand why this feature is absent.

Using the present approach, I have to pass the list to the TreeSet and then
use it. This has to be done for ever user session that wants to access the
cached entity.

Is there any work around ? Is this supported in the spring framework ? I'm
using org.springframework.orm.ibatis.support.SqlMapClientDaoSupport .

regards

Zeppelin
-- 
View this message in context: http://www.nabble.com/using-java-SortedSet-instead-of-List-for-the-resultMap-tp19310126p19310126.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: using java SortedSet instead of List for the resultMap

Posted by Clinton Begin <cl...@gmail.com>.
Yes, 1 array = 1 object in the cache when using queryForList, as does 1
instance if you were to load one object with queryForObject.

Think of size as "how many queries to cache", rather than how many objects.

Clinton

On Thu, Sep 4, 2008 at 3:56 PM, zeppelin <sh...@gmail.com> wrote:

>
> Right, web tier caching would be best. I just wanted to know if my
> understanding of the 'size' attribute was correct. Is it ?
> --
> View this message in context:
> http://www.nabble.com/using-java-SortedSet-instead-of-List-for-the-resultMap-tp19310126p19320827.html
> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>
>

Re: using java SortedSet instead of List for the resultMap

Posted by zeppelin <sh...@gmail.com>.
Right, web tier caching would be best. I just wanted to know if my
understanding of the 'size' attribute was correct. Is it ? 
-- 
View this message in context: http://www.nabble.com/using-java-SortedSet-instead-of-List-for-the-resultMap-tp19310126p19320827.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: using java SortedSet instead of List for the resultMap

Posted by Clinton Begin <cl...@gmail.com>.
Don't set the cache to 1, that would be silly. :-)

Don't try to be too clever about it.  Just configure it simply and let it
work the way it works.

If you're trying to achieve some ultimate level of performance, then your
best bet is to cache outside of your persistence framework into something
like memcached or Coherence using your own business rules.  And of course
caching at the web tier is the biggest bang for your buck anyway.

Clinton

On Thu, Sep 4, 2008 at 2:45 PM, zeppelin <sh...@gmail.com> wrote:

>
> ' In a nutshell, cache lists, don't cache individual objects...' -  a
> little
> confusing
>
> If I'm ONLY caching a list, the size I need is only 1. Right ?
>        <cacheModel id="lruCache" type="LRU">
>                <flushInterval hours="24"/>
>                <property name="size" value="1" />
>        </cacheModel>
>
> If I decide to cache another object (POJO) and use the same cacheModel id
> (lruCache), I would need to change the size ( size="2" ) and the LRU
> algorithm will take care of expelling either of the two objects (POJO and
> list). Is this correct ?
>
> Sorry if all this has been answered before. I read the pdf a while back and
> still have some questions on caching.
> --
> View this message in context:
> http://www.nabble.com/using-java-SortedSet-instead-of-List-for-the-resultMap-tp19310126p19319593.html
> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>
>

Re: using java SortedSet instead of List for the resultMap

Posted by zeppelin <sh...@gmail.com>.
' In a nutshell, cache lists, don't cache individual objects...' -  a little
confusing

If I'm ONLY caching a list, the size I need is only 1. Right ?
	<cacheModel id="lruCache" type="LRU">
		<flushInterval hours="24"/>
		<property name="size" value="1" />
	</cacheModel>

If I decide to cache another object (POJO) and use the same cacheModel id
(lruCache), I would need to change the size ( size="2" ) and the LRU
algorithm will take care of expelling either of the two objects (POJO and
list). Is this correct ?

Sorry if all this has been answered before. I read the pdf a while back and
still have some questions on caching.
-- 
View this message in context: http://www.nabble.com/using-java-SortedSet-instead-of-List-for-the-resultMap-tp19310126p19319593.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: using java SortedSet instead of List for the resultMap

Posted by Clinton Begin <cl...@gmail.com>.
1.  Right.

2.  iBATIS caching can be globally distributed, at the app level, or at the
session level.   It's just really hard to configure!   :-)

Here's a simple breakdown

For a local/session scoped read/write cache, use: serializable=false,
readOnly=false
For a shared read-only cache, use: serializable=false, readOnly=true
For a shared read/write cache, use: serializable=true, readOnly=false

In this context, read/write refers to whether you expect anyone to actually
modify the cached instance of the object... thus tainting them if you
weren't careful to clone them.

I usually suggest using read-only caches and specifically retrieving
non-cached instances for updates.  In a nutshell, cache lists, don't cache
individual objects, flush on update.

For globally distributed caches, use OSCache or your own adapter for
EHCache, JBossCache or Coherence and depending on their implementation, the
rules above may change.

Clinton

On Thu, Sep 4, 2008 at 9:37 AM, zeppelin <sh...@gmail.com> wrote:
>
> Thanks for that. I had previously read about RowHandler. Tell me if these
are
> correct :
>
> 1. Using the RowHandler, I would have to handle the cache myself and not
> rely on iBATIS. Therefore, the 'cacheModel' attribute will be ignored. But
> what I really wanted to use was the flushing mechanism.
>
> 2. Technically the caching in iBATIS is at application level. It is
> described to be at session level since we can chage the way a user session
> received an object -  a cloned object or a reference to the same object.
>
> Just wanted to cofirm these. Also, it's a little strange that stored proc
> out params cannot be cached.
> Thanks again.
> Zeppelin
>
>
> Clinton Begin wrote:
> >
> > You can pass in a RowHandler and have the results collect in whatever
sort
> > of collection you like.  The default implementation itself is a
> > rowhandler,
> > something (not exactly) like this:
> >
> > public class ListRowHandler implements RowHandler {
> >   private List list = new ArrayList();
> >
> >   public void handleRow(Object valueObject) {
> >     list.add(valueObject);
> >   }
> >
> >   public List getList() {
> >     return list;
> >   }
> > }
> >
> > Clinton
> >
> > On Thu, Sep 4, 2008 at 8:41 AM, zeppelin <sh...@gmail.com> wrote:
> >
> >>
> >> I have seen a similar question on this forum but it's not answered.
> >>
> >> My scenario :
> >> * I'd like to use the iBATIS cache. It's working fine.
> >> * My requirement is to use TreeSet cos I specifically want to use the
> >> subset(...) method.
> >>
> >> It appears there's just no way in iBATIS to return a Set instead of a
> >> List.
> >> I can't understand why this feature is absent.
> >>
> >> Using the present approach, I have to pass the list to the TreeSet and
> >> then
> >> use it. This has to be done for ever user session that wants to access
> >> the
> >> cached entity.
> >>
> >> Is there any work around ? Is this supported in the spring framework ?
> >> I'm
> >> using org.springframework.orm.ibatis.support.SqlMapClientDaoSupport .
> >>
> >> regards
> >>
> >> Zeppelin
> >> --
> >> View this message in context:
> >>
http://www.nabble.com/using-java-SortedSet-instead-of-List-for-the-resultMap-tp19310126p19310126.html
> >> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
> >>
> >>
> >
> >
>
> --
> View this message in context:
http://www.nabble.com/using-java-SortedSet-instead-of-List-for-the-resultMap-tp19310126p19313314.html
> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>

Re: using java SortedSet instead of List for the resultMap

Posted by zeppelin <sh...@gmail.com>.
Thanks for that. I had previously read about RowHandler. Tell me if these are
correct :

1. Using the RowHandler, I would have to handle the cache myself and not
rely on iBATIS. Therefore, the 'cacheModel' attribute will be ignored. But
what I really wanted to use was the flushing mechanism.

2. Technically the caching in iBATIS is at application level. It is
described to be at session level since we can chage the way a user session
received an object -  a cloned object or a reference to the same object.

Just wanted to cofirm these. Also, it's a little strange that stored proc
out params cannot be cached.
Thanks again.
Zeppelin


Clinton Begin wrote:
> 
> You can pass in a RowHandler and have the results collect in whatever sort
> of collection you like.  The default implementation itself is a
> rowhandler,
> something (not exactly) like this:
> 
> public class ListRowHandler implements RowHandler {
>   private List list = new ArrayList();
> 
>   public void handleRow(Object valueObject) {
>     list.add(valueObject);
>   }
> 
>   public List getList() {
>     return list;
>   }
> }
> 
> Clinton
> 
> On Thu, Sep 4, 2008 at 8:41 AM, zeppelin <sh...@gmail.com> wrote:
> 
>>
>> I have seen a similar question on this forum but it's not answered.
>>
>> My scenario :
>> * I'd like to use the iBATIS cache. It's working fine.
>> * My requirement is to use TreeSet cos I specifically want to use the
>> subset(...) method.
>>
>> It appears there's just no way in iBATIS to return a Set instead of a
>> List.
>> I can't understand why this feature is absent.
>>
>> Using the present approach, I have to pass the list to the TreeSet and
>> then
>> use it. This has to be done for ever user session that wants to access
>> the
>> cached entity.
>>
>> Is there any work around ? Is this supported in the spring framework ?
>> I'm
>> using org.springframework.orm.ibatis.support.SqlMapClientDaoSupport .
>>
>> regards
>>
>> Zeppelin
>> --
>> View this message in context:
>> http://www.nabble.com/using-java-SortedSet-instead-of-List-for-the-resultMap-tp19310126p19310126.html
>> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/using-java-SortedSet-instead-of-List-for-the-resultMap-tp19310126p19313314.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: using java SortedSet instead of List for the resultMap

Posted by Clinton Begin <cl...@gmail.com>.
You can pass in a RowHandler and have the results collect in whatever sort
of collection you like.  The default implementation itself is a rowhandler,
something (not exactly) like this:

public class ListRowHandler implements RowHandler {
  private List list = new ArrayList();

  public void handleRow(Object valueObject) {
    list.add(valueObject);
  }

  public List getList() {
    return list;
  }
}

Clinton

On Thu, Sep 4, 2008 at 8:41 AM, zeppelin <sh...@gmail.com> wrote:

>
> I have seen a similar question on this forum but it's not answered.
>
> My scenario :
> * I'd like to use the iBATIS cache. It's working fine.
> * My requirement is to use TreeSet cos I specifically want to use the
> subset(...) method.
>
> It appears there's just no way in iBATIS to return a Set instead of a List.
> I can't understand why this feature is absent.
>
> Using the present approach, I have to pass the list to the TreeSet and then
> use it. This has to be done for ever user session that wants to access the
> cached entity.
>
> Is there any work around ? Is this supported in the spring framework ? I'm
> using org.springframework.orm.ibatis.support.SqlMapClientDaoSupport .
>
> regards
>
> Zeppelin
> --
> View this message in context:
> http://www.nabble.com/using-java-SortedSet-instead-of-List-for-the-resultMap-tp19310126p19310126.html
> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>
>