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 Josh Joy <jo...@gmail.com> on 2008/10/22 02:36:58 UTC

dynamic resultmap?

I need two different resultmaps/resultclass.

One resultclass is an "int" for when I do a select count(*).
The second is a resultmap for the actual query.

The query is being filtered (using various where clauses). I need to reuse
this sql fragment for the paging with filtering as well as the count(*) so I
can have this info for my web page.

I also need to do this for a lot of queries. I have a reusable count sql
fragment and paging fragment, and I could just write my sql and then for
each sql have a count and paging which includes my fragments.

Though what I would like to do, is in my DAO, to pass in a single statement
id, though have a findCount and a findPaging which both take in the sql id
to be executed, though includes the appropiate header as well as sets the
appropiate result class.

Is this possible?

Thanks,
Josh

Re: dynamic resultmap?

Posted by Jeff Butler <je...@gmail.com>.
You can't change the resultMap/resultClass on the fly.  The best you
can do there is to use a HashMap as the resultClass and set
remapResults="true".  Then you have to figure out what got returned on
the Java side.

The includes can be *sort of* dynamic.  The trick is to ALWAYS include
the SQL fragment, and then write the fragment like this:

<sql id="pagingCode">
  <isEqual property="includePaging" compareValue="true">
    -- paging fragment here
  </isEqual>
</sql>

Of course this means more work on the Java side of things.  For
example, in this case you need to make sure that there is always an
"includePaging" property in your parameter class.

So, you can accomplish what you're asking for, but it's still kind of ugly.

Jeff Butler




On Tue, Oct 21, 2008 at 7:36 PM, Josh Joy <jo...@gmail.com> wrote:
> I need two different resultmaps/resultclass.
>
> One resultclass is an "int" for when I do a select count(*).
> The second is a resultmap for the actual query.
>
> The query is being filtered (using various where clauses). I need to reuse
> this sql fragment for the paging with filtering as well as the count(*) so I
> can have this info for my web page.
>
> I also need to do this for a lot of queries. I have a reusable count sql
> fragment and paging fragment, and I could just write my sql and then for
> each sql have a count and paging which includes my fragments.
>
> Though what I would like to do, is in my DAO, to pass in a single statement
> id, though have a findCount and a findPaging which both take in the sql id
> to be executed, though includes the appropiate header as well as sets the
> appropiate result class.
>
> Is this possible?
>
> Thanks,
> Josh
>
>
>

Re: dynamic resultmap?

Posted by joson yu <yu...@gmail.com>.
look into the <sql /> and <include/> elements?i met this problem too.could
you show me some example?

thanks

Re: dynamic resultmap?

Posted by Larry Meadors <la...@gmail.com>.
On Tue, Oct 21, 2008 at 6:36 PM, Josh Joy <jo...@gmail.com> wrote:
> Is this possible?

Yes. :)

Larry


PS: look into the <sql /> and <include/> elements.