Batch Calls - V1 and V2 - Read Example
V2 - class sap.ui.model.odata.v2.ODataModel
onAfterOpen: function (param) {
var oModel = this.getOwnerComponent().getModel();
oModel.setDeferredGroups(["batchget"]);
oModel.setUseBatch(true);
oModel.read("/DocumentPartnerFunctionSet", {
filters: [new Filter("DocumentNumber", sap.ui.model.FilterOperator.EQ, this.oDocNumber)],
groupId: "batchget",
changeSetId: "batchget",
success: function (oResponse) {
var oPFModel = new JSONModel(oResponse.results);
oPFModel.setSizeLimit(oResponse.results.length);
sap.ui.core.Fragment.byId("idRDialog", "idPFMCBR").setModel(oPFModel);
var convTo = this.getView().getModel().getData()[0].ConvPartFuncTo;
var newarray = convTo.split(";");
sap.ui.core.Fragment.byId("idRDialog", "idPFMCBR").setSelectedKeys(newarray);
sap.ui.core.BusyIndicator.hide();
}.bind(this),
error: function (oError) {
this.showReadWriteErrors(oError);
sap.ui.core.BusyIndicator.hide();
}.bind(this)
});
oModel.read("/ConversationReasonCodesSet", {
groupId: "batchget",
changeSetId: "batchget",
success: function (oResponse) {
var oRCModel = new JSONModel(oResponse.results);
oRCModel.setSizeLimit(oResponse.results.length);
sap.ui.core.Fragment.byId("idRDialog", "idRCMCBR").setModel(oRCModel);
//var reasonCodes = this.getView().getModel("docNumModel").getproperty("/ConvReasonCode")[0];
var reasonCodes = this.getView().getModel().getData()[0].ConvReasonCode;
var newarray = reasonCodes.split(";");
sap.ui.core.Fragment.byId("idRDialog", "idRCMCBR").setSelectedKeys(newarray);
sap.ui.core.BusyIndicator.hide();
}.bind(this),
error: function (oError) {
this.showReadWriteErrors(oError);
sap.ui.core.BusyIndicator.hide();
}.bind(this)
});
oModel.submitChanges({
groupId: "batchget",
changeSetId: "batchget",
success: function (data, response) {
oModel.setUseBatch(false);
},
error: function (e) {
oModel.setUseBatch(false);
}
});
},
Changeset related methods are supposed to be triggered only for Create, Update, Delete related operations and read requests related methods will be called separately even though they are in the same batch request.--- this is wr.t Odata.
class sap.ui.model.odata.ODataModel
Batch Processing
The v2.ODataModel
supports batch processing ($batch
) in two different ways:
Default: All requests in a thread are collected and bundled in batch requests, meaning that request is sent in a timeout immediately after the current call stack is finished. This includes all manual CRUD requests as well as requests triggered by a binding.
Deferred: The requests are stored and can be submitted with a manual
submitChanges()
call by the application. This also includes all manual CRUD requests as well as requests triggered by a binding.
The model cannot decide how to bundle the requests. For this, SAPUI5 provides the groupId
. For each Context and List Binding and each manual request, a groupId
can be specified. All requests belonging to the same group are bundled into one batch request. Request without a groupId
are bundled in the default batch group. You can use a changeSetId
for changes. The same principle applies: Each change belonging to the same changeSetId
is bundled into one changeSet
in the batch request. Per default, all changes have their own changeSet
.
You can use the setDeferredGroups()
method to set a subset of previously defined groups to deferred.
The same is also valid for setChangeGroups()
and getChangeGroups()
.
group
are then stored in a request queue. The deferred batch group must then be submitted manually by means of the submitChanges()
method. If you do not specify a batch group ID when calling submitChanges
, all deferred batch groups are submitted.Set a subset of groups to deferred:
// "ODataModel" required from module "sap/ui/model/odata/v2/ODataModel" var oModel = new ODataModel(myServiceUrl);
Pass the groupId
to a binding:
{path:"/myEntities", parameters: {groupId: "myId"}}
Set the groupId
to deferred:
- Get the list of deferred groups:
var aDeferredGroups = oModel.getDeferredGroups();
- Append your
groupId
to the list:aDeferredGroups=aDeferredGroups.concat(["myId"]);
- Set all groups to deferred:
oModel.setDeferredGroups(aDeferredGroups);
Submit all deferred groups:
oModel.submitChanges({success: mySuccessHandler, error: myErrorHandler});
Comments
Post a Comment