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 Javier Leyba <xl...@gmail.com> on 2006/10/05 15:43:32 UTC

Transform List resultmap to Map

Hi

In my application I´m calling a query that includes a join and return
a result to a resultMap wich has a field that holds a List with other
resultMap, like this:

---------------
    <resultMap id="notificationListResult" class="notification">
		<result property="id" column="id" />
		<result property="topicId" column="topic_id" />
		<result property="sourceTypeId" column="source_type_id" />
		<result property="notificationTypeId"
			column="notification_type_id" />
		<result property="category" column="category" />
		<result property="priority" column="priority" />
		<result property="source" column="source" />
		<result property="expiration" column="expiration"
			javaType="java.util.Date" />
		<result property="notificationDescription"
			resultMap="Notification.notificationDescriptionListResult" />	
	</resultMap>

	<resultMap id="notificationDescriptionListResult"
		class="notificationDescription">
		<result property="notificationId" column="id" />
		<result property="topicId" column="topic_id" />
		<result property="sourceTypeId"
			column="source_type_id" />
		<result property="notificationTypeId"
			column="notification_type_id" />
		<result property="locale" column="description_locale" />
		<result property="title" column="title" />
		<result property="description" column="description" />
	</resultMap>

--------------


It work well but I´m having problem with List and I wonder if could I
make a custom class or something else to transform
notificationListResult.notificationDescription from List to Map before
return the final List of objects to my app.

Also, I would like to know if there is a plan to allow iBatis to
accept Maps instead of List.

Thanks in advance

J

Re: Transform List resultmap to Map

Posted by Javier Leyba <xl...@gmail.com>.
On 10/5/06, Larry Meadors <lm...@apache.org> wrote:
> There are several things you could do here.
>
> Instead of mapping the child results in the config, you could step
> through the parent list and use queryForMap() in the dao to populate
> the child maps.
>
> You could leave the config as is and walk through the lists and turn
> them into maps, that would work ok, and if there are not a ton of
> results, that might be easiest.
>
> You could use groupby to do this all in one SQL statement, then walk
> through the lists and turn them into maps, which would probably be the
> most work, but I think you'd get the better performance that way.
>
> Or you could use a rowhandler and do the object creation
> yourself..that would be even more work, but I think you would get the
> top performance with that.
>
> Larry


Larry

Thanks for your reply.

I want to know how rowHandler works.

Iin this case, rowHandler will do the same as the select ? I mean, if
I pass my Notification.class to rowHandler query it will use mappings
and return  me a Notification object with the List properties filled ?

Thanks in advance

J

Re: Transform List resultmap to Map

Posted by Larry Meadors <lm...@apache.org>.
There are several things you could do here.

Instead of mapping the child results in the config, you could step
through the parent list and use queryForMap() in the dao to populate
the child maps.

You could leave the config as is and walk through the lists and turn
them into maps, that would work ok, and if there are not a ton of
results, that might be easiest.

You could use groupby to do this all in one SQL statement, then walk
through the lists and turn them into maps, which would probably be the
most work, but I think you'd get the better performance that way.

Or you could use a rowhandler and do the object creation
yourself..that would be even more work, but I think you would get the
top performance with that.

Larry


On 10/5/06, Javier Leyba <xl...@gmail.com> wrote:
> Hi
>
> In my application I´m calling a query that includes a join and return
> a result to a resultMap wich has a field that holds a List with other
> resultMap, like this:
>
> ---------------
>     <resultMap id="notificationListResult" class="notification">
>                 <result property="id" column="id" />
>                 <result property="topicId" column="topic_id" />
>                 <result property="sourceTypeId" column="source_type_id" />
>                 <result property="notificationTypeId"
>                         column="notification_type_id" />
>                 <result property="category" column="category" />
>                 <result property="priority" column="priority" />
>                 <result property="source" column="source" />
>                 <result property="expiration" column="expiration"
>                         javaType="java.util.Date" />
>                 <result property="notificationDescription"
>                         resultMap="Notification.notificationDescriptionListResult" />
>         </resultMap>
>
>         <resultMap id="notificationDescriptionListResult"
>                 class="notificationDescription">
>                 <result property="notificationId" column="id" />
>                 <result property="topicId" column="topic_id" />
>                 <result property="sourceTypeId"
>                         column="source_type_id" />
>                 <result property="notificationTypeId"
>                         column="notification_type_id" />
>                 <result property="locale" column="description_locale" />
>                 <result property="title" column="title" />
>                 <result property="description" column="description" />
>         </resultMap>
>
> --------------
>
>
> It work well but I´m having problem with List and I wonder if could I
> make a custom class or something else to transform
> notificationListResult.notificationDescription from List to Map before
> return the final List of objects to my app.
>
> Also, I would like to know if there is a plan to allow iBatis to
> accept Maps instead of List.
>
> Thanks in advance
>
> J
>