21
21
import java .lang .annotation .Retention ;
22
22
import java .lang .annotation .Target ;
23
23
24
- import org .springframework .jdbc .datasource .init .ScriptUtils ;
25
-
26
24
import static java .lang .annotation .ElementType .*;
27
25
import static java .lang .annotation .RetentionPolicy .*;
28
26
46
44
* attribute. Thus, in order to support overrides of <em>inherited</em> global
47
45
* configuration, {@code @SqlConfig} attributes have an <em>explicit</em>
48
46
* {@code default} value of either {@code ""} for Strings or {@code DEFAULT} for
49
- * Enums. This approach allows local declarations {@code @SqlConfig} to
47
+ * Enums. This approach allows local declarations of {@code @SqlConfig} to
50
48
* selectively override individual attributes from global declarations of
51
49
* {@code @SqlConfig} by providing a value other than {@code ""} or {@code DEFAULT}.
52
50
*
@@ -91,22 +89,50 @@ static enum TransactionMode {
91
89
DEFAULT ,
92
90
93
91
/**
94
- * Indicates that the transaction mode to use when executing SQL scripts
95
- * should be <em>inferred</em> based on whether or not a Spring-managed
96
- * transaction is currently present.
97
- * <p>SQL scripts will be executed within the current transaction if present;
98
- * otherwise, scripts will be executed in a new transaction that will be
99
- * immediately committed.
100
- * <p>The <em>current</em> transaction will typically be managed by the
101
- * {@link org.springframework.test.context.transaction.TransactionalTestExecutionListener
102
- * TransactionalTestExecutionListener}.
92
+ * Indicates that the transaction mode to use when executing SQL
93
+ * scripts should be <em>inferred</em> using the rules listed below.
94
+ * In the context of these rules, the term "<em>available</em>"
95
+ * means that the bean for the data source or transaction manager
96
+ * is either explicitly specified via a corresponding annotation
97
+ * attribute in {@code @SqlConfig} or discoverable via conventions. See
98
+ * {@link org.springframework.test.context.transaction.TestContextTransactionUtils TestContextTransactionUtils}
99
+ * for details on the conventions used to discover such beans in
100
+ * the {@code ApplicationContext}.
101
+ *
102
+ * <h4>Inference Rules</h4>
103
+ * <ol>
104
+ * <li>If neither a transaction manager nor a data source is
105
+ * available, an exception will be thrown.
106
+ * <li>If a transaction manager is not available but a data source
107
+ * is available, SQL scripts will be executed directly against the
108
+ * data source without a transaction.
109
+ * <li>If a transaction manager is available:
110
+ * <ul>
111
+ * <li>If a data source is not available, an attempt will be made
112
+ * to retrieve it from the transaction manager by using reflection
113
+ * to invoke a public method named {@code getDataSource()} on the
114
+ * transaction manager. If the attempt fails, an exception will be
115
+ * thrown.
116
+ * <li>Using the resolved transaction manager and data source, SQL
117
+ * scripts will be executed within an existing transaction if
118
+ * present; otherwise, scripts will be executed in a new transaction
119
+ * that will be immediately committed. An <em>existing</em>
120
+ * transaction will typically be managed by the
121
+ * {@link org.springframework.test.context.transaction.TransactionalTestExecutionListener TransactionalTestExecutionListener}.
122
+ * </ul>
123
+ * </ol>
103
124
* @see #ISOLATED
125
+ * @see org.springframework.test.context.transaction.TestContextTransactionUtils#retrieveDataSource
126
+ * @see org.springframework.test.context.transaction.TestContextTransactionUtils#retrieveTransactionManager
104
127
*/
105
128
INFERRED ,
106
129
107
130
/**
108
131
* Indicates that SQL scripts should always be executed in a new,
109
132
* <em>isolated</em> transaction that will be immediately committed.
133
+ * <p>In contrast to {@link #INFERRED}, this mode requires the
134
+ * presence of a transaction manager <strong>and</strong> a data
135
+ * source.
110
136
*/
111
137
ISOLATED
112
138
}
@@ -164,18 +190,24 @@ static enum ErrorMode {
164
190
165
191
166
192
/**
167
- * The bean name of the {@link javax.sql.DataSource} against which the scripts
168
- * should be executed.
169
- * <p>The name is only used if there is more than one bean of type
170
- * {@code DataSource} in the test's {@code ApplicationContext}. If there is
171
- * only one such bean, it is not necessary to specify a bean name.
193
+ * The bean name of the {@link javax.sql.DataSource} against which the
194
+ * scripts should be executed.
195
+ * <p>The name is only required if there is more than one bean of type
196
+ * {@code DataSource} in the test's {@code ApplicationContext}. If there
197
+ * is only one such bean, it is not necessary to specify a bean name.
172
198
* <p>Defaults to an empty string, requiring that one of the following is
173
199
* true:
174
200
* <ol>
201
+ * <li>An explicit bean name is defined in a global declaration of
202
+ * {@code @SqlConfig}.
203
+ * <li>The data source can be retrieved from the transaction manager
204
+ * by using reflection to invoke a public method named
205
+ * {@code getDataSource()} on the transaction manager.
175
206
* <li>There is only one bean of type {@code DataSource} in the test's
176
207
* {@code ApplicationContext}.</li>
177
208
* <li>The {@code DataSource} to use is named {@code "dataSource"}.</li>
178
209
* </ol>
210
+ * @see org.springframework.test.context.transaction.TestContextTransactionUtils#retrieveDataSource
179
211
*/
180
212
String dataSource () default "" ;
181
213
@@ -188,6 +220,8 @@ static enum ErrorMode {
188
220
* <p>Defaults to an empty string, requiring that one of the following is
189
221
* true:
190
222
* <ol>
223
+ * <li>An explicit bean name is defined in a global declaration of
224
+ * {@code @SqlConfig}.
191
225
* <li>There is only one bean of type {@code PlatformTransactionManager} in
192
226
* the test's {@code ApplicationContext}.</li>
193
227
* <li>{@link org.springframework.transaction.annotation.TransactionManagementConfigurer
@@ -197,6 +231,7 @@ static enum ErrorMode {
197
231
* <li>The {@code PlatformTransactionManager} to use is named
198
232
* {@code "transactionManager"}.</li>
199
233
* </ol>
234
+ * @see org.springframework.test.context.transaction.TestContextTransactionUtils#retrieveTransactionManager
200
235
*/
201
236
String transactionManager () default "" ;
202
237
@@ -223,32 +258,35 @@ static enum ErrorMode {
223
258
* SQL scripts.
224
259
* <p>Implicitly defaults to {@code ";"} if not specified and falls back to
225
260
* {@code "\n"} as a last resort.
226
- * <p>May be set to {@link ScriptUtils#EOF_STATEMENT_SEPARATOR} to signal
227
- * that each script contains a single statement without a separator.
228
- * @see ScriptUtils#DEFAULT_STATEMENT_SEPARATOR
261
+ * <p>May be set to
262
+ * {@link org.springframework.jdbc.datasource.init.ScriptUtils#EOF_STATEMENT_SEPARATOR}
263
+ * to signal that each script contains a single statement without a
264
+ * separator.
265
+ * @see org.springframework.jdbc.datasource.init.ScriptUtils#DEFAULT_STATEMENT_SEPARATOR
266
+ * @see org.springframework.jdbc.datasource.init.ScriptUtils#EOF_STATEMENT_SEPARATOR
229
267
*/
230
268
String separator () default "" ;
231
269
232
270
/**
233
271
* The prefix that identifies single-line comments within the SQL scripts.
234
272
* <p>Implicitly defaults to {@code "--"}.
235
- * @see ScriptUtils#DEFAULT_COMMENT_PREFIX
273
+ * @see org.springframework.jdbc.datasource.init. ScriptUtils#DEFAULT_COMMENT_PREFIX
236
274
*/
237
275
String commentPrefix () default "" ;
238
276
239
277
/**
240
278
* The start delimiter that identifies block comments within the SQL scripts.
241
279
* <p>Implicitly defaults to {@code "/*"}.
242
280
* @see #blockCommentEndDelimiter
243
- * @see ScriptUtils#DEFAULT_BLOCK_COMMENT_START_DELIMITER
281
+ * @see org.springframework.jdbc.datasource.init. ScriptUtils#DEFAULT_BLOCK_COMMENT_START_DELIMITER
244
282
*/
245
283
String blockCommentStartDelimiter () default "" ;
246
284
247
285
/**
248
286
* The end delimiter that identifies block comments within the SQL scripts.
249
287
* <p>Implicitly defaults to <code>"*/"</code>.
250
288
* @see #blockCommentStartDelimiter
251
- * @see ScriptUtils#DEFAULT_BLOCK_COMMENT_END_DELIMITER
289
+ * @see org.springframework.jdbc.datasource.init. ScriptUtils#DEFAULT_BLOCK_COMMENT_END_DELIMITER
252
290
*/
253
291
String blockCommentEndDelimiter () default "" ;
254
292
0 commit comments