Question

I want to implement row locking for jQGrid edits. Since my back end uses JDBC, I am thinking of using optimistic locking on the back end and if the lock is not obtained, then displaying an error message on the grid.

Is this the best way to do it or is there a better alternative? Is it possible to lock the row on the grid itself such that no other user (on a different system and browser) can edit a particular row while it is being edited ?

Please help.

Thanks

Was it helpful?

Solution

I'm not JDBC developer. There are some common principals how one can implement concurrency control. One from the ways is optimistic concurrency control. There are many implementation examples of such concurrency.

Because I work mostly with Microsoft SQL Server I use always the way with binary timestamp value saved in every row of tables of the database. I add in every table a column of non-nulable rowversion type which is semantically equivalent to a binary(8) type. The main advantage is that one don't need fill the column manually. SQL Server hold a counter associated with the database. On every row insert or row update in any database table the column having rowversion will be assigned to the current value of the counter. After that the counter will be incremented. In the way one have "timestemp" of the row. If some modification take place with the row then one have increased value in the column having rowversion type. So to implement optimistic concurrency one need just extend every jqGrid table with additional hidden column which hold the rowversion value. If one need to modify the data I send the value of the hidden rowversion column to the server together with modified data. The request for modification should be interpreted in the following way: I get the data with the rowversion value and modified it to new value. My server code need to validate before making the changes whether the content of the data in the database still corresponds to the same rowversion value. If it's so then the data are not changed by other user and one can safe do the modification. If the value of rowversion is now higher then the server should return back to jqGrid error message about concurrency error. It's recommended to reload the grid with current data.

For more information about the implementation you can read the answer and this old one.

I am not sure that you can use the describe above approach directly, because you use JDBC, but I think that the main idea of the implementation could be the same.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top