The plugin is supported for use with applications on the Android and iOS platforms. The plugin provides the client with the ability to define offline stores for an OData producer. 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.
Offline plugin是保证我们offline application能运行的最核心的组件了。帮助文档上说:The Offline OData plugin provides a OData httpclient based on datajs, a cross-browser JavaScript library. Thehttpclient resolves requests with the Offline OData plugin if the service root of the request matches one of the open stores. The httpclient defaults to using the original OData.defaultHttpClient if the requests service root does not match any of the currently open stores.
根据帮助文档描述:Offline app运行在设备上时,每次发起odata request时,首先会检查该request是否能够通过设备的local DB取值,如果能,直接从设备的local DB取。
我看了这个文档就有两个问题:
对于第一个问题:
我们project的config.xml里声明了这个offline plugin的引用:
进入这个plugin的folder,会看到一个配置文件:
里面指定了这个plugin可直接供UI5 框架调用的OData.js和OfflineStore.js,以及JS直接访问Android device DB的Java文件:
回到之前的问题,plugin咋知道哪些url可以从local DB取,哪些url需要发到后台?
代码写得很清楚:在OData.js里,我们应用define的url会存在openStores里。在Js的request方法里,会逐一比较当前request url是否在offline store里定义过,
如果是,handle = true.
就进这个分支,通过odata.request call设备原生API访问local DB
否则call 默认的httprequest把请求发给后台:
那么js 又是如何call原生的Java API?通过exec。
在Android folder下有exec的实现代码:
这里写了,技术上来说:两种方式实现js call Java: