I am using room database to store comments and RxJava as a listener to do some stuff when the database is changed.
I want to not call the callback when delete is called on the table, only when insert is called.
What i found out so far is that Room library has triggers
that are called on delete
, insert
and update
of the table that in turn call RxJava's methods.
Is there any way to drop the delete
trigger and get callbacks only for the insert
and update
methods?
Here is my CommentDAO:
@Query("SELECT * FROM comments" )
fun getAll(): Flowable<List<Comment>>
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(comment: Comment)
@Delete
fun delete(comment: Comment)
And my RxJava callback functions:
/**
* Inserts comment into comment database
*
* @param object that's going to be inserted to the database
*/
fun saveComment(comment: Comment) {
Observable.just(comment).subscribeOn(Schedulers.io()).map({ comment1 -> commentdb.commentDao().insert(comment1) }).subscribe()
}
/**
* Removes comment from the database
*
* @param comment object that's going to be removed
*/
fun removeComment(comment: Comment){
Observable.just(comment).subscribeOn(Schedulers.io()).map({ comment1 -> commentdb.commentDao().delete(comment1) }).subscribe()
}
fun createCommentObservable(uploader: CommentUploader) {
commentdb.commentDao().getAll().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(
{
success -> uploader.queue(success)
}
)
}