Question: I need update and if not exist insert row to ROOM DB.

I make this: `productRepository.updateProducts(productsResponse.getProductItems());`

And:

```
@Override
public void updateProducts(final List<ProductItem> products) {
    new Thread(() -> {
        for (ProductItem item : products) {
            Product product = createProduct(item);
            productDao.insert(product);
        }
    }).start();
}

```

And in DAO:

```
@Insert
void insert(Product products);

```

But I have method 

```
@Update
void update(Product product);

```

And I have some questions:

1. both methods is void. How can I return saved Product or boolean flag or inserted count after insert?
2. if I try call `update` and I have not row will it be inserted?
3. How can I update(if not - insert) row and return count updatet or inserted rows?

Answer: 
```
@Query("SELECT * FROM pojo WHERE pojo.id = :id")
Maybe<POJO> checkPOJO(String id);

```

you can insertOrUpdate like this:

```
checkPOJO(id).toSingle().concatMapCompletable(pojo->update(pojo))
   .onErrorResumeNext(t -> t instanceof NoSuchElementException ? 
   insert(...): Completable.error(t));

```
You should use Rx Android ***Single*** to solve this problem. Example:

```
@Query("SELECT * FROM subjectFormTable WHERE study_subject_id ==:subjectFormId")
fun getSubjectForm(subjectFormId: Int): Single<SubjectFormEntity>

```

We use 

```
val compositeDisposable = CompositeDisposable()

```

And

```
compositeDisposable.add(
            subjectFormDao.getSubjectForm(studySubjectId)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe({
                Log.e(TAG, "successful ")
            }, {
                Log.e(TAG, "error "+it.message)
                //Insert or Update data here
            })
    )

```