当前位置: 首页>>代码示例>>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;未经允许,请勿转载。