on 09-16-2020 7:40 AM
Hi,
We're looking into creating a batch update to our on-prem SAP servive from the cloud. We're using the Odata gateway, cloud connector etc. Our java app is deployed on SAP CloudFoundry and reading data with the cloud sdk for java works fine.
Now we need to start updating data and want to do that with a odata batch update. I've been looking into the docs and blog posts, but I cannot find any good java code examples on this.
Can someone provide a good example on how to use the cloud SDK for java on batch updates?
Thanks,
Danny
We are aware that a documentation or a tutorial is missing and have that on the radar.
In the meantime, hereafter is a brief outline of invoking batch requests with the OData VDM. I'll use the Business Partner OData API to demonstrate the usage.
final BusinessPartnerService service = new DefaultBusinessPartnerService();
final HttpDestination destination = obtainHttpDestination();
final BusinessPartnerAddress address1 = createBusinessPartnerAddress();
final BusinessPartnerAddress address2 = createBusinessPartnerAddress();
final BatchResponse result =
service
.batch()
.beginChangeSet()
.createBusinessPartnerAddress(address1)
.createBusinessPartnerAddress(address2)
.endChangeSet()
.executeRequest(destination);
final Try<BatchResponseChangeSet> changeSetTry = result.get(0);
//error handling can be made with the Try type, like Try#isSuccess
if (changeSetTry.isSucces()) {
//now you can access the created entities
final List<VdmEntity<?>> createdEntities = changeSet.get().getCreatedEntities();
}
Kindly follow-up with additional replies to refine your question if my response does not help you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks,
I'll try this out later today and get back on the results.
One thing I'm wondering about, is that this is based on the generated typed client (using the odata-generator-cli).
Is there a more generalized ("low level") way of using the SDK without having the dependency on a generated client
Something like:
final Dienst dienst0 = Dienst.builder().build(); //own object, not generated from odata EDMX
final ServiceProps props = getServiceProps();
final ODataUpdateRequest updateRequest = ODataUpdateRequestBuilder
.withEntity(props.getName(), props.getEntitySet(), )
.withBodyAs(dienst0)
.build();
ChangeSetBuilder builder = ChangeSetBuilder.getInstance();
final ChangeSet set = builder.addUpdateRequest(updateRequest).build();
final BatchRequest batchReq = BatchRequestBuilder.withService("odata/ZCU_PE_ORDER_SRV")
.addChangeSet(set)
.build();
BatchResult result = batchReq
.execute(props.getDestination());
Here is the code snippet you might find useful:
final Try<BatchResponseChangeSet> changeSetTry = result.get(0);
//error handling can be made with the Try type, like Try#isSuccess
if (changeSetTry.isSucces()) {
//now you can access the created entities
final List<VdmEntity<?>> createdEntities = changeSetTry.get().getCreatedEntities();
Kindly open a new question on Stackoverflow: https://stackoverflow.com/questions/tagged/sap-cloud-sdk
Please provide all relevant details such as your full code snippet, the SAP Cloud SDK version you use (please use always the latest version) and share the full stack trace with us.
The provided error message is insufficient to provide you a solution.
User | Count |
---|---|
84 | |
11 | |
10 | |
8 | |
8 | |
6 | |
6 | |
6 | |
6 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.