Tuesday, June 11, 2013

Apex Prevent Lost Updates with Checksum

So this post is more of a placeholder for my notes, than a truly educational resource. I suppose if you are looking for a barebones explanation of what is need to accomplish this task, then this may work.

So the issue is how to prevent lost updates when dealing with Apex pages. In other words, you read a page into your browser, and while you are making changes in the page, somebody else goes in and changes the database. If you proceed to save your changes, you could overwrite what somebody else has done, thus creating the phenomenon of lost updates.

So to handle this, store a checksum of all your page items as a hidden field on the page. You can use the following PL/SQL package to generate the checksum.

wwv_flow_item.MD5(pageitem1,pageitem2,...,pageitem50);

Now, when you go to save your data, generate another checksum and compare it to your saved checksum. If they are the same, then you are good to go. If they are different, you should raise an error and prompt the user to re-enter the data, first re-reading from the database.

No comments:

Post a Comment