|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2015 the original author or authors. |
|
|
|
* Copyright 2002-2016 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -27,8 +27,8 @@ import org.springframework.util.Assert; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* {@code MergedSqlConfig} encapsulates the <em>merged</em> {@link SqlConfig @SqlConfig} |
|
|
|
* {@code MergedSqlConfig} encapsulates the <em>merged</em> {@link SqlConfig @SqlConfig} |
|
|
|
* attributes declared locally via {@link Sql#config} and globally as a |
|
|
|
* attributes declared locally via {@link Sql#config} and globally as a class-level annotation. |
|
|
|
* class-level annotation. |
|
|
|
* |
|
|
|
* <p>Explicit local configuration attributes override global configuration attributes. |
|
|
|
* <p>Explicit local configuration attributes override global configuration attributes. |
|
|
|
* |
|
|
|
* |
|
|
|
* @author Sam Brannen |
|
|
|
* @author Sam Brannen |
|
|
|
@ -56,23 +56,6 @@ class MergedSqlConfig { |
|
|
|
private final ErrorMode errorMode; |
|
|
|
private final ErrorMode errorMode; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static <E extends Enum<?>> E getEnum(AnnotationAttributes attributes, String attributeName, |
|
|
|
|
|
|
|
E inheritedOrDefaultValue, E defaultValue) { |
|
|
|
|
|
|
|
E value = attributes.getEnum(attributeName); |
|
|
|
|
|
|
|
if (value == inheritedOrDefaultValue) { |
|
|
|
|
|
|
|
value = defaultValue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return value; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static String getString(AnnotationAttributes attributes, String attributeName, String defaultValue) { |
|
|
|
|
|
|
|
String value = attributes.getString(attributeName); |
|
|
|
|
|
|
|
if ("".equals(value)) { |
|
|
|
|
|
|
|
value = defaultValue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return value; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Construct a {@code MergedSqlConfig} instance by merging the configuration |
|
|
|
* Construct a {@code MergedSqlConfig} instance by merging the configuration |
|
|
|
* from the supplied local (potentially method-level) {@code @SqlConfig} annotation |
|
|
|
* from the supplied local (potentially method-level) {@code @SqlConfig} annotation |
|
|
|
@ -86,8 +69,8 @@ class MergedSqlConfig { |
|
|
|
Assert.notNull(testClass, "testClass must not be null"); |
|
|
|
Assert.notNull(testClass, "testClass must not be null"); |
|
|
|
|
|
|
|
|
|
|
|
// Get global attributes, if any.
|
|
|
|
// Get global attributes, if any.
|
|
|
|
AnnotationAttributes attributes = AnnotatedElementUtils.findMergedAnnotationAttributes(testClass, |
|
|
|
AnnotationAttributes attributes = AnnotatedElementUtils.findMergedAnnotationAttributes( |
|
|
|
SqlConfig.class.getName(), false, false); |
|
|
|
testClass, SqlConfig.class.getName(), false, false); |
|
|
|
|
|
|
|
|
|
|
|
// Override global attributes with local attributes.
|
|
|
|
// Override global attributes with local attributes.
|
|
|
|
if (attributes != null) { |
|
|
|
if (attributes != null) { |
|
|
|
@ -95,7 +78,7 @@ class MergedSqlConfig { |
|
|
|
Object value = AnnotationUtils.getValue(localSqlConfig, key); |
|
|
|
Object value = AnnotationUtils.getValue(localSqlConfig, key); |
|
|
|
if (value != null) { |
|
|
|
if (value != null) { |
|
|
|
// Is the value explicit (i.e., not a 'default')?
|
|
|
|
// Is the value explicit (i.e., not a 'default')?
|
|
|
|
if (!value.equals("") && (value != TransactionMode.DEFAULT) && (value != ErrorMode.DEFAULT)) { |
|
|
|
if (!value.equals("") && value != TransactionMode.DEFAULT && value != ErrorMode.DEFAULT) { |
|
|
|
attributes.put(key, value); |
|
|
|
attributes.put(key, value); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -187,17 +170,36 @@ class MergedSqlConfig { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public String toString() { |
|
|
|
public String toString() { |
|
|
|
return new ToStringCreator(this)//
|
|
|
|
return new ToStringCreator(this) |
|
|
|
.append("dataSource", dataSource)//
|
|
|
|
.append("dataSource", this.dataSource) |
|
|
|
.append("transactionManager", transactionManager)//
|
|
|
|
.append("transactionManager", this.transactionManager) |
|
|
|
.append("transactionMode", transactionMode)//
|
|
|
|
.append("transactionMode", this.transactionMode) |
|
|
|
.append("encoding", encoding)//
|
|
|
|
.append("encoding", this.encoding) |
|
|
|
.append("separator", separator)//
|
|
|
|
.append("separator", this.separator) |
|
|
|
.append("commentPrefix", commentPrefix)//
|
|
|
|
.append("commentPrefix", this.commentPrefix) |
|
|
|
.append("blockCommentStartDelimiter", blockCommentStartDelimiter)//
|
|
|
|
.append("blockCommentStartDelimiter", this.blockCommentStartDelimiter) |
|
|
|
.append("blockCommentEndDelimiter", blockCommentEndDelimiter)//
|
|
|
|
.append("blockCommentEndDelimiter", this.blockCommentEndDelimiter) |
|
|
|
.append("errorMode", errorMode)//
|
|
|
|
.append("errorMode", this.errorMode) |
|
|
|
.toString(); |
|
|
|
.toString(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static <E extends Enum<?>> E getEnum(AnnotationAttributes attributes, String attributeName, |
|
|
|
|
|
|
|
E inheritedOrDefaultValue, E defaultValue) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
E value = attributes.getEnum(attributeName); |
|
|
|
|
|
|
|
if (value == inheritedOrDefaultValue) { |
|
|
|
|
|
|
|
value = defaultValue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return value; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static String getString(AnnotationAttributes attributes, String attributeName, String defaultValue) { |
|
|
|
|
|
|
|
String value = attributes.getString(attributeName); |
|
|
|
|
|
|
|
if ("".equals(value)) { |
|
|
|
|
|
|
|
value = defaultValue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return value; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|