當前位置: 首頁>>代碼示例>>Java>>正文


Java TransactionStatus.isCompleted方法代碼示例

本文整理匯總了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);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:41,代碼來源:AbstractPlatformTransactionManager.java

示例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;
}
 
開發者ID:onsoul,項目名稱:os,代碼行數:36,代碼來源:RetriableTransactionInterceptor.java

示例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);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:18,代碼來源:AbstractPlatformTransactionManager.java


注:本文中的org.springframework.transaction.TransactionStatus.isCompleted方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。