coool
coool

Reputation: 8297

How to detect odata model change on server side before updating the changes

when the Update is being done by different users on the same entity at the same time, how to detect if that entity has been updated just before saving and prevent the second update from happening and push the new data to the second user.

Can e-tag be used?

Upvotes: 0

Views: 1057

Answers (2)

Ekansh Saxena
Ekansh Saxena

Reputation: 61

SAP Gateway doesn't support pessimistic locking (i.e. expecting someone else to edit the same document while someone else is already editing it) instead supports optimistic locking(i.e. does not expects someone else to edit at the same time) due to stateless nature of RESTful web services. So here are the options:

  1. Use etags as mentioned in pguddi's answer
  2. custom functionality to have a lastUpdate timestamp property which UI receives while reading the entity and send back while update request, backend matches with the lastUpdated timestamp and raises exception if the record is already updated in backend else goes ahead
  3. If you are using CDS view and BOPF based OData service, then there is some kind of pessimistic locking supported. Details can be found here https://blogs.sap.com/2019/01/25/locking-the-gui-apps-from-the-fioriui5-has-never-been-so-easier-via-the-durable-locks-for-abap-programming-model-for-fiori/

Upvotes: 0

pguddi
pguddi

Reputation: 345

Yes, that is exactly what etags are for. In case it is SAP Gateway as a backend, there is already support there and in the ODataModel in SAPUI5, so just need to send the etag to the client and validate it (on the server) when an update is made. If it has been changed in the mean time, an error will be sent to the client informing him that the entity has been changed since he loaded it (HTTP status 412).

Upvotes: 0

Related Questions