public class OnlineODataProvider extends java.lang.Object implements DataServiceProvider
A data service provider for online OData.
Constructor and Description |
---|
OnlineODataProvider(java.lang.String serviceName,
java.lang.String serviceRoot)
|
OnlineODataProvider(java.lang.String serviceName,
java.lang.String serviceRoot,
HttpHandler httpHandler)
Constructs an online OData provider.
|
Modifier and Type | Method and Description |
---|---|
void |
acquireToken()
If this data service requires a security token, then acquire it now.
|
void |
beginTransaction()
Begin a server transaction.
|
void |
commit()
Commit the current server transaction.
|
void |
createEntity(EntityValue entity,
HttpHeaders headers,
RequestOptions options)
Create an entity in the target system.
|
void |
createLink(EntityValue from,
Property property,
EntityValue to,
HttpHeaders headers,
RequestOptions options)
Create a link from a source entity to a target entity.
|
void |
createMedia(EntityValue entity,
StreamBase content,
HttpHeaders headers,
RequestOptions options)
Create a media entity with the specified content in the target system.
|
void |
deleteByQuery(DataQuery query,
HttpHeaders headers,
RequestOptions options)
Execute query to delete data from the target system.
|
void |
deleteEntity(EntityValue entity,
HttpHeaders headers,
RequestOptions options)
Delete an entity from the target system.
|
void |
deleteLink(EntityValue from,
Property property,
EntityValue to,
HttpHeaders headers,
RequestOptions options)
Delete a link from a source entity to a target entity.
|
void |
deleteRepeatableRequest(GuidValue requestID)
Ask the server to forget (delete) the repeatable request with the specified
requestID . |
void |
deleteRepeatableRequests(GuidValue clientID)
Ask the server to forget (delete) the repeatable requests with the specified
clientID . |
void |
deleteStream(EntityValue entity,
StreamLink link,
HttpHeaders headers,
RequestOptions options)
Delete the content of a stream property from the target system.
|
DeltaStream |
deltaStream(DataQuery query)
Execute a query and obtain the result as a stream of delta items.
|
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,
HttpHeaders headers,
RequestOptions options)
Obtain a stream for downloading the content of a stream property from the target system.
|
DataContext |
entityContext(EntitySet entitySet)
|
DataContext |
entityContext(EntitySet entitySet,
StructureType derivedType)
|
DataContext |
entityContext(EntitySet entitySet,
StructureType derivedType,
int format)
|
DataContext |
entityContext(EntitySet entitySet,
StructureType derivedType,
int format,
int version)
See Also:
|
EntityStream |
entityStream(DataQuery query)
Execute a query and obtain the result as a stream of entity values.
|
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,
HttpHeaders headers,
RequestOptions options)
Execute a data query to get data from the target system.
|
CsdlDocument |
fetchMetadata(HttpHeaders headers,
RequestOptions options)
Fetch latest service metadata and return it, but don't change the
OnlineODataProvider.metadata property. |
DataTransaction |
getDataTransaction()
Return obtain a thread-local transaction manager for this data service.
|
HttpCookies |
getHttpCookies()
Return obsolete.
|
HttpHeaders |
getHttpHeaders()
Return obsolete.
|
CsdlDocument |
getMetadata()
Return the OData CSDL document (service metadata).
|
NetworkOptions |
getNetworkOptions()
Return options for network communication, which for OData uses HTTP or HTTPS.
|
boolean |
getPrettyTracing()
Return should
OnlineODataProvider.traceWithData show pretty-printed JSON/XML content? Defaults to false . |
java.lang.String |
getServiceName()
Return the service name.
|
ServiceOptions |
getServiceOptions()
Return options for this data service, both client-side and server-side.
|
java.lang.String |
getServiceRoot()
Return the service root URL.
|
HttpCookies |
getSessionCookies()
Return HTTP cookies which should be sent in future online requests (by the current session / thread).
|
HttpHeaders |
getSessionHeaders()
Return HTTP headers which should be sent in future online requests (by the current session / thread).
|
HttpCookies |
getSharedCookies()
Return HTTP cookies which should be sent in future online requests (shared by all sessions / threads).
|
HttpHeaders |
getSharedHeaders()
Return HTTP headers which should be sent in future online requests (shared by all sessions / threads).
|
boolean |
getTraceRequests()
Return should all requests for this data service be traced? Defaults to
false . |
boolean |
getTraceWithData()
Return if
OnlineODataProvider.traceRequests is also true , should all requests for this data service be traced with data? Defaults to false . |
boolean |
hasMetadata()
Return
true if the service metadata has been loaded by OnlineODataProvider.loadMetadata , or is automatically available in a generated DataService proxy class. |
void |
loadMetadata(HttpHeaders headers,
RequestOptions options)
Load service metadata (if not already loaded).
|
void |
login(java.lang.String username,
java.lang.String password)
Set the shared
Authorization header to be used for HTTP/HTTPS with pre-emptive BASIC authentication. |
java.lang.String |
metadataText(int format)
Return an OData metadata document for the current service.
|
void |
pingServer(HttpHeaders headers,
RequestOptions options)
Ping the server, by sending a non-changing request that the server can respond to quickly.
|
void |
processBatch(RequestBatch batch,
HttpHeaders headers,
RequestOptions options)
Execute a request batch in the target system.
|
DataContext |
queryContext()
See queryContext(int).
|
DataContext |
queryContext(int version)
See Also:
|
void |
rollback()
Rollback the current server transaction.
|
java.lang.String |
serviceDocument(int format)
Return the service document, in XML or JSON format.
|
void |
setMetadata(CsdlDocument value)
Set the OData CSDL document (service metadata).
|
void |
setPrettyTracing(boolean value)
Set should
OnlineODataProvider.traceWithData show pretty-printed JSON/XML content? Defaults to false . |
void |
setServiceRoot(java.lang.String value)
Set the service root URL.
|
void |
setTraceRequests(boolean value)
Set should all requests for this data service be traced? Defaults to
false . |
void |
setTraceWithData(boolean value)
Set if
OnlineODataProvider.traceRequests is also true , should all requests for this data service be traced with data? Defaults to false . |
void |
transaction(com.sap.cloud.server.odata.core.Action0 work)
Perform some work within a service-managed transaction.
|
void |
unloadMetadata()
Unload service metadata (if previously loaded).
|
void |
updateEntity(EntityValue entity,
HttpHeaders headers,
RequestOptions options)
Update an entity in the target system.
|
void |
updateLink(EntityValue from,
Property property,
EntityValue to,
HttpHeaders headers,
RequestOptions options)
Update a link from a source entity to a target entity.
|
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.
|
void |
uploadStream(EntityValue entity,
StreamLink link,
StreamBase content,
HttpHeaders headers,
RequestOptions options)
Upload content for a stream property to the target system.
|
public OnlineODataProvider(java.lang.String serviceName, java.lang.String serviceRoot)
serviceName
- ServiceName parameter.serviceRoot
- ServiceRoot parameter.public OnlineODataProvider(java.lang.String serviceName, java.lang.String serviceRoot, HttpHandler httpHandler)
Constructs an online OData provider.
serviceName
- Service name.serviceRoot
- Service root URL.httpHandler
- (nullable) HTTP handler (optional).public void acquireToken()
If this data service requires a security token, then acquire it now.
public void beginTransaction()
Begin a server transaction.
beginTransaction
in interface DataServiceProvider
public void commit()
Commit the current server transaction.
commit
in interface DataServiceProvider
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.
DataServiceException
if the entity set hasn't been explicitly provided before calling createEntity
and there isn't a unique entity set for the entity type.
createEntity
in interface DataServiceProvider
entity
- Entity to be created.headers
- Request-specific headers.options
- Request-specific options.public void createLink(EntityValue from, Property property, EntityValue to, HttpHeaders headers, RequestOptions options)
Create a link from a source entity to a target entity.
createLink
in interface DataServiceProvider
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 createMedia(EntityValue entity, StreamBase content, HttpHeaders headers, RequestOptions options)
Create a media entity with the specified content in the target system.
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.
createMedia
in interface DataServiceProvider
entity
- Entity to be created.content
- Initial content. Must be a ByteStream
or CharStream
. Will be closed before this function returns.headers
- Request-specific headers.options
- Request-specific options.public void deleteByQuery(DataQuery query, HttpHeaders headers, RequestOptions options)
Execute query to delete data from the target system.
deleteByQuery
in interface DataServiceProvider
query
- Data query specifying the information to be deleted.headers
- Request-specific headers.options
- Request-specific options.public void deleteEntity(EntityValue entity, HttpHeaders headers, RequestOptions options)
Delete an entity from the target system.
deleteEntity
in interface DataServiceProvider
entity
- Entity to be deleted.headers
- Request-specific headers.options
- Request-specific options.public void deleteLink(EntityValue from, Property property, EntityValue to, HttpHeaders headers, RequestOptions options)
Delete a link from a source entity to a target entity.
deleteLink
in interface DataServiceProvider
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 void deleteRepeatableRequest(GuidValue requestID)
Ask the server to forget (delete) the repeatable request with the specified requestID
.
requestID
- Repeatability-Request-ID header value used in previous repeatable request.public void deleteRepeatableRequests(GuidValue clientID)
Ask the server to forget (delete) the repeatable requests with the specified clientID
.
clientID
- Repeatability-Client-ID header value used in previous repeatable requests.public void deleteStream(EntityValue entity, StreamLink link, HttpHeaders headers, RequestOptions options)
Delete the content of a stream property from the target system.
deleteStream
in interface DataServiceProvider
entity
- Entity containing the stream property whose content is to be deleted.headers
- Request-specific headers.options
- Request-specific options.link
- Stream link for the stream to be deleted.public DeltaStream deltaStream(DataQuery query)
Execute a query and obtain the result as a stream of delta items.
query
- Data query.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.
downloadMedia
in interface DataServiceProvider
entity
- Entity whose content is to be downloaded.headers
- Request-specific headers.options
- Request-specific options.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.
downloadStream
in interface DataServiceProvider
entity
- Entity containing the stream property whose content is to be downloaded.link
- Stream link for the stream to be downloaded.headers
- Request-specific headers.options
- Request-specific options.public DataContext entityContext(EntitySet entitySet)
entitySet
- EntitySet parameter.public DataContext entityContext(EntitySet entitySet, StructureType derivedType)
entitySet
- EntitySet parameter.derivedType
- DerivedType parameter.public DataContext entityContext(EntitySet entitySet, StructureType derivedType, int format)
entitySet
- EntitySet parameter.derivedType
- DerivedType parameter.format
- Format parameter.public DataContext entityContext(EntitySet entitySet, StructureType derivedType, int format, int version)
entityContext
in interface DataServiceProvider
entitySet
- Entity set for the context.derivedType
- (nullable) Derived type for query results.format
- Data format for the context. If zero or not specified, then the ServiceOptions.dataFormat
for this data service is used.version
- Data version for the context. If zero or not specified, then the ServiceOptions.dataVersion
for this data service is used.public EntityStream entityStream(DataQuery query)
Execute a query and obtain the result as a stream of entity values.
query
- Data query.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.
DataServiceException
or DataNetworkException
if an error occurs during action invocation.
executeMethod
in interface DataServiceProvider
method
- Data method.parameters
- Method parameters.headers
- Request-specific headers.options
- Request-specific options.public QueryResult executeQuery(DataQuery query, HttpHeaders headers, RequestOptions options)
Execute a data query to get data from the target system.
executeQuery
in interface DataServiceProvider
query
- Data query specifying the information to be returned.headers
- Request-specific headers.options
- Request-specific options.public CsdlDocument fetchMetadata(HttpHeaders headers, RequestOptions options)
Fetch latest service metadata and return it, but don't change the OnlineODataProvider.metadata
property.
fetchMetadata
in interface DataServiceProvider
headers
- Optional request-specific headers.options
- Optional request-specific options.public DataTransaction getDataTransaction()
Return obtain a thread-local transaction manager for this data service.
getDataTransaction
in interface DataServiceProvider
public HttpCookies getHttpCookies()
Return obsolete. Use OnlineODataProvider.sessionCookies
or OnlineODataProvider.sharedCookies
.
OnlineODataProvider.sessionCookies
or OnlineODataProvider.sharedCookies
.public HttpHeaders getHttpHeaders()
Return obsolete. Use OnlineODataProvider.sessionHeaders
or OnlineODataProvider.sharedHeaders
.
OnlineODataProvider.sessionHeaders
or OnlineODataProvider.sharedHeaders
.public CsdlDocument getMetadata()
Return the OData CSDL document (service metadata).
getMetadata
in interface DataServiceProvider
public final NetworkOptions getNetworkOptions()
Return options for network communication, which for OData uses HTTP or HTTPS.
public boolean getPrettyTracing()
Return should OnlineODataProvider.traceWithData
show pretty-printed JSON/XML content? Defaults to false
.
OnlineODataProvider.traceWithData
show pretty-printed JSON/XML content? Defaults to false
.public java.lang.String getServiceName()
Return the service name.
getServiceName
in interface DataServiceProvider
public final ServiceOptions getServiceOptions()
Return options for this data service, both client-side and server-side.
public java.lang.String getServiceRoot()
Return the service root URL. The service root URL always terminates with a forward slash.
public HttpCookies getSessionCookies()
Return HTTP cookies which should be sent in future online requests (by the current session / thread).
public HttpHeaders getSessionHeaders()
Return HTTP headers which should be sent in future online requests (by the current session / thread).
public HttpCookies getSharedCookies()
Return HTTP cookies which should be sent in future online requests (shared by all sessions / threads).
public HttpHeaders getSharedHeaders()
Return HTTP headers which should be sent in future online requests (shared by all sessions / threads).
public boolean getTraceRequests()
Return should all requests for this data service be traced? Defaults to false
.
false
.public boolean getTraceWithData()
Return if OnlineODataProvider.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.
OnlineODataProvider.traceRequests
is also true
, should all requests for this data service be traced with data? Defaults to false
.public boolean hasMetadata()
Return true
if the service metadata has been loaded by OnlineODataProvider.loadMetadata
, or is automatically available in a generated DataService proxy class.
hasMetadata
in interface DataServiceProvider
true
if the service metadata has been loaded by OnlineODataProvider.loadMetadata
, or is automatically available in a generated DataService proxy class.public void loadMetadata(HttpHeaders headers, RequestOptions options)
Load service metadata (if not already loaded).
loadMetadata
in interface DataServiceProvider
headers
- Optional request-specific headers.options
- Optional request-specific options.public void login(java.lang.String username, java.lang.String password)
Set the shared Authorization
header to be used for HTTP/HTTPS with pre-emptive BASIC authentication.
If credentials are required by the remote data service, they must be set before
any function calls (such as OnlineODataProvider.loadMetadata
) which may make a network request.
For services which require challenge-based authentication, a request interceptor/observer should be used.
username
- Client's username.password
- Client's password.public java.lang.String metadataText(int format)
Return an OData metadata document for the current service.
metadataText
in interface DataServiceProvider
format
- Metadata format. Only XML is presently supported.public void pingServer(HttpHeaders headers, RequestOptions options)
Ping the server, by sending a non-changing request that the server can respond to quickly. The default ping behaviour is to send a HEAD request for the service document.
pingServer
in interface DataServiceProvider
headers
- Optional request-specific headers.options
- Optional request-specific options.public void processBatch(RequestBatch batch, HttpHeaders headers, RequestOptions options)
Execute a request batch in the target system.
processBatch
in interface DataServiceProvider
batch
- The request batch.headers
- Request-specific headers.options
- Request-specific options.public DataContext queryContext()
public DataContext queryContext(int version)
queryContext
in interface DataServiceProvider
version
- Data version for the context. If zero or not specified, then the ServiceOptions.dataVersion
for this data service is used.public void rollback()
Rollback the current server transaction.
rollback
in interface DataServiceProvider
public java.lang.String serviceDocument(int format)
Return the service document, in XML or JSON format.
serviceDocument
in interface DataServiceProvider
format
- Data format (XML or JSON).public void setMetadata(CsdlDocument value)
Set the OData CSDL document (service metadata).
setMetadata
in interface DataServiceProvider
value
- The OData CSDL document (service metadata).public void setPrettyTracing(boolean value)
Set should OnlineODataProvider.traceWithData
show pretty-printed JSON/XML content? Defaults to false
.
value
- Should OnlineODataProvider.traceWithData
show pretty-printed JSON/XML content? Defaults to false
.public void setServiceRoot(java.lang.String value)
Set the service root URL. The service root URL always terminates with a forward slash.
value
- The service root URL.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 OnlineODataProvider.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 OnlineODataProvider.traceRequests
is also true
, should all requests for this data service be traced with data? Defaults to false
.public void transaction(com.sap.cloud.server.odata.core.Action0 work)
Perform some work within a service-managed transaction.
work
- Work to be executed within a transaction.public void unloadMetadata()
Unload service metadata (if previously loaded).
unloadMetadata
in interface DataServiceProvider
public void updateEntity(EntityValue entity, HttpHeaders headers, RequestOptions options)
Update an entity in the target system.
updateEntity
in interface DataServiceProvider
entity
- Entity to be updated.headers
- Request-specific headers.options
- Request-specific options.public void updateLink(EntityValue from, Property property, EntityValue to, HttpHeaders headers, RequestOptions options)
Update a link from a source entity to a target entity.
updateLink
in interface DataServiceProvider
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.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
.
uploadMedia
in interface DataServiceProvider
entity
- Entity whose content is to be uploaded.content
- Upload stream content. Will be closed before this function returns.headers
- Request-specific headers.options
- Request-specific options.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.
uploadStream
in interface DataServiceProvider
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
- Request-specific headers.options
- Request-specific options.