You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-cs@ibatis.apache.org by Ron Grabowski <ro...@yahoo.com> on 2007/04/20 06:12:23 UTC

Re: RE : iBatis.Net - Optimistic concurrency control

You can put the items in an IDictionary and pass that in:

ListDictionary parameters = new ListDictionary();
parameters["Employee"] = employee;
parameters["Timestamp"] = timestamp;
int rowsUpdated = sqlMapper.Update("Employee.Update", parameters);

<update id="UpdateEmployee">
UPDATE dbo.Employee 
SET FirstName = #Employee._firstNam#,
       LastName = #Employee._lastName#,
       SSN = #Employee._ssn#
WHERE EmployeId = #Employee._employeeId#
AND [Timestamp] = #Timestamp#
</update> 
 
----- Original Message ----
From: Philippe Peuret <ph...@neoxia.com>
To: user-cs@ibatis.apache.org
Sent: Thursday, April 19, 2007 8:20:40 AM
Subject: RE : iBatis.Net - Optimistic concurrency control

I agree with your two solutions, but each time, there is two diferrent parameter in the SQL query : the first parameter is the Object to update (with all its data) and the second parameter is the timestamp or a second object which contains data of the original object. So, how do you do to pass two parameters to the SQL query ?
 
In the examples below, you can see only one parameter for the current object "Employee" :
 
<update id="UpdateEmployee" parameterClass="Employee">
UPDATE dbo.Employee 
SET FirstName = #_firstNam#,
       LastName = #_lastName#,
       SSN = #_ssn#
WHERE EmployeId = #_employeeId#
AND [Timestamp] = #_timestamp#
</update> 
 
or
 
<update id="UpdateEmployee" parameterClass="Employee">

UPDATE dbo.Employee

SET FirstName = #_firstName#

            , LastName = #_lastName#

            , SSN = #_ssn#

WHERE FirstName = #OriginalObject._firstName#

            AND LastName = #OriginalObject._lastName#

            AND SSN = #OriginalObject._ssn#

</update>

 
________________________________

De: Henrik Uffe Jensen [mailto:huj@corewit.com]
Date: mer. 18-avr.-07 20:43
À: user-cs@ibatis.apache.org
Objet : Re: iBatis.Net - Optimistic concurrency control


Another solution :
 
Make timestamp column (SQL Server but probably similary data types in other databases). This column is automatically updated by
sql server each time the row is changed, so you know that if the timestamp column has changed since you pulled out the data then 
there is a concurrency violation. So in your updates / deletes you add [Timestamp] = #_timeStamp# to your where clause, for example
 
UPDATE dbo.Employee 
SET FirstName = #_firstNam#,
       LastName = #_lastName#,
       SSN = #_ssn#
WHERE EmployeId = #_employeeId#
AND [Timestamp] = #_timestamp#
   
You can then use the rows affected returned by the Delete/Update methods on the SqlMapper, and if it's 0 then at there is a concurrency
violation and you can throw an exception or whatever you do.
 
regards
 
Henrik Uffe Jensen

    ----- Original Message ----- 
    From: Nguyen, Tom <ma...@rels.info>  
    To: user-cs@ibatis.apache.org 
    Sent: Wednesday, April 18, 2007 8:04 PM
    Subject: RE: iBatis.Net - Optimistic concurrency control


    Unless I'm behind on my knowledge, I don't believe that iBatis.Net has automatic optimistic concurrency implementation.  You will have to implement this yourself.

     

    This is the pseudo of how I implemented mine:

    BusinessBase<T> : IClonable

    -Clone()

    -OriginalObject AS T

     

    Employee : BusinessBase<Employee>

    -SSN

    -FirstName

    -LastName

     

    1.    Retrieve Employee 
    2.    Clone Employee and store in OriginalObject 
    3.    Employee is parameter class of Update Ibatis Mapping 

     

    UPDATE dbo.Employee

    SET FirstName = #_firstName#

                , LastName = #_lastName#

                , SSN = #_ssn#

    WHERE FirstName = #OriginalObject._firstName#

                AND LastName = #OriginalObject._lastName#

                AND SSN = #OriginalObject._ssn#

     

     

    Unless you have build some kind of framework to do this, it is a lot of manual, repetitive work.  Only do it when you really need to.

     

    Regards,

    
    Tom Nguyen 
    Sr. Developer
    tom.nguyen@rels.info <ma...@rels.info> 
    
    

    
________________________________


    From: Philippe Peuret [mailto:philippe.peuret@neoxia.com] 
    Sent: Wednesday, April 18, 2007 7:20 AM
    To: user-cs@ibatis.apache.org
    Subject: TR: iBatis.Net - Optimistic concurrency control

     

    Hello,

     

    How to use the optimistic concurrency control when we update the database with iBatis.Net ?

    Because, when we use the <insert> or <update> elements, we can only pass one parameter : the object to insert or to update. But there is no other parameter to pass the data to the optimistic concurrency control.

     

    Thank you for your help.

    
________________________________


    

    This e-mail message and any files transmitted herewith, are intended solely for the use of the individual(s) addressed and may contain confidential, proprietary or privileged information.  If you are not the addressee indicated in this message (or responsible for delivery of this message to such person) you may not review, use, disclose or distribute this message or any files transmitted herewith.  If you receive this message in error, please contact the sender by reply e-mail and delete this message and all copies of it from your system. 

    
________________________________