Android领域:回滚交易

时间:2017-02-02 15:39:28

标签: android realm

我试图找出远程和本地更新领域对象的操作顺序。 基本上是:

a)更新本地领域对象 b)远程保存对象 c)如果出现错误,则回滚先前的提交。

User user = ... // Fetched from realm.
RealmList<FavoriteSong> realmList = new RealmList<>();
realmList.addAll(favoriteSongs); // The collection of favorite songs that has been selected.
user.setFavoriteSongs(realmList);
// At this point my local copy of User has been updated with favorite songs.

// Now I will update remotely.
mUserServices.updateUser(user, new UserServices.UserListener() {
    @Override
    public void done(Exception e) {
        if(e != null) {
            // Since there was a remote update failure, can I roll back the local copy to the previous state?
        }
    }
});

是否可以回滚,如果没有,使用Realm处理此场景的首选策略是什么?

0 个答案:

没有答案