locking - How to don incremental multi user updates with NHibernate -


I am using nhibernate as my orm and I'm trying to implement something that is easy Appears, but has become unsuccessful as it concerns how to implement a concurrent update of an entity, where it is expected that the unit will be updated simultaneously in a multi-disciplinary scenario by more than one user. An entity is an account with a balance of which

An example is an inventory system that requires the balance of inventory items to be updated, which is either inside or outside the movement entries. I have included a short version of the code below. I code only saves insertion and relies on the netnet which saves all the way to the item in cascade.

The system is expected to handle many users, the objects are built in the UI during the period of time. The balance of each item will be adjusted in quantity when the entry was made in the UI and the object was received. Ultimately saving the user can take several minutes.

If another user has created other entries on the same item, then the rest of the user that is working is no longer illegal. I know that if attempted to save, NHibernate has a stale data Throw an exception but it is not what I want because concurrent updates are an accomplishment. What I want is that the current balance of the object increases or becomes necessary according to the amount of admission. Or is it that the item is brought again during the update, locked, recalculated one and then finally updated, but I do not know how to achieve this in this scenario and where the code remains. By controlling pessimistic locking etc. I would like to avoid having it in domain object / an application / firmness concern. It seems that this should be a normal scenario, but I have not discussed anything on this.

PS I am worried about this matter as to how refact-lock-recalculated-update approaches I have mentioned above where there are many lines in an entry for different lock requests for each item Or one way to get the locks for all items of entries in a way.

Any help would be appreciated.

  Class Test Consultant Updates {Isation Session; Entry entry; Mothership items replay; Entry repository entry; Zero testing method () {... login entry = new login (); Item Item 1 = Item Response Go (item1id); Item Item 2 = Item Replayy Go (item1id); Item Item 3 = Item Response Gate (item 1 aid); Entry.lines Add (New Entryline (this, Item 1, 10)); Entry.lines Add (New Entryline (this, Item 2, -4)); Entry.lines. Add (new entryline (this, item 3, 2)); (Using ITRansaction transaction = session.BeginTransaction ()) {entryRep.Save (entry); Transaction.Commit (); }}} Item {string name; Double balance; IList & LT; EntryLine & gt; Entries = new list & lt; EntryLine & gt; (); Public Double getBalance () {Return Balance; } Zero addEntryLine (entry line) {entries.add (line); Balance + = line.Greativeness (); }} Class entry {IList & lt; EntryLine & gt; Line = new list & lt; Entryline & gt; (); Public IList & lt; EntryLine & gt; Lines {Get return lines; }}} Class entry {login entry; Double volume; Item items; Public entry (entry entry, item item, double volume) {this.entry = entry; This.quantity = Quantity; This.item = item; Item.addEntryLine (this); } Public Double Hoquity () {Return Amount; }}  


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -