|
| 1 | +package cn.javaer.snippets.spring.transaction; |
| 2 | + |
| 3 | +import org.springframework.core.annotation.AliasFor; |
| 4 | +import org.springframework.stereotype.Component; |
| 5 | +import org.springframework.transaction.TransactionDefinition; |
| 6 | +import org.springframework.transaction.annotation.Isolation; |
| 7 | +import org.springframework.transaction.annotation.Propagation; |
| 8 | +import org.springframework.transaction.annotation.Transactional; |
| 9 | + |
| 10 | +import java.lang.annotation.Documented; |
| 11 | +import java.lang.annotation.ElementType; |
| 12 | +import java.lang.annotation.Inherited; |
| 13 | +import java.lang.annotation.Retention; |
| 14 | +import java.lang.annotation.RetentionPolicy; |
| 15 | +import java.lang.annotation.Target; |
| 16 | + |
| 17 | +/** |
| 18 | + * {@link Component} and {@link Transactional}. |
| 19 | + * <p>But default, a transaction will be rolling back on {@link Throwable}. |
| 20 | + * |
| 21 | + * @author cn-src |
| 22 | + */ |
| 23 | +@Target({ElementType.TYPE}) |
| 24 | +@Retention(RetentionPolicy.RUNTIME) |
| 25 | +@Documented |
| 26 | +@Inherited |
| 27 | +@Component |
| 28 | +@Transactional(rollbackFor = Throwable.class) |
| 29 | +public @interface TxReadOnlyService { |
| 30 | + |
| 31 | + @AliasFor(attribute = "value", annotation = Component.class) |
| 32 | + String value() default ""; |
| 33 | + |
| 34 | + @AliasFor(attribute = "value", annotation = Component.class) |
| 35 | + String name() default ""; |
| 36 | + |
| 37 | + @AliasFor(attribute = "transactionManager", annotation = Transactional.class) |
| 38 | + String transactionManager() default ""; |
| 39 | + |
| 40 | + @AliasFor(annotation = Transactional.class) |
| 41 | + Propagation propagation() default Propagation.REQUIRED; |
| 42 | + |
| 43 | + @AliasFor(annotation = Transactional.class) |
| 44 | + Isolation isolation() default Isolation.DEFAULT; |
| 45 | + |
| 46 | + @AliasFor(annotation = Transactional.class) |
| 47 | + int timeout() default TransactionDefinition.TIMEOUT_DEFAULT; |
| 48 | + |
| 49 | + @AliasFor(annotation = Transactional.class) |
| 50 | + boolean readOnly() default true; |
| 51 | + |
| 52 | + @AliasFor(annotation = Transactional.class) |
| 53 | + Class<? extends Throwable>[] noRollbackFor() default {}; |
| 54 | + |
| 55 | + @AliasFor(annotation = Transactional.class) |
| 56 | + String[] noRollbackForClassName() default {}; |
| 57 | +} |
0 commit comments