ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Fabien Le Floc'h <logo...@gmail.com>
Subject dynamic query template?
Date Wed, 22 Jun 2005 21:47:07 GMT

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">
<isEqual property="value" compareValue="count">
<isNotEqual property="value" compareValue="count">
FROM user_tbl [...] WHERE category="admin" AND ...

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,


View raw message