I have the necessity for a client application to "lock" (aka "check-out" certain business entities store in the database.
The workflow is such that:
The user navigates to a page for some business object.
The user hits "edit".
This locks the item from being edited by anyone else.
Other users on other workstations will see a little "lock" icon by the item being edited and the "edit" button will be read-only.
Admin users may click a button to "force" unlocking the item.
Pretty standard, right? I've done this a bunch of times in the past and I'm looking for some thoughts on the "right" way of doing this this time...
Namely, I guess there are two approaches:
Have my business objects implement some ILockable interface which has a LockOwnerId property and have the corresponding table in the DB have that same LockOwnerId.
Have a centralized "EntityLocks" table in the DB that manages all entity-type/primary key pairs of entities that are currently locked/checked out.
As for the API for acquiring a lock, I'm simply thinking of something along the lines of a CheckOut method:
// Returns true if the check-out was successful,
// false if the check-out was not successful, becase the item was already locked. If
// force is set to true, will check out the toCheckOut to the current user, regardless
// of existing check-outs.
bool CheckOut(object toCheckOut, bool force)
Thoughts?
Thanks.