I am using Room in a project and I have the following DAO interface:
@Dao
interface BalanceDao {
@Query("SELECT * FROM balance")
fun getAllBalances(): Flowable<List<BalanceDataModel>>
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertBalanceList(balanceDataModelList: List<BalanceDataModel>): List<Long>
}
Insert works fantastically, but the getAllBalances() method does not work, since it does not retrieve any row. I extracted the DB after the insertion and I can see all the rows there; SELECT * from balance works perfectly when locally executed to the extracted DB with a desktop app.
I also tried to change the return type of getAllBalances() from Flowable<List<BalanceDataModel>> to Single<List<BalanceDataModel>> but the same keeps happening: no results.
I have a PortfolioManager, from which I call the following method and I pass the observer and the owner from my Fragment.
fun getAllCoins(owner: LifecycleOwner, observer: Observer<List<Balance>>) {
portfolioViewModel
.balanceListLiveData
.observe(owner, observer)
return portfolioViewModel.getPortfolioCoins()
}
Then in the PortfolioManager, I have access to a ViewModel, from which I call the following method:
fun getPortfolioCoins() {
coinRepository
.getBalanceListPortfolio()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeBy(onSuccess = {
balanceListLiveData.postValue(it)
})
}
And in the repository class, I have this:
fun getBalanceListPortfolio(): Single<List<Balance>> {
val converter = BalanceDataModelConverter()
val balanceList = mutableListOf<Balance>()
coinDatabase.balanceDao()
.getAllBalances()
.toObservable()
.flatMapIterable { t: List<BalanceDataModel> -> t }
.map { t: BalanceDataModel ->
{
val a: Balance = converter.fromFirstToSecond(t)
balanceList.add(a)
}
}
return Single.just(balanceList.toList())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
}
Anybody knows what could be wrong? Thanks a lot in advance!