public class RequestBatch
extends java.lang.Object
Encapsulates an OData batch request.
public void processBatchExample() {
DataService service = this.getService();
EntitySet suppliersEntitySet = service.getEntitySet("Suppliers");
EntitySet productsEntitySet = service.getEntitySet("Products");
EntityType supplierEntityType = suppliersEntitySet.getEntityType();
Property companyNameProperty = supplierEntityType.getProperty("CompanyName");
EntityType productEntityType = productsEntitySet.getEntityType();
Property productNameProperty = productEntityType.getProperty("ProductName");
Property supplierProperty = productEntityType.getProperty("Supplier");
EntityValue supplier1 = service.executeQuery(new DataQuery()
.from(suppliersEntitySet).top(1))
.getRequiredEntity();
EntityValue supplier2 = supplier1.copyEntity();
EntityValue supplier3 = supplier1.copyEntity();
EntityValue supplier4 = supplier1.copyEntity();
companyNameProperty.setString(supplier2, "Alpha Inc.");
companyNameProperty.setString(supplier3, "Beta Inc.");
service.createEntity(supplier2);
service.createEntity(supplier3);
companyNameProperty.setString(supplier3, "Gamma Inc.");
EntityValue product1 = service.executeQuery(new DataQuery()
.from(productsEntitySet).top(1))
.getRequiredEntity();
EntityValue product2 = product1.copyEntity();
productNameProperty.setString(product2, "Delta Cake");
RequestBatch batch = new RequestBatch();
ChangeSet changes = new ChangeSet();
changes.createEntity(supplier4);
changes.updateEntity(supplier3);
changes.deleteEntity(supplier2);
changes.createEntity(product2);
changes.createLink(product2, supplierProperty, supplier4);
DataQuery query = new DataQuery().from(suppliersEntitySet);
batch.addChanges(changes);
batch.addQuery(query);
service.processBatch(batch);
EntityValueList suppliers = batch.getQueryResult(query).getEntityList();
Example.show("There are now ", Example.formatInt(suppliers.length()),
" suppliers.");
}
public void processBatchExample() {
NorthwindService service = this.getService();
Supplier supplier1 = service.getSupplier(new DataQuery().top(1));
Supplier supplier2 = supplier1.copy();
Supplier supplier3 = supplier1.copy();
Supplier supplier4 = supplier1.copy();
supplier2.setCompanyName("Alpha Inc.");
supplier3.setCompanyName("Beta Inc.");
service.createEntity(supplier2);
service.createEntity(supplier3);
supplier3.setCompanyName("Gamma Inc.");
Product product1 = service.getProduct(new DataQuery().top(1));
Product product2 = product1.copy();
product2.setProductName("Delta Cake");
RequestBatch batch = new RequestBatch();
ChangeSet changes = new ChangeSet();
changes.createEntity(supplier4);
changes.updateEntity(supplier3);
changes.deleteEntity(supplier2);
changes.createEntity(product2);
changes.createLink(product2, Product.supplier, supplier4);
changes.updateLink(product2, Product.supplier, supplier3);
changes.deleteLink(product2, Product.supplier, supplier3);
DataQuery query = new DataQuery()
.from(NorthwindServiceMetadata.EntitySets.suppliers);
batch.addChanges(changes);
batch.addQuery(query);
service.processBatch(batch);
Supplier__List suppliers = Supplier.list(batch.getQueryResult(query)
.getEntityList());
Example.show("There are now ", Example.formatInt(suppliers.length()),
" suppliers.");
}
| Constructor and Description |
|---|
RequestBatch() |
| Modifier and Type | Method and Description |
|---|---|
void |
addChanges(ChangeSet changes)
|
void |
addChanges(ChangeSet changes,
HttpHeaders headers)
|
void |
addChanges(ChangeSet changes,
HttpHeaders headers,
RequestOptions options)
Add a change set to this request batch.
|
void |
addQuery(DataQuery query)
|
void |
addQuery(DataQuery query,
HttpHeaders headers)
|
void |
addQuery(DataQuery query,
HttpHeaders headers,
RequestOptions options)
Add a data query to this request batch.
|
void |
addQueryResult(DataQuery query,
QueryResult result)
Add a query result to this request batch.
|
ChangeSet |
getChangeSet(int index)
Return the change set, if
isChangeSet(index) is true; otherwise throws undefined. |
boolean |
getContinueOnError()
Return should the server continue executing all requests in a batch if one or nmore of the requests returns an error status.
|
DataQuery |
getDataQuery(int index)
Return the data query, if
isDataQuery(index) is true; otherwise throws undefined. |
DataServiceException |
getError()
Return (nullable) Error if
status does not represent a successful response. |
DataQuery |
getFunction(int index)
Return the DataQuery for the Function, if
isFunction(index) is true; otherwise throws undefined |
HttpHeaders |
getHeaders(int index)
Return the HTTP headers for the request at
index. |
RequestOptions |
getOptions(int index)
Return the request options for the request at
index. |
QueryResult |
getQueryResult(DataQuery query)
Return the result of a data query within this batch.
|
int |
getStatus()
Return response status (e.g.
|
DataQuery |
invokeFunction(DataMethod method)
|
DataQuery |
invokeFunction(DataMethod method,
ParameterList parameters)
|
DataQuery |
invokeFunction(DataMethod method,
ParameterList parameters,
HttpHeaders headers)
|
DataQuery |
invokeFunction(DataMethod method,
ParameterList parameters,
HttpHeaders headers,
RequestOptions options)
Add a function to the batch.
|
boolean |
isChangeSet(int index)
Return
true if index is a valid request index, and the request at that index is a ChangeSet; otherwise false. |
boolean |
isDataQuery(int index)
Return
true if index is a valid request index, and the request at that index is a DataQuery; otherwise false. |
boolean |
isFunction(int index)
Return
true if index is a valid change index, and the request at that index is for a function |
void |
setContinueOnError(boolean value)
Set should the server continue executing all requests in a batch if one or nmore of the requests returns an error status.
|
void |
setError(DataServiceException value)
Set error if
status does not represent a successful response. |
void |
setStatus(int value)
Set response status (e.g.
|
int |
size()
Return the number of requests in this request batch.
|
public void addChanges(ChangeSet changes)
changes - Changes parameter.public void addChanges(ChangeSet changes, HttpHeaders headers)
changes - Changes parameter.headers - Headers parameter.public void addChanges(ChangeSet changes, HttpHeaders headers, RequestOptions options)
Add a change set to this request batch.
changes - Change set.headers - Change set headers.options - Change set options.public void addQuery(DataQuery query)
query - Query parameter.public void addQuery(DataQuery query, HttpHeaders headers)
query - Query parameter.headers - Headers parameter.public void addQuery(DataQuery query, HttpHeaders headers, RequestOptions options)
Add a data query to this request batch.
query - Data query.headers - Data query headers.options - Data query options.public void addQueryResult(DataQuery query, QueryResult result)
Add a query result to this request batch.
query - Data query, which must have been previously added to this batch using addQuery.result - Query result.public ChangeSet getChangeSet(int index)
Return the change set, if isChangeSet(index) is true; otherwise throws undefined.
index - From zero to size - 1.isChangeSet(index) is true; otherwise throws undefined.public boolean getContinueOnError()
Return should the server continue executing all requests in a batch if one or nmore of the requests returns an error status. Defaults to true.
true.public DataQuery getDataQuery(int index)
Return the data query, if isDataQuery(index) is true; otherwise throws undefined.
index - From zero to size - 1.isDataQuery(index) is true; otherwise throws undefined.public DataServiceException getError()
Return (nullable) Error if status does not represent a successful response.
status does not represent a successful response.public DataQuery getFunction(int index)
Return the DataQuery for the Function, if isFunction(index) is true; otherwise throws undefined
index - From zero to size - 1isFunction(index) is true; otherwise throws undefinedpublic HttpHeaders getHeaders(int index)
Return the HTTP headers for the request at index.
index - From zero to size - 1.index.public RequestOptions getOptions(int index)
Return the request options for the request at index.
index - From zero to size - 1.index.public QueryResult getQueryResult(DataQuery query)
Return the result of a data query within this batch.
query - Data query.public int getStatus()
Return response status (e.g. HTTP status code 200 = OK).
public DataQuery invokeFunction(DataMethod method)
method - Method parameter.public DataQuery invokeFunction(DataMethod method, ParameterList parameters)
method - Method parameter.parameters - Parameters parameter.public DataQuery invokeFunction(DataMethod method, ParameterList parameters, HttpHeaders headers)
method - Method parameter.parameters - Parameters parameter.headers - Headers parameter.public DataQuery invokeFunction(DataMethod method, ParameterList parameters, HttpHeaders headers, RequestOptions options)
Add a function to the batch. If the method is not a function, throws an undefined.
DataQuery.bind and DataQuery.from, for setting the binding parameter for a bound function (either can be applied to the returned query).
method - Function to be called.parameters - Method parameters.headers - Request-specific headers.options - Request-specific options.public boolean isChangeSet(int index)
Return true if index is a valid request index, and the request at that index is a ChangeSet; otherwise false.
index - From zero to size - 1.true if index is a valid request index, and the request at that index is a ChangeSet; otherwise false.public boolean isDataQuery(int index)
Return true if index is a valid request index, and the request at that index is a DataQuery; otherwise false.
index - From zero to size - 1.true if index is a valid request index, and the request at that index is a DataQuery; otherwise false.public boolean isFunction(int index)
Return true if index is a valid change index, and the request at that index is for a function
index - From zero to size - 1true if index is a valid change index, and the request at that index is for a functionpublic void setContinueOnError(boolean value)
Set should the server continue executing all requests in a batch if one or nmore of the requests returns an error status. Defaults to true.
value - Should the server continue executing all requests in a batch if one or nmore of the requests returns an error status. Defaults to true.public void setError(DataServiceException value)
Set error if status does not represent a successful response.
value - Error if status does not represent a successful response.public void setStatus(int value)
Set response status (e.g. HTTP status code 200 = OK).
value - Response status (e.g. HTTP status code 200 = OK).public int size()
Return the number of requests in this request batch.