ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Junyi <starbla...@gmail.com>
Subject resultMap class=Map need workaround
Date Thu, 19 Apr 2007 04:57:51 GMT
I want to be able to add arbitrary number of calculated columns (determined
at runtime) to a query and have those results placed into a Map along with
predefined columns. For example,

<resultMap id="someOrder">
    <result property="id" column="ID"/>
    <result property="order" column="ORDER"/>
    <result property="total" column="ORDER_TOTAL"/>
    <result property="calculations" resultMap="GenericMap"/>
 </resultMap>

 <resultMap id="GenericMap" class="Map"/>

<select id="getOrderStats" resultMap="someOrder">
     select id, order, order_total, $calcColumns$
         from main_orders
       where .... etc etc ...
</select>

Using this example, one might pass $calcColumn$ = "total*0.08 as \"
calculations.tax\", total/quantity as \"calculations.avgcost\""

This should map all columns with the name "calculations.XXX" into a Map
using put(XXX, * ).  Currently the code only allows using setXXX( * ).  But
since Map obviously doesn't have any setter methods, this fails to populate
the calculations property.

One ugly workaround requires running 2 queries (one with just predefined
columns and the other with the calculated columns) and having Java match the
two result sets.  Is there any other way without running 2 queries?   I
tried to send this issue as an iBatis improvement but got rejected.  Thanks.

Mime
View raw message