當前位置: 首頁>>代碼示例>>Java>>正文


Java Transactional.TxType方法代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:apache,項目名稱:aries-jpa,代碼行數:49,代碼來源:TransactionalInterceptor.java


注:本文中的javax.transaction.Transactional.TxType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。