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