Spring 事務管理-Spring Framework transaction

public interface PlatformTransactionManager {
    TransactionStatus getTransaction(TransactionDefinition definition) throws TransactionException;    
            void commit(TransactionStatus status) throws TransactionException;    
            void rollback(TransactionStatus status) throws TransactionException;
}

The getTransaction(..) method returns a TransactionStatus object, depending on a TransactionDefinition parameter. The returned TransactionStatus might represent a new transaction, or can represent an existing transaction if a matching transaction exists in the current call stack. The implication in this latter case is that, as with Java EE transaction contexts, a TransactionStatus is associated with a thread of execution.html

The TransactionDefinition interface specifies:java

  • Isolation: 隔離性。The degree to which this transaction is isolated from the work of other transactions. For example, can this transaction see uncommitted writes from other transactions?spring

  • Propagation: 連續性。Typically, all code executed within a transaction scope will run in that transaction. However, you have the option of specifying the behavior in the event that a transactional method is executed when a transaction context already exists. For example, code can continue running in the existing transaction (the common case); or the existing transaction can be suspended and a new transaction created. Spring offers all of the transaction propagation options familiar from EJB CMT. To read about the semantics of transaction propagation in Spring, see Section 11.5.7, 「Transaction propagation」.this

  • Timeout: 超時。How long this transaction runs before timing out and being rolled back automatically by the underlying transaction infrastructure.spa

  • Read-only status: 只讀。A read-only transaction can be used when your code reads but does not modify data. Read-only transactions can be a useful optimization in some cases, such as when you are using Hibernate.code

public interface TransactionStatus extends SavepointManager {   
 boolean isNewTransaction();   
 boolean hasSavepoint();    
 void setRollbackOnly();    
 boolean isRollbackOnly();    
 void flush();    
 boolean isCompleted();
}
相關文章
相關標籤/搜索