Skip to Content
Author's profile photo Jerry Wang

How is OData offline store opened in Android platform

I am studying Kapsel OData offline plugin recently. In SAP help the source code of OData.js is provided:

/wp-content/uploads/2016/08/clipboard1_1009443.png

The source code clearly conveys the idea documented in SAP help: “When an offline store is first opened, it synchronizes with the OData producer. OData requests made against this plugin use the available open offline stores.“.

And I am curious how this offline store is opened in the real application. So I use a CRM Fiori offline application to have a look.

1. In offline project folder there is a config.xml, which defines the entry point for offline application access, the index.html file.

/wp-content/uploads/2016/08/clipboard2_1009444.png

2. Open this index.html, there is a script file “createStores.js”:

/wp-content/uploads/2016/08/clipboard3_1009448.png

This file has constructed an object sap.smp.registration:

/wp-content/uploads/2016/08/clipboard4_1009449.png

There is a public method setup exposed which accepts an array for offline store collection and call a private method _setupStore one by one. Once the asynchronous setup process is done successfully, callback success is called.

/wp-content/uploads/2016/08/clipboard5_1009451.png

In implementation of _setupStore, the sap.OData.createOfflineStore(properties) and sap.OData.applyHttpClient() mentioned in sap help could be found.

/wp-content/uploads/2016/08/clipboard6_1009452.png

3. back to index.html, there is a file contentplace.js:

/wp-content/uploads/2016/08/clipboard7_1009453.png

In this file, offline store will be opened in line 14, and application specific initialization is called in callback function defined in line 5.

/wp-content/uploads/2016/08/clipboard8_1009454.png

4. finally, the createContentPlaceFunction is called in index.html in line 196:

/wp-content/uploads/2016/08/clipboard9_1009455.png

5. Now check how OfflineStore open is implemented in Android platform via Java:

/wp-content/uploads/2016/08/clipboard10_1009456.png

In line 215, offline store instance is created and a listener is registered, since open operation is done asynchronously:

/wp-content/uploads/2016/08/clipboard11_1009457.png

And open operation is started here:

/wp-content/uploads/2016/08/clipboard12_1009458.png

Check in ODataOfflineStore class, a new thread is created to perform open action:

/wp-content/uploads/2016/08/clipboard13_1009459.png

In run method, the call is delegated back to ODataOfflineStore.openStoreSync:

/wp-content/uploads/2016/08/clipboard14_1009460.png

The core open operation is done in this.store.open:

/wp-content/uploads/2016/08/clipboard15_1009461.png

If open is done successfully, the listener registered in ODataOfflineStore instance will be notified with ODataOfflineStoreOpen state:

/wp-content/uploads/2016/08/clipboard16_1009462.png

The core implementation of open method in Store class is implemented natively and could not be visible in Java stack:

/wp-content/uploads/2016/08/clipboard17_1009463.png

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.