当前位置: 首页>>代码示例>>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;未经允许,请勿转载。