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


Java Rollback.value方法代碼示例

本文整理匯總了Java中org.springframework.test.annotation.Rollback.value方法的典型用法代碼示例。如果您正苦於以下問題:Java Rollback.value方法的具體用法?Java Rollback.value怎麽用?Java Rollback.value使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.test.annotation.Rollback的用法示例。


在下文中一共展示了Rollback.value方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: isDefaultRollback

import org.springframework.test.annotation.Rollback; //導入方法依賴的package包/類
/**
 * Determine whether or not to rollback transactions by default for the
 * supplied {@linkplain TestContext test context}.
 * <p>Supports {@link Rollback @Rollback} or
 * {@link TransactionConfiguration @TransactionConfiguration} at the
 * class-level.
 * @param testContext the test context for which the default rollback flag
 * should be retrieved
 * @return the <em>default rollback</em> flag for the supplied test context
 * @throws Exception if an error occurs while determining the default rollback flag
 */
@SuppressWarnings("deprecation")
protected final boolean isDefaultRollback(TestContext testContext) throws Exception {
	Class<?> testClass = testContext.getTestClass();
	Rollback rollback = findAnnotation(testClass, Rollback.class);
	boolean rollbackPresent = (rollback != null);
	TransactionConfigurationAttributes txConfigAttributes = retrieveConfigurationAttributes(testContext);

	if (rollbackPresent && txConfigAttributes != defaultTxConfigAttributes) {
		throw new IllegalStateException(String.format("Test class [%s] is annotated with both @Rollback "
				+ "and @TransactionConfiguration, but only one is permitted.", testClass.getName()));
	}

	if (rollbackPresent) {
		boolean defaultRollback = rollback.value();
		if (logger.isDebugEnabled()) {
			logger.debug(String.format("Retrieved default @Rollback(%s) for test class [%s].", defaultRollback,
				testClass.getName()));
		}
		return defaultRollback;
	}

	// else
	return txConfigAttributes.isDefaultRollback();
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:36,代碼來源:TransactionalTestExecutionListener.java

示例2: isRollback

import org.springframework.test.annotation.Rollback; //導入方法依賴的package包/類
/**
 * Determine whether or not to rollback transactions for the supplied
 * {@linkplain TestContext test context} by taking into consideration the
 * {@linkplain #isDefaultRollback(TestContext) default rollback} flag and a
 * possible method-level override via the {@link Rollback @Rollback}
 * annotation.
 * @param testContext the test context for which the rollback flag
 * should be retrieved
 * @return the <em>rollback</em> flag for the supplied test context
 * @throws Exception if an error occurs while determining the rollback flag
 */
protected final boolean isRollback(TestContext testContext) throws Exception {
	boolean rollback = isDefaultRollback(testContext);
	Rollback rollbackAnnotation = findAnnotation(testContext.getTestMethod(), Rollback.class);
	if (rollbackAnnotation != null) {
		boolean rollbackOverride = rollbackAnnotation.value();
		if (logger.isDebugEnabled()) {
			logger.debug(String.format(
				"Method-level @Rollback(%s) overrides default rollback [%s] for test context %s.",
				rollbackOverride, rollback, testContext));
		}
		rollback = rollbackOverride;
	}
	else {
		if (logger.isDebugEnabled()) {
			logger.debug(String.format(
				"No method-level @Rollback override: using default rollback [%s] for test context %s.", rollback,
				testContext));
		}
	}
	return rollback;
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:33,代碼來源:TransactionalTestExecutionListener.java


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