Class DefaultJdoDialect

  • All Implemented Interfaces:
    JdoDialect, org.springframework.dao.support.PersistenceExceptionTranslator

    public class DefaultJdoDialect
    extends Object
    implements JdoDialect, org.springframework.dao.support.PersistenceExceptionTranslator
    Default implementation of the JdoDialect interface. As of Spring 4.0, designed for JDO 3.0 (or rather, semantics beyond JDO 3.0). Used as default dialect by JdoTransactionManager.

    Simply begins a standard JDO transaction in beginTransaction. Returns a handle for a JDO DataStoreConnection on getJdbcConnection. Calls the corresponding JDO PersistenceManager operation on flush Uses a Spring SQLExceptionTranslator for exception translation, if applicable.

    Note that, even with JDO 3.0, vendor-specific subclasses are still necessary for special transaction semantics and more sophisticated exception translation. Furthermore, vendor-specific subclasses are encouraged to expose the native JDBC Connection on getJdbcConnection, rather than JDO 3.0's wrapper handle.

    This class also implements the PersistenceExceptionTranslator interface, as autodetected by Spring's PersistenceExceptionTranslationPostProcessor, for AOP-based translation of native exceptions to Spring DataAccessExceptions. Hence, the presence of a standard DefaultJdoDialect bean automatically enables a PersistenceExceptionTranslationPostProcessor to translate JDO exceptions.

    See Also:
    setJdbcExceptionTranslator(org.springframework.jdbc.support.SQLExceptionTranslator), JdoTransactionManager.setJdoDialect(org.apache.isis.persistence.jdo.spring.integration.JdoDialect), PersistenceExceptionTranslationPostProcessor
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Object beginTransaction​(javax.jdo.Transaction transaction, org.springframework.transaction.TransactionDefinition definition)
      This implementation invokes the standard JDO Transaction.begin() method and also Transaction.setIsolationLevel(String) if necessary.
      void cleanupTransaction​(Object transactionData)
      This implementation does nothing, as the default beginTransaction implementation does not require any cleanup.
      protected String extractSqlStringFromException​(javax.jdo.JDOException ex)
      Template method for extracting a SQL String from the given exception.
      org.springframework.jdbc.datasource.ConnectionHandle getJdbcConnection​(javax.jdo.PersistenceManager pm, boolean readOnly)
      This implementation returns a DataStoreConnectionHandle for JDO.
      org.springframework.jdbc.support.SQLExceptionTranslator getJdbcExceptionTranslator()
      Return the JDBC exception translator for this dialect, if any.
      protected String getJdoIsolationLevel​(org.springframework.transaction.TransactionDefinition definition)
      Determine the JDO isolation level String to use for the given Spring transaction definition.
      void releaseJdbcConnection​(org.springframework.jdbc.datasource.ConnectionHandle conHandle, javax.jdo.PersistenceManager pm)
      This implementation does nothing, assuming that the Connection will implicitly be closed with the PersistenceManager.
      void setJdbcExceptionTranslator​(org.springframework.jdbc.support.SQLExceptionTranslator jdbcExceptionTranslator)
      Set the JDBC exception translator for this dialect.
      org.springframework.dao.DataAccessException translateException​(javax.jdo.JDOException ex)
      This implementation delegates to PersistenceManagerFactoryUtils.
      org.springframework.dao.DataAccessException translateExceptionIfPossible​(RuntimeException ex)
      Implementation of the PersistenceExceptionTranslator interface, as autodetected by Spring's PersistenceExceptionTranslationPostProcessor.
    • Method Detail

      • setJdbcExceptionTranslator

        public void setJdbcExceptionTranslator​(org.springframework.jdbc.support.SQLExceptionTranslator jdbcExceptionTranslator)
        Set the JDBC exception translator for this dialect.

        Applied to any SQLException root cause of a JDOException, if specified. The default is to rely on the JDO provider's native exception translation.

        Parameters:
        jdbcExceptionTranslator - exception translator
        See Also:
        SQLException, JDOException.getCause(), SQLErrorCodeSQLExceptionTranslator, SQLStateSQLExceptionTranslator
      • getJdbcExceptionTranslator

        public org.springframework.jdbc.support.SQLExceptionTranslator getJdbcExceptionTranslator()
        Return the JDBC exception translator for this dialect, if any.
      • beginTransaction

        public Object beginTransaction​(javax.jdo.Transaction transaction,
                                       org.springframework.transaction.TransactionDefinition definition)
                                throws javax.jdo.JDOException,
                                       SQLException,
                                       org.springframework.transaction.TransactionException
        This implementation invokes the standard JDO Transaction.begin() method and also Transaction.setIsolationLevel(String) if necessary.
        Specified by:
        beginTransaction in interface JdoDialect
        Parameters:
        transaction - the JDO transaction to begin
        definition - the Spring transaction definition that defines semantics
        Returns:
        an arbitrary object that holds transaction data, if any (to be passed into cleanupTransaction)
        Throws:
        javax.jdo.JDOException - if thrown by JDO methods
        SQLException - if thrown by JDBC methods
        org.springframework.transaction.TransactionException - in case of invalid arguments
        See Also:
        Transaction.begin(), InvalidIsolationLevelException
      • getJdoIsolationLevel

        protected String getJdoIsolationLevel​(org.springframework.transaction.TransactionDefinition definition)
        Determine the JDO isolation level String to use for the given Spring transaction definition.
        Parameters:
        definition - the Spring transaction definition
        Returns:
        the corresponding JDO isolation level String, or null to indicate that no isolation level should be set explicitly
        See Also:
        Transaction.setIsolationLevel(String), Constants.TX_SERIALIZABLE, Constants.TX_REPEATABLE_READ, Constants.TX_READ_COMMITTED, Constants.TX_READ_UNCOMMITTED
      • getJdbcConnection

        public org.springframework.jdbc.datasource.ConnectionHandle getJdbcConnection​(javax.jdo.PersistenceManager pm,
                                                                                      boolean readOnly)
                                                                               throws javax.jdo.JDOException,
                                                                                      SQLException
        This implementation returns a DataStoreConnectionHandle for JDO.

        NOTE: A JDO DataStoreConnection is always a wrapper, never the native JDBC Connection. If you need access to the native JDBC Connection (or the connection pool handle, to be unwrapped via a Spring NativeJdbcExtractor), override this method to return the native Connection through the corresponding vendor-specific mechanism.

        A JDO DataStoreConnection is only "borrowed" from the PersistenceManager: it needs to be returned as early as possible. Effectively, JDO requires the fetched Connection to be closed before continuing PersistenceManager work. For this reason, the exposed ConnectionHandle eagerly releases its JDBC Connection at the end of each JDBC data access operation (that is, on DataSourceUtils.releaseConnection).

        Specified by:
        getJdbcConnection in interface JdoDialect
        Parameters:
        pm - the current JDO PersistenceManager
        readOnly - whether the Connection is only needed for read-only purposes
        Returns:
        a handle for the JDBC Connection, to be passed into releaseJdbcConnection, or null if no JDBC Connection can be retrieved
        Throws:
        javax.jdo.JDOException - if thrown by JDO methods
        SQLException - if thrown by JDBC methods
        See Also:
        PersistenceManager.getDataStoreConnection(), org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor, DataSourceUtils.releaseConnection(java.sql.Connection, javax.sql.DataSource)
      • releaseJdbcConnection

        public void releaseJdbcConnection​(org.springframework.jdbc.datasource.ConnectionHandle conHandle,
                                          javax.jdo.PersistenceManager pm)
                                   throws javax.jdo.JDOException,
                                          SQLException
        This implementation does nothing, assuming that the Connection will implicitly be closed with the PersistenceManager.

        If the JDO provider returns a Connection handle that it expects the application to close, the dialect needs to invoke Connection.close here.

        Specified by:
        releaseJdbcConnection in interface JdoDialect
        Parameters:
        conHandle - the JDBC Connection handle to release
        pm - the current JDO PersistenceManager
        Throws:
        javax.jdo.JDOException - if thrown by JDO methods
        SQLException - if thrown by JDBC methods
        See Also:
        Connection.close()
      • translateExceptionIfPossible

        public org.springframework.dao.DataAccessException translateExceptionIfPossible​(RuntimeException ex)
        Implementation of the PersistenceExceptionTranslator interface, as autodetected by Spring's PersistenceExceptionTranslationPostProcessor.

        Converts the exception if it is a JDOException, using this JdoDialect. Else returns null to indicate an unknown exception.

        Specified by:
        translateExceptionIfPossible in interface org.springframework.dao.support.PersistenceExceptionTranslator
        See Also:
        PersistenceExceptionTranslationPostProcessor, translateException(javax.jdo.JDOException)
      • extractSqlStringFromException

        protected String extractSqlStringFromException​(javax.jdo.JDOException ex)
        Template method for extracting a SQL String from the given exception.

        Default implementation always returns null. Can be overridden in subclasses to extract SQL Strings for vendor-specific exception classes.

        Parameters:
        ex - the JDOException, containing a SQLException
        Returns:
        the SQL String, or null if none found