Here's an idea... Take the normal map that you'd get from Christopher's
suggestion and just build the map that you want returned as part of the
routine...
public Map getCustomerData( String id ) throws Exception {
// untested
Map m = new HashMap();
map.put("id", id );
Object o = sqlMap.execute("stored_proc", map );
Customer c = new Customer();
BeanUtils.copyProperties(c, map);
Map returnMap = new HashMap();
returnMap.put ("customer", c );
returnMap.put("status", (Integer) map.get("status") );
return returnMap;
}
-----Original Message-----
From: Craig Tataryn [mailto:[EMAIL PROTECTED]
Sent: Tue 2/12/2008 5:47 PM
To: [email protected]
Cc:
Subject: Re: Stored procedure help.
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 <[EMAIL PROTECTED]> 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" <[EMAIL PROTECTED]> wrote:
> friendly *bump*
>
> On 2/11/08, Craig Tataryn <[EMAIL PROTECTED]> 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
>>
<<winmail.dat>>
