本文整理汇总了Java中com.google.inject.persist.Transactional.rollbackOn方法的典型用法代码示例。如果您正苦于以下问题:Java Transactional.rollbackOn方法的具体用法?Java Transactional.rollbackOn怎么用?Java Transactional.rollbackOn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.inject.persist.Transactional
的用法示例。
在下文中一共展示了Transactional.rollbackOn方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: rollbackIfNecessary
import com.google.inject.persist.Transactional; //导入方法依赖的package包/类
/**
* Returns True if rollback DID NOT HAPPEN (i.e. if commit should continue).
*
* @param transactional
* The metadata annotaiton of the method
* @param e
* The exception to test for rollback
* @param txn
* A JPA Transaction to issue rollbacks on
*/
private boolean rollbackIfNecessary(Transactional transactional, Exception e, Transaction txn)
{
boolean commit = true;
//check rollback clauses
for (Class<? extends Exception> rollBackOn : transactional.rollbackOn())
{
//if one matched, try to perform a rollback
if (rollBackOn.isInstance(e))
{
commit = false;
//check ignore clauses (supercedes rollback clause)
for (Class<? extends Exception> exceptOn : transactional.ignore())
{
//An exception to the rollback clause was found, DON'T rollback
// (i.e. commit and throw anyway)
if (exceptOn.isInstance(e))
{
commit = true;
break;
}
}
//rollback only if nothing matched the ignore check
if (!commit)
{
try
{
txn.rollback();
}
finally
{
txn.close();
}
}
//otherwise continue to commit
break;
}
}
return commit;
}