事务的属性有哪些?通过事务注解来了解一下:
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
public @interface Transactional {
@AliasFor("transactionManager")
String value() default ""; //给该事务指定别名
@AliasFor("value")
String transactionManager() default ""; //指定事务管理器,不指定时使用配置文件中指定的事务管理器
Propagation propagation() default Propagation.REQUIRED; //事务传播属性
Isolation isolation() default Isolation.DEFAULT; //事务隔离级别
int timeout() default TransactionDefinition.TIMEOUT_DEFAULT;//事务超时机制
boolean readOnly() default false;//事务是否只读
Class<? extends Throwable>[] rollbackFor() default {};//事务回滚规则
String[] rollbackForClassName() default {};//事务回滚规则
Class<? extends Throwable>[] noRollbackFor() default {};//事务回滚规则
String[] noRollbackForClassName() default {};//事务回滚规则
}
public interface TransactionDefinition { //事务属性设置
//传播属性设置
int PROPAGATION_REQUIRED = 0;
int PROPAGATION_SUPPORTS = 1;
int PROPAGATION_MANDATORY = 2;
int PROPAGATION_REQUIRES_NEW = 3;
int PROPAGATION_NOT_SUPPORTED = 4;
int PROPAGATION_NEVER = 5;
int PROPAGATION_NESTED = 6;
//隔离级别属性设置
int ISOLATION_DEFAULT = -1;
int ISOLATION_READ_UNCOMMITTED = Connection.TRANSACTION_READ_UNCOMMITTED;
int ISOLATION_READ_COMMITTED = Connection.TRANSACTION_READ_COMMITTED;
int ISOLATION_REPEATABLE_READ = Connection.TRANSACTION_REPEATABLE_READ;
int ISOLATION_SERIALIZABLE = Connection.TRANSACTION_SERIALIZABLE;
//超时机制设置
int TIMEOUT_DEFAULT = -1;
int getPropagationBehavior();
int getIsolationLevel();
int getTimeout();
//是否只读属性
boolean isReadOnly();
String getName();
}
从源码中可以看出事务的主要属性有:
1、传播属性
2、事务的隔离级别
3、事务是否只读
4、事务的超时机制
5、事务的回滚规则