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 Chris Olsen <ch...@gmail.com> on 2009/12/10 17:51:16 UTC

Ibatis 3 Annotaion - Get # Rows updated

Using the V3 Annotations and session.GetMapper trying to figure out if there
is a way to figure out how many rows were updated.  I have seen some other
posts that reference a way using some of the other methods but I can not
find any docs for the Annotations methods or docs for the API's.  Any
pointers greatly appreciated. 
 
  Thanks - Chris Olsen

Sample code:
        try {
            session = sqlMapper.openSession();
            final ScriptMapper mapper =
session.getMapper(ScriptMapper.class);
            mapper.updateScript(script);
            session.commit();
        } catch(IbatisException ex) {
            logger.log(Level.WARNING, "Unable to update script entry: " +
script.getId(), ex);
        }
        finally {
            if (session != null ) {
                session.close();
            }
        }
-- 
View this message in context: http://old.nabble.com/Ibatis-3-Annotaion---Get---Rows-updated-tp26730660p26730660.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Re: Ibatis 3 Annotaion - Get # Rows updated

Posted by Chris Olsen <ch...@gmail.com>.
Guy,
  Got it figured out.  We are using the Annotations not XML, but that did
not really matter.
In the prototype for the updateScript I had void instead of int,  stupid but
now I know!.

Thanks for pointing me in the right direction!!

    @Update("UPDATE script SET path = #{path, jdbcType=VARCHAR}"
            + ", description = #{description, jdbcType=VARCHAR}"
            + ", cwd = #{cwd, jdbcType=VARCHAR}"
            + ", env_id = #{envId, jdbcType=VARCHAR}"
            + " WHERE id = #{id, jdbcType=VARCHAR}"
    )
    void updateScript(Script log)

-- 
View this message in context: http://old.nabble.com/Ibatis-3-Annotaion---Get---Rows-updated-tp26730660p26736065.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Re: Ibatis 3 Annotaion - Get # Rows updated

Posted by Guy Rouillier <gu...@burntmail.com>.
On 12/10/2009 2:38 PM, Chris Olsen wrote:
>
> Guy,
>    Using the 212 build that function returns a void and not an integer and
> will not compile.
> Thanks for the thought, any other places we might look?

I have a SQL statement in my XML file defined using <update>.  Here is 
the corresponding method in my Java mapper file:

    int updateBundleNameAndTimeZone(@Param("custId") String custId, 
@Param("bundle") BundleSummaryData bundle);

And here is the invocation:

    BossMapper mapper = session.getMapper(BossMapper.class);

    int iRowCount = mapper.updateBundleNameAndTimeZone(custId, bundle);
    if (iRowCount == 1) {
      session.commit();
    } else {
      session.rollback();
    }

This works fine; iRowCount is 1 after an update.

What doesn't compile for you?


>
> -- Chris Olsen
>
>
> Guy Rouillier-2 wrote:
>>
>> On 12/10/2009 11:51 AM, Chris Olsen wrote:
>>>
>>> Using the V3 Annotations and session.GetMapper trying to figure out if
>>> there
>>> is a way to figure out how many rows were updated.  I have seen some
>>> other
>>> posts that reference a way using some of the other methods but I can not
>>> find any docs for the Annotations methods or docs for the API's.  Any
>>> pointers greatly appreciated.
>>
>> The update methods (insert, update and delete) return a rowcount.  So use
>>
>>     int rowsUpdated = mapper.updateScript(script);
>>
>>>
>>>     Thanks - Chris Olsen
>>>
>>> Sample code:
>>>           try {
>>>               session = sqlMapper.openSession();
>>>               final ScriptMapper mapper =
>>> session.getMapper(ScriptMapper.class);
>>>               mapper.updateScript(script);
>>>               session.commit();
>>>           } catch(IbatisException ex) {
>>>               logger.log(Level.WARNING, "Unable to update script entry: "
>>> +
>>> script.getId(), ex);
>>>           }
>>>           finally {
>>>               if (session != null ) {
>>>                   session.close();
>>>               }
>>>           }
>>
>>
>> --
>> Guy Rouillier
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
>> For additional commands, e-mail: user-java-help@ibatis.apache.org
>>
>>
>>
>


-- 
Guy Rouillier

---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Re: Ibatis 3 Annotaion - Get # Rows updated

Posted by Chris Olsen <ch...@gmail.com>.
Guy,
  Using the 212 build that function returns a void and not an integer and
will not compile.
Thanks for the thought, any other places we might look?

-- Chris Olsen


Guy Rouillier-2 wrote:
> 
> On 12/10/2009 11:51 AM, Chris Olsen wrote:
>>
>> Using the V3 Annotations and session.GetMapper trying to figure out if
>> there
>> is a way to figure out how many rows were updated.  I have seen some
>> other
>> posts that reference a way using some of the other methods but I can not
>> find any docs for the Annotations methods or docs for the API's.  Any
>> pointers greatly appreciated.
> 
> The update methods (insert, update and delete) return a rowcount.  So use
> 
>    int rowsUpdated = mapper.updateScript(script);
> 
>>
>>    Thanks - Chris Olsen
>>
>> Sample code:
>>          try {
>>              session = sqlMapper.openSession();
>>              final ScriptMapper mapper =
>> session.getMapper(ScriptMapper.class);
>>              mapper.updateScript(script);
>>              session.commit();
>>          } catch(IbatisException ex) {
>>              logger.log(Level.WARNING, "Unable to update script entry: "
>> +
>> script.getId(), ex);
>>          }
>>          finally {
>>              if (session != null ) {
>>                  session.close();
>>              }
>>          }
> 
> 
> -- 
> Guy Rouillier
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-java-help@ibatis.apache.org
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/Ibatis-3-Annotaion---Get---Rows-updated-tp26730660p26733292.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Re: Ibatis 3 Annotaion - Get # Rows updated

Posted by Guy Rouillier <gu...@burntmail.com>.
On 12/10/2009 11:51 AM, Chris Olsen wrote:
>
> Using the V3 Annotations and session.GetMapper trying to figure out if there
> is a way to figure out how many rows were updated.  I have seen some other
> posts that reference a way using some of the other methods but I can not
> find any docs for the Annotations methods or docs for the API's.  Any
> pointers greatly appreciated.

The update methods (insert, update and delete) return a rowcount.  So use

   int rowsUpdated = mapper.updateScript(script);

>
>    Thanks - Chris Olsen
>
> Sample code:
>          try {
>              session = sqlMapper.openSession();
>              final ScriptMapper mapper =
> session.getMapper(ScriptMapper.class);
>              mapper.updateScript(script);
>              session.commit();
>          } catch(IbatisException ex) {
>              logger.log(Level.WARNING, "Unable to update script entry: " +
> script.getId(), ex);
>          }
>          finally {
>              if (session != null ) {
>                  session.close();
>              }
>          }


-- 
Guy Rouillier

---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org