读书人

Spring事宜配置属性参数

发布时间: 2012-12-21 12:03:49 作者: rapoo

Spring事务配置属性参数

Spring事务描述信息都由TransactionDefinition接口定义,有如下几个方面:

?

1、事务移植性(propagation):

?

int PROPAGATION_REQUIRED = 0;

?

/** * Support a current transaction; create a new one if none exists. * Analogous to the EJB transaction attribute of the same name. * <p>This is typically the default setting of a transaction definition, * and typically defines a transaction synchronization scope. */int PROPAGATION_REQUIRED = 0;

?

?int PROPAGATION_SUPPORTS = 1;

?

/** * Support a current transaction; execute non-transactionally if none exists. * Analogous to the EJB transaction attribute of the same name. * <p><b>NOTE:</b> For transaction managers with transaction synchronization, * <code>PROPAGATION_SUPPORTS</code> is slightly different from no transaction * at all, as it defines a transaction scope that synchronization might apply to. * As a consequence, the same resources (a JDBC <code>Connection</code>, a * Hibernate <code>Session</code>, etc) will be shared for the entire specified * scope. Note that the exact behavior depends on the actual synchronization * configuration of the transaction manager! * <p>In general, use <code>PROPAGATION_SUPPORTS</code> with care! In particular, do * not rely on <code>PROPAGATION_REQUIRED</code> or <code>PROPAGATION_REQUIRES_NEW</code> * <i>within</i> a <code>PROPAGATION_SUPPORTS</code> scope (which may lead to * synchronization conflicts at runtime). If such nesting is unavoidable, make sure * to configure your transaction manager appropriately (typically switching to * "synchronization on actual transaction"). * @see org.springframework.transaction.support.AbstractPlatformTransactionManager#setTransactionSynchronization * @see org.springframework.transaction.support.AbstractPlatformTransactionManager#SYNCHRONIZATION_ON_ACTUAL_TRANSACTION */int PROPAGATION_SUPPORTS = 1;

?

?int PROPAGATION_MANDATORY = 2;

?

/** * Support a current transaction; throw an exception if no current transaction * exists. Analogous to the EJB transaction attribute of the same name. * <p>Note that transaction synchronization within a <code>PROPAGATION_MANDATORY</code> * scope will always be driven by the surrounding transaction. */int PROPAGATION_MANDATORY = 2;
?

?

int PROPAGATION_REQUIRES_NEW = 3;

?

?

/** * Create a new transaction, suspending the current transaction if one exists. * Analogous to the EJB transaction attribute of the same name. * <p><b>NOTE:</b> Actual transaction suspension will not work out-of-the-box * on all transaction managers. This in particular applies to * {@link org.springframework.transaction.jta.JtaTransactionManager}, * which requires the <code>javax.transaction.TransactionManager</code> * to be made available it to it (which is server-specific in standard J2EE). * <p>A <code>PROPAGATION_REQUIRES_NEW</code> scope always defines its own * transaction synchronizations. Existing synchronizations will be suspended * and resumed appropriately. * @see org.springframework.transaction.jta.JtaTransactionManager#setTransactionManager */int PROPAGATION_REQUIRES_NEW = 3;

?

?int PROPAGATION_NOT_SUPPORTED = 4;

?

?int PROPAGATION_NEVER = 5;

?

?int PROPAGATION_NESTED = 6;

?

2、事务隔离度:

int ISOLATION_DEFAULT = -1;

?

/** * Use the default isolation level of the underlying datastore. * All other levels correspond to the JDBC isolation levels. * @see java.sql.Connection */int ISOLATION_DEFAULT = -1;
?

?

3、超时时间设置

?

int TIMEOUT_DEFAULT = -1;

?

?

/** * Use the default timeout of the underlying transaction system, * or none if timeouts are not supported.  */int TIMEOUT_DEFAULT = -1;

?

?

4.+/- Exception配置

?

表示在方法内部抛出异常(可以是特定异常)时候,都提交或者回滚事务。

?

读书人网 >编程

热点推荐