001/*
002 *  Copyright (c) 2022-2025, Mybatis-Flex (fuhai999@gmail.com).
003 *  <p>
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *  <p>
008 *  http://www.apache.org/licenses/LICENSE-2.0
009 *  <p>
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package com.mybatisflex.core.transaction;
017
018/**
019 * 事务的传递方式,参考 spring
020 */
021public enum Propagation {
022    /**
023     * 若存在当前事务,则加入当前事务,若不存在当前事务,则创建新的事务
024     */
025    REQUIRED(0),
026
027    /**
028     * 若存在当前事务,则加入当前事务,若不存在当前事务,则已非事务的方式运行
029     */
030    SUPPORTS(1),
031
032    /**
033     * 若存在当前事务,则加入当前事务,若不存在当前事务,则抛出异常
034     */
035    MANDATORY(2),
036
037    /**
038     * 始终以新事务的方式运行,若存在当前事务,则暂停(挂起)当前事务。
039     */
040    REQUIRES_NEW(3),
041
042    /**
043     * 以非事务的方式运行,若存在当前事务,则暂停(挂起)当前事务。
044     */
045    NOT_SUPPORTED(4),
046
047    /**
048     * 以非事务的方式运行,若存在当前事务,则抛出异常。
049     */
050    NEVER(5),
051
052    /**
053     * 如果存在当前事务,则在嵌套事务中执行,否则行为类似于 PROPAGATION_REQUIRED
054     */
055    NESTED(6),
056    ;
057
058    private final int value;
059
060    Propagation(int value) {
061        this.value = value;
062    }
063
064    public int getValue() {
065        return value;
066    }
067}