Questions about stored procedures and MyBatis documentation

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Questions about stored procedures and MyBatis documentation

ColoradoPete
I'm trying to set up to call a stored procedure that accepts one
String argument and returns an Integer (on an Informix server, if
that's relevant) but I'm having difficulty figuring out exactly how to
do this. I can't see anything specific in the user guide that
addresses stored procedures.

While searching for information I saw a reference to a Developer Guide
and I think this is where I'll find the answers, but I can't see where
to get hold of this document (the User Guide is right there on the
Java page under mybatis.org, but I see no mention of a Developer
guide).

Also, I can't find the MyBatis Javadocs anywhere. Where are they?
Reply | Threaded
Open this post in threaded view
|

Re: Questions about stored procedures and MyBatis documentation

Nate Weiss
Hi Pete--

To call the stored procedure I believe sure you will want to use a
<update> with type="CALLABLE" (callable is jdbc speak for stored
procedure). Based on what I've done in the past (not with mybatis), I
think you will want something like the following. I am assuming that
the proc takes two parameters, one in the "in" string, and the other
is the "out" Integer.

If you are using xml mapper, you would have something like:

<update type="callable" ... >
  call myProcName( #{myInParam}, #{myOutParam} )
</update>

If you are using mapper interface w/ annotations instead of xml, i
guess something like this:

@Update("call myProcName( #{myInParam}, #{myOutParam} )")
void myProcName(
  @Param("myInParam") String myInParam,
  @Param("myOutParam") Integer myOutParam
)

Then to actually use the thing you would do something like:

String in = "hello";
Integer out = 0; // Just to have something to pass in
mysession.getMapper(MyMapper.class).myProcName(in, out);

...I would think that "out" will now be set to the value returned by
the proc. I haven't tried it and I haven't used procs w/ mybatis at
this time, but that would be my guess based on what's documented
crossed with how I've seen it done elsewhere. Agreed that the docs
don't really get you there. If you figure it out maybe a doc
contribution is in order! :)

nmw
Reply | Threaded
Open this post in threaded view
|

Re: Questions about stored procedures and MyBatis documentation

Nate Weiss
In reply to this post by ColoradoPete
Oh, I found a copy of the javadoc online:

http://www.jarvana.com/jarvana/view/org/mybatis/mybatis/3.0.2/mybatis-3.0.2-javadoc.jar!/index.html?overview-summary.html

...I think in prior releases it was included in the bundle if I'm not
mistaken. I guess we can grab the source and build the doc but it
would be handy to have it in the bundle....
Reply | Threaded
Open this post in threaded view
|

Re: Questions about stored procedures and MyBatis documentation

ColoradoPete
In reply to this post by Nate Weiss
Thanks for this, Nate. My current XML mapping is set up as a <select>
with the type set to CALLABLE, but as you say I may need to change
this to an <update>. It looks like the stored procedure I'm calling
works as a function, so it accepts a String and returns an Integer
(it's an existing procedure that I have no control over), so it looks
like something like this might work:

<update id="myProc" parameterType="String" returnType="int"
statementType="CALLABLE">
    CALL myProc(#{value}) RETURNING x
</update>

I'll probably have to tweak this a bit to get it working right,
although I can't test it yet (the DB people haven't set up the
firewall yet, so I can't hit the server). However it kinda looks
right, so I'm hopeful. Thanks again.

On Sep 29, 9:27 pm, Nate Weiss <[hidden email]> wrote:

> Hi Pete--
>
> To call the stored procedure I believe sure you will want to use a
> <update> with type="CALLABLE" (callable is jdbc speak for stored
> procedure). Based on what I've done in the past (not with mybatis), I
> think you will want something like the following. I am assuming that
> the proc takes two parameters, one in the "in" string, and the other
> is the "out" Integer.
>
> If you are using xml mapper, you would have something like:
>
> <update type="callable" ... >
>   call myProcName( #{myInParam}, #{myOutParam} )
> </update>
>
> If you are using mapper interface w/ annotations instead of xml, i
> guess something like this:
>
> @Update("call myProcName( #{myInParam}, #{myOutParam} )")
> void myProcName(
>   @Param("myInParam") String myInParam,
>   @Param("myOutParam") Integer myOutParam
> )
>
> Then to actually use the thing you would do something like:
>
> String in = "hello";
> Integer out = 0; // Just to have something to pass in
> mysession.getMapper(MyMapper.class).myProcName(in, out);
>
> ...I would think that "out" will now be set to the value returned by
> the proc. I haven't tried it and I haven't used procs w/ mybatis at
> this time, but that would be my guess based on what's documented
> crossed with how I've seen it done elsewhere. Agreed that the docs
> don't really get you there. If you figure it out maybe a doc
> contribution is in order! :)
>
> nmw
Reply | Threaded
Open this post in threaded view
|

Re: Questions about stored procedures and MyBatis documentation

ColoradoPete
In reply to this post by Nate Weiss
Thanks for the link. I checked the bundle to make sure I hadn't missed
it but you're right, it's not there. However the source Jar is and I
could, if I had time, use that to generate the docs. It would be
better if it was available for download, though (either in the bundle
or as a separate file).

On the other question, though - *is* there a Developer Guide separate
from the User Guide? It looks like someone may have simply confused
the terms, but if there's a separate Dev guide I'd like to get hold of
it.

On Sep 29, 9:28 pm, Nate Weiss <[hidden email]> wrote:
> Oh, I found a copy of the javadoc online:
>
> http://www.jarvana.com/jarvana/view/org/mybatis/mybatis/3.0.2/mybatis...
>
> ...I think in prior releases it was included in the bundle if I'm not
> mistaken. I guess we can grab the source and build the doc but it
> would be handy to have it in the bundle....