This blog is about the locking concept in SAP Gateway odata for update deep method. As there are already many blogs on optimistic and pessimistic locking mechanism. And in Gateway Odata there are different ways to implement optimistic lock for concurrency control. below are the ways which I am trying to categorizing
1.) Using Timestamp for E-tag
2.) Using Hash for E-tag
3.) Making Soft State(state-full) service(which I believe is not a good approach as it will lose Rest architecture constraint of stateless, and service will consume more resources to maintain state.
4) Durable locks using CDS-BOPF concept.
Note: For beginners, there are blogs/SAP help out there which explains the locking concept using lock objects in SAP.
Here comes the issue with the UI Apps which consumes odata service, which will not persist the locks as the session will be closed after every request(REST is stateless).
For example, If we call a OData request to lock the sales order, the request will go to the backend by opening a session, locks the sales order and when the request is completed, the session will be closed and all the locks will be removed.
To persist above we can either make a soft-state or use optimistic lock.
And if we are not using BOPF then E-tag is the best option for the locking mechanism. So for any update, patch, merge or delete operation it works fine. Challenge comes in Update deep entity as in Odata there is no such operation called update deep entity method.
So to overcome this problem many projects use create deep entity for both purposes Create deep entity and update deep entity(If the key is there then update operation).
Now coming back to E-tag based on timestamp which again has two methods to implement in DPC class with below methods in DPC_EXT class —
1.) If we are using function import then this method need to redefine and implement—
GET_IS_CONDI_IMPLE_FOR_ACTION Get flag if conditional handling is done for function import
2.) if we are not using function import but normal entity set then below method—
GET_IS_CONDITIONAL_IMPLEMENTED Get flag if conditional handling is done by provider App
if update deep entity is there, then those scenarios are not covered with standard gateway odata as for creating deep entity or for create entity there is no locking mechanism(which is obvious).
So to solve this issue I created the custom E-tag in creating deep entity itself.
Below are the steps involve how to create custom E-tag
Step 1
There should be timestamp in entity, and that should be mandatorily updated for each update operation so we can compare the timestamp for optimistic lock.
And make that property as etag,
So if simple entity is there which were created using structure then just put the property name of timestamp as below image —
No comments:
Post a Comment