Introduce @Commit alias for @Rollback(false)
Due to common usage of @Rollback(false), this commit introduces a new @Commit annotation that more clearly conveys the intent of the code while retaining the run-time semantics. @Commit is in fact meta-annotated with @Rollback(false). Issue: SPR-13279
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 2002-2015 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.test.annotation;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import static java.lang.annotation.ElementType.*;
|
||||
import static java.lang.annotation.RetentionPolicy.*;
|
||||
|
||||
/**
|
||||
* {@code @Commit} is a test annotation that is used to indicate that a
|
||||
* <em>test-managed transaction</em> should be <em>committed</em> after
|
||||
* the test method has completed.
|
||||
*
|
||||
* <p>Consult the class-level Javadoc for
|
||||
* {@link org.springframework.test.context.transaction.TransactionalTestExecutionListener}
|
||||
* for an explanation of <em>test-managed transactions</em>.
|
||||
*
|
||||
* <p>When declared as a class-level annotation, {@code @Commit} defines
|
||||
* the default commit semantics for all test methods within the test class
|
||||
* hierarchy. When declared as a method-level annotation, {@code @Commit}
|
||||
* defines commit semantics for the specific test method, potentially
|
||||
* overriding class-level default commit or rollback semantics.
|
||||
*
|
||||
* <p><strong>Warning</strong>: {@code @Commit} can be used as direct
|
||||
* replacement for {@code @Rollback(false)}; however, it should
|
||||
* <strong>not</strong> be declared alongside {@code @Rollback}. Declaring
|
||||
* {@code @Commit} and {@code @Rollback} on the same test method or on the
|
||||
* same test class is unsupported and may lead to unpredictable results.
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 4.2
|
||||
* @see Rollback
|
||||
* @see org.springframework.test.context.transaction.TransactionalTestExecutionListener
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RUNTIME)
|
||||
@Target({ TYPE, METHOD })
|
||||
@Rollback(false)
|
||||
public @interface Commit {
|
||||
}
|
||||
@@ -24,8 +24,9 @@ import static java.lang.annotation.ElementType.*;
|
||||
import static java.lang.annotation.RetentionPolicy.*;
|
||||
|
||||
/**
|
||||
* Test annotation used to indicate whether a <em>test-managed transaction</em>
|
||||
* should be <em>rolled back</em> after the test method has completed.
|
||||
* {@code @Rollback} is a test annotation that is used to indicate whether
|
||||
* a <em>test-managed transaction</em> should be <em>rolled back</em> after
|
||||
* the test method has completed.
|
||||
*
|
||||
* <p>Consult the class-level Javadoc for
|
||||
* {@link org.springframework.test.context.transaction.TransactionalTestExecutionListener}
|
||||
@@ -35,13 +36,22 @@ import static java.lang.annotation.RetentionPolicy.*;
|
||||
* the default rollback semantics for all test methods within the test class
|
||||
* hierarchy. When declared as a method-level annotation, {@code @Rollback}
|
||||
* defines rollback semantics for the specific test method, potentially
|
||||
* overriding class-level default rollback semantics.
|
||||
* overriding class-level default commit or rollback semantics.
|
||||
*
|
||||
* <p>As of Spring Framework 4.0, this annotation may be used as a
|
||||
* <em>meta-annotation</em> to create custom <em>composed annotations</em>.
|
||||
* <p>As of Spring Framework 4.2, {@code @Commit} can be used as direct
|
||||
* replacement for {@code @Rollback(false)}.
|
||||
*
|
||||
* <p><strong>Warning</strong>: Declaring {@code @Commit} and {@code @Rollback}
|
||||
* on the same test method or on the same test class is unsupported and may
|
||||
* lead to unpredictable results.
|
||||
*
|
||||
* <p>This annotation may be used as a <em>meta-annotation</em> to create
|
||||
* custom <em>composed annotations</em>. Consult the source code for
|
||||
* {@link Commit @Commit} for a concrete example.
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 2.5
|
||||
* @see Commit
|
||||
* @see org.springframework.test.context.transaction.TransactionalTestExecutionListener
|
||||
*/
|
||||
@Documented
|
||||
@@ -54,6 +64,7 @@ public @interface Rollback {
|
||||
* after the test method has completed.
|
||||
* <p>If {@code true}, the transaction will be rolled back; otherwise,
|
||||
* the transaction will be committed.
|
||||
* <p>Defaults to {@code true}.
|
||||
*/
|
||||
boolean value() default true;
|
||||
|
||||
|
||||
@@ -85,6 +85,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
* @see org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener
|
||||
* @see org.springframework.test.context.transaction.TransactionConfiguration
|
||||
* @see org.springframework.transaction.annotation.Transactional
|
||||
* @see org.springframework.test.annotation.Commit
|
||||
* @see org.springframework.test.annotation.Rollback
|
||||
* @see org.springframework.test.context.transaction.BeforeTransaction
|
||||
* @see org.springframework.test.context.transaction.AfterTransaction
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 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.
|
||||
@@ -69,6 +69,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
* @see org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener
|
||||
* @see org.springframework.test.context.transaction.TransactionConfiguration
|
||||
* @see org.springframework.transaction.annotation.Transactional
|
||||
* @see org.springframework.test.annotation.Commit
|
||||
* @see org.springframework.test.annotation.Rollback
|
||||
* @see org.springframework.test.context.transaction.BeforeTransaction
|
||||
* @see org.springframework.test.context.transaction.AfterTransaction
|
||||
|
||||
@@ -34,6 +34,7 @@ import java.lang.annotation.Target;
|
||||
* @since 2.5
|
||||
* @see TransactionalTestExecutionListener
|
||||
* @see org.springframework.transaction.annotation.Transactional
|
||||
* @see org.springframework.test.annotation.Commit
|
||||
* @see org.springframework.test.annotation.Rollback
|
||||
* @see org.springframework.test.context.jdbc.Sql
|
||||
* @see org.springframework.test.context.jdbc.SqlConfig
|
||||
|
||||
@@ -120,6 +120,7 @@ import static org.springframework.core.annotation.AnnotationUtils.*;
|
||||
* @since 2.5
|
||||
* @see org.springframework.transaction.annotation.TransactionManagementConfigurer
|
||||
* @see org.springframework.transaction.annotation.Transactional
|
||||
* @see org.springframework.test.annotation.Commit
|
||||
* @see org.springframework.test.annotation.Rollback
|
||||
* @see BeforeTransaction
|
||||
* @see AfterTransaction
|
||||
|
||||
Reference in New Issue
Block a user