public class DataClient
extends java.lang.Object
The DataClient is the access point to the
Gluon CloudLink Data Storage service.
It assists in using the DataProvider
with data stored on Gluon CloudLink as the data source. For instance,
to retrieve a list from Gluon CloudLink, you can use the following code:
DataClient dataClient = DataClientBuilder.create().build(); GluonObservableList<Item> items = DataProvider.retrieveList(dataClient.createListDataReader("items", Item.class));
Note: data will be always be stored in the private storage location for the application on the device. As
a result, the DataClient depends on the StorageService
, so make sure that the
storage plugin has been enabled in your Gluon Mobile application build configuration:
jfxmobile { downConfig { plugins = 'storage', ... } }
Modifier and Type | Method and Description |
---|---|
<E> ListDataReader<E> |
createListDataReader(RemoteFunction function,
java.lang.Class<E> objectClass)
Creates an instance of
ListDataReader that triggers a call to the provided function . |
<E> ListDataReader<E> |
createListDataReader(RemoteFunction function,
InputStreamIterableInputConverter<E> converter)
Creates an instance of
ListDataReader that triggers a call to the provided function . |
<E> ListDataReader<E> |
createListDataReader(java.lang.String identifier,
java.lang.Class<E> objectClass)
Creates an instance of
ListDataReader that can be passed directly in the
DataProvider.retrieveList(ListDataReader) method. |
<E> ListDataReader<E> |
createListDataReader(java.lang.String identifier,
java.lang.Class<E> objectClass,
SyncFlag... syncFlags)
Creates an instance of
ListDataReader that can be passed directly in the
DataProvider.retrieveList(ListDataReader) method. |
<E> ListDataReader<E> |
createListDataReaderAsync(RemoteFunction function,
java.lang.Class<E> objectClass)
Creates an instance of
ListDataReader that triggers a call to the provided function . |
<E> ListDataReader<E> |
createListDataReaderAsync(RemoteFunction function,
InputStreamIterableInputConverter<E> converter)
Creates an instance of
ListDataReader that triggers a call to the provided function . |
<T> ObjectDataReader<T> |
createObjectDataReader(RemoteFunction function,
java.lang.Class<T> objectClass)
Creates an instance of
ObjectDataReader that triggers a call to the provided function . |
<T> ObjectDataReader<T> |
createObjectDataReader(RemoteFunction function,
InputStreamInputConverter<T> converter)
Creates an instance of
ObjectDataReader that triggers a call to the provided function . |
<T> ObjectDataReader<T> |
createObjectDataReader(java.lang.String identifier,
java.lang.Class<T> objectClass,
SyncFlag... syncFlags)
Creates an instance of
ObjectDataReader that can be passed directly in the
DataProvider.retrieveObject(ObjectDataReader) method. |
<T> ObjectDataRemover<T> |
createObjectDataRemover()
Creates an instance of
ObjectDataRemover that can be passed directly in the
DataProvider.removeObject(GluonObservableObject, ObjectDataRemover) method. |
<T> ObjectDataWriter<T> |
createObjectDataWriter(java.lang.String identifier,
java.lang.Class<T> objectClass,
SyncFlag... syncFlags)
Creates an instance of
ObjectDataWriter that can be passed directly in the
DataProvider.storeObject(Object, ObjectDataWriter) method. |
OperationMode |
getOperationMode()
Get the operation mode to use when storing or retrieving data with this DataClient instance.
|
<E> void |
push(GluonObservableList<E> list)
Push any changes made to the list.
|
<E> void |
push(GluonObservableList<E> list,
boolean fully)
Push any changes made to the list.
|
<T> void |
push(GluonObservableObject<T> object)
Push any changes made to the object.
|
public OperationMode getOperationMode()
public <T> ObjectDataReader<T> createObjectDataReader(java.lang.String identifier, java.lang.Class<T> objectClass, SyncFlag... syncFlags)
ObjectDataReader
that can be passed directly in the
DataProvider.retrieveObject(ObjectDataReader)
method. The object data reader will read the object with
the specified identifier
.
Any of the following synchronization flags can be passed in with the syncFlags
parameter:
SyncFlag.OBJECT_READ_THROUGH
and SyncFlag.OBJECT_WRITE_THROUGH
. All other flags will be silently
ignored.
T
- the type of the object that is retrievedidentifier
- the identifier of the object to retrieveobjectClass
- the class of the object to retrievesyncFlags
- an optional list of synchronization flagspublic <T> ObjectDataWriter<T> createObjectDataWriter(java.lang.String identifier, java.lang.Class<T> objectClass, SyncFlag... syncFlags)
ObjectDataWriter
that can be passed directly in the
DataProvider.storeObject(Object, ObjectDataWriter)
method. The object data writer will write the object
with the specified identifier
.
Any of the following synchronization flags can be passed in with the syncFlags
parameter:
SyncFlag.OBJECT_READ_THROUGH
and SyncFlag.OBJECT_WRITE_THROUGH
. All other flags will be silently
ignored.
T
- the type of the object that is storedidentifier
- the identifier of the object to storeobjectClass
- the class of the object to storesyncFlags
- an optional list of synchronization flagspublic <T> ObjectDataRemover<T> createObjectDataRemover()
ObjectDataRemover
that can be passed directly in the
DataProvider.removeObject(GluonObservableObject, ObjectDataRemover)
method. The observable object that is
passed in with the removeObject method will be used to get the identifier of the object that needs to be removed.
Note: this method can only be used for removing observable objects that were either retrieved using an ObjectDataReader created by a DataClient instance or stored using an ObjectDataWriter created by a DataClient instance.
T
- the type of the object to removepublic <T> ObjectDataReader<T> createObjectDataReader(RemoteFunction function, java.lang.Class<T> objectClass)
ObjectDataReader
that triggers a call to the provided function
. The
returned instance can be passed directly in the DataProvider.retrieveObject(ObjectDataReader)
method.
The converter that is responsible for providing an instance of objectClass
based on the response of
the remote function call will be determined automatically. Use
createObjectDataReader(RemoteFunction, InputStreamInputConverter)
to specify a custom converter that can
handle the response.T
- the type of the object that is retrievedfunction
- the remote function to call for retrieving the objectobjectClass
- the class of the object to retrievepublic <T> ObjectDataReader<T> createObjectDataReader(RemoteFunction function, InputStreamInputConverter<T> converter)
ObjectDataReader
that triggers a call to the provided function
. The
returned instance can be passed directly in the DataProvider.retrieveObject(ObjectDataReader)
method.
The response from the call to the remote function will be converted by the specified converter
.T
- the type of the object that is retrievedfunction
- the remote function to call for retrieving the objectconverter
- the converter to use for transforming the response into an objectpublic <E> ListDataReader<E> createListDataReader(java.lang.String identifier, java.lang.Class<E> objectClass)
ListDataReader
that can be passed directly in the
DataProvider.retrieveList(ListDataReader)
method. This method is the same as calling
createListDataReader(String, Class, SyncFlag...)
with the following two synchronization flags:
SyncFlag.LIST_READ_THROUGH
and SyncFlag.LIST_WRITE_THROUGH
.E
- the type of the objects contained in the list to readidentifier
- the identifier of the list to retrieveobjectClass
- the class of the objects contained in the list to readpublic <E> ListDataReader<E> createListDataReader(java.lang.String identifier, java.lang.Class<E> objectClass, SyncFlag... syncFlags)
ListDataReader
that can be passed directly in the
DataProvider.retrieveList(ListDataReader)
method. The list data reader will read the list with the
specified identifier
together with the objects it contains.E
- the type of the objects contained in the list to readidentifier
- the identifier of the list to retrieveobjectClass
- the class of the objects contained in the list to readsyncFlags
- an optional list of synchronization flagspublic <E> ListDataReader<E> createListDataReader(RemoteFunction function, java.lang.Class<E> objectClass)
ListDataReader
that triggers a call to the provided function
. The
returned instance can be passed directly in the DataProvider.retrieveList(ListDataReader)
method. The
converter that is responsible for providing instances of objectClass
based on the response of the
remote function call will be determined automatically. Use
createListDataReader(RemoteFunction, InputStreamIterableInputConverter)
to specify a custom converter
that can handle the response.E
- the type of the objects contained in the list to readfunction
- the remote function to call for retrieving the listobjectClass
- the class of the objects contained in the list to readpublic <E> ListDataReader<E> createListDataReaderAsync(RemoteFunction function, java.lang.Class<E> objectClass)
Creates an instance of ListDataReader
that triggers a call to the provided function
. The
returned instance can be passed directly in the DataProvider.retrieveList(ListDataReader)
method.
The actual call to the endpoint of the remote function will be handled asynchronously. The response that is
returned by the remote function should have chunked transfer encoding enabled. Each chunk that is received while
reading from the response will be passed on to the returned list data reader and converted by an automatically
determined converter based on the provided objectClass
. Use
createListDataReaderAsync(RemoteFunction, InputStreamIterableInputConverter)
to specify a custom
converter that can handle the chunks.
E
- the type of the objects contained in the list to readfunction
- the remote function to call asynchronously for retrieving the listobjectClass
- the class of the objects contained in the list to readpublic <E> ListDataReader<E> createListDataReader(RemoteFunction function, InputStreamIterableInputConverter<E> converter)
ListDataReader
that triggers a call to the provided function
. The
returned instance can be passed directly in the DataProvider.retrieveList(ListDataReader)
method. The
response from the call to the remote function will be converted by the specified converter
.E
- the type of the objects contained in the list to readfunction
- the remote function to call for retrieving the listconverter
- the converter to use for transforming the response into a list of objectspublic <E> ListDataReader<E> createListDataReaderAsync(RemoteFunction function, InputStreamIterableInputConverter<E> converter)
Creates an instance of ListDataReader
that triggers a call to the provided function
. The
returned instance can be passed directly in the DataProvider.retrieveList(ListDataReader)
method.
The actual call to the endpoint of the remote function will be handled asynchronously. The response that is
returned by the remote function should have chunked transfer encoding enabled. Each chunk that is received while
reading from the response will be passed on to the returned list data reader and converted by the specified
converter
.
E
- the type of the objects contained in the list to readfunction
- the remote function to call asynchronously for retrieving the listconverter
- the converter to use for transforming the response into a list of objectspublic <E> void push(GluonObservableList<E> list)
push(GluonObservableList, boolean)
with a value of true
for the fully
parameter.E
- the type of the objects contained in the list to pushlist
- the observable list to pushpush(GluonObservableList, boolean)
public <E> void push(GluonObservableList<E> list, boolean fully)
When the fully
parameter is set to true
, all items in the list will be considered as
marked for update. Otherwise, only items that were removed or added or updated manually will be pushed. Again,
note that when using fully
with a value of true
, items that were marked for removal
will still be removed because the removal marker takes precedence over the update marker.
E
- the type of the objects contained in the list to pushlist
- the observable list to pushfully
- when true
all items in the list are considered as marked for updatepublic <T> void push(GluonObservableObject<T> object)
write through flag
.
A push can be used as a convenient way to store updates to an observable object that was already retrieved. Consider the following code, to see an example of the push method:
GluonObservableObject<Sample> sample = DataProvider.retrieveObject(dataClient.createObjectDataReader("sample", Sample.class)); // somewhere the object gets updated and you want to store the updates dataClient.push(sample);
Actually, the push method is a simple alternative to the storeObject
method that is available in DataProvider. Using that method, updating the object can be done as follows, which
is more cumbersome to write and you need to pass in the object identifier again:
DataProvider.storeObject(sample.get(), dataClient.createObjectDataWriter("sample", Sample.class));
Note: this method can only be used with observable objects that were either retrieved using an ObjectDataReader created by a DataClient instance or stored using an ObjectDataWriter created by a DataClient instance.
T
- the type of the object to pushobject
- the observable object to push