Concurency handling

Posts   
 
    
methodman
User
Posts: 194
Joined: 24-Aug-2009
# Posted on: 07-Dec-2009 09:36:03   

Hello there.

Like in every application I need to somehow implement concurency handling. I would like to implement the "First Save Wins" concurency model. I dont have a timestap column on my tables.

Something like:


            AnalitikaEntity analitikaEntity = new AnalitikaEntity("51200");
            AnalitikaEntity analitikaEntity2 = new AnalitikaEntity("51200");
        
            adapter.FetchEntity(analitikaEntity);
            adapter.FetchEntity(analitikaEntity2);

            analitikaEntity2.Norma = 1;

            adapter.SaveEntity(analitikaEntity2);

            analitikaEntity.Norma = 2;

            // now would pop an exception !!
            adapter.SaveEntity(analitikaEntity);
        

Can I use for this any LLBLGen classes or do I have to implement it on my own ? I read something about IConcurrencyPredicateFactory at Frans blog. But if I do understand it right,this is usable only in the timestapvalue case. Or am I wrong ?

I'm using the adapter aproach.

Walaa avatar
Walaa
Support Team
Posts: 14983
Joined: 21-Aug-2005
# Posted on: 07-Dec-2009 10:12:26   

You should have a field for concurrency control. Be it a timestamp field, a numeric version field, whatever gets updated when a user updates the entity.

methodman
User
Posts: 194
Joined: 24-Aug-2009
# Posted on: 07-Dec-2009 10:20:31   

Its a legacy database. We cant add new fields.

Walaa avatar
Walaa
Support Team
Posts: 14983
Joined: 21-Aug-2005
# Posted on: 07-Dec-2009 10:58:23   

Then you should find a way to store the concurrency information. Maybe a memory dctionary to old IDs vs timestamp or something like that.

methodman
User
Posts: 194
Joined: 24-Aug-2009
# Posted on: 07-Dec-2009 11:21:15   

I know that, but can i use for the processing the IConcurrencyPredicateFactory interface ? Or works it only with timestamp values ?

Walaa avatar
Walaa
Support Team
Posts: 14983
Joined: 21-Aug-2005
# Posted on: 07-Dec-2009 14:34:37   

The predicate is useful to check a value in the entity with a database value. Cause it's a predicate at the end of the day and all it does is append some filter to the Update statement.

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 07-Dec-2009 15:24:23   

The usual method if you do not have a timestamp field available is to cache/remember all of the field values that you loaded from the database, and compare them to the values in the database at the time you come to do your update - if anything has changed then you know the record has been modified underneath you.

Matt