View Javadoc
1   /*
2    *    Copyright 2013-2023 the original author or authors.
3    *
4    *    Licensed under the Apache License, Version 2.0 (the "License");
5    *    you may not use this file except in compliance with the License.
6    *    You may obtain a copy of the License at
7    *
8    *       https://www.apache.org/licenses/LICENSE-2.0
9    *
10   *    Unless required by applicable law or agreed to in writing, software
11   *    distributed under the License is distributed on an "AS IS" BASIS,
12   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *    See the License for the specific language governing permissions and
14   *    limitations under the License.
15   */
16  package org.mybatis.cdi;
17  
18  import jakarta.enterprise.util.Nonbinding;
19  import jakarta.interceptor.InterceptorBinding;
20  
21  import java.lang.annotation.ElementType;
22  import java.lang.annotation.Retention;
23  import java.lang.annotation.RetentionPolicy;
24  import java.lang.annotation.Target;
25  
26  import org.apache.ibatis.session.ExecutorType;
27  
28  /**
29   * Adds transaction demarcation to the annotated method.
30   *
31   * @author Frank David Martínez
32   */
33  @InterceptorBinding
34  @Target({ ElementType.METHOD, ElementType.TYPE })
35  @Retention(RetentionPolicy.RUNTIME)
36  public @interface Transactional {
37  
38    /**
39     * Returns the constant indicating the myBatis executor type.
40     *
41     * @return ExecutorType.SIMPLE by default, user defined otherwise.
42     */
43    @Nonbinding
44    ExecutorType executorType() default ExecutorType.SIMPLE;
45  
46    /**
47     * Returns the constant indicating the transaction isolation level.
48     *
49     * @return Isolation.DEFAULT by default, user defined otherwise.
50     */
51    @Nonbinding
52    Isolation isolation() default Isolation.DEFAULT;
53  
54    /**
55     * Flag to indicate that myBatis has to force the transaction {@code commit().}
56     *
57     * @return false by default, user defined otherwise.
58     */
59    @Nonbinding
60    boolean force() default false;
61  
62    /**
63     * If true, the transaction will never committed but rather rolled back, useful for testing purposes.
64     *
65     * @return false by default, user defined otherwise.
66     */
67    @Nonbinding
68    boolean rollbackOnly() default false;
69  
70    /**
71     * Defines zero (0) or more exception {@code Class classes}, which must be a subclass of {@code Throwable}, indicating
72     * which exception types must cause a transaction rollback.
73     *
74     * @return an empty array by default, user defined otherwise.
75     */
76    @Nonbinding
77    Class<? extends Throwable>[] rollbackFor() default {};
78  
79  }