Polish MergedSqlConfig

This commit is contained in:
Sam Brannen 2019-07-28 18:41:26 +02:00
parent f53cdb8bd2
commit c72bf10eb9
1 changed files with 37 additions and 34 deletions

View File

@ -77,8 +77,25 @@ class MergedSqlConfig {
Assert.notNull(localSqlConfig, "Local @SqlConfig must not be null");
Assert.notNull(testClass, "testClass must not be null");
AnnotationAttributes mergedAttributes;
AnnotationAttributes mergedAttributes = mergeAttributes(localSqlConfig, testClass);
this.dataSource = mergedAttributes.getString("dataSource");
this.transactionManager = mergedAttributes.getString("transactionManager");
this.transactionMode = getEnum(mergedAttributes, "transactionMode", TransactionMode.DEFAULT,
TransactionMode.INFERRED);
this.encoding = mergedAttributes.getString("encoding");
this.separator = getString(mergedAttributes, "separator", ScriptUtils.DEFAULT_STATEMENT_SEPARATOR);
this.commentPrefixes = getCommentPrefixes(mergedAttributes);
this.blockCommentStartDelimiter = getString(mergedAttributes, "blockCommentStartDelimiter",
ScriptUtils.DEFAULT_BLOCK_COMMENT_START_DELIMITER);
this.blockCommentEndDelimiter = getString(mergedAttributes, "blockCommentEndDelimiter",
ScriptUtils.DEFAULT_BLOCK_COMMENT_END_DELIMITER);
this.errorMode = getEnum(mergedAttributes, "errorMode", ErrorMode.DEFAULT, ErrorMode.FAIL_ON_ERROR);
}
private AnnotationAttributes mergeAttributes(SqlConfig localSqlConfig, Class<?> testClass) {
AnnotationAttributes localAttributes = AnnotationUtils.getAnnotationAttributes(localSqlConfig, false, false);
// Enforce comment prefix aliases within the local @SqlConfig.
enforceCommentPrefixAliases(localAttributes);
@ -86,7 +103,11 @@ class MergedSqlConfig {
AnnotationAttributes globalAttributes = AnnotatedElementUtils.findMergedAnnotationAttributes(
testClass, SqlConfig.class.getName(), false, false);
if (globalAttributes != null) {
// Use local attributes only?
if (globalAttributes == null) {
return localAttributes;
}
// Enforce comment prefix aliases within the global @SqlConfig.
enforceCommentPrefixAliases(globalAttributes);
@ -105,25 +126,7 @@ class MergedSqlConfig {
}
}
}
mergedAttributes = globalAttributes;
}
else {
// Otherwise, use local attributes only.
mergedAttributes = localAttributes;
}
this.dataSource = mergedAttributes.getString("dataSource");
this.transactionManager = mergedAttributes.getString("transactionManager");
this.transactionMode = getEnum(mergedAttributes, "transactionMode", TransactionMode.DEFAULT,
TransactionMode.INFERRED);
this.encoding = mergedAttributes.getString("encoding");
this.separator = getString(mergedAttributes, "separator", ScriptUtils.DEFAULT_STATEMENT_SEPARATOR);
this.commentPrefixes = getCommentPrefixes(mergedAttributes);
this.blockCommentStartDelimiter = getString(mergedAttributes, "blockCommentStartDelimiter",
ScriptUtils.DEFAULT_BLOCK_COMMENT_START_DELIMITER);
this.blockCommentEndDelimiter = getString(mergedAttributes, "blockCommentEndDelimiter",
ScriptUtils.DEFAULT_BLOCK_COMMENT_END_DELIMITER);
this.errorMode = getEnum(mergedAttributes, "errorMode", ErrorMode.DEFAULT, ErrorMode.FAIL_ON_ERROR);
return globalAttributes;
}
/**