类 HibernateTransactionManager

java.lang.Object
org.springframework.transaction.support.AbstractPlatformTransactionManager
org.beangle.orm.hibernate.HibernateTransactionManager
所有已实现的接口:
Serializable, org.springframework.beans.factory.InitializingBean, org.springframework.transaction.PlatformTransactionManager, org.springframework.transaction.support.ResourceTransactionManager

public class HibernateTransactionManager extends org.springframework.transaction.support.AbstractPlatformTransactionManager implements org.springframework.transaction.support.ResourceTransactionManager, org.springframework.beans.factory.InitializingBean
Simplify HibernateTransactionManager in spring-orm bundle. Just add SessionUtils.isEnableThreadBinding() support in doGetTranscation
版本:
$Id: HibernateTransactionManager.java Feb 28, 2012 10:32:50 PM chaostone $
作者:
chaostone
另请参阅:
  • 字段概要

    从类继承的字段 org.springframework.transaction.support.AbstractPlatformTransactionManager

    SYNCHRONIZATION_ALWAYS, SYNCHRONIZATION_NEVER, SYNCHRONIZATION_ON_ACTUAL_TRANSACTION
  • 构造器概要

    构造器
    构造器
    说明
    Create a new HibernateTransactionManager instance.
    HibernateTransactionManager(org.hibernate.SessionFactory sessionFactory)
    Create a new HibernateTransactionManager instance.
  • 方法概要

    修饰符和类型
    方法
    说明
    void
     
    protected org.springframework.dao.DataAccessException
    convertHibernateAccessException(org.hibernate.HibernateException ex)
    Convert the given HibernateException to an appropriate exception from the org.springframework.dao hierarchy.
    protected void
    doBegin(Object transaction, org.springframework.transaction.TransactionDefinition definition)
     
    protected void
     
    protected void
    doCommit(org.springframework.transaction.support.DefaultTransactionStatus status)
     
    protected Object
     
    protected void
    doResume(Object transaction, Object suspendedResources)
     
    protected void
    doRollback(org.springframework.transaction.support.DefaultTransactionStatus status)
     
    protected void
    doSetRollbackOnly(org.springframework.transaction.support.DefaultTransactionStatus status)
     
    protected Object
    doSuspend(Object transaction)
     
    protected DataSource
    Return the JDBC DataSource that this instance manages transactions for.
     
    org.hibernate.SessionFactory
    Return the SessionFactory that this instance should manage transactions for.
    protected boolean
     
    protected boolean
    isSameConnectionForEntireSession(org.hibernate.Session session)
    Return whether the given Hibernate Session will always hold the same JDBC Connection.
    void
    setHibernateManagedSession(boolean hibernateManagedSession)
    Set whether to operate on a Hibernate-managed Session instead of a Spring-managed Session, that is, whether to obtain the Session through Hibernate's SessionFactory.getCurrentSession() instead of SessionFactory.openSession() (with a Spring TransactionSynchronizationManager check preceding it).
    void
    setPrepareConnection(boolean prepareConnection)
    Set whether to prepare the underlying JDBC Connection of a transactional Hibernate Session, that is, whether to apply a transaction-specific isolation level and/or the transaction's read-only flag to the underlying JDBC Connection.
    void
    setSessionFactory(org.hibernate.SessionFactory sessionFactory)
    Set the SessionFactory that this instance should manage transactions for.

    从类继承的方法 org.springframework.transaction.support.AbstractPlatformTransactionManager

    commit, determineTimeout, getDefaultTimeout, getTransaction, getTransactionSynchronization, invokeAfterCompletion, isFailEarlyOnGlobalRollbackOnly, isGlobalRollbackOnParticipationFailure, isNestedTransactionAllowed, isRollbackOnCommitFailure, isValidateExistingTransaction, newTransactionStatus, prepareForCommit, prepareSynchronization, prepareTransactionStatus, registerAfterCompletionWithExistingTransaction, resume, rollback, setDefaultTimeout, setFailEarlyOnGlobalRollbackOnly, setGlobalRollbackOnParticipationFailure, setNestedTransactionAllowed, setRollbackOnCommitFailure, setTransactionSynchronization, setTransactionSynchronizationName, setValidateExistingTransaction, shouldCommitOnGlobalRollbackOnly, suspend, triggerBeforeCommit, triggerBeforeCompletion, useSavepointForNestedTransaction

    从类继承的方法 java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    从接口继承的方法 org.springframework.transaction.PlatformTransactionManager

    commit, getTransaction, rollback
  • 构造器详细资料

    • HibernateTransactionManager

      public HibernateTransactionManager()
      Create a new HibernateTransactionManager instance. A SessionFactory has to be set to be able to use it.
      另请参阅:
    • HibernateTransactionManager

      public HibernateTransactionManager(org.hibernate.SessionFactory sessionFactory)
      Create a new HibernateTransactionManager instance.
      参数:
      sessionFactory - SessionFactory to manage transactions for
  • 方法详细资料

    • setSessionFactory

      public void setSessionFactory(org.hibernate.SessionFactory sessionFactory)
      Set the SessionFactory that this instance should manage transactions for.
    • getSessionFactory

      public org.hibernate.SessionFactory getSessionFactory()
      Return the SessionFactory that this instance should manage transactions for.
    • getDataSource

      protected DataSource getDataSource()
      Return the JDBC DataSource that this instance manages transactions for.
    • setPrepareConnection

      public void setPrepareConnection(boolean prepareConnection)
      Set whether to prepare the underlying JDBC Connection of a transactional Hibernate Session, that is, whether to apply a transaction-specific isolation level and/or the transaction's read-only flag to the underlying JDBC Connection.

      Default is "true". If you turn this flag off, the transaction manager will not support per-transaction isolation levels anymore. It will not call Connection.setReadOnly(true) for read-only transactions anymore either. If this flag is turned off, no cleanup of a JDBC Connection is required after a transaction, since no Connection settings will get modified.

      另请参阅:
    • setHibernateManagedSession

      public void setHibernateManagedSession(boolean hibernateManagedSession)
      Set whether to operate on a Hibernate-managed Session instead of a Spring-managed Session, that is, whether to obtain the Session through Hibernate's SessionFactory.getCurrentSession() instead of SessionFactory.openSession() (with a Spring TransactionSynchronizationManager check preceding it).

      Default is "false", i.e. using a Spring-managed Session: taking the current thread-bound Session if available (e.g. in an Open-Session-in-View scenario), creating a new Session for the current transaction otherwise.

      Switch this flag to "true" in order to enforce use of a Hibernate-managed Session. Note that this requires SessionFactory.getCurrentSession() to always return a proper Session when called for a Spring-managed transaction; transaction begin will fail if the getCurrentSession() call fails.

      This mode will typically be used in combination with a custom Hibernate

      invalid @link
      org.hibernate.context.CurrentSessionContext
      implementation that stores Sessions in a place other than Spring's TransactionSynchronizationManager. It may also be used in combination with Spring's Open-Session-in-View support (using Spring's default BeangleSessionContext), in which case it subtly differs from the Spring-managed Session mode: The pre-bound Session will not receive a clear() call (on rollback) or a disconnect() call (on transaction completion) in such a scenario; this is rather left up to a custom CurrentSessionContext implementation (if desired).
    • afterPropertiesSet

      public void afterPropertiesSet()
      指定者:
      afterPropertiesSet 在接口中 org.springframework.beans.factory.InitializingBean
    • getResourceFactory

      public Object getResourceFactory()
      指定者:
      getResourceFactory 在接口中 org.springframework.transaction.support.ResourceTransactionManager
    • doGetTransaction

      protected Object doGetTransaction()
      指定者:
      doGetTransaction 在类中 org.springframework.transaction.support.AbstractPlatformTransactionManager
    • isExistingTransaction

      protected boolean isExistingTransaction(Object transaction)
      覆盖:
      isExistingTransaction 在类中 org.springframework.transaction.support.AbstractPlatformTransactionManager
    • doBegin

      protected void doBegin(Object transaction, org.springframework.transaction.TransactionDefinition definition)
      指定者:
      doBegin 在类中 org.springframework.transaction.support.AbstractPlatformTransactionManager
    • doSuspend

      protected Object doSuspend(Object transaction)
      覆盖:
      doSuspend 在类中 org.springframework.transaction.support.AbstractPlatformTransactionManager
    • doResume

      protected void doResume(Object transaction, Object suspendedResources)
      覆盖:
      doResume 在类中 org.springframework.transaction.support.AbstractPlatformTransactionManager
    • doCommit

      protected void doCommit(org.springframework.transaction.support.DefaultTransactionStatus status)
      指定者:
      doCommit 在类中 org.springframework.transaction.support.AbstractPlatformTransactionManager
    • doRollback

      protected void doRollback(org.springframework.transaction.support.DefaultTransactionStatus status)
      指定者:
      doRollback 在类中 org.springframework.transaction.support.AbstractPlatformTransactionManager
    • doSetRollbackOnly

      protected void doSetRollbackOnly(org.springframework.transaction.support.DefaultTransactionStatus status)
      覆盖:
      doSetRollbackOnly 在类中 org.springframework.transaction.support.AbstractPlatformTransactionManager
    • doCleanupAfterCompletion

      protected void doCleanupAfterCompletion(Object transaction)
      覆盖:
      doCleanupAfterCompletion 在类中 org.springframework.transaction.support.AbstractPlatformTransactionManager
    • isSameConnectionForEntireSession

      protected boolean isSameConnectionForEntireSession(org.hibernate.Session session)
      Return whether the given Hibernate Session will always hold the same JDBC Connection. This is used to check whether the transaction manager can safely prepare and clean up the JDBC Connection used for a transaction.

      Default implementation checks the Session's connection release mode to be "on_close". Unfortunately, this requires casting to SessionImpl, as of Hibernate 3.1. If that cast doesn't work, we'll simply assume we're safe and return true.

      参数:
      session - the Hibernate Session to check
      另请参阅:
      • invalid @see
        org.hibernate.impl.SessionImpl#getConnectionReleaseMode()
      • ConnectionReleaseMode.ON_CLOSE
    • convertHibernateAccessException

      protected org.springframework.dao.DataAccessException convertHibernateAccessException(org.hibernate.HibernateException ex)
      Convert the given HibernateException to an appropriate exception from the org.springframework.dao hierarchy.

      Will automatically apply a specified SQLExceptionTranslator to a Hibernate JDBCException, else rely on Hibernate's default translation.

      参数:
      ex - HibernateException that occured
      返回:
      a corresponding DataAccessException