diff --git a/spring-core/src/main/java/org/springframework/core/OrderComparator.java b/spring-core/src/main/java/org/springframework/core/OrderComparator.java index 0a121dd2278..3d976d94af1 100644 --- a/spring-core/src/main/java/org/springframework/core/OrderComparator.java +++ b/spring-core/src/main/java/org/springframework/core/OrderComparator.java @@ -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"); * you may not use this file except in compliance with the License. @@ -203,7 +203,7 @@ public class OrderComparator implements Comparator { * Strategy interface to provide an order source for a given object. * @since 4.1 */ - public static interface OrderSourceProvider { + public interface OrderSourceProvider { /** * Return an order source for the specified object, i.e. an object that diff --git a/spring-test/src/main/java/org/springframework/test/context/jdbc/Sql.java b/spring-test/src/main/java/org/springframework/test/context/jdbc/Sql.java index b5659127162..e413b7b3e0c 100644 --- a/spring-test/src/main/java/org/springframework/test/context/jdbc/Sql.java +++ b/spring-test/src/main/java/org/springframework/test/context/jdbc/Sql.java @@ -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"); * you may not use this file except in compliance with the License. @@ -68,29 +68,10 @@ import static java.lang.annotation.RetentionPolicy.*; @Documented @Inherited @Retention(RUNTIME) -@Target({ TYPE, METHOD }) +@Target({TYPE, METHOD}) @Repeatable(SqlGroup.class) public @interface Sql { - /** - * Enumeration of phases that dictate when SQL scripts are executed. - */ - static enum ExecutionPhase { - - /** - * The configured SQL scripts and statements will be executed - * before the corresponding test method. - */ - BEFORE_TEST_METHOD, - - /** - * The configured SQL scripts and statements will be executed - * after the corresponding test method. - */ - AFTER_TEST_METHOD - } - - /** * Alias for {@link #scripts}. *

This attribute may not be used in conjunction with @@ -173,4 +154,23 @@ public @interface Sql { */ SqlConfig config() default @SqlConfig(); + + /** + * Enumeration of phases that dictate when SQL scripts are executed. + */ + enum ExecutionPhase { + + /** + * The configured SQL scripts and statements will be executed + * before the corresponding test method. + */ + BEFORE_TEST_METHOD, + + /** + * The configured SQL scripts and statements will be executed + * after the corresponding test method. + */ + AFTER_TEST_METHOD + } + } diff --git a/spring-test/src/main/java/org/springframework/test/context/jdbc/SqlConfig.java b/spring-test/src/main/java/org/springframework/test/context/jdbc/SqlConfig.java index 6a94a827549..9c0d55a6a0a 100644 --- a/spring-test/src/main/java/org/springframework/test/context/jdbc/SqlConfig.java +++ b/spring-test/src/main/java/org/springframework/test/context/jdbc/SqlConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -65,12 +65,122 @@ import static java.lang.annotation.RetentionPolicy.*; @Target(TYPE) public @interface SqlConfig { + /** + * The bean name of the {@link javax.sql.DataSource} against which the + * scripts should be executed. + *

The name is only required if there is more than one bean of type + * {@code DataSource} in the test's {@code ApplicationContext}. If there + * is only one such bean, it is not necessary to specify a bean name. + *

Defaults to an empty string, requiring that one of the following is + * true: + *

    + *
  1. An explicit bean name is defined in a global declaration of + * {@code @SqlConfig}. + *
  2. The data source can be retrieved from the transaction manager + * by using reflection to invoke a public method named + * {@code getDataSource()} on the transaction manager. + *
  3. There is only one bean of type {@code DataSource} in the test's + * {@code ApplicationContext}.
  4. + *
  5. The {@code DataSource} to use is named {@code "dataSource"}.
  6. + *
+ * @see org.springframework.test.context.transaction.TestContextTransactionUtils#retrieveDataSource + */ + String dataSource() default ""; + + /** + * The bean name of the {@link org.springframework.transaction.PlatformTransactionManager + * PlatformTransactionManager} that should be used to drive transactions. + *

The name is only used if there is more than one bean of type + * {@code PlatformTransactionManager} in the test's {@code ApplicationContext}. + * If there is only one such bean, it is not necessary to specify a bean name. + *

Defaults to an empty string, requiring that one of the following is + * true: + *

    + *
  1. An explicit bean name is defined in a global declaration of + * {@code @SqlConfig}. + *
  2. There is only one bean of type {@code PlatformTransactionManager} in + * the test's {@code ApplicationContext}.
  3. + *
  4. {@link org.springframework.transaction.annotation.TransactionManagementConfigurer + * TransactionManagementConfigurer} has been implemented to specify which + * {@code PlatformTransactionManager} bean should be used for annotation-driven + * transaction management.
  5. + *
  6. The {@code PlatformTransactionManager} to use is named + * {@code "transactionManager"}.
  7. + *
+ * @see org.springframework.test.context.transaction.TestContextTransactionUtils#retrieveTransactionManager + */ + String transactionManager() default ""; + + /** + * The mode to use when determining whether SQL scripts should be + * executed within a transaction. + *

Defaults to {@link TransactionMode#DEFAULT DEFAULT}. + *

Can be set to {@link TransactionMode#ISOLATED} to ensure that the SQL + * scripts are executed in a new, isolated transaction that will be immediately + * committed. + * @see TransactionMode + */ + TransactionMode transactionMode() default TransactionMode.DEFAULT; + + /** + * The encoding for the supplied SQL scripts, if different from the platform + * encoding. + *

An empty string denotes that the platform encoding should be used. + */ + String encoding() default ""; + + /** + * The character string used to separate individual statements within the + * SQL scripts. + *

Implicitly defaults to {@code ";"} if not specified and falls back to + * {@code "\n"} as a last resort. + *

May be set to + * {@link org.springframework.jdbc.datasource.init.ScriptUtils#EOF_STATEMENT_SEPARATOR} + * to signal that each script contains a single statement without a + * separator. + * @see org.springframework.jdbc.datasource.init.ScriptUtils#DEFAULT_STATEMENT_SEPARATOR + * @see org.springframework.jdbc.datasource.init.ScriptUtils#EOF_STATEMENT_SEPARATOR + */ + String separator() default ""; + + /** + * The prefix that identifies single-line comments within the SQL scripts. + *

Implicitly defaults to {@code "--"}. + * @see org.springframework.jdbc.datasource.init.ScriptUtils#DEFAULT_COMMENT_PREFIX + */ + String commentPrefix() default ""; + + /** + * The start delimiter that identifies block comments within the SQL scripts. + *

Implicitly defaults to {@code "/*"}. + * @see #blockCommentEndDelimiter + * @see org.springframework.jdbc.datasource.init.ScriptUtils#DEFAULT_BLOCK_COMMENT_START_DELIMITER + */ + String blockCommentStartDelimiter() default ""; + + /** + * The end delimiter that identifies block comments within the SQL scripts. + *

Implicitly defaults to "*/". + * @see #blockCommentStartDelimiter + * @see org.springframework.jdbc.datasource.init.ScriptUtils#DEFAULT_BLOCK_COMMENT_END_DELIMITER + */ + String blockCommentEndDelimiter() default ""; + + /** + * The mode to use when an error is encountered while executing an + * SQL statement. + *

Defaults to {@link ErrorMode#DEFAULT DEFAULT}. + * @see ErrorMode + */ + ErrorMode errorMode() default ErrorMode.DEFAULT; + + /** * Enumeration of modes that dictate whether SQL scripts should be * executed within a transaction and what the transaction propagation behavior * should be. */ - static enum TransactionMode { + enum TransactionMode { /** * Indicates that the default transaction mode should be used. @@ -137,11 +247,12 @@ public @interface SqlConfig { ISOLATED } + /** * Enumeration of modes that dictate how errors are handled while * executing SQL statements. */ - static enum ErrorMode { + enum ErrorMode { /** * Indicates that the default error mode should be used. @@ -188,114 +299,4 @@ public @interface SqlConfig { IGNORE_FAILED_DROPS } - - /** - * The bean name of the {@link javax.sql.DataSource} against which the - * scripts should be executed. - *

The name is only required if there is more than one bean of type - * {@code DataSource} in the test's {@code ApplicationContext}. If there - * is only one such bean, it is not necessary to specify a bean name. - *

Defaults to an empty string, requiring that one of the following is - * true: - *

    - *
  1. An explicit bean name is defined in a global declaration of - * {@code @SqlConfig}. - *
  2. The data source can be retrieved from the transaction manager - * by using reflection to invoke a public method named - * {@code getDataSource()} on the transaction manager. - *
  3. There is only one bean of type {@code DataSource} in the test's - * {@code ApplicationContext}.
  4. - *
  5. The {@code DataSource} to use is named {@code "dataSource"}.
  6. - *
- * @see org.springframework.test.context.transaction.TestContextTransactionUtils#retrieveDataSource - */ - String dataSource() default ""; - - /** - * The bean name of the {@link org.springframework.transaction.PlatformTransactionManager - * PlatformTransactionManager} that should be used to drive transactions. - *

The name is only used if there is more than one bean of type - * {@code PlatformTransactionManager} in the test's {@code ApplicationContext}. - * If there is only one such bean, it is not necessary to specify a bean name. - *

Defaults to an empty string, requiring that one of the following is - * true: - *

    - *
  1. An explicit bean name is defined in a global declaration of - * {@code @SqlConfig}. - *
  2. There is only one bean of type {@code PlatformTransactionManager} in - * the test's {@code ApplicationContext}.
  3. - *
  4. {@link org.springframework.transaction.annotation.TransactionManagementConfigurer - * TransactionManagementConfigurer} has been implemented to specify which - * {@code PlatformTransactionManager} bean should be used for annotation-driven - * transaction management.
  5. - *
  6. The {@code PlatformTransactionManager} to use is named - * {@code "transactionManager"}.
  7. - *
- * @see org.springframework.test.context.transaction.TestContextTransactionUtils#retrieveTransactionManager - */ - String transactionManager() default ""; - - /** - * The mode to use when determining whether SQL scripts should be - * executed within a transaction. - *

Defaults to {@link TransactionMode#DEFAULT DEFAULT}. - *

Can be set to {@link TransactionMode#ISOLATED} to ensure that the SQL - * scripts are executed in a new, isolated transaction that will be immediately - * committed. - * @see TransactionMode - */ - TransactionMode transactionMode() default TransactionMode.DEFAULT; - - /** - * The encoding for the supplied SQL scripts, if different from the platform - * encoding. - *

An empty string denotes that the platform encoding should be used. - */ - String encoding() default ""; - - /** - * The character string used to separate individual statements within the - * SQL scripts. - *

Implicitly defaults to {@code ";"} if not specified and falls back to - * {@code "\n"} as a last resort. - *

May be set to - * {@link org.springframework.jdbc.datasource.init.ScriptUtils#EOF_STATEMENT_SEPARATOR} - * to signal that each script contains a single statement without a - * separator. - * @see org.springframework.jdbc.datasource.init.ScriptUtils#DEFAULT_STATEMENT_SEPARATOR - * @see org.springframework.jdbc.datasource.init.ScriptUtils#EOF_STATEMENT_SEPARATOR - */ - String separator() default ""; - - /** - * The prefix that identifies single-line comments within the SQL scripts. - *

Implicitly defaults to {@code "--"}. - * @see org.springframework.jdbc.datasource.init.ScriptUtils#DEFAULT_COMMENT_PREFIX - */ - String commentPrefix() default ""; - - /** - * The start delimiter that identifies block comments within the SQL scripts. - *

Implicitly defaults to {@code "/*"}. - * @see #blockCommentEndDelimiter - * @see org.springframework.jdbc.datasource.init.ScriptUtils#DEFAULT_BLOCK_COMMENT_START_DELIMITER - */ - String blockCommentStartDelimiter() default ""; - - /** - * The end delimiter that identifies block comments within the SQL scripts. - *

Implicitly defaults to "*/". - * @see #blockCommentStartDelimiter - * @see org.springframework.jdbc.datasource.init.ScriptUtils#DEFAULT_BLOCK_COMMENT_END_DELIMITER - */ - String blockCommentEndDelimiter() default ""; - - /** - * The mode to use when an error is encountered while executing an - * SQL statement. - *

Defaults to {@link ErrorMode#DEFAULT DEFAULT}. - * @see ErrorMode - */ - ErrorMode errorMode() default ErrorMode.DEFAULT; - } diff --git a/spring-test/src/main/java/org/springframework/test/context/jdbc/SqlGroup.java b/spring-test/src/main/java/org/springframework/test/context/jdbc/SqlGroup.java index fb6a09fd7c8..6e052bd607f 100644 --- a/spring-test/src/main/java/org/springframework/test/context/jdbc/SqlGroup.java +++ b/spring-test/src/main/java/org/springframework/test/context/jdbc/SqlGroup.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,7 +42,7 @@ import static java.lang.annotation.RetentionPolicy.*; @Documented @Inherited @Retention(RUNTIME) -@Target({ TYPE, METHOD }) +@Target({TYPE, METHOD}) public @interface SqlGroup { Sql[] value();