1 /*
2  * Copyright (C) 2010 Google, Inc.
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 com.google.inject.persist;
18 
19 import java.lang.annotation.ElementType;
20 import java.lang.annotation.Inherited;
21 import java.lang.annotation.Retention;
22 import java.lang.annotation.RetentionPolicy;
23 import java.lang.annotation.Target;
24 
25 /**
26  * Any method or class marked with this annotation will be considered for transactionality. Consult
27  * the documentation on https://github.com/google/guice/wiki/GuicePersist for detailed semantics.
28  * Marking a method {@code @Transactional} will start a new transaction before the method executes
29  * and commit it after the method returns.
30  *
31  * <p>If the method throws an exception, the transaction will be rolled back <em>unless</em> you
32  * have specifically requested not to in the {@link #ignore()} clause.
33  *
34  * <p>Similarly, the set of exceptions that will trigger a rollback can be defined in the {@link
35  * #rollbackOn()} clause. By default, only unchecked exceptions trigger a rollback.
36  *
37  * @author Dhanji R. Prasanna (dhanji@gmail.com)
38  */
39 @Target({ElementType.METHOD, ElementType.TYPE})
40 @Retention(RetentionPolicy.RUNTIME)
41 @Inherited
42 public @interface Transactional {
43 
44   /**
45    * A list of exceptions to rollback on, if thrown by the transactional method. These exceptions
46    * are propagated correctly after a rollback.
47    */
rollbackOn()48   Class<? extends Exception>[] rollbackOn() default RuntimeException.class;
49 
50   /**
51    * A list of exceptions to <b>not<b> rollback on. A caveat to the rollbackOn clause. The
52    * disjunction of rollbackOn and ignore represents the list of exceptions that will trigger a
53    * rollback. The complement of rollbackOn and the universal set plus any exceptions in the ignore
54    * set represents the list of exceptions that will trigger a commit. Note that ignore exceptions
55    * take precedence over rollbackOn, but with subtype granularity.
56    */
ignore()57   Class<? extends Exception>[] ignore() default {};
58 }
59