001/*
002 * Copyright 2002-2019 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.test.context.jdbc;
018
019import java.lang.annotation.Documented;
020import java.lang.annotation.ElementType;
021import java.lang.annotation.Inherited;
022import java.lang.annotation.Retention;
023import java.lang.annotation.RetentionPolicy;
024import java.lang.annotation.Target;
025
026/**
027 * {@code @SqlMergeMode} is used to annotate a test class or test method to
028 * configure whether method-level {@code @Sql} declarations are merged with
029 * class-level {@code @Sql} declarations.
030 *
031 * <p>A method-level {@code @SqlMergeMode} declaration overrides a class-level
032 * declaration.
033 *
034 * <p>If {@code @SqlMergeMode} is not declared on a test class or test method,
035 * {@link MergeMode#OVERRIDE} will be used by default.
036 *
037 * <p>This annotation may be used as a <em>meta-annotation</em> to create custom
038 * <em>composed annotations</em> with attribute overrides.
039 *
040 * @author Sam Brannen
041 * @author Dmitry Semukhin
042 * @since 5.2
043 * @see Sql
044 * @see MergeMode#MERGE
045 * @see MergeMode#OVERRIDE
046 */
047@Target({ElementType.TYPE, ElementType.METHOD})
048@Retention(RetentionPolicy.RUNTIME)
049@Documented
050@Inherited
051public @interface SqlMergeMode {
052
053        /**
054         * Indicates whether method-level {@code @Sql} annotations should be merged
055         * with class-level {@code @Sql} annotations or override them.
056         */
057        MergeMode value();
058
059
060        /**
061         * Enumeration of <em>modes</em> that dictate whether method-level {@code @Sql}
062         * declarations are merged with class-level {@code @Sql} declarations.
063         */
064        enum MergeMode {
065
066                /**
067                 * Indicates that method-level {@code @Sql} declarations should be merged
068                 * with class-level {@code @Sql} declarations, with class-level SQL
069                 * scripts and statements executed before method-level scripts and
070                 * statements.
071                 */
072                MERGE,
073
074                /**
075                 * Indicates that method-level {@code @Sql} declarations should override
076                 * class-level {@code @Sql} declarations.
077                 */
078                OVERRIDE
079
080        }
081
082}