|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2021 the original author or authors. |
| 2 | + * Copyright 2002-2022 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
37 | 37 | * <a href="https://docs.spring.io/spring-framework/docs/current/reference/html/data-access.html#transaction">Transaction Management</a>
|
38 | 38 | * section of the reference manual.
|
39 | 39 | *
|
40 |
| - * <p>This annotation type is generally directly comparable to Spring's |
| 40 | + * <p>This annotation is generally directly comparable to Spring's |
41 | 41 | * {@link org.springframework.transaction.interceptor.RuleBasedTransactionAttribute}
|
42 | 42 | * class, and in fact {@link AnnotationTransactionAttributeSource} will directly
|
43 |
| - * convert the data to the latter class, so that Spring's transaction support code |
44 |
| - * does not have to know about annotations. If no custom rollback rules apply, |
45 |
| - * the transaction will roll back on {@link RuntimeException} and {@link Error} |
46 |
| - * but not on checked exceptions. |
| 43 | + * convert this annotation's attributes to properties in {@code RuleBasedTransactionAttribute}, |
| 44 | + * so that Spring's transaction support code does not have to know about annotations. |
47 | 45 | *
|
48 |
| - * <p>For specific information about the semantics of this annotation's attributes, |
49 |
| - * consult the {@link org.springframework.transaction.TransactionDefinition} and |
50 |
| - * {@link org.springframework.transaction.interceptor.TransactionAttribute} javadocs. |
| 46 | + * <h3>Attribute Semantics</h3> |
| 47 | + * |
| 48 | + * <p>If no custom rollback rules are configured in this annotation, the transaction |
| 49 | + * will roll back on {@link RuntimeException} and {@link Error} but not on checked |
| 50 | + * exceptions. |
| 51 | + * |
| 52 | + * <p>Rollback rules determine if a transaction should be rolled back when a given |
| 53 | + * exception is thrown, and the rules are based on patterns. A pattern can be a |
| 54 | + * fully qualified class name or a substring of a fully qualified class name for |
| 55 | + * an exception type (which must be a subclass of {@code Throwable}), with no |
| 56 | + * wildcard support at present. For example, a value of |
| 57 | + * {@code "javax.servlet.ServletException"} or {@code "ServletException"} will |
| 58 | + * match {@code javax.servlet.ServletException} and its subclasses. |
| 59 | + * |
| 60 | + * <p>Rollback rules may be configured via {@link #rollbackFor}/{@link #noRollbackFor} |
| 61 | + * and {@link #rollbackForClassName}/{@link #noRollbackForClassName}, which allow |
| 62 | + * patterns to be specified as {@link Class} references or {@linkplain String |
| 63 | + * strings}, respectively. When an exception type is specified as a class reference |
| 64 | + * its fully qualified name will be used as the pattern. Consequently, |
| 65 | + * {@code @Transactional(rollbackFor = example.CustomException.class)} is equivalent |
| 66 | + * to {@code @Transactional(rollbackForClassName = "example.CustomException")}. |
| 67 | + * |
| 68 | + * <p><strong>WARNING:</strong> You must carefully consider how specific the pattern |
| 69 | + * is and whether to include package information (which isn't mandatory). For example, |
| 70 | + * {@code "Exception"} will match nearly anything and will probably hide other |
| 71 | + * rules. {@code "java.lang.Exception"} would be correct if {@code "Exception"} |
| 72 | + * were meant to define a rule for all checked exceptions. With more unique |
| 73 | + * exception names such as {@code "BaseBusinessException"} there is likely no |
| 74 | + * need to use the fully qualified class name for the exception pattern. Furthermore, |
| 75 | + * rollback rules may result in unintentional matches for similarly named exceptions |
| 76 | + * and nested classes. This is due to the fact that a thrown exception is considered |
| 77 | + * to be a match for a given rollback rule if the name of thrown exception contains |
| 78 | + * the exception pattern configured for the rollback rule. For example, given a |
| 79 | + * rule configured to match on {@code com.example.CustomException}, that rule |
| 80 | + * would match against an exception named |
| 81 | + * {@code com.example.CustomExceptionV2} (an exception in the same package as |
| 82 | + * {@code CustomException} but with an additional suffix) or an exception named |
| 83 | + * {@code com.example.CustomException$AnotherException} |
| 84 | + * (an exception declared as a nested class in {@code CustomException}). |
| 85 | + * |
| 86 | + * <p>For specific information about the semantics of other attributes in this |
| 87 | + * annotation, consult the {@link org.springframework.transaction.TransactionDefinition} |
| 88 | + * and {@link org.springframework.transaction.interceptor.TransactionAttribute} javadocs. |
| 89 | + * |
| 90 | + * <h3>Transaction Management</h3> |
51 | 91 | *
|
52 | 92 | * <p>This annotation commonly works with thread-bound transactions managed by a
|
53 | 93 | * {@link org.springframework.transaction.PlatformTransactionManager}, exposing a
|
|
167 | 207 | boolean readOnly() default false;
|
168 | 208 |
|
169 | 209 | /**
|
170 |
| - * Defines zero (0) or more exception {@link Class classes}, which must be |
| 210 | + * Defines zero (0) or more exception {@linkplain Class classes}, which must be |
171 | 211 | * subclasses of {@link Throwable}, indicating which exception types must cause
|
172 | 212 | * a transaction rollback.
|
173 |
| - * <p>By default, a transaction will be rolling back on {@link RuntimeException} |
| 213 | + * <p>By default, a transaction will be rolled back on {@link RuntimeException} |
174 | 214 | * and {@link Error} but not on checked exceptions (business exceptions). See
|
175 | 215 | * {@link org.springframework.transaction.interceptor.DefaultTransactionAttribute#rollbackOn(Throwable)}
|
176 | 216 | * for a detailed explanation.
|
177 | 217 | * <p>This is the preferred way to construct a rollback rule (in contrast to
|
178 |
| - * {@link #rollbackForClassName}), matching the exception class and its subclasses. |
179 |
| - * <p>Similar to {@link org.springframework.transaction.interceptor.RollbackRuleAttribute#RollbackRuleAttribute(Class clazz)}. |
| 218 | + * {@link #rollbackForClassName}), matching the exception type, its subclasses, |
| 219 | + * and its nested classes. See the {@linkplain Transactional class-level javadocs} |
| 220 | + * for further details on rollback rule semantics and warnings regarding possible |
| 221 | + * unintentional matches. |
180 | 222 | * @see #rollbackForClassName
|
| 223 | + * @see org.springframework.transaction.interceptor.RollbackRuleAttribute#RollbackRuleAttribute(Class) |
181 | 224 | * @see org.springframework.transaction.interceptor.DefaultTransactionAttribute#rollbackOn(Throwable)
|
182 | 225 | */
|
183 | 226 | Class<? extends Throwable>[] rollbackFor() default {};
|
184 | 227 |
|
185 | 228 | /**
|
186 |
| - * Defines zero (0) or more exception names (for exceptions which must be a |
| 229 | + * Defines zero (0) or more exception name patterns (for exceptions which must be a |
187 | 230 | * subclass of {@link Throwable}), indicating which exception types must cause
|
188 | 231 | * a transaction rollback.
|
189 |
| - * <p>This can be a substring of a fully qualified class name, with no wildcard |
190 |
| - * support at present. For example, a value of {@code "ServletException"} would |
191 |
| - * match {@code javax.servlet.ServletException} and its subclasses. |
192 |
| - * <p><b>NB:</b> Consider carefully how specific the pattern is and whether |
193 |
| - * to include package information (which isn't mandatory). For example, |
194 |
| - * {@code "Exception"} will match nearly anything and will probably hide other |
195 |
| - * rules. {@code "java.lang.Exception"} would be correct if {@code "Exception"} |
196 |
| - * were meant to define a rule for all checked exceptions. With more unusual |
197 |
| - * {@link Exception} names such as {@code "BaseBusinessException"} there is no |
198 |
| - * need to use a FQN. |
199 |
| - * <p>Similar to {@link org.springframework.transaction.interceptor.RollbackRuleAttribute#RollbackRuleAttribute(String exceptionName)}. |
| 232 | + * <p>See the {@linkplain Transactional class-level javadocs} for further details |
| 233 | + * on rollback rule semantics, patterns, and warnings regarding possible |
| 234 | + * unintentional matches. |
200 | 235 | * @see #rollbackFor
|
| 236 | + * @see org.springframework.transaction.interceptor.RollbackRuleAttribute#RollbackRuleAttribute(String) |
201 | 237 | * @see org.springframework.transaction.interceptor.DefaultTransactionAttribute#rollbackOn(Throwable)
|
202 | 238 | */
|
203 | 239 | String[] rollbackForClassName() default {};
|
|
206 | 242 | * Defines zero (0) or more exception {@link Class Classes}, which must be
|
207 | 243 | * subclasses of {@link Throwable}, indicating which exception types must
|
208 | 244 | * <b>not</b> cause a transaction rollback.
|
209 |
| - * <p>This is the preferred way to construct a rollback rule (in contrast |
210 |
| - * to {@link #noRollbackForClassName}), matching the exception class and |
211 |
| - * its subclasses. |
212 |
| - * <p>Similar to {@link org.springframework.transaction.interceptor.NoRollbackRuleAttribute#NoRollbackRuleAttribute(Class clazz)}. |
| 245 | + * <p>This is the preferred way to construct a rollback rule (in contrast to |
| 246 | + * {@link #noRollbackForClassName}), matching the exception type, its subclasses, |
| 247 | + * and its nested classes. See the {@linkplain Transactional class-level javadocs} |
| 248 | + * for further details on rollback rule semantics and warnings regarding possible |
| 249 | + * unintentional matches. |
213 | 250 | * @see #noRollbackForClassName
|
| 251 | + * @see org.springframework.transaction.interceptor.NoRollbackRuleAttribute#NoRollbackRuleAttribute(Class) |
214 | 252 | * @see org.springframework.transaction.interceptor.DefaultTransactionAttribute#rollbackOn(Throwable)
|
215 | 253 | */
|
216 | 254 | Class<? extends Throwable>[] noRollbackFor() default {};
|
217 | 255 |
|
218 | 256 | /**
|
219 |
| - * Defines zero (0) or more exception names (for exceptions which must be a |
| 257 | + * Defines zero (0) or more exception name patterns (for exceptions which must be a |
220 | 258 | * subclass of {@link Throwable}) indicating which exception types must <b>not</b>
|
221 | 259 | * cause a transaction rollback.
|
222 |
| - * <p>See the description of {@link #rollbackForClassName} for further |
223 |
| - * information on how the specified names are treated. |
224 |
| - * <p>Similar to {@link org.springframework.transaction.interceptor.NoRollbackRuleAttribute#NoRollbackRuleAttribute(String exceptionName)}. |
| 260 | + * <p>See the {@linkplain Transactional class-level javadocs} for further details |
| 261 | + * on rollback rule semantics, patterns, and warnings regarding possible |
| 262 | + * unintentional matches. |
225 | 263 | * @see #noRollbackFor
|
| 264 | + * @see org.springframework.transaction.interceptor.NoRollbackRuleAttribute#NoRollbackRuleAttribute(String) |
226 | 265 | * @see org.springframework.transaction.interceptor.DefaultTransactionAttribute#rollbackOn(Throwable)
|
227 | 266 | */
|
228 | 267 | String[] noRollbackForClassName() default {};
|
|
0 commit comments