房间事务回滚或取消 [英] Room Transaction rollback or cancel

查看:37
本文介绍了房间事务回滚或取消的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

@Transaction 中 Room 是否默认使用回滚?

它是否只取消 @Transaction 内部的下一个查询而不回滚?

它实际上在出错时做了什么?

解决方案

我假设您指的是使用 @Transaction 注释的已实现方法,例如:

@Transactionpublic void transferMoney(String accountA, String accountB, int amount) {updateMoney(accountA, -amount);updateMoney(accountB, +amount);}

<块引用>

在@Transaction 中,Room 是否默认使用回滚?

是的,如果在用 @Transaction 注释的方法中抛出异常,那么 Room 将执行 ROLLBACK TRANSACTION

<块引用>

是否只取消@Transaction 内部的下一个查询而不回滚?

它取消方法中的每个后续查询,并回滚方法中任何其他查询所做的任何更改,直到失败点.

<块引用>

它实际上在出错时做了什么?

它回滚事务.

<小时>

如果你指的是 @Query 注释的方法,也用 @Transaction 注释,那么那些是只读查询,所以真的没有什么可以回滚的,但是,当结果数据很大或返回的数据具有 @Relation 时,则保证数据.请参阅:https://developer.android.com/reference/android/拱门/持久性/房间/交易

Is Room using rollback as default in @Transaction?

Does it only cancel next query inside @Transaction without rollbacking?

What it actually does on error?

解决方案

I'm assuming you are refering to implemented methods annotated with @Transaction such as:

@Transaction
public void transferMoney(String accountA, String accountB, int amount) {
  updateMoney(accountA, -amount);
  updateMoney(accountB, +amount);
}

Is Room using rollback as default in @Transaction?

Yes, if an exception is thrown in the method annotated with @Transaction then Room will perform a ROLLBACK TRANSACTION

Does it only cancel next query inside @Transaction without rollbacking?

It cancels every subsequent query in the method and rollbacks any changes made by any other query within the method up to the point of failure.

What it actually does on error?

It rollsback the transaction.


If you are referring to @Query annotated methods that are also annotated with @Transaction, then those are read-only queries, so there is really nothing to rollback, however, when the resulting data is big or the returning data has an @Relation then data is guaranteed. See: https://developer.android.com/reference/android/arch/persistence/room/Transaction

这篇关于房间事务回滚或取消的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆