- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在实现同时写入数据库和 Oracle Coherence 3.7.1,并希望使整个操作成为事务性的。
我想对我的方法提出批评。
目前,我创建了这样的外观类:
public class Facade {
@EJB
private JdbcDao jdbcDao;
@EJB
private CoherenceDao coherenceDao;
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
private void updateMethod(List<DomainObject> list) {
jdbcDao.update(list);
coherenceDao.update(list);
}
}
我猜 JDBC DAO 不需要对事务做任何特定的事情,如果发生什么事情,Hibernate 会抛出某种 RuntimeException。
public class JdbcDao {
private void update(List<DomainObject> list) {
// I presume there is nothing specific I have to do about transactions.
// if I don't catch any exceptions it would work just fine
}
}
这是有趣的部分。如何让 Coherence 支持交易?我想我应该在 update() 方法中打开一致性事务,并且对于其中的任何异常我应该自己抛出 RuntimeException 吗?
我目前正在考虑这样的事情:
public class CoherenceDao {
private void update(List<DomainObject> list) {
// how should I make it transactional?
// I guess it should somehow throw RuntimeException?
TransactionMap mapTx = CacheFactory.getLocalTransaction(cache);
mapTx.setTransactionIsolation(TransactionMap.TRANSACTION_REPEATABLE_GET);
mapTx.setConcurrency(TransactionMap.CONCUR_PESSIMISTIC);
// gather the cache(s) into a Collection
Collection txnCollection = Collections.singleton(mapTx);
try {
mapTx.begin();
// put into mapTx here
CacheFactory.commitTransactionCollection(txnCollection, 1);
} catch (Throwable t) {
CacheFactory.rollbackTransactionCollection(txnCollection);
throw new RuntimeException();
}
}
}
这种方法会按预期工作吗?
最佳答案
我知道您一年前就问过这个问题,一年后我现在的回答可能对您来说没有多大值(value),但我仍然尝试一下。
只要在 coherenceDao.update(list);
的方法调用之后没有 RuneTimeException,您尝试执行的操作就有效。您可能会假设该行之后没有任何代码行,但这并不是故事的全部。
举个例子:您的数据库中可能有一些可延迟的约束。当容器尝试提交 updateMethod(List<DomainObject> list)
方法导出处的事务时,将应用这些约束。在您的方法调用 coherenceDao.update(list)
之后。另一种情况是之后数据库连接超时 coherenceDao.update(list)
已执行但仍在事务提交之前。在这两种情况下,您的 CoherenceDAO 类的更新方法都会安全可靠地执行,并且您的一致性事务不再回滚,这将使您的缓存处于不一致的状态,因为您将因这些 DB 或 Hibernate 异常而得到 RuneTimeException,这将导致您的容器托管事务将被回滚!
关于java - 一致性和容器管理的事务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20091417/
GhostScript PDF/A 生成好像有错误 当您通过 GhostScript 生成 PDF/A 文档时,当您单击 Adobe Reader 时,会出现一个一致性选项卡,其中显示: “一致性
我有一个需要测试的 XPath 引擎实现。 是否有一组标准的一致性测试可以用来验证是否符合 XPath 规范(与 XSLT 相关)。 什么将是完美的 XML 文档 XPath 表达式和预期的结果。 最
帮助我了解在这种情况下我可以期望与 MongoDB 的一致性级别。 我们正在运行一个副本集,其中 Mongoid 中的 consistency 标志设置为 strong,这意味着只读到 master。
假设我有一个采用一个参数的方法。 此参数应满足以下要求: 'of type':方法需要知道参数属于特定类(或子类)。 'implements interface':方法需要知道参数实现了特定的接口(i
当协议(protocol)将属性声明为可选而具体类型将其声明为非可选时,如何使具体类型符合协议(protocol)? 这是问题所在: protocol Track { var trackNum
我正在考虑使用浏览器的 navigator.mimeTypes 数组作为第三级用户/浏览器标识符。例如,当我在 Chrome 上运行时... console.log(navigator.mimeTyp
我有以下协议(protocol): protocol ProtoAInput { func funcA() } protocol ProtoA { var input: ProtoAI
如果选择“最终”一致性,则发生写入的区域内的一致性是什么? 如果我只需要区域强一致性,应该选择哪个选项? 最佳答案 如果您需要在主要区域内进行强读取,则应该选择强一致性或有界过时一致性。 关于azur
您好,我是一名初学者,目前正在尝试学习 java 编程。课本上的问题: 编写一个程序来帮助人们决定是否购买混合动力汽车。你的程序的输入应该是:•新车的成本•预计每年行驶里程•预计汽油价格 •每加仑英里
我正在尝试制作一个可以在 UILabel 上使用的 Swift 协议(protocol), UITextField , 和 UITextView包含他们的text , attributedText ,
我有一个类扩展: extension UICollectionViewCell { class func registerFromNibInCollectionView(collectionV
为了在 Swift 中模拟对象进行测试,我通常遵循这样的模式:编写一个协议(protocol)来描述我想要的对象的行为,然后使用 Cuckoo 为其生成模拟以进行测试。 通常,这些协议(protoco
假设我有两个非通用协议(protocol)(1) protocol StringValue { var asString: String {get} } protocol StringProv
我有一组协议(protocol)可以在 UITableView 中显示一个元素: protocol TableRepresentableRow { var title: String { get
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topi
用“class”标记 CacheManager 解决了我的问题。 案例:一个简单的缓存器,mutating get 不是我想要的,那么对于引用类型或类类型应该怎么做? protocol Cacher
我想要一个符合协议(protocol)的变量,但是 swift 编译器告诉我协议(protocol)没有确认。 protocol A {} protocol B { var a : A { g
如果我有一个类 Christmas 和一个协议(protocol) Merry,要使 Christmas 符合 Merry,很多人会这样做: class Christmas { ... } e
@objc public protocol P1 { func p1foo() } @objc public protocol P2 { func p2foo() } class A: NSO
我有一些结构符合的基本协议(protocol)(模型)。它们也符合 Hashable protocol Model {} struct Contact: Model, Hashable { v
我是一名优秀的程序员,十分优秀!