Skip to Content

I found no end-to-end example “How to use eTag based locking”. So implement a simple prototype which a share to you.

My question : Is there a better way to handle the eTag on the client side as is describe below ?

Definiton


Locking :  Ensure that a user don’t change already updated data.

Prototypscenario

/wp-content/uploads/2016/01/prototypescenario_876792.gif

Backend implementation

1. Persistence and Datatypes

1.1. Table

/wp-content/uploads/2016/01/table_876793.gif

1.2. Source structure for SAP Gateway Service generation

/wp-content/uploads/2016/01/structure_876806.gif

SAP Gateway Definition

The OData Service definition is strate foreward only the ETag Property definition is special.

etag definition.gif

As you see: The service has only four attributes and LastChanged is the Timestamp updated during updates on the given record.

SAP Gateway Implementation


Four methods are implemented:

….._get_entityset : Return all employees

/wp-content/uploads/2016/01/get_entity_set_876994.gif

……_get_entity : Return given employee

/wp-content/uploads/2016/01/get_entoty_876998.gif

….._update_entity : Update given employee

/wp-content/uploads/2016/01/update_entity_877000.gif

In the update method a new timestamp is calculated and written to db and send back to SAP Gateway framework.

….._create_entity : Create employee entry

/wp-content/uploads/2016/01/create_entry_877001.gif

How ETag works in SAP Gateway ?

The Response of a GET (Entity or EntitySet) contain for each object the etag property . In this prototype this is assigned to the LastChanged attribute.

/wp-content/uploads/2016/01/get_entity_test_877003.gif

/wp-content/uploads/2016/01/create_876955.gif

If you send now a Update or DeleteRequest with the needed etag the following happens:

  1. SAP Gateway call the ….._get_entity method and read the attribute bound to the eTag Property.
  2. SAP Gateway compare the eTag given in the Request with the eTag returned from the ….._get_entity method.
  3. If both eTags are equal the …._update_entity method will called within this method the attribute bound to the eTag Property will set to a new value and the new value is given back to the caller.

If both eTags are not equal (Data changed between read and update) an exeption will returned to the caller.

process flow.gif

In the screenshot below you see the eTag provided in the Request and the new eTag after the update.

/wp-content/uploads/2016/01/update_gwclient_877015.gif

Below the Status_code 412 if you try to change changed data.

/wp-content/uploads/2016/01/fail_877016.gif

Frontend Implementation

The frontend implementation is a strate foreward implementation.

  1. onInit function

onInit.gif

Bind the OData Entity to the Overview Table

  1. onRow function

onRow.gif

Called if the user select a row to change the data and bind the element to a simpleform to change the data.

  1. onUpdate function

/wp-content/uploads/2016/01/update_877026.gif

Called to send the updated data to the backend and  set the eTag in the request.

Question : Is there a better way to get the etag  ??


I only found it within the object in the __metadata object.

Javascript.gif

I you have any question or you have a better way to get the etag on client side etc. please send a comment.

Kind regards,

Gerald

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply