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 
  To: [email protected] 
  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
  [EMAIL PROTECTED]




------------------------------------------------------------------------------

  From: Philippe Peuret [mailto:[EMAIL PROTECTED] 
  Sent: Wednesday, April 18, 2007 7:20 AM
  To: [email protected]
  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. 



------------------------------------------------------------------------------


Reply via email to