ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brandon Goodin <brandon.goo...@gmail.com>
Subject Re: dynamic query template?
Date Wed, 22 Jun 2005 22:22:38 GMT
I'm curious what _would_ be considered elegant? Anyway, the solution
you provided should be fine. Be sure to use remapResults="true". The
other route is simply to duplicate the two queries so that they
present cleaner and you don't need ot place a count boolean into your
parameter object.

Brandon

On 6/22/05, Fabien Le Floc'h <logos01@gmail.com> wrote:
> Hi,
>  
>  I was wondering what would be the best way to write 2 queries that share
> almost everything with iBatis.
>  
>  For example if I want to do 
>  SELECT * FROM user_tbl [...] WHERE category="admin" AND ... LIMIT 50
>  SELECT COUNT(*) FROM user_tbl [...] WHERE category="admin" AND ...
>  
>  ideally one would have 2 names, because it is a quite different result, but
> you want to perform both queries on the same set.
>  
>  The way I found is to use a dynamic query with a parameter that will act as
> a switch.
>  <select id="getUsers" parameterClass="java.lang.String">
>      SELECT 
>      <isEqual property="value" compareValue="count">
>           COUNT(*)
>      </isEqual>
>      <isNotEqual property="value" compareValue="count">
>           *
>      </isNotEqual>
>       FROM user_tbl [...] WHERE category="admin" AND ...
>  </select>
>  
>  As you can see, this is not very elegant. I could generate the xml, but
> should this kind of case be handled by iBatis?
>  
>  The paginate queryForPaginatedList does not seem to support the total
> number of items available.
>  
>  So if you have a more elegant solution I'll be very happy to hear from you.
>  
>  Thanks for the great work on ibatis,
>  
>  Fabien.
>

Mime
View raw message