本文整理匯總了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);
}
}