接口 JpaDialect

    • 方法详细资料

      • prepareTransaction

        Object prepareTransaction​(EntityManager entityManager,
                                  boolean readOnly,
                                  String name)
                           throws PersistenceException
        Prepare a JPA transaction, applying the specified semantics. Called by EntityManagerFactoryUtils when enlisting an EntityManager in a JTA transaction or a locally joined transaction (e.g. after upgrading an unsynchronized EntityManager to a synchronized one).

        An implementation can apply the read-only flag as flush mode. In that case, a transaction data object can be returned that holds the previous flush mode (and possibly other data), to be reset in cleanupTransaction.

        Implementations can also use the Spring transaction name to optimize for specific data access use cases (effectively using the current transaction name as use case identifier).

        参数:
        entityManager - the EntityManager to begin a JPA transaction on
        readOnly - whether the transaction is supposed to be read-only
        name - the name of the transaction (if any)
        返回:
        an arbitrary object that holds transaction data, if any (to be passed into cleanupTransaction)
        抛出:
        PersistenceException - if thrown by JPA methods
        另请参阅:
        cleanupTransaction(java.lang.Object)
      • getJdbcConnection

        ConnectionHandle getJdbcConnection​(EntityManager entityManager,
                                           boolean readOnly)
                                    throws PersistenceException,
                                           SQLException
        Retrieve the JDBC Connection that the given JPA EntityManager uses underneath, if accessing a relational database. This method will just get invoked if actually needing access to the underlying JDBC Connection, usually within an active JPA transaction (for example, by JpaTransactionManager). The returned handle will be passed into the releaseJdbcConnection method when not needed anymore.

        This strategy is necessary as JPA does not provide a standard way to retrieve the underlying JDBC Connection (due to the fact that a JPA implementation might not work with a relational database at all).

        Implementations are encouraged to return an unwrapped Connection object, i.e. the Connection as they got it from the connection pool. This makes it easier for application code to get at the underlying native JDBC Connection, like an OracleConnection, which is sometimes necessary for LOB handling etc. We assume that calling code knows how to properly handle the returned Connection object.

        In a simple case where the returned Connection will be auto-closed with the EntityManager or can be released via the Connection object itself, an implementation can return a SimpleConnectionHandle that just contains the Connection. If some other object is needed in releaseJdbcConnection, an implementation should use a special handle that references that other object.

        参数:
        entityManager - the current JPA EntityManager
        readOnly - whether the Connection is only needed for read-only purposes
        返回:
        a handle for the Connection, to be passed into releaseJdbcConnection, or null if no JDBC Connection can be retrieved
        抛出:
        PersistenceException - if thrown by JPA methods
        SQLException - if thrown by JDBC methods
        另请参阅:
        releaseJdbcConnection(org.springframework.jdbc.datasource.ConnectionHandle, javax.persistence.EntityManager), ConnectionHandle.getConnection(), SimpleConnectionHandle, JpaTransactionManager.setDataSource(javax.sql.DataSource), NativeJdbcExtractor