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 "Alejandro D. Garin" <ag...@gmail.com> on 2008/11/26 13:27:22 UTC

with parameterMap and parameterClass ?

Hello!

Could I use an <update> statement using a parameterMap and a parameterClass
? How to use a parameterClass property?

Example:

<update id="update1" parameterMap="personMap" parameterClass="Person">

UPDATE Person SET name=?,lastname=? WHERE id = (how to reference the value
from parameter class Person here?)

</update>

I can't found any examples of these case!

Thank you!
Regards,
Alejandro.

Re: with parameterMap and parameterClass ?

Posted by "Alejandro D. Garin" <ag...@gmail.com>.
Great!
Thank you Nicholoz.

On Wed, Nov 26, 2008 at 8:32 PM, Nicholoz Koka Kiknadze
<ki...@gmail.com>wrote:

>     <parameterMap id="messageParameterMap" class="Message">
>>         <parameter property="id1" jdbcType="INTEGER"/>
>>         <parameter property="id2" jdbcType="INTEGER"/>
>>         <parameter property="messageCount" jdbcType="INTEGER" />
>>         <parameter property="title" jdbcType="VARCHAR"/>
>>     </parameterMap>
>>
>>     <insert id="insertMessage" parameterMap="messageParameterMap" >
>>         INSERT INTO MSGS ( SY_ID1, SY_ID2, MS_COUNT, MS_TITLE)
>>         VALUES (#id1#,#id2,#messageCount#,#title#)
>>     </insert>
>>
>>     <update id="update" parameterMap="messageParameterMap" >
>>         UPDATE MSGS SET MS_COUNT=#messageCount#, MS_TITLE=#title# WHERE
>> SY_ID1=#id1# AND SY_ID2 = #id2#
>>     </update>
>>
>>
> I.e. for selects/crud replace question marks with actual property name
> enclosed with ##.
> However you'll have to use questionmark placeholders when calling stored
> procedures, and there you'll need to care about the order in your parameter
> map.
>

Re: with parameterMap and parameterClass ?

Posted by Nicholoz Koka Kiknadze <ki...@gmail.com>.
>
>     <parameterMap id="messageParameterMap" class="Message">
>         <parameter property="id1" jdbcType="INTEGER"/>
>         <parameter property="id2" jdbcType="INTEGER"/>
>         <parameter property="messageCount" jdbcType="INTEGER" />
>         <parameter property="title" jdbcType="VARCHAR"/>
>     </parameterMap>
>
>     <insert id="insertMessage" parameterMap="messageParameterMap" >
>         INSERT INTO MSGS ( SY_ID1, SY_ID2, MS_COUNT, MS_TITLE)
>         VALUES (#id1#,#id2,#messageCount#,#title#)
>     </insert>
>
>     <update id="update" parameterMap="messageParameterMap" >
>         UPDATE MSGS SET MS_COUNT=#messageCount#, MS_TITLE=#title# WHERE
> SY_ID1=#id1# AND SY_ID2 = #id2#
>     </update>
>
>
I.e. for selects/crud replace question marks with actual property name
enclosed with ##.
However you'll have to use questionmark placeholders when calling stored
procedures, and there you'll need to care about the order in your parameter
map.

Re: with parameterMap and parameterClass ?

Posted by "Alejandro D. Garin" <ag...@gmail.com>.
Hi Nicholoz,

OK, I understand, but with the following example:

    <parameterMap id="messageParameterMap" class="Message">
        <parameter property="id1" jdbcType="INTEGER"/>
        <parameter property="id2" jdbcType="INTEGER"/>
        <parameter property="messageCount" jdbcType="INTEGER" />
        <parameter property="title" jdbcType="VARCHAR"/>
    </parameterMap>

    <insert id="insertMessage" parameterMap="messageParameterMap" >
        INSERT INTO MSGS ( SY_ID1, SY_ID2, MS_COUNT, MS_TITLE)
        VALUES (?,?,?,?)
    </insert>

    <update id="update" parameterMap="messageParameterMap" >
        UPDATE MSGS SET MS_COUNT=?, MS_TITLE=? WHERE SY_ID1=? AND SY_ID2 = ?
    </update>

How to indicate in the update statement that the SY_ID1 AND SY_ID2 must be
in the where? I must change the order of the parameterMap ?

Thanks

On Wed, Nov 26, 2008 at 12:16 PM, Nicholoz Koka Kiknadze <kiknadze@gmail.com
> wrote:

>
>
> On Wed, Nov 26, 2008 at 8:05 AM, Alejandro D. Garin <ag...@gmail.com>wrote:
>
>> Hi Ingmar
>>
>>
>>> provide an instance of Person as parameter, witch contains the values to
>>> store.
>>>
>>> <update id="update1" parameterClass="Person">
>>>  UPDATE Person SET
>>>    name = #name:VARCHAR#,
>>>    lastname = #lastname:VARCHAR#
>>>  WHERE id = #id:INTEGER#
>>> </update>
>>>
>>
>> OK, but, what if I have defined a parameterMap for an <insert>? can't
>> reuse it for an <update> statement?
>>
>
> Sure you can reuse it:
> <update id="update1" parameterMap="personMap"> ... </update>
>
> You can not use BOTH parameterMap and parameterClass in a single update
> definition, so if you already have defined and populated your parameterMap,
> go ahead, use it.
>
>

Re: with parameterMap and parameterClass ?

Posted by Nicholoz Koka Kiknadze <ki...@gmail.com>.
On Wed, Nov 26, 2008 at 8:05 AM, Alejandro D. Garin <ag...@gmail.com>wrote:

> Hi Ingmar
>
>
>> provide an instance of Person as parameter, witch contains the values to
>> store.
>>
>> <update id="update1" parameterClass="Person">
>>  UPDATE Person SET
>>    name = #name:VARCHAR#,
>>    lastname = #lastname:VARCHAR#
>>  WHERE id = #id:INTEGER#
>> </update>
>>
>
> OK, but, what if I have defined a parameterMap for an <insert>? can't reuse
> it for an <update> statement?
>

Sure you can reuse it:
<update id="update1" parameterMap="personMap"> ... </update>

You can not use BOTH parameterMap and parameterClass in a single update
definition, so if you already have defined and populated your parameterMap,
go ahead, use it.

Re: with parameterMap and parameterClass ?

Posted by Ingmar Lötzsch <il...@asci-systemhaus.de>.
Hello Alejandro,

I think in case of presence of parameterMap and parameterClass one of 
them is ignored, but don't know surely. Maybe other user can help you.

What ist the gain in reusing the parameterMap? Instead you can reuse 
your class Person.

Why do you use the parameterMap? I've never used this attribute.

Ingmar

>     provide an instance of Person as parameter, witch contains the
>     values to store.
> 
>     <update id="update1" parameterClass="Person">
>      UPDATE Person SET
>        name = #name:VARCHAR#,
>        lastname = #lastname:VARCHAR#
>      WHERE id = #id:INTEGER#
>     </update>
> 
> 
> OK, but, what if I have defined a parameterMap for an <insert>? can't 
> reuse it for an <update> statement?


Re: with parameterMap and parameterClass ?

Posted by "Alejandro D. Garin" <ag...@gmail.com>.
Hi Ingmar


> provide an instance of Person as parameter, witch contains the values to
> store.
>
> <update id="update1" parameterClass="Person">
>  UPDATE Person SET
>    name = #name:VARCHAR#,
>    lastname = #lastname:VARCHAR#
>  WHERE id = #id:INTEGER#
> </update>
>

OK, but, what if I have defined a parameterMap for an <insert>? can't reuse
it for an <update> statement?

Re: with parameterMap and parameterClass ?

Posted by Ingmar Lötzsch <il...@asci-systemhaus.de>.
> Could I use an <update> statement using a parameterMap and a 
> parameterClass ? How to use a parameterClass property?
> 
> Example:
> 
> <update id="update1" parameterMap="personMap" parameterClass="Person">
> 
> UPDATE Person SET name=?,lastname=? WHERE id = (how to reference the 
> value from parameter class Person here?)
> </update>

Hello Alejandro,

provide an instance of Person as parameter, witch contains the values to 
store.

<update id="update1" parameterClass="Person">
   UPDATE Person SET
     name = #name:VARCHAR#,
     lastname = #lastname:VARCHAR#
   WHERE id = #id:INTEGER#
</update>

Or put the name, lastname and id in the map with keys "name", "lastname" 
and "id".

<update id="update1" parameterClass="map">
   UPDATE Person SET
     name = #name:VARCHAR#,
     lastname = #lastname:VARCHAR#
   WHERE id = #id:INTEGER#
</update>

You don't need the parameterMap attribute.

Ingmar