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 Paul Sanders <te...@gmail.com> on 2007/04/12 20:45:52 UTC

New Stored Proc Question - Creating a Bean From Partial Results

[At this rate I fear I'm going to be asking about every stored procedure in
my database but hopefully not...]

I have this definition for my a stored procedure:

Procedure getBanPolicyById (
  piBanPolicyId in number,
  poApplicationId out number,
  poMinBanCount out number,
  poMaxBanCount out number,
  poAccountBandays out number,
  poDnasBandays out number,
  poBanReasonID out number,
  poDidSucceed out number);

So I wrote some XML:

   <parameterMap id="fetch-ban-policy-by-id" class="map">
       <parameter property="banPolicyID" jdbcType="INTEGER" mode="IN" />
       <parameter property="applicationID" jdbcType="INTEGER" mode="OUT" />
       <parameter property="minBanCount" jdbcType="INTEGER" mode="OUT" />
       <parameter property="maxBanCount" jdbcType="INTEGER" mode="OUT" />
       <parameter property="accountBanDays" jdbcType="INTEGER" mode="OUT" />
       <parameter property="dnasBanDays" jdbcType="INTEGER" mode="OUT" />
       <parameter property="banReasonId" jdbcType="INTEGER" mode="OUT" />
       <parameter property="didSucceed" jdbcType="INTEGER" mode="OUT" />      
   </parameterMap>

   <procedure id="fetch-ban-policy-by-id"
parameterMap="fetch-ban-policy-by-id"  >
      { call getBanPolicyById(?,?,?,?,?,?,?,?) }
   </procedure>

and a test method:

public void fetchBanPolicyById(Integer policyId)
{
	Map map = new HashMap();
	map.put("banPolicyID", policyId);

	getSqlMapClientTemplate().queryForList("fetch-ban-policy-by-id", map);
	System.out.println(map.toString());
}

The printed map is everything I expect. 

My question is: is there any way to have the framework create the BanPolicy
object from the first 7 values in the map? My understanding is that a
resultMap only works with a resultSet but thats not how the sproc was
written. 

Thanks again

Paul
-- 
View this message in context: http://www.nabble.com/New-Stored-Proc-Question---Creating-a-Bean-From-Partial-Results-tf3567480.html#a9965793
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: New Stored Proc Question - Creating a Bean From Partial Results

Posted by Paul Sanders <te...@gmail.com>.
It took me a little while to figure out how to get around the fact that the
'didSucceed' OUT param is not part of the object (solution: it now is, but
it lives in a superclass for "fetchableBeans") and it works just fine.

The really good news is that somewhere amidst these questions I "got it" and
was able to do the rest of my read procs as well as the insert/update and
delete ones without needing help. 

Thanks to all who helped, and especially you Jeff.

Cheers

Paul

Jeff Butler-2 wrote:
> 
> What if you create the object and pass it as the parameter instead of
> using
> a Map?  Change your parameterMap to use class="BanPolicy", then...
> 
> BanPolicy bp = new BanPolicy();
> bp.setBanPolicyId(33);
> getSqlMapClientTemplate().queryForList("fetch-ban-policy-by-id", bp);
> return bp;
> 
> Jeff Butler
> 

-- 
View this message in context: http://www.nabble.com/New-Stored-Proc-Question---Creating-a-Bean-From-Partial-Results-tf3567480.html#a9970595
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: New Stored Proc Question - Creating a Bean From Partial Results

Posted by Jeff Butler <je...@gmail.com>.
What if you create the object and pass it as the parameter instead of using
a Map?  Change your parameterMap to use class="BanPolicy", then...

BanPolicy bp = new BanPolicy();
bp.setBanPolicyId(33);
getSqlMapClientTemplate().queryForList("fetch-ban-policy-by-id", bp);
return bp;

Jeff Butler


On 4/12/07, Paul Sanders <te...@gmail.com> wrote:
>
>
> [At this rate I fear I'm going to be asking about every stored procedure
> in
> my database but hopefully not...]
>
> I have this definition for my a stored procedure:
>
> Procedure getBanPolicyById (
> piBanPolicyId in number,
> poApplicationId out number,
> poMinBanCount out number,
> poMaxBanCount out number,
> poAccountBandays out number,
> poDnasBandays out number,
> poBanReasonID out number,
> poDidSucceed out number);
>
> So I wrote some XML:
>
>   <parameterMap id="fetch-ban-policy-by-id" class="map">
>       <parameter property="banPolicyID" jdbcType="INTEGER" mode="IN" />
>       <parameter property="applicationID" jdbcType="INTEGER" mode="OUT" />
>       <parameter property="minBanCount" jdbcType="INTEGER" mode="OUT" />
>       <parameter property="maxBanCount" jdbcType="INTEGER" mode="OUT" />
>       <parameter property="accountBanDays" jdbcType="INTEGER" mode="OUT"
> />
>       <parameter property="dnasBanDays" jdbcType="INTEGER" mode="OUT" />
>       <parameter property="banReasonId" jdbcType="INTEGER" mode="OUT" />
>       <parameter property="didSucceed" jdbcType="INTEGER" mode="OUT" />
>   </parameterMap>
>
>   <procedure id="fetch-ban-policy-by-id"
> parameterMap="fetch-ban-policy-by-id"  >
>      { call getBanPolicyById(?,?,?,?,?,?,?,?) }
>   </procedure>
>
> and a test method:
>
> public void fetchBanPolicyById(Integer policyId)
> {
>        Map map = new HashMap();
>        map.put("banPolicyID", policyId);
>
>        getSqlMapClientTemplate().queryForList("fetch-ban-policy-by-id",
> map);
>        System.out.println(map.toString());
> }
>
> The printed map is everything I expect.
>
> My question is: is there any way to have the framework create the
> BanPolicy
> object from the first 7 values in the map? My understanding is that a
> resultMap only works with a resultSet but thats not how the sproc was
> written.
>
> Thanks again
>
> Paul
> --
> View this message in context:
> http://www.nabble.com/New-Stored-Proc-Question---Creating-a-Bean-From-Partial-Results-tf3567480.html#a9965793
> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>
>