public class OfflineDataService extends DataService
For internal use only.
Constructor and Description |
---|
OfflineDataService(OfflineODataProvider provider)
Construct an offline data service using an offline provider.
|
Modifier and Type | Method and Description |
---|---|
void |
createEntity(EntityValue entity)
|
void |
createEntity(EntityValue entity,
HttpHeaders headers)
|
void |
createEntity(EntityValue entity,
HttpHeaders headers,
RequestOptions options)
Create an entity in the target system.
|
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)
Create a link from a source entity to a target entity in the target system.
|
void |
createMedia(EntityValue entity,
StreamBase content)
|
void |
createMedia(EntityValue entity,
StreamBase content,
HttpHeaders headers)
|
void |
createMedia(EntityValue entity,
StreamBase content,
HttpHeaders headers,
RequestOptions options)
Create a media entity with the specified content.
|
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)
Create an entity in the target system, related to a parent entity via a parent navigation property.
|
void |
createRelatedMedia(EntityValue entity,
StreamBase content,
EntityValue parent,
Property property)
|
void |
createRelatedMedia(EntityValue entity,
StreamBase content,
EntityValue parent,
Property property,
HttpHeaders headers)
|
void |
createRelatedMedia(EntityValue entity,
StreamBase content,
EntityValue parent,
Property property,
HttpHeaders headers,
RequestOptions options)
Create an media entity in the target system, related to a parent entity via a parent navigation property.
|
void |
deleteByQuery(DataQuery query)
|
void |
deleteByQuery(DataQuery query,
HttpHeaders headers)
|
void |
deleteByQuery(DataQuery query,
HttpHeaders headers,
RequestOptions options)
Execute query to delete data from the target system.
|
void |
deleteEntity(EntityValue entity)
|
void |
deleteEntity(EntityValue entity,
HttpHeaders headers)
|
void |
deleteEntity(EntityValue entity,
HttpHeaders headers,
RequestOptions options)
Delete an entity from the target system.
|
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)
Delete a link from a source entity to a target entity.
|
void |
deleteStream(EntityValue entity,
StreamLink link)
|
void |
deleteStream(EntityValue entity,
StreamLink link,
HttpHeaders headers)
|
void |
deleteStream(EntityValue entity,
StreamLink link,
HttpHeaders headers,
RequestOptions options)
Delete the content of a stream property from the target system.
|
void |
download()
See download(StringList).
|
void |
download(StringList groups)
Download backend data changes into the local offline store.
|
ByteStream |
downloadMedia(EntityValue entity)
|
ByteStream |
downloadMedia(EntityValue entity,
HttpHeaders headers)
|
ByteStream |
downloadMedia(EntityValue entity,
HttpHeaders headers,
RequestOptions options)
Obtain a stream for downloading the content of a media entity from the target system.
|
ByteStream |
downloadStream(EntityValue entity,
StreamLink link)
|
ByteStream |
downloadStream(EntityValue entity,
StreamLink link,
HttpHeaders headers)
|
ByteStream |
downloadStream(EntityValue entity,
StreamLink link,
HttpHeaders headers,
RequestOptions options)
Obtain a stream for downloading the content of a stream property from the target system.
|
DataValue |
executeMethod(DataMethod method)
|
DataValue |
executeMethod(DataMethod method,
ParameterList parameters)
|
DataValue |
executeMethod(DataMethod method,
ParameterList parameters,
HttpHeaders headers)
|
DataValue |
executeMethod(DataMethod method,
ParameterList parameters,
HttpHeaders headers,
RequestOptions options)
Execute a data method (action or function) in the target system.
|
QueryResult |
executeQuery(DataQuery query)
|
QueryResult |
executeQuery(DataQuery query,
HttpHeaders headers)
|
QueryResult |
executeQuery(DataQuery query,
HttpHeaders headers,
RequestOptions options)
Execute a data query to get data from the target system.
|
PendingRequestList |
getFailedRequests()
|
PendingRequestList |
getFailedRequests(DataQuery query) |
OfflineODataProvider |
getOfflineProvider()
Return the offline provider supporting this data service.
|
OnlineODataProvider |
getOnlineProvider()
Return the online provider supporting this data service.
|
boolean |
getPrettyTracing()
Return should
OfflineDataService.traceWithData show pretty-printed JSON/XML content? Defaults to false . |
PendingRequestList |
getQueuedRequests()
|
PendingRequestList |
getQueuedRequests(DataQuery query) |
ServiceOptions |
getServiceOptions()
Return service options for the associated online provider.
|
StorageOptions |
getStorageOptions()
Return storage options for the associated local database.
|
boolean |
getTraceRequests()
Return should all requests for this data service be traced? Defaults to
false . |
boolean |
getTraceWithData()
Return if
OfflineDataService.traceRequests is also true , should all requests for this data service be traced with data? Defaults to false . |
void |
open()
Open the
OfflineDataService.offlineProvider , performing any necessary initialization such as creation of the local offline store. |
void |
pingServer()
|
void |
pingServer(HttpHeaders headers)
|
void |
pingServer(HttpHeaders headers,
RequestOptions options)
Ping the server.
|
void |
processBatch(RequestBatch batch)
|
void |
processBatch(RequestBatch batch,
HttpHeaders headers)
|
void |
processBatch(RequestBatch batch,
HttpHeaders headers,
RequestOptions options)
Execute a request batch in the target system.
|
void |
setPrettyTracing(boolean value)
Set should
OfflineDataService.traceWithData show pretty-printed JSON/XML content? Defaults to false . |
void |
setTraceRequests(boolean value)
Set should all requests for this data service be traced? Defaults to
false . |
void |
setTraceWithData(boolean value)
Set if
OfflineDataService.traceRequests is also true , should all requests for this data service be traced with data? Defaults to false . |
void |
updateEntity(EntityValue entity)
|
void |
updateEntity(EntityValue entity,
HttpHeaders headers)
|
void |
updateEntity(EntityValue entity,
HttpHeaders headers,
RequestOptions options)
Update an entity in the target system.
|
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)
Update a link from a source entity to a target entity.
|
void |
upload()
Upload local pending changes to the backend OData service.
|
void |
uploadMedia(EntityValue entity,
StreamBase content)
|
void |
uploadMedia(EntityValue entity,
StreamBase content,
HttpHeaders headers)
|
void |
uploadMedia(EntityValue entity,
StreamBase content,
HttpHeaders headers,
RequestOptions options)
Upload content for a media entity to the target system.
|
void |
uploadStream(EntityValue entity,
StreamLink link,
StreamBase content)
|
void |
uploadStream(EntityValue entity,
StreamLink link,
StreamBase content,
HttpHeaders headers)
|
void |
uploadStream(EntityValue entity,
StreamLink link,
StreamBase content,
HttpHeaders headers,
RequestOptions options)
Upload content for a stream property to the target system.
|
applyChanges, applyChanges, applyChanges, applyChangesAsync, applyChangesAsync, applyChangesAsync, asyncAction, asyncAction, asyncAction, asyncFunction, asyncFunction, asyncFunction, createEntityAsync, createEntityAsync, createEntityAsync, createLinkAsync, createLinkAsync, createLinkAsync, createMediaAsync, createMediaAsync, createMediaAsync, createRelatedEntityAsync, createRelatedEntityAsync, createRelatedEntityAsync, deleteByQueryAsync, deleteByQueryAsync, deleteByQueryAsync, deleteEntityAsync, deleteEntityAsync, deleteEntityAsync, deleteLinkAsync, deleteLinkAsync, deleteLinkAsync, deleteStreamAsync, deleteStreamAsync, deleteStreamAsync, downloadMediaAsync, downloadMediaAsync, downloadMediaAsync, downloadStreamAsync, downloadStreamAsync, downloadStreamAsync, entityContext, entityContext, entityContext, entityContext, executeMethodAsync, executeMethodAsync, executeMethodAsync, executeQueryAsync, executeQueryAsync, executeQueryAsync, fetchMetadata, fetchMetadata, fetchMetadata, fetchMetadataAsync, fetchMetadataAsync, fetchMetadataAsync, getActionExecutor, getDataMethod, getDataTransaction, getEntitySet, getFunctionExecutor, getMetadata, getMetadataLock, getName, getProvider, hasMetadata, loadEntity, loadEntity, loadEntity, loadEntity, loadEntityAsync, loadEntityAsync, loadEntityAsync, loadMetadata, loadMetadata, loadMetadata, loadMetadataAsync, loadMetadataAsync, loadMetadataAsync, loadProperty, loadProperty, loadProperty, loadProperty, loadPropertyAsync, loadPropertyAsync, loadPropertyAsync, metadataText, pingServerAsync, pingServerAsync, pingServerAsync, processBatchAsync, processBatchAsync, processBatchAsync, queryContext, refreshMetadata, saveEntity, saveEntity, saveEntity, saveEntityAsync, saveEntityAsync, saveEntityAsync, serviceDocument, setActionExecutor, setFunctionExecutor, unloadMetadata, unloadMetadataAsync, unloadMetadataAsync, unloadMetadataAsync, updateEntityAsync, updateEntityAsync, updateEntityAsync, updateLinkAsync, updateLinkAsync, updateLinkAsync, uploadMediaAsync, uploadMediaAsync, uploadMediaAsync, uploadStreamAsync, uploadStreamAsync, uploadStreamAsync, upsertEntity, upsertEntity, upsertEntity
public OfflineDataService(OfflineODataProvider provider)
Construct an offline data service using an offline provider.
provider
- Offline provider.public void createEntity(EntityValue entity)
createEntity
in class DataService
entity
- Entity parameter.public void createEntity(EntityValue entity, HttpHeaders headers)
createEntity
in class DataService
entity
- Entity parameter.headers
- Headers parameter.public void createEntity(EntityValue entity, HttpHeaders headers, RequestOptions options)
Create an entity in the target system.
Automatically calls CsdlDocument.resolveEntity
to ensure that EntityValue.entitySet
is available.
public void createEntityExample() { NorthwindService service = this.getService(); Customer customer = new Customer(); customer.setCompanyName("Enterprise Inc."); customer.setContactName("Jean-Luc Picard"); service.createEntity(customer); }
public void createEntityInSetExample() { NorthwindService service = this.getService(); Customer customer = new Customer(); customer.setCompanyName("Voyager Inc."); customer.setContactName("Kathryn Janeway"); service.createEntity(customer.inSet(NorthwindServiceMetadata.EntitySets.customers)); }
public void createEntityExample() { DataService service = this.getService(); EntitySet customersEntitySet = service.getEntitySet("Customers"); EntityType customerEntityType = customersEntitySet.getEntityType(); Property companyNameProperty = customerEntityType.getProperty("CompanyName"); Property contactNameProperty = customerEntityType.getProperty("ContactName"); EntityValue customer = EntityValue.ofType(customerEntityType); companyNameProperty.setString(customer, "Enterprise Inc."); contactNameProperty.setString(customer, "Jean-Luc Picard"); service.createEntity(customer); }
public void createEntityInSetExample() { DataService service = this.getService(); EntitySet customersEntitySet = service.getEntitySet("Customers"); EntityType customerEntityType = customersEntitySet.getEntityType(); Property companyNameProperty = customerEntityType.getProperty("CompanyName"); Property contactNameProperty = customerEntityType.getProperty("ContactName"); EntityValue customer = EntityValue.ofType(customerEntityType); companyNameProperty.setString(customer, "Voyager Inc."); contactNameProperty.setString(customer, "Kathryn Janeway"); service.createEntity(customer.inSet(customersEntitySet)); }
createEntity
in class DataService
entity
- Entity to be created.headers
- Optional request-specific headers.options
- Optional request-specific options.public void createLink(EntityValue from, Property property, EntityValue to)
createLink
in class DataService
from
- From parameter.property
- Property parameter.to
- To parameter.public void createLink(EntityValue from, Property property, EntityValue to, HttpHeaders headers)
createLink
in class DataService
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)
Create a link from a source entity to a target entity in the target system.
public void createLinkExample() { NorthwindService service = this.getService(); Category category = service.getCategory(new DataQuery().skip(1).top(1)); Product product = service.getProduct(new DataQuery().top(1)); service.createLink(category, Category.products, product); }
public void createLinkExample() { DataService service = this.getService(); EntitySet categoriesEntitySet = service.getEntitySet("Categories"); EntitySet productsEntitySet = service.getEntitySet("Products"); EntityType categoryEntityType = categoriesEntitySet.getEntityType(); Property productsProperty = categoryEntityType.getProperty("Products"); EntityValue category = service.executeQuery(new DataQuery() .from(categoriesEntitySet).skip(1).top(1)) .getRequiredEntity(); EntityValue product = service.executeQuery(new DataQuery() .from(productsEntitySet).top(1)) .getRequiredEntity(); service.createLink(category, productsProperty, product); }
createLink
in class DataService
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
- Optional request-specific headers.options
- Optional request-specific options.public void createMedia(EntityValue entity, StreamBase content)
createMedia
in class DataService
entity
- Entity parameter.content
- Content parameter.public void createMedia(EntityValue entity, StreamBase content, HttpHeaders headers)
createMedia
in class DataService
entity
- Entity parameter.content
- Content parameter.headers
- Headers parameter.public void createMedia(EntityValue entity, StreamBase content, HttpHeaders headers, RequestOptions options)
Create a media entity with the specified content.
If the entity
has non-stream structural properties in addition to the key properties and media content, such as label
in the examples below,
then this function will send two requests to the server: a first request to upload (POST) the media stream,
and a second request (PATCH/PUT) to update the non-stream properties. It is not currently supported to make these two calls atomic.
Caution: Having too many threads simultaneously creating streams
may result in out-of-memory conditions on memory-constrained devices.
public void createMediaExample() { MediaService service = this.getService(); Image image = new Image(); image.setLabel("Smiley"); ByteStream content = ByteStream.fromBinary(com.sap.cloud.server.odata.core.StringFunction.toBinary(":-)")); content.setMediaType("text/plain"); service.createMedia(image, content); }
public void createMediaExample() { DataService service = this.getService(); EntitySet imagesEntitySet = service.getEntitySet("Images"); EntityType imageEntityType = imagesEntitySet.getEntityType(); Property labelProperty = imageEntityType.getProperty("label"); EntityValue image = EntityValue.ofType(imageEntityType); labelProperty.setString(image, "Smiley"); ByteStream content = ByteStream.fromBinary(com.sap.cloud.server.odata.core.StringFunction.toBinary(":-)")); content.setMediaType("text/plain"); service.createMedia(image, content); }
createMedia
in class DataService
entity
- Entity to be created.content
- Initial content. Must be a ByteStream
or CharStream
. Will be closed before this function returns.headers
- Optional request-specific headers.options
- Optional request-specific options.public void createRelatedEntity(EntityValue entity, EntityValue parent, Property property)
createRelatedEntity
in class DataService
entity
- Entity parameter.parent
- Parent parameter.property
- Property parameter.public void createRelatedEntity(EntityValue entity, EntityValue parent, Property property, HttpHeaders headers)
createRelatedEntity
in class DataService
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)
Create an entity in the target system, related to a parent entity via a parent navigation property.
public void createRelatedEntityExample() { NorthwindService service = this.getService(); Customer customer = service.getCustomer(new DataQuery().top(1) .filter(Customer.customerID.equal("ALFKI"))); Order__List orders = service.getOrders(new DataQuery().top(1)); Order newOrder = orders.first().copy(); service.createRelatedEntity(newOrder, customer, Customer.orders); }
public void createRelatedEntityExample() { 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(1)) .getEntityList(); EntityValue customer = customers.first(); EntityValue newOrder = orders.first().copyEntity(); service.createRelatedEntity(newOrder, customer, ordersProperty); }
createRelatedEntity
in class DataService
entity
- Entity to be created.parent
- Previously created parent entity.property
- Parent's navigation property.headers
- Optional request-specific headers.options
- Optional request-specific options.public void createRelatedMedia(EntityValue entity, StreamBase content, EntityValue parent, Property property)
createRelatedMedia
in class DataService
entity
- Entity parameter.content
- Content parameter.parent
- Parent parameter.property
- Property parameter.public void createRelatedMedia(EntityValue entity, StreamBase content, EntityValue parent, Property property, HttpHeaders headers)
createRelatedMedia
in class DataService
entity
- Entity parameter.content
- Content parameter.parent
- Parent parameter.property
- Property parameter.headers
- Headers parameter.public void createRelatedMedia(EntityValue entity, StreamBase content, EntityValue parent, Property property, HttpHeaders headers, RequestOptions options)
Create an media entity in the target system, related to a parent entity via a parent navigation property.
public void createRelatedMediaExample() { MediaService service = this.getService(); Artist artist = new Artist(); artist.setFirstName("Salvador"); artist.setLastName("Dali"); artist.setDateOfBirth(LocalDate.of(1904, 5, 11)); artist.setPlaceOfBirth(GeographyPoint.withLatitudeLongitude(42.266667d, 2.965d)); service.createEntity(artist); Image image = new Image(); image.setLabel("Dream"); ByteStream content = ByteStream.fromBinary(com.sap.cloud.server.odata.core.StringFunction.toBinary("Dream Caused by the Flight of a Bee around a Pomegranate a Second Before Awakening")); content.setMediaType("text/plain"); service.createRelatedMedia(image, content, artist, Artist.images); }
public void createRelatedMediaExample() { DataService service = this.getService(); EntitySet artistsEntitySet = service.getEntitySet("Artists"); EntityType artistEntityType = artistsEntitySet.getEntityType(); Property firstNameProperty = artistEntityType.getProperty("firstName"); Property lastNameProperty = artistEntityType.getProperty("lastName"); Property dateOfBirthProperty = artistEntityType.getProperty("dateOfBirth"); Property placeOfBirthProperty = artistEntityType.getProperty("placeOfBirth"); Property imagesProperty = artistEntityType.getProperty("images"); EntitySet imagesEntitySet = service.getEntitySet("Images"); EntityType imageEntityType = imagesEntitySet.getEntityType(); Property labelProperty = imageEntityType.getProperty("label"); EntityValue artist = EntityValue.ofType(artistEntityType); firstNameProperty.setString(artist, "Maurits"); lastNameProperty.setString(artist, "Escher"); dateOfBirthProperty.setValue(artist, LocalDate.of(1898, 6, 17)); placeOfBirthProperty.setValue(artist, GeographyPoint.withLatitudeLongitude(53.2d, 5.783333d)); service.createEntity(artist); EntityValue image = EntityValue.ofType(imageEntityType); labelProperty.setString(image, "Hands"); ByteStream content = ByteStream.fromBinary(com.sap.cloud.server.odata.core.StringFunction.toBinary("Drawing Hands")); content.setMediaType("text/plain"); service.createRelatedMedia(image, content, artist, imagesProperty); }
createRelatedMedia
in class DataService
entity
- Entity to be created.content
- Initial content. Must be a ByteStream
or CharStream
. Will be closed before this function returns.parent
- Previously created parent entity.property
- Parent's navigation property.headers
- Optional request-specific headers.options
- Optional request-specific options.public void deleteByQuery(DataQuery query)
deleteByQuery
in class DataService
query
- Query parameter.public void deleteByQuery(DataQuery query, HttpHeaders headers)
deleteByQuery
in class DataService
query
- Query parameter.headers
- Headers parameter.public void deleteByQuery(DataQuery query, HttpHeaders headers, RequestOptions options)
Execute query to delete data from the target system.
deleteByQuery
in class DataService
query
- Data query specifying the information to be deleted.headers
- Optional request-specific headers.options
- Optional request-specific options.public void deleteEntity(EntityValue entity)
deleteEntity
in class DataService
entity
- Entity parameter.public void deleteEntity(EntityValue entity, HttpHeaders headers)
deleteEntity
in class DataService
entity
- Entity parameter.headers
- Headers parameter.public void deleteEntity(EntityValue entity, HttpHeaders headers, RequestOptions options)
Delete an entity from the target system.
public void deleteEntityExample() { NorthwindService service = this.getService(); DataQuery query = new DataQuery().top(1).selectKey() .filter(Customer.contactName.equal("William Riker")); Customer customer = service.getCustomer(query); service.deleteEntity(customer); }
public void deleteEntityExample() { DataService service = this.getService(); EntitySet customersEntitySet = service.getEntitySet("Customers"); EntityType customerEntityType = customersEntitySet.getEntityType(); Property contactNameProperty = customerEntityType.getProperty("ContactName"); DataQuery query = new DataQuery().top(1).selectKey().from(customersEntitySet) .filter(contactNameProperty.equal("William Riker")); EntityValue customer = service.executeQuery(query).getRequiredEntity(); service.deleteEntity(customer); }
deleteEntity
in class DataService
entity
- Entity to be deleted.headers
- Optional request-specific headers.options
- Optional request-specific options.public void deleteLink(EntityValue from, Property property)
deleteLink
in class DataService
from
- From parameter.property
- Property parameter.public void deleteLink(EntityValue from, Property property, EntityValue to)
deleteLink
in class DataService
from
- From parameter.property
- Property parameter.to
- To parameter.public void deleteLink(EntityValue from, Property property, EntityValue to, HttpHeaders headers)
deleteLink
in class DataService
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)
Delete a link from a source entity to a target entity.
public void deleteLinkExample1() { NorthwindService service = this.getService(); Product product = service.getProduct(new DataQuery().top(1)); service.deleteLink(product, Product.supplier); }
public void deleteLinkExample2() { NorthwindService service = this.getService(); Category category = service.getCategory(new DataQuery().skip(1).top(1)); Product product = service.getProduct(new DataQuery().top(1)); service.deleteLink(category, Category.products, product); }
public void deleteLinkExample1() { DataService service = this.getService(); EntitySet productsEntitySet = service.getEntitySet("Products"); EntityType productEntityType = productsEntitySet.getEntityType(); Property supplierProperty = productEntityType.getProperty("Supplier"); EntityValue product = service.executeQuery(new DataQuery() .from(productsEntitySet).top(1)) .getRequiredEntity(); service.deleteLink(product, supplierProperty); }
public void deleteLinkExample2() { DataService service = this.getService(); EntitySet categoriesEntitySet = service.getEntitySet("Categories"); EntitySet productsEntitySet = service.getEntitySet("Products"); EntityType categoryEntityType = categoriesEntitySet.getEntityType(); Property productsProperty = categoryEntityType.getProperty("Products"); EntityValue category = service.executeQuery(new DataQuery() .from(categoriesEntitySet).skip(1).top(1)) .getRequiredEntity(); EntityValue product = service.executeQuery(new DataQuery() .from(productsEntitySet).top(1)) .getRequiredEntity(); service.deleteLink(category, productsProperty, product); }
deleteLink
in class DataService
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. Can be omitted for a single-valued navigation property.headers
- Optional request-specific headers.options
- Optional request-specific options.public void deleteStream(EntityValue entity, StreamLink link)
deleteStream
in class DataService
entity
- Entity parameter.link
- Link parameter.public void deleteStream(EntityValue entity, StreamLink link, HttpHeaders headers)
deleteStream
in class DataService
entity
- Entity parameter.link
- Link parameter.headers
- Headers parameter.public void deleteStream(EntityValue entity, StreamLink link, HttpHeaders headers, RequestOptions options)
Delete the content of a stream property from the target system.
deleteStream
in class DataService
entity
- Entity containing the stream property whose content is to be deleted.link
- Stream link for the stream to be deleted.headers
- Optional request-specific headers.options
- Optional request-specific options.public void download()
public void download(StringList groups)
Download backend data changes into the local offline store.
groups
- If empty, then download from all entity sets. If non-empty, then it specifies groups to be included.public ByteStream downloadMedia(EntityValue entity)
downloadMedia
in class DataService
entity
- Entity parameter.public ByteStream downloadMedia(EntityValue entity, HttpHeaders headers)
downloadMedia
in class DataService
entity
- Entity parameter.headers
- Headers parameter.public ByteStream downloadMedia(EntityValue entity, HttpHeaders headers, RequestOptions options)
Obtain a stream for downloading the content of a media entity from the target system.
Caution: streams are often used for large content that may not fit (all at once) in available application memory.
Having too many threads simultaneously downloading streams, or using ByteStream.readAndClose
,
may result in out-of-memory conditions on memory-constrained devices.
public void downloadMediaExample() { MediaService service = this.getService(); DataQuery query = new DataQuery().filter(Image.label.equal("Smiley")) .top(1); Image image = service.getImage(query); ByteStream stream = service.downloadMedia(image); byte[] data = stream.readAndClose(); assert BinaryOperator.equal(data, com.sap.cloud.server.odata.core.StringFunction.toBinary(";-)")); assert NullableString.hasValue(stream.getMediaType(), "text/plain"); }
public void downloadMediaExample() { DataService service = this.getService(); EntitySet imagesEntitySet = service.getEntitySet("Images"); EntityType imageEntityType = imagesEntitySet.getEntityType(); Property labelProperty = imageEntityType.getProperty("label"); DataQuery query = new DataQuery().from(imagesEntitySet) .filter(labelProperty.equal("Smiley")).top(1); EntityValue image = service.executeQuery(query).getRequiredEntity(); ByteStream stream = service.downloadMedia(image); byte[] data = stream.readAndClose(); assert BinaryOperator.equal(data, com.sap.cloud.server.odata.core.StringFunction.toBinary(";-)")); assert NullableString.hasValue(stream.getMediaType(), "text/plain"); }
downloadMedia
in class DataService
entity
- Entity whose content is to be downloaded.headers
- Optional request-specific headers.options
- Optional request-specific options.public ByteStream downloadStream(EntityValue entity, StreamLink link)
downloadStream
in class DataService
entity
- Entity parameter.link
- Link parameter.public ByteStream downloadStream(EntityValue entity, StreamLink link, HttpHeaders headers)
downloadStream
in class DataService
entity
- Entity parameter.link
- Link parameter.headers
- Headers parameter.public ByteStream downloadStream(EntityValue entity, StreamLink link, HttpHeaders headers, RequestOptions options)
Obtain a stream for downloading the content of a stream property from the target system.
Caution: streams are often used for large content that may not fit (all at once) in available application memory.
Having too many threads simultaneously downloading streams, or using ByteStream.readAndClose
,
may result in out-of-memory conditions on memory-constrained devices.
public void downloadStreamExample() { MediaService service = this.getService(); DataQuery query = new DataQuery().filter(Video.label.equal("Happier")) .top(1); Video video = service.getVideo(query); ByteStream stream = service.downloadStream(video, video.getContent()); byte[] data = stream.readAndClose(); assert BinaryOperator.equal(data, com.sap.cloud.server.odata.core.StringFunction.toBinary("...")); assert NullableString.hasValue(stream.getMediaType(), "text/plain"); }
public void downloadStreamExample() { DataService service = this.getService(); EntitySet videosEntitySet = service.getEntitySet("Videos"); EntityType videoEntityType = videosEntitySet.getEntityType(); Property labelProperty = videoEntityType.getProperty("label"); Property contentProperty = videoEntityType.getProperty("content"); DataQuery query = new DataQuery().from(videosEntitySet) .filter(labelProperty.equal("Happier")).top(1); EntityValue video = service.executeQuery(query).getRequiredEntity(); StreamLink link = contentProperty.getStreamLink(video); ByteStream stream = service.downloadStream(video, link); byte[] data = stream.readAndClose(); assert BinaryOperator.equal(data, com.sap.cloud.server.odata.core.StringFunction.toBinary("...")); assert NullableString.hasValue(stream.getMediaType(), "text/plain"); }
downloadStream
in class DataService
entity
- Entity containing the stream property whose content is to be downloaded.link
- Stream link for the stream to be downloaded.headers
- Optional request-specific headers.options
- Optional request-specific options.public DataValue executeMethod(DataMethod method)
executeMethod
in class DataService
method
- Method parameter.public DataValue executeMethod(DataMethod method, ParameterList parameters)
executeMethod
in class DataService
method
- Method parameter.parameters
- Parameters parameter.public DataValue executeMethod(DataMethod method, ParameterList parameters, HttpHeaders headers)
executeMethod
in class DataService
method
- Method parameter.parameters
- Parameters parameter.headers
- Headers parameter.public DataValue executeMethod(DataMethod method, ParameterList parameters, HttpHeaders headers, RequestOptions options)
Execute a data method (action or function) in the target system. Actions may have backend side-effects. Functions should not have backend side-effects.
executeMethod
in class DataService
method
- Data method.parameters
- Method parameters.headers
- Optional request-specific headers.options
- Optional request-specific options.null
if the method has no result.public QueryResult executeQuery(DataQuery query)
executeQuery
in class DataService
query
- Query parameter.public QueryResult executeQuery(DataQuery query, HttpHeaders headers)
executeQuery
in class DataService
query
- Query parameter.headers
- Headers parameter.public QueryResult executeQuery(DataQuery query, HttpHeaders headers, RequestOptions options)
Execute a data query to get data from the target system.
executeQuery
in class DataService
query
- Data query specifying the information to be returned.headers
- Optional request-specific headers.options
- Optional request-specific options.public PendingRequestList getFailedRequests()
public PendingRequestList getFailedRequests(DataQuery query)
public OfflineODataProvider getOfflineProvider()
Return the offline provider supporting this data service.
public OnlineODataProvider getOnlineProvider()
Return the online provider supporting this data service.
public boolean getPrettyTracing()
Return should OfflineDataService.traceWithData
show pretty-printed JSON/XML content? Defaults to false
.
OfflineDataService.traceWithData
show pretty-printed JSON/XML content? Defaults to false
.public PendingRequestList getQueuedRequests()
public PendingRequestList getQueuedRequests(DataQuery query)
public ServiceOptions getServiceOptions()
Return service options for the associated online provider.
public StorageOptions getStorageOptions()
Return storage options for the associated local database.
public boolean getTraceRequests()
Return should all requests for this data service be traced? Defaults to false
.
false
.public boolean getTraceWithData()
Return if OfflineDataService.traceRequests
is also true
, should all requests for this data service be traced with data? Defaults to false
.
Note that care must be taken when enabling tracing with data, as the resulting log files may contain sensitive information.
On the other hand, tracing with data may sometimes be invaluable for troubleshooting purposes.
OfflineDataService.traceRequests
is also true
, should all requests for this data service be traced with data? Defaults to false
.public void open()
Open the OfflineDataService.offlineProvider
, performing any necessary initialization such as creation of the local offline store.
public void pingServer()
pingServer
in class DataService
public void pingServer(HttpHeaders headers)
pingServer
in class DataService
headers
- Headers parameter.public void pingServer(HttpHeaders headers, RequestOptions options)
Ping the server.
pingServer
in class DataService
headers
- Optional request-specific headers.options
- Optional request-specific options.public void processBatch(RequestBatch batch)
processBatch
in class DataService
batch
- Batch parameter.public void processBatch(RequestBatch batch, HttpHeaders headers)
processBatch
in class DataService
batch
- Batch parameter.headers
- Headers parameter.public void processBatch(RequestBatch batch, HttpHeaders headers, RequestOptions options)
Execute a request batch in the target system.
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."); }
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."); }
processBatch
in class DataService
batch
- The request batch.headers
- Optional request-specific headers.options
- Optional request-specific options.public void setPrettyTracing(boolean value)
Set should OfflineDataService.traceWithData
show pretty-printed JSON/XML content? Defaults to false
.
value
- Should OfflineDataService.traceWithData
show pretty-printed JSON/XML content? Defaults to false
.public void setTraceRequests(boolean value)
Set should all requests for this data service be traced? Defaults to false
.
value
- Should all requests for this data service be traced? Defaults to false
.public void setTraceWithData(boolean value)
Set if OfflineDataService.traceRequests
is also true
, should all requests for this data service be traced with data? Defaults to false
.
Note that care must be taken when enabling tracing with data, as the resulting log files may contain sensitive information.
On the other hand, tracing with data may sometimes be invaluable for troubleshooting purposes.
value
- If OfflineDataService.traceRequests
is also true
, should all requests for this data service be traced with data? Defaults to false
.public void updateEntity(EntityValue entity)
updateEntity
in class DataService
entity
- Entity parameter.public void updateEntity(EntityValue entity, HttpHeaders headers)
updateEntity
in class DataService
entity
- Entity parameter.headers
- Headers parameter.public void updateEntity(EntityValue entity, HttpHeaders headers, RequestOptions options)
Update an entity in the target system.
public void updateEntityExample() { NorthwindService service = this.getService(); DataQuery query = new DataQuery().top(1) .filter(Customer.contactName.equal("Jean-Luc Picard")); Customer customer = service.getCustomer(query); customer.setContactName("Beverly Crusher"); service.updateEntity(customer); }
public void updateEntityExample() { DataService service = this.getService(); EntitySet customersEntitySet = service.getEntitySet("Customers"); EntityType customerEntityType = customersEntitySet.getEntityType(); Property contactNameProperty = customerEntityType.getProperty("ContactName"); DataQuery query = new DataQuery().top(1).from(customersEntitySet) .filter(contactNameProperty.equal("Jean-Luc Picard")); EntityValue customer = service.executeQuery(query).getRequiredEntity(); contactNameProperty.setString(customer, "Beverly Crusher"); service.updateEntity(customer); }
public void updateEntityWithReplaceExample() { NorthwindService service = this.getService(); DataQuery query = new DataQuery().top(1) .filter(Customer.contactName.equal("Beverly Crusher")); Customer customer = service.getCustomer(query); customer.setContactName("William Riker"); RequestOptions options = new RequestOptions(); options.setUpdateMode(UpdateMode.REPLACE); service.updateEntity(customer, com.sap.cloud.server.odata.http.HttpHeaders.empty, options); }
public void updateEntityWithReplaceExample() { DataService service = this.getService(); EntitySet customersEntitySet = service.getEntitySet("Customers"); EntityType customerEntityType = customersEntitySet.getEntityType(); Property contactNameProperty = customerEntityType.getProperty("ContactName"); DataQuery query = new DataQuery().top(1).from(customersEntitySet) .filter(contactNameProperty.equal("Beverly Crusher")); EntityValue customer = service.executeQuery(query).getRequiredEntity(); contactNameProperty.setString(customer, "William Riker"); RequestOptions options = new RequestOptions(); options.setUpdateMode(UpdateMode.REPLACE); service.updateEntity(customer, com.sap.cloud.server.odata.http.HttpHeaders.empty, options); }
updateEntity
in class DataService
entity
- Entity to be updated.headers
- Optional request-specific headers.options
- Optional request-specific options.public void updateLink(EntityValue from, Property property, EntityValue to)
updateLink
in class DataService
from
- From parameter.property
- Property parameter.to
- To parameter.public void updateLink(EntityValue from, Property property, EntityValue to, HttpHeaders headers)
updateLink
in class DataService
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)
Update a link from a source entity to a target entity.
public void updateLinkExample() { NorthwindService service = this.getService(); Product product = service.getProduct(new DataQuery().top(1)); Category category = service.getCategory(new DataQuery().skip(2).top(1)); service.updateLink(product, Product.category, category); }
public void updateLinkExample() { DataService service = this.getService(); EntitySet productsEntitySet = service.getEntitySet("Products"); EntitySet categoriesEntitySet = service.getEntitySet("Categories"); EntityType productEntityType = productsEntitySet.getEntityType(); Property categoryProperty = productEntityType.getProperty("Category"); EntityValue product = service.executeQuery(new DataQuery() .from(productsEntitySet).top(1)) .getRequiredEntity(); EntityValue category = service.executeQuery(new DataQuery() .from(categoriesEntitySet).skip(2).top(1)) .getRequiredEntity(); service.updateLink(product, categoryProperty, category); }
updateLink
in class DataService
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
- Optional request-specific headers.options
- Optional request-specific options.public void upload()
Upload local pending changes to the backend OData service.
public void uploadMedia(EntityValue entity, StreamBase content)
uploadMedia
in class DataService
entity
- Entity parameter.content
- Content parameter.public void uploadMedia(EntityValue entity, StreamBase content, HttpHeaders headers)
uploadMedia
in class DataService
entity
- Entity parameter.content
- Content parameter.headers
- Headers parameter.public void uploadMedia(EntityValue entity, StreamBase content, HttpHeaders headers, RequestOptions options)
Upload content for a media entity to the target system.
Caution: Having too many threads simultaneously uploading streams
may result in out-of-memory conditions on memory-constrained devices.
Note: this function cannot be used to create a media entity. See DataService.createMedia
.
public void uploadMediaExample() { MediaService service = this.getService(); DataQuery query = new DataQuery().filter(Image.label.equal("Smiley")) .top(1); Image image = service.getImage(query); ByteStream content = ByteStream.fromBinary(com.sap.cloud.server.odata.core.StringFunction.toBinary(";-)")); content.setMediaType("text/plain"); service.uploadMedia(image, content); }
public void uploadMediaExample() { DataService service = this.getService(); EntitySet imagesEntitySet = service.getEntitySet("Images"); EntityType imageEntityType = imagesEntitySet.getEntityType(); Property labelProperty = imageEntityType.getProperty("label"); DataQuery query = new DataQuery().from(imagesEntitySet) .filter(labelProperty.equal("Smiley")).top(1); EntityValue image = service.executeQuery(query).getRequiredEntity(); ByteStream content = ByteStream.fromBinary(com.sap.cloud.server.odata.core.StringFunction.toBinary(";-)")); content.setMediaType("text/plain"); service.uploadMedia(image, content); }
uploadMedia
in class DataService
content
- Upload stream content. Will be closed before this function returns.entity
- Entity whose content is to be uploaded.headers
- Optional request-specific headers.options
- Optional request-specific options.public void uploadStream(EntityValue entity, StreamLink link, StreamBase content)
uploadStream
in class DataService
entity
- Entity parameter.link
- Link parameter.content
- Content parameter.public void uploadStream(EntityValue entity, StreamLink link, StreamBase content, HttpHeaders headers)
uploadStream
in class DataService
entity
- Entity parameter.link
- Link parameter.content
- Content parameter.headers
- Headers parameter.public void uploadStream(EntityValue entity, StreamLink link, StreamBase content, HttpHeaders headers, RequestOptions options)
Upload content for a stream property to the target system. Caution: Having too many threads simultaneously uploading streams may result in out-of-memory conditions on memory-constrained devices.
public void uploadStreamExample() { MediaService service = this.getService(); Video video = new Video(); video.setLabel("Happy"); ByteStream content = ByteStream.fromBinary(com.sap.cloud.server.odata.core.StringFunction.toBinary("...")); content.setMediaType("text/plain"); service.createEntity(video); String contentETagAfterCreate = video.getContent().getEntityTag(); assert contentETagAfterCreate == null; service.uploadStream(video, video.getContent(), content); service.loadEntity(video); String contentETagAfterUpload = video.getContent().getEntityTag(); assert contentETagAfterUpload != null; video.setLabel("Happier"); service.updateEntity(video); String contentETagAfterUpdate = video.getContent().getEntityTag(); assert NullableString.equal(contentETagAfterUpdate, contentETagAfterUpload); }
public void uploadStreamExample() { DataService service = this.getService(); EntitySet videosEntitySet = service.getEntitySet("Videos"); EntityType videoEntityType = videosEntitySet.getEntityType(); Property labelProperty = videoEntityType.getProperty("label"); Property contentProperty = videoEntityType.getProperty("content"); EntityValue video = EntityValue.ofType(videoEntityType); labelProperty.setString(video, "Happy"); ByteStream content = ByteStream.fromBinary(com.sap.cloud.server.odata.core.StringFunction.toBinary("...")); content.setMediaType("text/plain"); service.createEntity(video); StreamLink link = contentProperty.getStreamLink(video); String contentETagAfterCreate = link.getEntityTag(); assert contentETagAfterCreate == null; service.uploadStream(video, link, content); service.loadEntity(video); String contentETagAfterUpload = link.getEntityTag(); assert contentETagAfterUpload != null; labelProperty.setString(video, "Happier"); service.updateEntity(video); String contentETagAfterUpdate = link.getEntityTag(); assert NullableString.equal(contentETagAfterUpdate, contentETagAfterUpload); }
uploadStream
in class DataService
entity
- Entity containing the stream property whose content is to be uploaded.link
- Stream link for the stream to be uploaded.content
- Upload stream content. Will be closed before this function returns.headers
- Optional request-specific headers.options
- Optional request-specific options.