Return-Path: Delivered-To: apmail-ibatis-user-java-archive@www.apache.org Received: (qmail 96052 invoked from network); 26 Apr 2007 12:53:49 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 26 Apr 2007 12:53:49 -0000 Received: (qmail 29466 invoked by uid 500); 26 Apr 2007 12:53:55 -0000 Delivered-To: apmail-ibatis-user-java-archive@ibatis.apache.org Received: (qmail 28852 invoked by uid 500); 26 Apr 2007 12:53:54 -0000 Mailing-List: contact user-java-help@ibatis.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user-java@ibatis.apache.org Delivered-To: mailing list user-java@ibatis.apache.org Received: (qmail 28841 invoked by uid 99); 26 Apr 2007 12:53:54 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 26 Apr 2007 05:53:54 -0700 X-ASF-Spam-Status: No, hits=2.0 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: domain of jeffgbutler@gmail.com designates 64.233.162.234 as permitted sender) Received: from [64.233.162.234] (HELO nz-out-0506.google.com) (64.233.162.234) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 26 Apr 2007 05:53:46 -0700 Received: by nz-out-0506.google.com with SMTP id q3so742861nzb for ; Thu, 26 Apr 2007 05:53:26 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=nkf38+xVeXLprpOZYMExooW8pP1gvotbuWUSHU/Yh8ZpfU3plt1K4Il6bxvKamMg2Qilz4qX8vaRbJy2PrYStHcnt/1FROJtstykiSloYCIju5Pmmd4617B3M4CkMSfDONPaBqXKMh+NSKD8v7EOW4PvyUoJMZzpZ/6ADREC06I= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=na1ZNekB7ESkYRQzPt5kb3cYitoUI1GTU7F9wo1g7UADyCYNw8Rzlpo5p60U/XAzDq8Gn9WYSrVp8ljfH9jpPa2JVirlpEhk372eZgR2DfQ0f2wVtKPHq0T6HYftYwW1R0kp4pwYSoiDZEAJNBzdL2GZZHIAWePBdB9QEWPQEFQ= Received: by 10.114.95.1 with SMTP id s1mr582670wab.1177592005846; Thu, 26 Apr 2007 05:53:25 -0700 (PDT) Received: by 10.114.72.19 with HTTP; Thu, 26 Apr 2007 05:53:25 -0700 (PDT) Message-ID: Date: Thu, 26 Apr 2007 07:53:25 -0500 From: "Jeff Butler" To: user-java@ibatis.apache.org Subject: Re: resultMap class=Map need workaround In-Reply-To: <37d9ea330704251827o56b76b5do11ebae1d482e5d54@mail.gmail.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_232616_30865900.1177592005579" References: <37d9ea330704182157t425d3e22l41167675639269b4@mail.gmail.com> <37d9ea330704251827o56b76b5do11ebae1d482e5d54@mail.gmail.com> X-Virus-Checked: Checked by ClamAV on apache.org ------=_Part_232616_30865900.1177592005579 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline iBATIS certanly does know that Maps require special handling. However, iBATIS will not do what you're wanting here. This is because iBATIS does not introspect the ResultsetMetaData - which is what would be required in this case. iBATIS only asks for column values out of a resultset that are specifically called out in a resultMap, or that match the setters of a bean in the case of no resultmap. This seems like a good place to use straight JDBC as you have a requirement that is far beyond the present capabilities of iBATIS. Jeff Butler On 4/25/07, Junyi wrote: > > Yes I've done that but it does not work. It doesn't bother filling in the > calculations map with anything because iBatis is only looking for getters > and setters and doesn't understand a Map requires special handling. > > > On 4/19/07, Larry Meadors wrote: > > > > Can you eliminate the result map, and use implicit field mapping > > instead? > > > > > > > > Make sure that the constructor for "SomeClass" creates the Map > > instance, too - or you'll get an NPE. > > > > Larry > > > > > > On 4/18/07, Junyi wrote: > > > 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, > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > 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. > > > > ------=_Part_232616_30865900.1177592005579 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline
iBATIS certanly does know that Maps require special handling.  However, iBATIS will not do what you're wanting here.  This is because iBATIS does not introspect the ResultsetMetaData - which is what would be required in this case.  iBATIS only asks for column values out of a resultset that are specifically called out in a resultMap, or that match the setters of a bean in the case of no resultmap.
 
This seems like a good place to use straight JDBC as you have a requirement that is far beyond the present capabilities of iBATIS.
 
Jeff Butler


 
On 4/25/07, Junyi <starblazer@gmail.com> wrote:
Yes I've done that but it does not work.  It doesn't bother filling in the calculations map with anything because iBatis is only looking for getters and setters and doesn't understand a Map requires special handling.



On 4/19/07, Larry Meadors <lmeadors@apache.org > wrote:
Can you eliminate the result map, and use implicit field mapping instead?

<select id="getOrderStats" resultClass="SomeClass" remapResults="true">
      select
          id,
          order,
          order_total as total,
          $calcColumns$
      from main_orders
      where .... etc etc ...
</select>

Make sure that the constructor for "SomeClass" creates the Map
instance, too - or you'll get an NPE.

Larry


On 4/18/07, Junyi <starblazer@gmail.com > wrote:
> 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.


------=_Part_232616_30865900.1177592005579--