All my of dao classes extend this class:
http://tinyurl.com/8uks6
http://svn.apache.org/repos/asf/ibatis/trunk/cs/npetshop/NPetshop.Persistence/MapperDao/BaseSqlMapDao.cs
You could make an overload for update that looks like this:
protected int ExecuteUpdate(string s, object arg, bool optLocking)
{
int itemsUpdated = ExecuteUpdate(s, arg);
if (optLocking && itemsUpdated == 0)
{
throw new ConcurrentException();
}
return itemsUpdated;
}
Where ConcurrentException is an exception in your persistence layer.
--- Anderson <[EMAIL PROTECTED]> wrote:
> I can see it's implemented on nHibernate.
> The problem is I'm using the iBatis mapper in my application.
> As you can see, I added a field for versioning: lastupdate datetime
> in each
> table of my app.
> But the update method has to throw an exception if no rows were
> updated...
>
> I'll try to implement it based on nHibernate and I'll send again.
>
> Thanks
>
> -----Mensagem original-----
> De: Ron Grabowski [mailto:[EMAIL PROTECTED]
> 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/[email protected]/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 <[EMAIL PROTECTED]> 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
> [EMAIL PROTECTED]
> 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
>
>
>
>
>
>
>
>
>