|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||
java.lang.Objectcom.amazonaws.mobileconnectors.cognito.DefaultSyncCallback
public class DefaultSyncCallback
A default implementation of SyncCallback. All methods but onConflict are stubbed with logging. onConflict resolves conflicts using a 'last writer wins' strategy
| Constructor Summary | |
|---|---|
DefaultSyncCallback()
|
|
| Method Summary | |
|---|---|
boolean |
onConflict(Dataset dataset,
java.util.List<SyncConflict> conflicts)
This can be triggered during two phases. |
boolean |
onDatasetDeleted(Dataset dataset,
java.lang.String datasetName)
This is triggered when the given dataset is deleted remotely. |
boolean |
onDatasetsMerged(Dataset dataset,
java.util.List<java.lang.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,
java.util.List<Record> updatedRecords)
This is called after remote changes are downloaded to local storage and local changes are uploaded to remote storage. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public DefaultSyncCallback()
| Method Detail |
|---|
public void onSuccess(Dataset dataset,
java.util.List<Record> updatedRecords)
Dataset.SyncCallbackDataset.SyncCallback.onConflict(com.amazonaws.mobileconnectors.cognito.Dataset, java.util.List) 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
downloaded
public boolean onConflict(Dataset dataset,
java.util.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 records
public boolean onDatasetDeleted(Dataset dataset,
java.lang.String datasetName)
Dataset.SyncCallback
onDatasetDeleted in interface Dataset.SyncCallbackdataset - dataset handlerdatasetName - the name of the dataset that is deleted remotely
public boolean onDatasetsMerged(Dataset dataset,
java.util.List<java.lang.String> datasetNames)
Dataset.SyncCallback
onDatasetsMerged in interface Dataset.SyncCallbackdataset - dataset handlerdatasetNames - a list of names of merged datasets'
public void onFailure(DataStorageException dse)
Dataset.SyncCallback
onFailure in interface Dataset.SyncCallbackdse - exception
|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||