I have a DAO interface, of which I have multiple implementations and I want one of them to be a Room implementation (Kotlin):
interface BaseDao {
fun getAll(): Single<List<SomeData>>
fun insert(data: List<SomeData>)
}
and my Room (RxRoom) interface:
@Dao
interface RxRoomBaseDao: BaseDao {
@Query("SELECT * FROM some_data")
override fun getAll(): Single<List<SomeData>>
@Insert(onConflict = OnConflictStrategy.REPLACE)
override fun insert(data: List<SomeData>)
}
It looks like the Room compiler tries to compile the BaseDao
instead of the RxRoomBaseDao
and complains error: Dao class must be annotated with @Dao
and for both methods error: A DAO method can be annotated with only one of the following:Insert,Delete,Query,Update
.
I have also tried an abstract class for the RxRoomBaseDao
with the same result.
Is this a known bug or limitation of the Room compiler? How can I achieve what I want without polluting my BaseDao
with Room's annotations?
It seems OP has since moved on from Room, but fwiw, it's possible to use generics to solve this problem:
interface BaseDao<T> {
@Insert
fun insert(vararg obj: T)
}
@Dao
abstract class DataDao : BaseDao<Data>() {
@Query("SELECT * FROM Data")
abstract fun getData(): List<Data>
}
Check out the "Use DAO's inheritance capability" section in this Official Room blog post
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With