on 12-17-2014 5:10 AM
What about multiple entities (e.g. Order x Items)? How can I add/set items to the parent entity?
As you stated, Deep Insert is not supported in Offline Mode. In this blog:
It says that this must be done with a batch call. Do you have any examples?
Could you help us? We are developing an Android Offline Application.
Thank you!
Best regards,
Rodrigo
Message was edited by: Michael Appleby
Hi Rodrigo,
Batch requests allow you to group multiple Odata requests into single HTTP request.
GET, POST, PUT, DELETE requests can be added to a batch request. You have to manage it from the device code.
Ex.
private static final String ODATA_BATCH_VERB = "$batch";
...
//Create the Batch Request
BatchRequest mBatchRequest = new BatchRequest(appEndPoint + ODATA_BATCH_VERB);
mBatchRequest.setListener(this);
mBatchRequest.setPriority(IRequest.PRIORITY_HIGH);
//Create the Batch Request
mBatchRequest.addRetrieveRequestToBatch(getRequest);
mBatchRequest.addRequestToChangeset(deleteRequest);
mBatchRequest.addRequestToChangeset(createRequest);
mBatchRequest.addRequestToChangeset(updateRequest);
//Close change Requests
mBatchRequest.closeExistingChangeSet();
//Execute the batch request
requestManager().makeRequest(mBatchRequest);
Regards,
Midhun VP
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Midhun VP,
In our scenario, 1 Header has many Line-Items. we have to post the header and line-items record in single request.
Like GenericList in SUP 2.X. For this scenario, Batch process is applicable? or how to solve this.
Regards,
Dinesh
Thanks Midhun VP, for your code snippet. Please keep in mind that this code does not use the offline store class. The SDK SP05 provides support for backward compatibility, so this code should work.
If you want to use the offline store SDK SP05+, a colleague, http://scn.sap.com/people/adam.hurst2 from SAP, pointed me to the following solution using the offline store.
// Create changeSet
ODataRequestChangeSet changeSetItem = new ODataRequestChangeSetDefaultImpl();
// Create the parent Entity
ODataEntity parentEntity = new ODataEntityDefaultImpl("something.Order");
parentEntity.getProperties().put("orderid", new ODataPropertyDefaultImpl("orderid", "1234"));
// Create parent item request
ODataRequestParamSingle req1 = new ODataRequestParamSingleDefaultImpl();
// Allocate parent Entity
req1.setResourcePath("Order");
req1.setMode(Mode.Create);
req1.setPayload(parentEntity);
//The contentID acts as a placeholder for address of the created entity.
//You can use it to address the new entity in subsequent requests in the same change set.
req1.setContentID("ID1");
//Note: headers may not be required... test with and without it in case of issues
Map<String, String> createHeaders = new HashMap<String, String>();
createHeaders.put("accept", "application/atom+xml");
createHeaders.put("content-type", "application/atom+xml");
req1.setOptions(createHeaders);
// Add request 1 to changeset
changeSetItem.add(req1);
// add the child item to the same changeset
ODataEntity childEntity = new ODataEntityDefaultImpl("something.OrderItems");
parentEntity.getProperties().put("orderitemid", new ODataPropertyDefaultImpl("orderitemid", "4321"));
// Create child item request
ODataRequestParamSingle req2 = new ODataRequestParamSingleDefaultImpl();
// Allocate child Entity
req2.setResourcePath("$ID1/OrderItems");
req2.setMode(Mode.Create);
req2.setPayload(childEntity);
req2.setOptions(createHeaders);
// Add request 2 to changeset
changeSetItem.add(req2);
// Add changeset to batch request
ODataRequestParamBatch requestParamBatch = new ODataRequestParamBatchDefaultImpl();
requestParamBatch.add(changeSetItem);
// Send batch request through the offline store
store.executeRequest(requestParamBatch);
For more information about the offline store visit
Best regards,
Claudia
User | Count |
---|---|
83 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.