public class DefaultSyncCallback extends Object implements Dataset.SyncCallback
| Constructor and Description |
|---|
DefaultSyncCallback() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
onConflict(Dataset dataset,
List<SyncConflict> conflicts)
This can be triggered during two phases.
|
boolean |
onDatasetDeleted(Dataset dataset,
String datasetName)
This is triggered when the given dataset is deleted remotely.
|
boolean |
onDatasetsMerged(Dataset dataset,
List<String> datasetNames)
If two or more datasets are merged as a result of identity merge,
this will be triggered.
|
void |
onFailure(DataStorageException dse)
This is called when an exception occurs during sync.
|
void |
onSuccess(Dataset dataset,
List<Record> updatedRecords)
This is called after remote changes are downloaded to local storage
and local changes are uploaded to remote storage.
|
public void onSuccess(Dataset dataset, List<Record> updatedRecords)
Dataset.SyncCallbackDataset.SyncCallback.onConflict(com.amazonaws.mobileconnectors.cognito.Dataset, java.util.List<com.amazonaws.mobileconnectors.cognito.SyncConflict>) after
several retries, then updatedRecords will be what are pulled down
from remote in the last retry.onSuccess in interface Dataset.SyncCallbackdataset - the dataset that performed syncupdatedRecords - new records from remote storage that are
downloadedpublic boolean onConflict(Dataset dataset, List<SyncConflict> conflicts)
Dataset.SyncCallback
List<Record> resolved = new ArrayList<Record>();
for (SyncConflict conflict : conflicts) {
resolved.add(conflicts.resolveWithRemoteRecord());
}
dataset.save(resolved);
return true; // so that synchronize() can retry
If you prefer to add additional logic when resolving conflict, you
can use SyncConflict.resolveWithValue(String)
int remoteMoney = Integer.valueOf(conflicts.getRemote().getValue()); int localMoney = Integer.valueOf(conflicts.getLocal().getValue()); int total = remoteMoney + localMoney; Record resolve = conflicts.resolveWithValue(String.valueOf(total));
onConflict in interface Dataset.SyncCallbackdataset - the dataset that performed syncconflicts - conflicting recordspublic boolean onDatasetDeleted(Dataset dataset, String datasetName)
Dataset.SyncCallbackonDatasetDeleted in interface Dataset.SyncCallbackdataset - dataset handlerdatasetName - the name of the dataset that is deleted remotelypublic boolean onDatasetsMerged(Dataset dataset, List<String> datasetNames)
Dataset.SyncCallbackonDatasetsMerged in interface Dataset.SyncCallbackdataset - dataset handlerdatasetNames - a list of names of merged datasets'public void onFailure(DataStorageException dse)
Dataset.SyncCallbackonFailure in interface Dataset.SyncCallbackdse - exceptionCopyright © 2010 Amazon Web Services, Inc. All Rights Reserved.