The locking code is supposed to be within that Data class. This means that when a record is locked ( lock(recNo) is called) no other client except the one that invoked the lock() is allowed to update/delete this record.
The question is how can I check in the update() and delete() methods who the client is?
Which raises 2 scenarios :
The stand-alone application, when we would like to reuse the code from the Data class. I would like to avoid passing a parameter to the Data class specifying whether we are in stand-alone mode. We lock a record, and we try to update it. When performing the update, the code checks to see whether that record is locked and is available for this client. How can he do that as in a stand-alone context we only have one client and cannot hold a Map<cliendId,recordId> or something of that kind...
The code in the business layer would be :
The code in the persistence layer would be :
and the second scenario, when running in server mode