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