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: 
You can check below method insertModel() where you can get onComplete() and onError() method:

```
    val db: AppDatabase = Room.databaseBuilder(mCtx, AppDatabase::class.java, "db_nam.sqlite").build()

    companion object {
        @SuppressLint("StaticFieldLeak")
        private var mInstance: DatabaseClient? = null

        @Synchronized
        fun getInstance(mCtx: Context): DatabaseClient {
            if (mInstance == null) {
                mInstance = DatabaseClient(mCtx)
            }
            return mInstance as DatabaseClient
        }
    }

    // SEE HERE FOR INSERTING DATA SUCCESSFULLY AND ERROR CODE  
    private fun insertModel(rss_Model: RSS_Model) {
        Completable.fromAction {

            db.database_dao().insertRSS(rss_Model)

        }.observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io()).subscribe(object : CompletableObserver {
                    override fun onSubscribe(d: Disposable) {}

                    override fun onComplete() {
                        // Log.e("onComplete","GET SUCCESS HERE")
                    }

                    override fun onError(e: Throwable) {
                        // Log.e("onError","onError")
                    }
                })
    }

```
You also can check if the entry exists in the database or not you can make your logic accordingly

**Kotlin**

```
@Query("SELECT * FROM Product WHERE productId == :id")
fun isProductExist(id: Int): Boolean

```

**Java**

```
@Query("SELECT * FROM Product WHERE productId == :id")
public boolean isExist(int id);

```