KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > transaction > annotation > Transactional


1 /*
2  * Copyright 2002-2006 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  * http://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
17 package org.springframework.transaction.annotation;
18
19 import java.lang.annotation.Documented JavaDoc;
20 import java.lang.annotation.ElementType JavaDoc;
21 import java.lang.annotation.Inherited JavaDoc;
22 import java.lang.annotation.Retention JavaDoc;
23 import java.lang.annotation.RetentionPolicy JavaDoc;
24 import java.lang.annotation.Target JavaDoc;
25
26 import org.springframework.transaction.TransactionDefinition;
27
28 /**
29  * Describes transaction attributes on a method or class.
30  *
31  * <p>This annotation type is generally directly comparable to Spring's
32  * {@link org.springframework.transaction.interceptor.RuleBasedTransactionAttribute}
33  * class, and in fact {@link AnnotationTransactionAttributeSource} will directly
34  * convert the data to the latter class, so that Spring's transaction support code
35  * does not have to know about annotations. If no rules are relevant to the exception,
36  * it will be treated like
37  * {@link org.springframework.transaction.interceptor.DefaultTransactionAttribute}
38  * (rolling back on runtime exceptions).
39  *
40  * @author Colin Sampaleanu
41  * @author Juergen Hoeller
42  * @since 1.2
43  * @see org.springframework.transaction.interceptor.DefaultTransactionAttribute
44  * @see org.springframework.transaction.interceptor.RuleBasedTransactionAttribute
45  */

46 @Target JavaDoc({ElementType.METHOD, ElementType.TYPE})
47 @Retention JavaDoc(RetentionPolicy.RUNTIME)
48 @Inherited JavaDoc
49 @Documented JavaDoc
50 public @interface Transactional {
51     
52     /**
53      * The transaction propagation type.
54      * <p>Defaults to {@link Propagation#REQUIRED}.
55      */

56     Propagation propagation() default Propagation.REQUIRED;
57     
58     /**
59      * The transaction isolation level.
60      * <p>Defaults to {@link Isolation#DEFAULT}.
61      */

62     Isolation isolation() default Isolation.DEFAULT;
63
64     /**
65      * The timeout for this transaction.
66      * <p>Defaults to the default timeout of the underlying transaction system.
67      */

68     int timeout() default TransactionDefinition.TIMEOUT_DEFAULT;
69
70     /**
71      * <code>true</code> if the transaction is read-only.
72      * <p>Defaults to <code>false</code>.
73      */

74     boolean readOnly() default false;
75     
76     /**
77      * Defines zero (0) or more exception {@link Class classes}, which must be a
78      * subclass of {@link Throwable}, indicating which exception types must cause
79      * a transaction rollback.
80      * <p>This is the preferred way to construct a rollback rule, matching the
81      * exception class and subclasses.
82      * <p>Similar to {@link org.springframework.transaction.interceptor.RollbackRuleAttribute#RollbackRuleAttribute(Class clazz)}
83      */

84     Class JavaDoc<? extends Throwable JavaDoc>[] rollbackFor() default {};
85     
86     /**
87      * Defines zero (0) or more exception names (for exceptions which must be a
88      * subclass of {@link Throwable}), indicating which exception types must cause
89      * a transaction rollback.
90      * <p>This can be a substring, with no wildcard support at present.
91      * A value of "ServletException" would match
92      * {@link javax.servlet.ServletException} and subclasses, for example.
93      * <p><b>NB: </b>Consider carefully how specific the pattern is, and whether
94      * to include package information (which isn't mandatory). For example,
95      * "Exception" will match nearly anything, and will probably hide other rules.
96      * "java.lang.Exception" would be correct if "Exception" was meant to define
97      * a rule for all checked exceptions. With more unusual {@link Exception}
98      * names such as "BaseBusinessException" there is no need to use a FQN.
99      * <p>Similar to {@link org.springframework.transaction.interceptor.RollbackRuleAttribute#RollbackRuleAttribute(String exceptionName)}
100      */

101     String JavaDoc[] rollbackForClassName() default {};
102     
103     /**
104      * Defines zero (0) or more exception {@link Class Classes}, which must be a
105      * subclass of {@link Throwable}, indicating which exception types must <b>not</b>
106      * cause a transaction rollback.
107      * <p>This is the preferred way to construct a rollback rule, matching the
108      * exception class and subclasses.
109      * <p>Similar to {@link org.springframework.transaction.interceptor.NoRollbackRuleAttribute#NoRollbackRuleAttribute(Class clazz)}
110      */

111     Class JavaDoc<? extends Throwable JavaDoc>[] noRollbackFor() default {};
112     
113     /**
114      * Defines zero (0) or more exception names (for exceptions which must be a
115      * subclass of {@link Throwable}) indicating which exception types must <b>not</b>
116      * cause a transaction rollback.
117      * <p>See the description of {@link #rollbackForClassName()} for more info on how
118      * the specified names are treated.
119      * <p>Similar to {@link org.springframework.transaction.interceptor.NoRollbackRuleAttribute#NoRollbackRuleAttribute(String exceptionName)}
120      */

121     String JavaDoc[] noRollbackForClassName() default {};
122
123 }
124
Popular Tags