tags:

views:

22

answers:

1

I use iBatis 2.3.4

I have the following query:

<select id="getUserList" resultMap="userListResult">
    SELECT
            id,
            name,
            login,
            email
    FROM
          users
</select>

And when I need to provide paging I use:

sqlMap.queryForList("base.getUserList", startPosition, numItems);

Then iBatis generates query without limit, and skips extra data during fetching. I belive that work with limits is more faster.

How can we push iBatis to use LIMIT generally? Is It possible? May be we can describe some dialect?

A: 

What's wrong with passing the limit,offset as parameters ? For example (in Postgresql, I think Mysql is similar) :

<select id="getUserList" resultMap="userListResult">
    SELECT  ...
    FROM  users
    LIMIT #limit:INTEGER# OFFSET #offset:INTEGER#
</select>

Then in your dao you could code:

  Map params = new HashMap();
  params.put("limit",10);
  params.put("offset",100);
  res = sqlMap.queryForList("base.getUserList", params);
leonbloy