Android Room Database Transaction

Jul 24, 2018
val db: AppDatabase = Room.databaseBuilder(app,, "MyDb.db")        .build()db.runInTransaction {    item.updateImage(imageDataSource)    dataSource.update(item)}


interface BaseDao<T> {    @Insert(onConflict = OnConflictStrategy.REPLACE)    fun insert(entity: T) : Long    @Insert(onConflict = OnConflictStrategy.REPLACE)    fun insertAll(vararg entity: T)    @Update    fun update(entity: T)    @Update    fun updateAll(vararg entity: T)    @Delete    fun delete(entity: T)}@Daointerface PinDao : BaseDao<Pin> {    @Transaction    public void replacePin(newPin: Pin, oldPin: Pin) {         insert(newPin)         delete(oldPin)    }}

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.