public class ChangeSet
extends java.lang.Object
Encapsulates an OData change set. A change set is used to group a set of entity or link changes into a single unit of work, like an atomic database transaction.
public void applyChangesExample() { NorthwindService service = this.getService(); Supplier__List suppliers = service.getSuppliers(new DataQuery().top(2)); Product__List products = service.getProducts(new DataQuery().top(3)); Product product1 = products.get(0).copy(); Product product2 = products.get(1).copy(); Product product3 = products.get(2).copy(); product1.setProductName("Blueberry Muffins"); product2.setProductName("Strawberry Yoghurt"); product3.setProductName("Raspberry Pie"); ChangeSet entityCreates = new ChangeSet(); entityCreates.createEntity(product1); entityCreates.createEntity(product2); entityCreates.createEntity(product3); service.applyChanges(entityCreates); ChangeSet entityChanges = new ChangeSet(); product2.setProductName("Blackberry Yoghurt"); entityChanges.updateEntity(product2); entityChanges.deleteEntity(product3); service.applyChanges(entityChanges); ChangeSet linkChanges = new ChangeSet(); Supplier supplier1 = suppliers.get(0); Supplier supplier2 = suppliers.get(1); linkChanges.createLink(product1, Product.supplier, supplier1); linkChanges.updateLink(product1, Product.supplier, supplier2); linkChanges.deleteLink(product1, Product.supplier); service.applyChanges(linkChanges); }
public void applyChangesExample() { DataService service = this.getService(); EntitySet suppliersEntitySet = service.getEntitySet("Suppliers"); EntitySet productsEntitySet = service.getEntitySet("Products"); EntityType productEntityType = productsEntitySet.getEntityType(); Property productNameProperty = productEntityType.getProperty("ProductName"); Property supplierProperty = productEntityType.getProperty("Supplier"); EntityValueList suppliers = service.executeQuery(new DataQuery() .from(suppliersEntitySet).top(2)) .getEntityList(); EntityValueList products = service.executeQuery(new DataQuery() .from(productsEntitySet).top(3)) .getEntityList(); EntityValue product1 = products.get(0).copyEntity(); EntityValue product2 = products.get(1).copyEntity(); EntityValue product3 = products.get(1).copyEntity(); productNameProperty.setString(product1, "Blueberry Yoghurt"); productNameProperty.setString(product2, "Strawberry Yoghurt"); productNameProperty.setString(product3, "Raspberry Pie"); ChangeSet entityCreates = new ChangeSet(); entityCreates.createEntity(product1); entityCreates.createEntity(product2); entityCreates.createEntity(product3); service.applyChanges(entityCreates); ChangeSet entityChanges = new ChangeSet(); productNameProperty.setString(product2, "Blackberry Yoghurt"); entityChanges.updateEntity(product2); entityChanges.deleteEntity(product3); service.applyChanges(entityChanges); ChangeSet linkChanges = new ChangeSet(); EntityValue supplier1 = suppliers.get(0); EntityValue supplier2 = suppliers.get(1); linkChanges.createLink(product1, supplierProperty, supplier1); linkChanges.updateLink(product1, supplierProperty, supplier2); linkChanges.deleteLink(product1, supplierProperty); service.applyChanges(linkChanges); }
Constructor and Description |
---|
ChangeSet() |
Modifier and Type | Method and Description |
---|---|
void |
addActionResult(DataQuery query,
QueryResult result)
Add a query result for action to this changeset.
|
void |
createEntity(EntityValue entity)
|
void |
createEntity(EntityValue entity,
HttpHeaders headers)
|
void |
createEntity(EntityValue entity,
HttpHeaders headers,
RequestOptions options)
Add a pending created entity to the change set.
|
void |
createLink(EntityValue from,
Property property,
EntityValue to)
|
void |
createLink(EntityValue from,
Property property,
EntityValue to,
HttpHeaders headers)
|
void |
createLink(EntityValue from,
Property property,
EntityValue to,
HttpHeaders headers,
RequestOptions options)
Add a pending created link to the change set.
|
void |
createRelatedEntity(EntityValue entity,
EntityValue parent,
Property property)
|
void |
createRelatedEntity(EntityValue entity,
EntityValue parent,
Property property,
HttpHeaders headers)
|
void |
createRelatedEntity(EntityValue entity,
EntityValue parent,
Property property,
HttpHeaders headers,
RequestOptions options)
Add a pending created entity to the change set, related to a parent entity via a parent navigation property.
|
void |
deleteEntity(EntityValue entity)
|
void |
deleteEntity(EntityValue entity,
HttpHeaders headers)
|
void |
deleteEntity(EntityValue entity,
HttpHeaders headers,
RequestOptions options)
Add a pending deleted entity to the change set.
|
void |
deleteLink(EntityValue from,
Property property)
|
void |
deleteLink(EntityValue from,
Property property,
EntityValue to)
|
void |
deleteLink(EntityValue from,
Property property,
EntityValue to,
HttpHeaders headers)
|
void |
deleteLink(EntityValue from,
Property property,
EntityValue to,
HttpHeaders headers,
RequestOptions options)
Add a pending deleted link to the change set.
|
DataQuery |
getAction(int index)
Return the DataQuery for the action, if
isAction(index) is true , otherwise throws undefined |
QueryResult |
getActionResult(DataQuery actionQuery)
Return the QueryResult for the action.
|
GlobalDateTime |
getCreated()
Return the date and time this change set was created.
|
EntityValue |
getEntity(int index)
Return the changed entity, if
isEntity(index) is true , otherwise throws undefined . |
DataServiceException |
getError()
Return (nullable) Error if
status does not represent a successful response. |
java.lang.String |
getGroup()
Return (nullable) The group of this change set.
|
HttpHeaders |
getHeaders(int index)
Return the HTTP headers for the change at
index . |
long |
getId()
Return the id of this change set.
|
java.lang.String |
getLabel()
Return (nullable) The label of this change set.
|
ChangedLink |
getLink(int index)
Return the changed link, if
isLink(index) is true , otherwise throws undefined . |
RequestOptions |
getOptions(int index)
Return the request options for the change at
index . |
int |
getStatus()
Return response status (e.g.
|
GlobalDateTime |
getSubmitted()
Return (nullable) The date and time this change set was submitted.
|
DataQuery |
invokeAction(DataMethod method)
|
DataQuery |
invokeAction(DataMethod method,
ParameterList parameters)
|
DataQuery |
invokeAction(DataMethod method,
ParameterList parameters,
HttpHeaders headers)
|
DataQuery |
invokeAction(DataMethod method,
ParameterList parameters,
HttpHeaders headers,
RequestOptions options)
Add an action to the change set.
|
boolean |
isAction(int index)
Return
true if index is a valid change index, and the change is for an action |
boolean |
isEntity(int index)
Return
true if index is a valid change index, and the change is for a created, updated or deleted entity; otherwise false . |
boolean |
isLink(int index)
Return
true if index is a valid change index, and the change is for a created, updated or deleted link; otherwise false . |
void |
saveEntity(EntityValue entity)
|
void |
saveEntity(EntityValue entity,
HttpHeaders headers)
|
void |
saveEntity(EntityValue entity,
HttpHeaders headers,
RequestOptions options)
|
void |
setCreated(GlobalDateTime value)
Set the date and time this change set was created.
|
void |
setError(DataServiceException value)
Set error if
status does not represent a successful response. |
void |
setGroup(java.lang.String value)
Set the group of this change set.
|
void |
setId(long value)
Set the id of this change set.
|
void |
setLabel(java.lang.String value)
Set the label of this change set.
|
void |
setStatus(int value)
Set response status (e.g.
|
void |
setSubmitted(GlobalDateTime value)
Set the date and time this change set was submitted.
|
int |
size()
Return the number of changes in this change set.
|
void |
updateEntity(EntityValue entity)
|
void |
updateEntity(EntityValue entity,
HttpHeaders headers)
|
void |
updateEntity(EntityValue entity,
HttpHeaders headers,
RequestOptions options)
Add an updated entity to the change set.
|
void |
updateLink(EntityValue from,
Property property,
EntityValue to)
|
void |
updateLink(EntityValue from,
Property property,
EntityValue to,
HttpHeaders headers)
|
void |
updateLink(EntityValue from,
Property property,
EntityValue to,
HttpHeaders headers,
RequestOptions options)
Add a pending updated link to the change set.
|
public void addActionResult(DataQuery query, QueryResult result)
Add a query result for action to this changeset.
query
- Data query for action, which must have been previously added to this changeset using invokeAction
.result
- Query result.public void createEntity(EntityValue entity)
entity
- Entity parameter.public void createEntity(EntityValue entity, HttpHeaders headers)
entity
- Entity parameter.headers
- Headers parameter.public void createEntity(EntityValue entity, HttpHeaders headers, RequestOptions options)
Add a pending created entity to the change set. The entity will be created when this change set is submitted.
entity
- Entity to be created.headers
- Request-specific headers.options
- Request-specific options.public void createLink(EntityValue from, Property property, EntityValue to)
from
- From parameter.property
- Property parameter.to
- To parameter.public void createLink(EntityValue from, Property property, EntityValue to, HttpHeaders headers)
from
- From parameter.property
- Property parameter.to
- To parameter.headers
- Headers parameter.public void createLink(EntityValue from, Property property, EntityValue to, HttpHeaders headers, RequestOptions options)
Add a pending created link to the change set. The link will be created when this change set is submitted.
from
- Source entity for the link to be created.property
- Source navigation property for the link to be created.to
- Target entity for the link to be created.headers
- Request-specific headers.options
- Request-specific options.public void createRelatedEntity(EntityValue entity, EntityValue parent, Property property)
entity
- Entity parameter.parent
- Parent parameter.property
- Property parameter.public void createRelatedEntity(EntityValue entity, EntityValue parent, Property property, HttpHeaders headers)
entity
- Entity parameter.parent
- Parent parameter.property
- Property parameter.headers
- Headers parameter.public void createRelatedEntity(EntityValue entity, EntityValue parent, Property property, HttpHeaders headers, RequestOptions options)
Add a pending created entity to the change set, related to a parent entity via a parent navigation property. The entity will be created when this change set is submitted.
public void createRelatedEntityInChangeSetExample() { NorthwindService service = this.getService(); Customer__List customers = service.getCustomers(new DataQuery() .filter(Customer.customerID.equal("ALFKI"))); Order__List orders = service.getOrders(new DataQuery().top(2)); ChangeSet changes = new ChangeSet(); Customer newCustomer = customers.first().copy(); changes.createEntity(newCustomer); Order firstOrder = orders.first().copy(); Order secondOrder = orders.last().copy(); changes.createRelatedEntity(firstOrder, newCustomer, Customer.orders); changes.createRelatedEntity(secondOrder, newCustomer, Customer.orders); service.applyChanges(changes); }
public void createRelatedEntityInChangeSetExample() { DataService service = this.getService(); EntitySet customersEntitySet = service.getEntitySet("Customers"); EntitySet ordersEntitySet = service.getEntitySet("Orders"); EntityType customerEntityType = customersEntitySet.getEntityType(); Property customerIDProperty = customerEntityType.getProperty("CustomerID"); Property ordersProperty = customerEntityType.getProperty("Orders"); EntityValueList customers = service.executeQuery(new DataQuery() .from(customersEntitySet).filter(customerIDProperty.equal("ALFKI"))) .getEntityList(); EntityValueList orders = service.executeQuery(new DataQuery() .from(ordersEntitySet).top(2)) .getEntityList(); ChangeSet changes = new ChangeSet(); EntityValue newCustomer = customers.first().copyEntity(); changes.createEntity(newCustomer); EntityValue firstOrder = orders.first().copyEntity(); EntityValue secondOrder = orders.last().copyEntity(); changes.createRelatedEntity(firstOrder, newCustomer, ordersProperty); changes.createRelatedEntity(secondOrder, newCustomer, ordersProperty); service.applyChanges(changes); }
entity
- Entity to be created.parent
- Previously created parent entity.property
- Parent's navigation property.headers
- Request-specific headers.options
- Request-specific options.public void deleteEntity(EntityValue entity)
entity
- Entity parameter.public void deleteEntity(EntityValue entity, HttpHeaders headers)
entity
- Entity parameter.headers
- Headers parameter.public void deleteEntity(EntityValue entity, HttpHeaders headers, RequestOptions options)
Add a pending deleted entity to the change set. The entity will be deleted when this change set is submitted.
entity
- Entity to be deleted.headers
- Request-specific headers.options
- Request-specific options.public void deleteLink(EntityValue from, Property property)
from
- From parameter.property
- Property parameter.public void deleteLink(EntityValue from, Property property, EntityValue to)
from
- From parameter.property
- Property parameter.to
- To parameter.public void deleteLink(EntityValue from, Property property, EntityValue to, HttpHeaders headers)
from
- From parameter.property
- Property parameter.to
- To parameter.headers
- Headers parameter.public void deleteLink(EntityValue from, Property property, EntityValue to, HttpHeaders headers, RequestOptions options)
Add a pending deleted link to the change set. The link will be deleted when this change set is submitted.
from
- Source entity for the link to be deleted.property
- Source navigation property for the link to be deleted.to
- Target entity for the link to be deleted.headers
- Request-specific headers.options
- Request-specific options.public DataQuery getAction(int index)
Return the DataQuery for the action, if isAction(index)
is true
, otherwise throws undefined
index
- From zero to size - 1
isAction(index)
is true
, otherwise throws undefined
public QueryResult getActionResult(DataQuery actionQuery)
Return the QueryResult for the action. Throws UsageException
if the result cannot be found for the query.
actionQuery
- The DataQuery containing the action call.UsageException
if the result cannot be found for the query.public GlobalDateTime getCreated()
Return the date and time this change set was created.
public EntityValue getEntity(int index)
Return the changed entity, if isEntity(index)
is true
, otherwise throws undefined
.
The EntityValue.isCreated
, EntityValue.isUpdated
and EntityValue.isDeleted
properties can be accessed on the resulting entity value to determine the type of change.
public void showChangedEntities(final ChangeSet changes) { int n = changes.size(); { int i = 0; for (; (i < n); i++) { if (changes.isEntity(i)) { EntityValue change = changes.getEntity(i); if (change.isCreated()) { Example.show("created entity"); } else if (change.isUpdated()) { Example.show("updated entity"); } else if (change.isDeleted()) { Example.show("deleted entity"); } } } } }
index
- From zero to size - 1
.isEntity(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 java.lang.String getGroup()
Return (nullable) The group of this change set.
Defaults to null
.
A change set group is only relevant if the change
set is stored offline for later synchronization.
public HttpHeaders getHeaders(int index)
Return the HTTP headers for the change at index
.
index
- From zero to size - 1
.index
.public long getId()
Return the id of this change set. Defaults to 0. A change set id is only relevant if the change set is stored offline for later submission.
public java.lang.String getLabel()
Return (nullable) The label of this change set.
Defaults to null
.
A change set label is only relevant if the change
set is stored offline for later synchronization.
public ChangedLink getLink(int index)
Return the changed link, if isLink(index)
is true
, otherwise throws undefined
.
The ChangedLink.isCreated
, ChangedLink.isUpdated
and ChangedLink.isDeleted
properties can be accessed on the resulting changed link to determine the type of change.
public void showChangedLinks(final ChangeSet changes) { int n = changes.size(); { int i = 0; for (; (i < n); i++) { if (changes.isLink(i)) { ChangedLink change = changes.getLink(i); if (change.isCreated()) { Example.show("created link"); } else if (change.isUpdated()) { Example.show("updated link"); } else if (change.isDeleted()) { Example.show("deleted link"); } } } } }
index
- From zero to size - 1
.isLink(index)
is true
, otherwise throws undefined
.public RequestOptions getOptions(int index)
Return the request options for the change at index
.
index
- From zero to size - 1
.index
.public int getStatus()
Return response status (e.g. HTTP status code 200 = OK).
public GlobalDateTime getSubmitted()
Return (nullable) The date and time this change set was submitted.
public DataQuery invokeAction(DataMethod method)
method
- Method parameter.public DataQuery invokeAction(DataMethod method, ParameterList parameters)
method
- Method parameter.parameters
- Parameters parameter.public DataQuery invokeAction(DataMethod method, ParameterList parameters, HttpHeaders headers)
method
- Method parameter.parameters
- Parameters parameter.headers
- Headers parameter.public DataQuery invokeAction(DataMethod method, ParameterList parameters, HttpHeaders headers, RequestOptions options)
Add an action to the change set. If the method is not an action throws an undefined
.
DataQuery.bind
and DataQuery.from
, for setting the binding parameter for a bound action (either can be applied to the returned query).
method
- Action to be called.parameters
- Method parameters.headers
- Request-specific headers.options
- Request-specific options.ChangeSet.getActionResult
.public boolean isAction(int index)
Return true
if index
is a valid change index, and the change is for an action
index
- From zero to size - 1
true
if index
is a valid change index, and the change is for an actionpublic boolean isEntity(int index)
Return true
if index
is a valid change index, and the change is for a created, updated or deleted entity; otherwise false
.
index
- From zero to size - 1
.true
if index
is a valid change index, and the change is for a created, updated or deleted entity; otherwise false
.public boolean isLink(int index)
Return true
if index
is a valid change index, and the change is for a created, updated or deleted link; otherwise false
.
index
- From zero to size - 1
.true
if index
is a valid change index, and the change is for a created, updated or deleted link; otherwise false
.public void saveEntity(EntityValue entity)
entity
- Entity parameter.public void saveEntity(EntityValue entity, HttpHeaders headers)
entity
- Entity parameter.headers
- Headers parameter.public void saveEntity(EntityValue entity, HttpHeaders headers, RequestOptions options)
Call ChangeSet.createEntity
, if entity.isNew == true
, otherwise call ChangeSet.updateEntity
.
entity
- Entity to be created or updated.headers
- Request-specific headers.options
- Request-specific options.public void setCreated(GlobalDateTime value)
Set the date and time this change set was created.
value
- The date and time this change set was created.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 setGroup(java.lang.String value)
Set the group of this change set.
Defaults to null
.
A change set group is only relevant if the change
set is stored offline for later synchronization.
value
- The group of this change set.public void setId(long value)
Set the id of this change set. Defaults to 0. A change set id is only relevant if the change set is stored offline for later submission.
value
- The id of this change set.public void setLabel(java.lang.String value)
Set the label of this change set.
Defaults to null
.
A change set label is only relevant if the change
set is stored offline for later synchronization.
value
- The label of this change set.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 void setSubmitted(GlobalDateTime value)
Set the date and time this change set was submitted.
value
- The date and time this change set was submitted.public int size()
Return the number of changes in this change set.
public void updateEntity(EntityValue entity)
entity
- Entity parameter.public void updateEntity(EntityValue entity, HttpHeaders headers)
entity
- Entity parameter.headers
- Headers parameter.public void updateEntity(EntityValue entity, HttpHeaders headers, RequestOptions options)
Add an updated entity to the change set. The entity will be updated when this change set is submitted.
entity
- Entity to be updated.headers
- Request-specific headers.options
- Request-specific options.public void updateLink(EntityValue from, Property property, EntityValue to)
from
- From parameter.property
- Property parameter.to
- To parameter.public void updateLink(EntityValue from, Property property, EntityValue to, HttpHeaders headers)
from
- From parameter.property
- Property parameter.to
- To parameter.headers
- Headers parameter.public void updateLink(EntityValue from, Property property, EntityValue to, HttpHeaders headers, RequestOptions options)
Add a pending updated link to the change set. The link will be updated when this change set is submitted.
from
- Source entity for the link to be updated.property
- Source navigation property for the link to be updated. This must be a one-to-one navigation property.to
- Target entity for the link to be updated.headers
- Request-specific headers.options
- Request-specific options.