打开Android studio,在工程的build.gradle里加入下面的依赖,导入SAP OData offline库:
implementation group:'com.sap.cloud.android', name:'offline-odata', version: sdkVersion
点击Sync now:
新建一个java文件:SAPServiceManager.java
使用的import如下:
import android.content.Context;
import android.util.Log;
import android.widget.Toast;
import com.sap.cloud.mobile.odata.core.AndroidSystem;
import com.sap.cloud.mobile.odata.offline.OfflineODataDefiningQuery;
import com.sap.cloud.mobile.odata.offline.OfflineODataException;
import com.sap.cloud.mobile.odata.offline.OfflineODataParameters;
import com.sap.cloud.mobile.odata.offline.OfflineODataProvider;
import java.net.MalformedURLException;
import java.net.URL;
// 将OfflineODataProvider注释掉,改为OfflineODataProvider
//private OnlineODataProvider provider;
private OfflineODataProvider provider;
private static final String TAG = SAPServiceManager.class.getName();
OData offiline datastore的setup方法:
public void openODataStore(Action0 callback, Context context) {
setupOfflineOData(callback, context);
}
private void setupOfflineOData(Action0 callback, Context context) {
try {
if (configurationData.loadData()) {
Toast.makeText(context, "Opening the offline store which may take a few moments the first time it is opened.", Toast.LENGTH_LONG).show();
//Initialize application context for use by OfflineODataProvider
AndroidSystem.setContext(context);
//commonly set parameters include setStoreEncryptionKey, setStoreName, setStorePath
OfflineODataParameters offParam = new OfflineODataParameters();
String serviceUrl = configurationData.getServiceUrl();
URL url = new URL(serviceUrl + CONNECTION_ID_ESPMCONTAINER);
provider = new OfflineODataProvider(url, offParam, ClientProvider.get());
//Specifies which entities we wish to include in the offline store
provider.addDefiningQuery(new OfflineODataDefiningQuery("Customers", "Customers", false));
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (OfflineODataException e) {
e.printStackTrace();
}
//opens the offline store. This can take a minute or so the first time it is called as it is created and populated.
Log.d(TAG, "About to call open on the offline store.");
provider.open(() -> {
Log.d(TAG, "Offline store opened.");
eSPMContainer = new ESPMContainer(provider);
callback.call();
syncOfflineData(); //TODO could be triggered via a menu action
}, (OfflineODataException offlineODataException) -> {
Log.d(TAG, "Offline store did not open.", offlineODataException);
});
}
public void syncOfflineData() {
//send the local changes to the back end OData service
Log.d(TAG, "About to call provider.upload.");
provider.upload(() -> {
Log.d(TAG, "Successfully uploaded the changed data.");
//get changes from the back end OData service.
provider.download(() -> {
Log.d(TAG, "Successfully downloaded the changed data.");
}, (error) -> {
Log.d(TAG, "Failed when downloading the changed data with error: " + error.getMessage());
});
}, (error) -> {
Log.d(TAG, "Failed when uploading the changed data with error: " + error.getMessage());
});
}
public String getServiceRoot() {
if (configurationData.loadData()) {
String serviceUrl = configurationData.getServiceUrl();
if (serviceRoot == null) {
serviceRoot = serviceUrl + "/" + CONNECTION_ID_ESPMCONTAINER;
}
}
else {
throw new IllegalStateException("SAPService manager configurationData.loadData() failed.");
}
return serviceRoot;
}
新建LogonActivity.java,调用之前实现的sapServiceManager.openODataStore:
第一次运行应用,会发现offline OData store的初始化日志:
现在可以测试离线模式了,打开移动设备的飞行模式:
选择存储于OData offline store上的某个客户,点击编辑按钮:
修改city字段:
关闭该应用,关闭设备的飞行模式,再启动该应用,在logcat里能观察到之前处于离线模式修改的数据已经自动同步到了后台online store里:
相关推荐
JAVA调用SAP ODATA服务.docx
解决方法:要先用GET方法从去调用ODATA中GET_ENTIY方法,例如:http://vhcals4h.com:44301/sap/opu/odata/sap/ztest_srv/HEADERSet('5000000001'),然后再将返回内容作为表身,传到ENTITYSET地址,如:...
SAP UI5作为前端开发框架,使用SAP Gataway开发后端OData Service
SAP ODATA ABAP开发教程
SAP Fiori OData Services. OData is used to define best practices that are required to build and consume RESTful APIs. It helps you to find out changes, defining functions for reusable procedures and ...
SapAPI 该程序正在读取SAP API。 此API从防火墙后面的SAP ECC系统公开ODATA。 需要一个天蓝色的AD帐户,一个SAP-id,包括访问SAP系统中技术角色的权限。 SAP API已在Azure API管理中注册。
SAP-odata文档
简单实现OData的一个demo,测试odata的api。$expand、 $filter、$inlinecount、$orderby 、$select、$skip、$top
SAP 后台ODATA开发步骤,供初学者参考!
SAP Gateway and OData, SAP低代码开发必备
SAP OData Framework 3.0 英文资料
Tutorial to Develop a SAPUI5 Application with oData Access.sap ui5使用odata进行数据的交互
SAP ODATA Training Agenda • Session 1: Introduction to SAPUI5 / FIORI (40 mins) ▫ Basic MVC concept: Model, View, Controller ▫ UI5 Control libraries • Session 2: Introduction to SAP Web IDE (20 ...
SAP-Fiori---快速指南
SAP OData Training Agenda • Session 1: Introduction to REST (20 mins) • Session 2: Introduction to OData Service (40 mins) • Hands on 1: Build your 1 st OData Service (60 mins) ▫ Transaction: SEGW...
OData库(Java)是使开发人员能够实现OData生产者和OData消费者的库,并且遵循以下原则: 提供符合OData 2.0规范的OData库(Java) 增强应该以兼容的方式进行 核心与API之间的清晰区分 选择在顶部构建扩展 更多...
SAPUI5-OData-V4 创建SAPUI5应用程序是为了学习,特别是为了了解如何访问,修改,聚合和过滤OData V4模型中的数据。
ABAP odata deep 例子如何实现
NULL 博文链接:https://milker.iteye.com/blog/1557722
Gateway最Unit 1: SAP Gateway Overview 3 Lesson: Explaining SAP Gateway 11 Lesson: Describing SAP Gateway Deployment Options 27 Unit 2: OData Overview 29 Lesson: Explaining Representational State ...