ibatis-user-cs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Anderson" <agcu...@superig.com.br>
Subject ENC: Concurrency control using optimistic locking. The best way and how to implement...
Date Wed, 13 Jul 2005 00:07:57 GMT


-----Mensagem original-----
De: Ron Grabowski [mailto:rongrabowski@yahoo.com] 
Enviada em: terça-feira, 12 de julho de 2005 18:57
Para: agcunha
Assunto: Re: Concurrency control using optimistic locking. The best way and
how to implement...

http://www.mail-archive.com/ibatis-user-cs@incubator.apache.org/msg00455.htm
l

Gilles' suggestion of having a Version column on your table may be a
simple solution.

You may be able to use this:

http://www.tek-tips.com/faqs.cfm?fid=761

to return the number of rows affected by the UPDATE statement. 

I'm sure other people on the list would be interested in this
discussion. You may want to forward my response to the list and
continue the conversation there.

- Ron

--- agcunha <agcunha@superig.com.br> wrote:


---------------------------------
 
Thanks Ron,

Now I know How to  implement the optimistic locking in my application.
 
But I still have a question :-)

I made the stored procedure above on SQL Server:

CREATE PROCEDURE dbo.[ps_updateAccount]
@Account_ID [int],
@FirstName varchar(32),
@LastName varchar(32),
@Email varchar(128),
@BannerOption varchar(255),
@CartOption [int],
@lastUpdate datetime
AS

DECLARE @AccountID int
DECLARE @V_DAT_ATUALIZACAO datetime;

declare @cur_account cursor

set @cur_account = cursor for
SELECT 
Account_ID
FROM
ACCOUNTS
where 
Account_ID=@Account_ID
and lastupdate = @lastUpdate
for update

open @cur_account

IF Cursor_Status('variable', '@cur_account') = 1 
begin

FETCH NEXT FROM @cur_account

WHILE @@Fetch_Status != -1
BEGIN

set @V_DAT_ATUALIZACAO = GetDate()
UPDATE ACCOUNTS SET Account_FirstName = @FirstName,
Account_LastName = @LastName,
Account_Email = @Email,
Account_Banner_Option = @BannerOption,
Account_Cart_Option = @CartOption,
lastupdate = @V_DAT_ATUALIZACAO 
WHERE CURRENT OF @cur_account

FETCH NEXT FROM @cur_account
end
end
else 
begin
set @V_DAT_ATUALIZACAO = NULL;
end

close @cur_account
deallocate @cur_account


I made somes unit tests on nUnit to test concurrency. I could see that
there is a code block on Update method of the SqlMapper class that is
commented.

 
// // check that statement affected a row
 
// if( rows == 0 )
 
// {
 
// // throw concurrency error if no record was affected
 
// throw new ConcurrentException();
 
// }
 
This code block is necessary to test concurrency and I saw that iBatis
users had some problems with it on making record changes.
 
I suggest to make an overload of this method to support Optimistic
Locking. Like this:
 
public int Update(string statementName, object parameterObject, bool
useOptimisticLocking)
 
This method will have the code that throws the exception uncommented.
 
What about?
 
Do you know where I can find the commented ConcurrentException class?
 
Thanks a lot,
 
Anderson
  








Mime
View raw message