@@ -56,52 +56,21 @@ class MergedSqlConfig {
56
56
private final ErrorMode errorMode ;
57
57
58
58
59
- private static TransactionMode retrieveTransactionMode (AnnotationAttributes attributes ) {
60
- TransactionMode transactionMode = attributes .getEnum ("transactionMode" );
61
- if (transactionMode == TransactionMode .DEFAULT ) {
62
- transactionMode = TransactionMode .INFERRED ;
59
+ private static <E extends Enum <?>> E getEnum (AnnotationAttributes attributes , String attributeName ,
60
+ E inheritOrOverrideValue , E defaultValue ) {
61
+ E value = attributes .getEnum (attributeName );
62
+ if (value == inheritOrOverrideValue ) {
63
+ value = defaultValue ;
63
64
}
64
- return transactionMode ;
65
+ return value ;
65
66
}
66
67
67
- private static ErrorMode retrieveErrorMode (AnnotationAttributes attributes ) {
68
- ErrorMode errorMode = attributes .getEnum ( "errorMode" );
69
- if (errorMode == ErrorMode . DEFAULT ) {
70
- errorMode = ErrorMode . FAIL_ON_ERROR ;
68
+ private static String getString (AnnotationAttributes attributes , String attributeName , String defaultValue ) {
69
+ String value = attributes .getString ( attributeName );
70
+ if ("" . equals ( value ) ) {
71
+ value = defaultValue ;
71
72
}
72
- return errorMode ;
73
- }
74
-
75
- private static String retrieveSeparator (AnnotationAttributes attributes ) {
76
- String separator = attributes .getString ("separator" );
77
- if ("" .equals (separator )) {
78
- separator = ScriptUtils .DEFAULT_STATEMENT_SEPARATOR ;
79
- }
80
- return separator ;
81
- }
82
-
83
- private static String retrieveCommentPrefix (AnnotationAttributes attributes ) {
84
- String commentPrefix = attributes .getString ("commentPrefix" );
85
- if ("" .equals (commentPrefix )) {
86
- commentPrefix = ScriptUtils .DEFAULT_COMMENT_PREFIX ;
87
- }
88
- return commentPrefix ;
89
- }
90
-
91
- private static String retrieveBlockCommentStartDelimiter (AnnotationAttributes attributes ) {
92
- String blockCommentStartDelimiter = attributes .getString ("blockCommentStartDelimiter" );
93
- if ("" .equals (blockCommentStartDelimiter )) {
94
- blockCommentStartDelimiter = ScriptUtils .DEFAULT_BLOCK_COMMENT_START_DELIMITER ;
95
- }
96
- return blockCommentStartDelimiter ;
97
- }
98
-
99
- private static String retrieveBlockCommentEndDelimiter (AnnotationAttributes attributes ) {
100
- String blockCommentEndDelimiter = attributes .getString ("blockCommentEndDelimiter" );
101
- if ("" .equals (blockCommentEndDelimiter )) {
102
- blockCommentEndDelimiter = ScriptUtils .DEFAULT_BLOCK_COMMENT_END_DELIMITER ;
103
- }
104
- return blockCommentEndDelimiter ;
73
+ return value ;
105
74
}
106
75
107
76
/**
@@ -139,13 +108,15 @@ private static String retrieveBlockCommentEndDelimiter(AnnotationAttributes attr
139
108
140
109
this .dataSource = attributes .getString ("dataSource" );
141
110
this .transactionManager = attributes .getString ("transactionManager" );
142
- this .transactionMode = retrieveTransactionMode (attributes );
111
+ this .transactionMode = getEnum (attributes , "transactionMode" , TransactionMode . DEFAULT , TransactionMode . INFERRED );
143
112
this .encoding = attributes .getString ("encoding" );
144
- this .separator = retrieveSeparator (attributes );
145
- this .commentPrefix = retrieveCommentPrefix (attributes );
146
- this .blockCommentStartDelimiter = retrieveBlockCommentStartDelimiter (attributes );
147
- this .blockCommentEndDelimiter = retrieveBlockCommentEndDelimiter (attributes );
148
- this .errorMode = retrieveErrorMode (attributes );
113
+ this .separator = getString (attributes , "separator" , ScriptUtils .DEFAULT_STATEMENT_SEPARATOR );
114
+ this .commentPrefix = getString (attributes , "commentPrefix" , ScriptUtils .DEFAULT_COMMENT_PREFIX );
115
+ this .blockCommentStartDelimiter = getString (attributes , "blockCommentStartDelimiter" ,
116
+ ScriptUtils .DEFAULT_BLOCK_COMMENT_START_DELIMITER );
117
+ this .blockCommentEndDelimiter = getString (attributes , "blockCommentEndDelimiter" ,
118
+ ScriptUtils .DEFAULT_BLOCK_COMMENT_END_DELIMITER );
119
+ this .errorMode = getEnum (attributes , "errorMode" , ErrorMode .DEFAULT , ErrorMode .FAIL_ON_ERROR );
149
120
}
150
121
151
122
/**
0 commit comments