RxJava2 + Room: data is not being inserted in DB after clearAllTables() call

瘦欲@ 提交于 2019-12-24 08:26:15

问题


In my Android application after successful login I'm saving session info in Room, then I'm retrieving user information from BE and saving it too. Everything works fine. I can see saved information in database tables.

When user logs out from application all tables are being cleared with appDatabase.clearAllTables() method call.

The catch is that on subsequent login there's no information that is being inserted in DB but my Rx calls aren't throwing any errors.

I've tried to use logging and debug but everything looks like normal.

Logging shows following actions being performed: login -> get user info from BE -> save session -> save user.

When debugging I can see that user info is being handled in UserDao_Impl's insertUser() method.

In application I use RxJava2 version 2.2.2, Room persistence library version 1.1.1, dependencies are being provided with Dagger version 2.19.

Here's my code snippets:

LoginUserUseCase.java

public Completable execute(@NonNull LoginInfo loginInfo) {
    Completable loginAndSaveSession = sessionRepository.loginUser(loginInfo)
                                                    .flatMapCompletable(
                                                            session -> sessionRepository.saveSession(
                                                                    session));
    Completable getAndSaveUserInfo = userRepository.getRemoteUserInfo()
                                                   .flatMapCompletable(
                                                           user -> userRepository.saveUser(
                                                                   user));
    return loginAndSaveSession.andThen(getAndSaveUserInfo);
}

UserRepository.java

public Completable saveUser(@NonNull User user) {
    return Completable.fromAction(() -> userDao.insertUser(user));
}

UserDao.java

@Insert(onConflict = OnConflictStrategy.REPLACE)
void insertUser(User user);

LogoutUserUseCase.java

public Completable execute() {
    return Completable.fromAction(() -> appDatabase.clearAllTables());
}

UPDATE (ISSUE RESOLVED): wasted a day on this bug. Finally come to understanding that some other library can affect application's work with Room. Turned out that Android Debug Database library that I've used to peek inside the database on device has a bug that breaks DB after you opened it once with its help.

Returning back to Stetho.

来源:https://stackoverflow.com/questions/53117103/rxjava2-room-data-is-not-being-inserted-in-db-after-clearalltables-call

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!