欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

SAP OData offline store在Android平台的技术实现 SAPSAP云平台SAP Cloud PlatformSAP成都研究院Cloud 

程序员文章站 2022-06-13 17:08:02
...

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

 

SAP OData offline store在Android平台的技术实现
            
    
    
        SAPSAP云平台SAP Cloud PlatformSAP成都研究院Cloud 

 

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.

 

SAP OData offline store在Android平台的技术实现
            
    
    
        SAPSAP云平台SAP Cloud PlatformSAP成都研究院Cloud 

 

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

 

SAP OData offline store在Android平台的技术实现
            
    
    
        SAPSAP云平台SAP Cloud PlatformSAP成都研究院Cloud 

 

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

 

SAP OData offline store在Android平台的技术实现
            
    
    
        SAPSAP云平台SAP Cloud PlatformSAP成都研究院Cloud 

 

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.

 

SAP OData offline store在Android平台的技术实现
            
    
    
        SAPSAP云平台SAP Cloud PlatformSAP成都研究院Cloud 

 

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

 

SAP OData offline store在Android平台的技术实现
            
    
    
        SAPSAP云平台SAP Cloud PlatformSAP成都研究院Cloud 

 

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

 

SAP OData offline store在Android平台的技术实现
            
    
    
        SAPSAP云平台SAP Cloud PlatformSAP成都研究院Cloud 

 

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

 

SAP OData offline store在Android平台的技术实现
            
    
    
        SAPSAP云平台SAP Cloud PlatformSAP成都研究院Cloud 

 

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

 

SAP OData offline store在Android平台的技术实现
            
    
    
        SAPSAP云平台SAP Cloud PlatformSAP成都研究院Cloud 

 

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

 

SAP OData offline store在Android平台的技术实现
            
    
    
        SAPSAP云平台SAP Cloud PlatformSAP成都研究院Cloud 

 

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

 

SAP OData offline store在Android平台的技术实现
            
    
    
        SAPSAP云平台SAP Cloud PlatformSAP成都研究院Cloud 

 

And open operation is started here:

 

SAP OData offline store在Android平台的技术实现
            
    
    
        SAPSAP云平台SAP Cloud PlatformSAP成都研究院Cloud 

 

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

 

SAP OData offline store在Android平台的技术实现
            
    
    
        SAPSAP云平台SAP Cloud PlatformSAP成都研究院Cloud 

 

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

 

SAP OData offline store在Android平台的技术实现
            
    
    
        SAPSAP云平台SAP Cloud PlatformSAP成都研究院Cloud 

 

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

 

SAP OData offline store在Android平台的技术实现
            
    
    
        SAPSAP云平台SAP Cloud PlatformSAP成都研究院Cloud 

 

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

 

SAP OData offline store在Android平台的技术实现
            
    
    
        SAPSAP云平台SAP Cloud PlatformSAP成都研究院Cloud 

 

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

 

SAP OData offline store在Android平台的技术实现
            
    
    
        SAPSAP云平台SAP Cloud PlatformSAP成都研究院Cloud 

 

要获取更多Jerry的原创文章,请关注公众号"汪子熙":

SAP OData offline store在Android平台的技术实现
            
    
    
        SAPSAP云平台SAP Cloud PlatformSAP成都研究院Cloud