ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Lamey <cla...@localmatters.com>
Subject Re: Stored procedure help.
Date Tue, 12 Feb 2008 23:17:24 GMT
BTW, you can always write a RowHandler that pulls things together into a Map
for you if the resultMap route doesn't work for whatever reason.


On 2/12/08 4:13 PM, "Christopher Lamey" <clamey@localmatters.com> wrote:

> So the next section of the iBATIS docs on page 37 talks about Complex
> Properties.
> 
> Looking at that, you might be able to do something like this:
> 
> <resultMap id=²get-product-result² class=²java.util.HashMap²>
>     <result property=²status² column=²STATUS²/>
>     <result property=²customer² resultMap=³get-customer-result²  />
> </resultMap> 
> 
> <resultMap id=²get-customer-result² class=²com.ibatis.example.Customer²>
>     <result property=²id² column=²CUST_ID² />
>     <result property=²name² column=²CUST_NAME² />
> </resultMap>
> 
> I've never tried it, but that should work.
> 
> Cheers,
> Chris
> 
> 
> On 2/12/08 3:47 PM, "Craig Tataryn" <craiger@tataryn.net> wrote:
> 
>> Hey Christopher, I appreciate the reply however that is for "simple"
>> result-columns-to-map-entries.  Take a look again at what I'm trying to do.
>> It's a bit more complicated, I do indeed want a map back, however I want one
>> entry to have the value of the out parameter for STATUS, and the other entry
>> to contain a fully "hydrated" customer object based off the remaining OUT
>> parameters.
>> 
>> Thanks,
>> 
>> Craig.
>> 
>> On 2/12/08, Christopher Lamey <clamey@localmatters.com> wrote:
>>> 
>>> Hello,
>>> 
>>> The following is from the iBATIS PDF, page 37:
>>> 
>>> Result Maps can also conveniently populate a Map instance such as HashMap
>>> or
>>> TreeMap.  Collections of such objects (e.g. Lists of Maps) can also be
>>> retrieved using the APIs described below (see queryForList()). Map types
>>> are
>>> mapped exactly the same way as a JavaBean, but instead of setting
>>> JavaBeans
>>> properties, the keys of the Map are set to reference the values for the
>>> corresponding mapped columns.  For example, if we wanted to load the
>>> values
>>> of a product quickly into a Map, we could do the following:
>>> 
>>> <resultMap id=²get-product-result² class=²java.util.HashMap²>
>>>     <result  property=²id² column=²PRD_ID²/>
>>>     <result  property=²code² column=²PRD_CODE²/>
>>>     <result  property=²description² column=²PRD_DESCRIPTION²/>
>>>     <result  property=²suggestedPrice² column=²PRD_SUGGESTED_PRICE²/>
>>> </resultMap>
>>> 
>>> In the example above, an instance of HashMap would be created and
>>> populated
>>> with the Product data.  The property name attributes (e.g. ³id²) would be
>>> the keys of the HashMap, and the values of the mapped columns would be the
>>> values in the HashMap.
>>> 
>>> Cheers,
>>> topher
>>> 
>>> On 2/12/08 8:32 AM, "Craig Tataryn" <craiger@tataryn.net> wrote:
>>> 
>>>> friendly *bump*
>>>> 
>>>> On 2/11/08, Craig Tataryn <craiger@tataryn.net> wrote:
>>>>> 
>>>>> Hi, relatively new to iBatis and have a question about a stored
>>> procedure
>>>>> I need to call that has one IN parameter and several OUT
>>> parameters.  The
>>>>> idea is, someone would call this stored proc to return exactly 1
>>> customer
>>>>> from the database.  The IN parameter corresponds to the customer's id,
>>> the
>>>>> OUT parameters consist of a bunch of properties on a Customer object
as
>>> well
>>>>> as an extra STATUS parameter which does not exist on the Customer
>>> object,
>>>>> but instead indicates whether a retrieval problem happened (for
>>> instance the
>>>>> ID you passed to the stored proc didn't exist in the DB for any
>>> customers).
>>>>> 
>>>>> So for instance, given the Customer class:
>>>>> 
>>>>> public class Customer {
>>>>>   private String name;
>>>>>   private String email;
>>>>>   private String gender;
>>>>> }
>>>>> 
>>>>> And a stored proc that looked like this:
>>>>> CREATE OR REPLACE PROCEDURE CUSTOMER_RD
>>>>>     -- read a record from the table CUSTOMER
>>>>> (
>>>>>     CUST_ID IN NUMERIC,
>>>>>     CUST_NAME OUT VARCHAR2,
>>>>>     CUST_EMAIL OUT VARCHAR2,
>>>>>     CUST_GENDER OUT CHAR,
>>>>>     STATUS OUT NUMERIC
>>>>> )
>>>>> .
>>>>> .
>>>>> .
>>>>> 
>>>>> I know how I could code an sqlMap such that each of OUT parameters
>>> get's
>>>>> populated into a Map entry, then I would manually iterate through the
>>> Map
>>>>> and populate a Customer object (disregarding the STATUS param for the
>>> time
>>>>> being), however what I'm hoping to do is instead get a map back from
>>> iBatis
>>>>> which looks like so:
>>>>> 
>>>>> {
>>>>>     "customer" => Customer
>>>>>     "status" => int
>>>>> }
>>>>> 
>>>>> Is this possible?  If so, what might the corresponding sqlMap look
>>> like?
>>>>> 
>>>>> Thanks
>>>>> 
>>> 
>>> 
> 


Mime
View raw message