1. 程式人生 > >Spring 事務傳播行為 Transaction Propagation

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; } }