本文整理汇总了Java中javax.transaction.Transactional.TxType方法的典型用法代码示例。如果您正苦于以下问题:Java Transactional.TxType方法的具体用法?Java Transactional.TxType怎么用?Java Transactional.TxType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.transaction.Transactional
的用法示例。
在下文中一共展示了Transactional.TxType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: requiresNew
import javax.transaction.Transactional; //导入方法依赖的package包/类
/**
* Determines whether it is necessary to begin a new transaction.
*
* @param active the status of the current transaction.
* @param attribute the transaction attribute of the current method.
* @return {@code Boolean.TRUE} if the interceptor should suspend the
* current transaction and invoke the method within a new
* transaction, {@code Boolean.FALSE} if the interceptor should
* invoke the method within the current transaction, {@code null} if
* the interceptor should suspend the current transaction and invoke
* the method outside of transaction.
*/
private Boolean requiresNew(boolean active, Transactional.TxType attribute) {
switch (attribute) {
case MANDATORY:
if (active) {
return false;
} else {
throw new IllegalStateException("Transaction is required to perform this method");
}
case NEVER:
if (!active) {
return null;
} else {
throw new IllegalStateException("This method cannot be invoked within a transaction");
}
case NOT_SUPPORTED:
return null;
case REQUIRED:
return !active;
case REQUIRES_NEW:
return true;
case SUPPORTS:
if (active) {
return false;
} else {
return null;
}
default:
throw new UnsupportedOperationException("Unsupported TransactionAttribute value " + attribute);
}
}