Spring 事务传播行为 Transaction Propagation

//事务注解用法
@Transactional(readOnly = false, propagation = Propagation.REQUIRED,rollbackFor=Exception.class,timeout=10)
public void save(Goods goods) throws Exception {...}

除了 propagation 其它几个属性都是字面意思,下面就看下 propagation

/*
 * Copyright 2002-2012 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.transaction.annotation;

import org.springframework.transaction.TransactionDefinition;

/**
 * Enumeration that represents transaction propagation behaviors for use
 * with the {@link Transactional} annotation, corresponding to the
 * {@link TransactionDefinition} interface.
 *
 * @author Colin Sampaleanu
 * @author Juergen Hoeller
 * @since 1.2
 */
public enum Propagation {

	/**
	 * 你有事务我就用你的,你没有我就自己创建一个,反正老子就是要事务。
	 */
	REQUIRED(TransactionDefinition.PROPAGATION_REQUIRED),

	/**
	 * 你有事务我就用你的,你没有就算了,我不稀罕。
	 */
	SUPPORTS(TransactionDefinition.PROPAGATION_SUPPORTS),

	/**
	 * 你没事务还敢调用老子,异常走你~~~~
	 */
	MANDATORY(TransactionDefinition.PROPAGATION_MANDATORY),

	/**
	 * 老子不管你那套,你有事务是你的事,一边待着。老子自己得创建自己的事务。
	 */
	REQUIRES_NEW(TransactionDefinition.PROPAGATION_REQUIRES_NEW),

	/**
	 * 老子不要事务,你调用我就了不起啊,让你事务一边待着去。
	 */
	NOT_SUPPORTED(TransactionDefinition.PROPAGATION_NOT_SUPPORTED),

	/**
	 * 老子说了不要事务你还来,异常走你~~~~~~~~~~~
	 */
	NEVER(TransactionDefinition.PROPAGATION_NEVER),

	/**
	 * 先说好,你有没有事务,咱们都井水不犯河水。我的事务我说了算,我提交、回滚与你无关。
	 */
	NESTED(TransactionDefinition.PROPAGATION_NESTED);

	private final int value;

	Propagation(int value) { this.value = value; }

	public int value() { return this.value; }

}

猜你喜欢

转载自blog.csdn.net/jx520/article/details/86474967