I have a question about transactions in the ROOM database. Is it possible to use @Transaction annotiation outside the DAO objects?
I have complex object to save so I do it by a manager that calls many methods from different daos. But I want to rollback transaction if any method fails.
It works with
roomDB.runInTransaction {
dao1.insert(object.object1)
dao2.insert(object.object2)
dao3.update(objec.object3)
}
And the second problem that I'm facing is not closed cursor. Sometimes I got such exception:
W/SQLiteCompiledSql: Releasing statement in a finalizer. Please ensure that you explicitly call close() on your cursor: DELETE FROM tableName WHERE status IN ( ?,? )
net.sqlcipher.database.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
Sample method that I'm using:
@TypeConverters(NameConverter::class)
@Query("UPDATE tableName SET status = :status, last_update_date = :updateDate , finish_date = :finishDate, problem_reason = :problemReason WHERE id = :id")
fun updateStatus(id: Long, status: WorkerStatus, updateDate: Long, finishDate: Long?, problemReason: String?)
Do I need to add additional annotation to the method to close a cursor?
Thanks for any advice ;)