简体   繁体   English

如何使用 Rxjava 执行房间交易

[英]How to perform a room transaction usin Rxjava

How can I do a room transaction across 2 different DAOs usin rxjava?如何使用 rxjava 跨 2 个不同的 DAO 进行房间交易?

I have this code that I would like to use with Rxjava but I need it to return some kind of observable我有这段代码,我想与 Rxjava 一起使用,但我需要它来返回某种可观察的

 @Transaction
fun insertStoreWithPictures(store: Store, pictures: List<StorePicture>) {

    insertStore(store)
    insertPictures(pictures)

}

The store DAO商店DAO

@Dao
abstract public class store {

@Insert
Single<Long> insert(store  entity);
}

The storePicture DAO商店图片 DAO

@Dao
abstract public class storePicture {

    @Insert
    Completable insert(storePicture... entity);
}

I think you can use zip or combine operator of RxJava .我认为您可以使用zipcombine RxJava的运算符。 It would create an observable from an iterators observable source.它将从迭代器可观察源创建一个可观察对象。

Best example you can follow to achieve the same - https://blog.mindorks.com/understanding-rxjava-zip-operator-with-example您可以遵循的最佳示例来实现相同的效果 - https://blog.mindorks.com/understanding-rxjava-zip-operator-with-example

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM