Show TOC

Locking Business ObjectsLocate this document in the navigation structure

Use

By implementing the logical lock mechanism in business objects, you can lock and unlock a business object with the options provided by Application Server Java Locking Concept.

The mechanism provided by CAF includes a built-in exclusive-cumulative lock for delete and update operations only. All other locks are the responsibility of the application developer.

As a result, the system prevents all concurrent updates and deletions. You have the flexibility to use a shared lock for a particular business object and be sure that nobody else can change or delete it.

More information: Working with the LogicalLocking API

Implementation

The methods exposed by business object local interface look like those provided by standard enqueue server. The difference is that neither lifetime nor name are expected to be passed.

The only parameter that makes a lock unique is the argument parameter, which is meant to be the business object key. The mode parameter is expected to be one of the constants defined in com.sap.caf.rt.bol.IBusinessObjectNodeServiceBase :

  • MODE_READ the same as the LogicalLocking.MODE_SHARED
  • MODE_WRITE the same as the LogicalLocking.MODE_EXCLUSIVE_CUMULATIVE
  • More information: Locks
Example

The code sample below shows an example of using the lock mechanism:

Customer customer = ...;  // A business object node instance.
CustomerServiceLocal customerService = ...; // The BO node service.
try{
  /* try to obtain a shared lock for the business object node instance */
   customerService.lock(customer.getKey(), IBusinessObjectNodeServiceBase.MODE_READ);
  try{
  /* now other thread can modify the instance */
  
}finally{
  /* release the lock */
   customerService.unlock(customer.getKey(), IBusinessObjectNodeServiceBase.MODE_READ);
}
}catch(CAFPessimisticLockException e) {
   //…

}