@@ -77,40 +77,7 @@ class MergedSqlConfig {
77
77
Assert .notNull (localSqlConfig , "Local @SqlConfig must not be null" );
78
78
Assert .notNull (testClass , "testClass must not be null" );
79
79
80
- AnnotationAttributes mergedAttributes ;
81
- AnnotationAttributes localAttributes = AnnotationUtils .getAnnotationAttributes (localSqlConfig , false , false );
82
- // Enforce comment prefix aliases within the local @SqlConfig.
83
- enforceCommentPrefixAliases (localAttributes );
84
-
85
- // Get global attributes, if any.
86
- AnnotationAttributes globalAttributes = AnnotatedElementUtils .findMergedAnnotationAttributes (
87
- testClass , SqlConfig .class .getName (), false , false );
88
-
89
- if (globalAttributes != null ) {
90
- // Enforce comment prefix aliases within the global @SqlConfig.
91
- enforceCommentPrefixAliases (globalAttributes );
92
-
93
- for (String key : globalAttributes .keySet ()) {
94
- Object value = localAttributes .get (key );
95
- if (isExplicitValue (value )) {
96
- // Override global attribute with local attribute.
97
- globalAttributes .put (key , value );
98
-
99
- // Ensure comment prefix aliases are honored during the merge.
100
- if (key .equals (COMMENT_PREFIX ) && isEmptyArray (localAttributes .get (COMMENT_PREFIXES ))) {
101
- globalAttributes .put (COMMENT_PREFIXES , value );
102
- }
103
- else if (key .equals (COMMENT_PREFIXES ) && isEmptyString (localAttributes .get (COMMENT_PREFIX ))) {
104
- globalAttributes .put (COMMENT_PREFIX , value );
105
- }
106
- }
107
- }
108
- mergedAttributes = globalAttributes ;
109
- }
110
- else {
111
- // Otherwise, use local attributes only.
112
- mergedAttributes = localAttributes ;
113
- }
80
+ AnnotationAttributes mergedAttributes = mergeAttributes (localSqlConfig , testClass );
114
81
115
82
this .dataSource = mergedAttributes .getString ("dataSource" );
116
83
this .transactionManager = mergedAttributes .getString ("transactionManager" );
@@ -126,6 +93,42 @@ else if (key.equals(COMMENT_PREFIXES) && isEmptyString(localAttributes.get(COMME
126
93
this .errorMode = getEnum (mergedAttributes , "errorMode" , ErrorMode .DEFAULT , ErrorMode .FAIL_ON_ERROR );
127
94
}
128
95
96
+ private AnnotationAttributes mergeAttributes (SqlConfig localSqlConfig , Class <?> testClass ) {
97
+ AnnotationAttributes localAttributes = AnnotationUtils .getAnnotationAttributes (localSqlConfig , false , false );
98
+
99
+ // Enforce comment prefix aliases within the local @SqlConfig.
100
+ enforceCommentPrefixAliases (localAttributes );
101
+
102
+ // Get global attributes, if any.
103
+ AnnotationAttributes globalAttributes = AnnotatedElementUtils .findMergedAnnotationAttributes (
104
+ testClass , SqlConfig .class .getName (), false , false );
105
+
106
+ // Use local attributes only?
107
+ if (globalAttributes == null ) {
108
+ return localAttributes ;
109
+ }
110
+
111
+ // Enforce comment prefix aliases within the global @SqlConfig.
112
+ enforceCommentPrefixAliases (globalAttributes );
113
+
114
+ for (String key : globalAttributes .keySet ()) {
115
+ Object value = localAttributes .get (key );
116
+ if (isExplicitValue (value )) {
117
+ // Override global attribute with local attribute.
118
+ globalAttributes .put (key , value );
119
+
120
+ // Ensure comment prefix aliases are honored during the merge.
121
+ if (key .equals (COMMENT_PREFIX ) && isEmptyArray (localAttributes .get (COMMENT_PREFIXES ))) {
122
+ globalAttributes .put (COMMENT_PREFIXES , value );
123
+ }
124
+ else if (key .equals (COMMENT_PREFIXES ) && isEmptyString (localAttributes .get (COMMENT_PREFIX ))) {
125
+ globalAttributes .put (COMMENT_PREFIX , value );
126
+ }
127
+ }
128
+ }
129
+ return globalAttributes ;
130
+ }
131
+
129
132
/**
130
133
* @see SqlConfig#dataSource()
131
134
*/
0 commit comments