本文整理匯總了Java中org.springframework.transaction.TransactionStatus.isCompleted方法的典型用法代碼示例。如果您正苦於以下問題:Java TransactionStatus.isCompleted方法的具體用法?Java TransactionStatus.isCompleted怎麽用?Java TransactionStatus.isCompleted使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.transaction.TransactionStatus
的用法示例。
在下文中一共展示了TransactionStatus.isCompleted方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: commit
import org.springframework.transaction.TransactionStatus; //導入方法依賴的package包/類
/**
* This implementation of commit handles participating in existing
* transactions and programmatic rollback requests.
* Delegates to {@code isRollbackOnly}, {@code doCommit}
* and {@code rollback}.
* @see org.springframework.transaction.TransactionStatus#isRollbackOnly()
* @see #doCommit
* @see #rollback
*/
@Override
public final void commit(TransactionStatus status) throws TransactionException {
if (status.isCompleted()) {
throw new IllegalTransactionStateException(
"Transaction is already completed - do not call commit or rollback more than once per transaction");
}
DefaultTransactionStatus defStatus = (DefaultTransactionStatus) status;
if (defStatus.isLocalRollbackOnly()) {
if (defStatus.isDebug()) {
logger.debug("Transactional code has requested rollback");
}
processRollback(defStatus);
return;
}
if (!shouldCommitOnGlobalRollbackOnly() && defStatus.isGlobalRollbackOnly()) {
if (defStatus.isDebug()) {
logger.debug("Global transaction is marked as rollback-only but transactional code requested commit");
}
processRollback(defStatus);
// Throw UnexpectedRollbackException only at outermost transaction boundary
// or if explicitly asked to.
if (status.isNewTransaction() || isFailEarlyOnGlobalRollbackOnly()) {
throw new UnexpectedRollbackException(
"Transaction rolled back because it has been marked as rollback-only");
}
return;
}
processCommit(defStatus);
}
示例2: retry
import org.springframework.transaction.TransactionStatus; //導入方法依賴的package包/類
@Around("@annotation(com.wise.core.aop.annotation.RetriableTransaction)")
public Object retry(ProceedingJoinPoint pjp) throws Throwable {
MethodSignature signature = (MethodSignature) pjp.getSignature();
Method method = signature.getMethod();
RetriableTransaction annotation = method.getAnnotation(RetriableTransaction.class);
int maxAttempts = annotation.maxRetries();
int attemptCount = 0;
List<Class<? extends Throwable>> exceptions = Arrays.asList(annotation.retryFor());
Throwable failure = null;
TransactionStatus currentTransactionStatus = null;
String businessName = pjp.getTarget().toString();
businessName = businessName.substring(0, businessName.lastIndexOf("@")) + "." + method.getName();
do {
attemptCount++;
try {
DefaultTransactionDefinition transactionDefinition = new DefaultTransactionDefinition();
transactionDefinition.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
currentTransactionStatus = transactionManager.getTransaction(transactionDefinition);
Object returnValue = pjp.proceed();
transactionManager.commit(currentTransactionStatus);
return returnValue;
} catch (Throwable t) {
if (!exceptions.contains(t.getClass())) {
throw t;
}
if (currentTransactionStatus != null && !currentTransactionStatus.isCompleted()) {
transactionManager.rollback(currentTransactionStatus);
failure = t;
}
LOGGER.debug("事務重試:["+businessName+":"+attemptCount+"/"+maxAttempts+"]");
}
} while (attemptCount < maxAttempts);
LOGGER.debug("事務重試:["+businessName+":已達最大重試次數]");
throw failure;
}
示例3: rollback
import org.springframework.transaction.TransactionStatus; //導入方法依賴的package包/類
/**
* This implementation of rollback handles participating in existing
* transactions. Delegates to {@code doRollback} and
* {@code doSetRollbackOnly}.
* @see #doRollback
* @see #doSetRollbackOnly
*/
@Override
public final void rollback(TransactionStatus status) throws TransactionException {
if (status.isCompleted()) {
throw new IllegalTransactionStateException(
"Transaction is already completed - do not call commit or rollback more than once per transaction");
}
DefaultTransactionStatus defStatus = (DefaultTransactionStatus) status;
processRollback(defStatus);
}