|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Dataset
Dataset is the container of Record
s. It can have up to 1k
Record
or 1 MB in size. A typical use of Dataset
is the
following.
// open or create dataset Dataset dataset = cognitoClient.openOrCreate("new dataset"); // synchronize. It pulls down latest changes from remote storage // and push local changes to remote storage dataset.synchronize(syncCallback); // reads value String highScore = dataset.getValue("high_score"); String name = dataset.getValue("name"); // sets value dataset.put("high_score", "90"); dataset.put("name", "John"); // push changes to remote if needed dataset.synchronizesyncCallback);
Nested Class Summary | |
---|---|
static interface |
Dataset.SyncCallback
This is the callback used in synchronize(SyncCallback) . |
Method Summary | |
---|---|
void |
delete()
Delete this Dataset . |
java.lang.String |
get(java.lang.String key)
Gets the value of a Record with the given key. |
java.util.Map<java.lang.String,java.lang.String> |
getAll()
Gets the key-value representation of all records of this dataset. |
java.util.List<Record> |
getAllRecords()
Retrieves all raw records, marked deleted or not, from local storage. |
DatasetMetadata |
getDatasetMetadata()
Retrieves the associated DatasetMetadata from local storage. |
long |
getLastSyncCount()
Get the last sync count of this Dataset . |
long |
getSizeInBytes(java.lang.String key)
Gets the size of a record with the given key. |
long |
getTotalSizeInBytes()
Gets the total size in bytes of this dataset. |
boolean |
isChanged(java.lang.String key)
Retrieves the status of a record. |
void |
put(java.lang.String key,
java.lang.String value)
Puts a Record with the given key and value into the
Dataset . |
void |
putAll(java.util.Map<java.lang.String,java.lang.String> values)
|
void |
remove(java.lang.String key)
Marks a Record with the given key as deleted. |
void |
resolve(java.util.List<Record> resolvedConflicts)
Saves resolved conflicting Record s into local storage. |
void |
subscribe()
Subscribes the user to update notifications for a dataset. |
void |
synchronize(Dataset.SyncCallback callback)
Synchronize Dataset between local storage and remote storage. |
void |
synchronizeOnConnectivity(Dataset.SyncCallback callback)
Attempt to synchronize Dataset when connectivity is available. |
void |
unsubscribe()
Unsubscribe the user from receiving notifications on updates to a dataset which has previously been subscribed to. |
Method Detail |
---|
DatasetMetadata getDatasetMetadata()
DatasetMetadata
from local storage.
void synchronize(Dataset.SyncCallback callback)
Dataset
between local storage and remote storage.
callback
- call backvoid synchronizeOnConnectivity(Dataset.SyncCallback callback)
Dataset
when connectivity is available. If
the connectivity is available right away, it behaves the same as
synchronize(SyncCallback)
. Otherwise it listens to connectivity
changes, and will do a sync once the connectivity is back. Note that if
this method is called multiple times, only the last synchronize request
is kept and only the last callback will fire. If either the dataset or
the callback is garbage collected, this method will not perform a sync
and the callback won't fire.
callback
- call backjava.lang.String get(java.lang.String key)
Record
with the given key. If the
Record
doesn't exist or is marked deleted, null will be returned.
key
- key of the record in the dataset.
void put(java.lang.String key, java.lang.String value)
Record
with the given key and value into the
Dataset
. If a Record
with the same key exists, its value
will be overwritten. If a Record
is marked as deleted previously,
then it will be resurrected with new value while the sync count continues
with previous value. No matter whether the value changes or not, the
record is considered as updated, and it will be written to Cognito Sync
service on next synchronize operation. If value is null, a
NullPointerException
will be thrown.
key
- key of the recordvalue
- string value of a Record
to be put into the
Dataset
void putAll(java.util.Map<java.lang.String,java.lang.String> values)
values
- void remove(java.lang.String key)
Record
with the given key as deleted. Nothing happens if
the Record
doesn't exist or is deleted already.
key
- void resolve(java.util.List<Record> resolvedConflicts)
Record
s into local storage. This is
used inside Dataset.SyncCallback.onConflict(Dataset, List)
after you
resolve all conflicts.
resolvedConflicts
- a list of records to save into local storagejava.util.List<Record> getAllRecords()
java.util.Map<java.lang.String,java.lang.String> getAll()
long getTotalSizeInBytes()
long getSizeInBytes(java.lang.String key)
key
- the key of a record
boolean isChanged(java.lang.String key)
key
- the key of a record
void delete()
Dataset
. No more following operations on this
dataset, or else IllegalStateException
will be thrown.
long getLastSyncCount()
Dataset
.
void subscribe()
void unsubscribe()
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |