Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create a custom function with body in dao room database

I want to create a DAO Object with a custom function like this

@Dao
interface DataAccessObjDao{
    @Insert
    fun insert(someEntity: SomeEntity)

    @Ignore
    fun sampleFun(){
        insert(SumEntity())
    }

}

but compiler complains about sample fun

Class 'DataAccessObjDao_Impl' must either be declared abstract or implement abstract method 'sampleFun()' in 'DataAccessObjDao

like image 683
max Avatar asked Jul 21 '18 06:07

max


1 Answers

@Ignore is for property or entity, can not be used on a method.
You can do this by extending your interface :

fun DataAccessObjDao.sampleFun(){
    // irrelevant code
}

or by adding @Transaction

@Transaction
fun sampleFun(){
    firstDelete()
    thenInsert()
}
like image 80
Jack Wang Avatar answered Nov 13 '22 12:11

Jack Wang