public enum Propagation extends Enum<Propagation>
| 枚举常量和说明 |
|---|
MANDATORY
The MANDATORY.
|
NEVER
The NEVER.
|
NOT_SUPPORTED
The NOT_SUPPORTED.
|
REQUIRED
The REQUIRED.
|
REQUIRES_NEW
The REQUIRES_NEW.
|
SUPPORTS
The SUPPORTS.
|
public static final Propagation REQUIRED
If transaction is existing, execute with current transaction, else execute with new transaction.
The logic is similar to the following code:
if (tx == null) {
try {
tx = beginNewTransaction(); // begin new transaction, is not existing
Object rs = business.execute(); // execute with new transaction
commitTransaction(tx);
return rs;
} catch (Exception ex) {
rollbackTransaction(tx);
throw ex;
}
} else {
return business.execute(); // execute with current transaction
}
public static final Propagation REQUIRES_NEW
If transaction is existing, suspend it, and then execute business with new transaction.
The logic is similar to the following code:
try {
if (tx != null) {
suspendedResource = suspendTransaction(tx); // suspend current transaction
}
try {
tx = beginNewTransaction(); // begin new transaction
Object rs = business.execute(); // execute with new transaction
commitTransaction(tx);
return rs;
} catch (Exception ex) {
rollbackTransaction(tx);
throw ex;
}
} finally {
if (suspendedResource != null) {
resumeTransaction(suspendedResource); // resume transaction
}
}
public static final Propagation NOT_SUPPORTED
If transaction is existing, suspend it, and then execute business without transaction.
The logic is similar to the following code:
try {
if (tx != null) {
suspendedResource = suspendTransaction(tx); // suspend current transaction
}
return business.execute(); // execute without transaction
} finally {
if (suspendedResource != null) {
resumeTransaction(suspendedResource); // resume transaction
}
}
public static final Propagation SUPPORTS
If transaction is not existing, execute without global transaction, else execute business with current transaction.
The logic is similar to the following code:
if (tx != null) {
return business.execute(); // execute with current transaction
} else {
return business.execute(); // execute without transaction
}
public static final Propagation NEVER
If transaction is existing, throw exception, else execute business without transaction.
The logic is similar to the following code:
if (tx != null) {
throw new TransactionException("existing transaction");
}
return business.execute(); // execute without transaction
public static final Propagation MANDATORY
If transaction is not existing, throw exception, else execute business with current transaction.
The logic is similar to the following code:
if (tx == null) {
throw new TransactionException("not existing transaction");
}
return business.execute(); // execute with current transaction
public static Propagation[] values()
for (Propagation c : Propagation.values()) System.out.println(c);
public static Propagation valueOf(String name)
name - 要返回的枚举常量的名称。IllegalArgumentException - 如果该枚举类型没有带有指定名称的常量NullPointerException - 如果参数为空值Copyright © 2020 Seata. All rights reserved.