类 DefaultJdoDialect
- java.lang.Object
- org.springframework.orm.jdo.DefaultJdoDialect
- 所有已实现的接口:
PersistenceExceptionTranslator
,JdoDialect
public class DefaultJdoDialect extends Object implements JdoDialect, PersistenceExceptionTranslator
Default implementation of theJdoDialect
interface. As of Spring 4.0, designed for JDO 3.0 (or rather, semantics beyond JDO 3.0). Used as default dialect byJdoTransactionManager
.Simply begins a standard JDO transaction in
beginTransaction
. Returns a handle for a JDO DataStoreConnection ongetJdbcConnection
. Calls the corresponding JDO PersistenceManager operation onflush
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.
构造器概要
构造器 构造器 说明 DefaultJdoDialect()
Create a new DefaultJdoDialect.DefaultJdoDialect(Object connectionFactory)
Create a new DefaultJdoDialect.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 Object
beginTransaction(javax.jdo.Transaction transaction, TransactionDefinition definition)
This implementation invokes the standard JDOTransaction.begin()
method and alsoTransaction.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.ConnectionHandle
getJdbcConnection(javax.jdo.PersistenceManager pm, boolean readOnly)
This implementation returns a DataStoreConnectionHandle for JDO.SQLExceptionTranslator
getJdbcExceptionTranslator()
Return the JDBC exception translator for this dialect, if any.protected String
getJdoIsolationLevel(TransactionDefinition definition)
Determine the JDO isolation level String to use for the given Spring transaction definition.void
releaseJdbcConnection(ConnectionHandle conHandle, javax.jdo.PersistenceManager pm)
This implementation does nothing, assuming that the Connection will implicitly be closed with the PersistenceManager.void
setJdbcExceptionTranslator(SQLExceptionTranslator jdbcExceptionTranslator)
Set the JDBC exception translator for this dialect.DataAccessException
translateException(javax.jdo.JDOException ex)
This implementation delegates to PersistenceManagerFactoryUtils.DataAccessException
translateExceptionIfPossible(RuntimeException ex)
Implementation of the PersistenceExceptionTranslator interface, as autodetected by Spring's PersistenceExceptionTranslationPostProcessor.
构造器详细资料
DefaultJdoDialect
public DefaultJdoDialect()
Create a new DefaultJdoDialect.
DefaultJdoDialect
public DefaultJdoDialect(Object connectionFactory)
Create a new DefaultJdoDialect.- 参数:
connectionFactory
- the connection factory of the JDO PersistenceManagerFactory, which is used to initialize the default JDBC exception translator- 另请参阅:
PersistenceManagerFactory.getConnectionFactory()
,PersistenceManagerFactoryUtils.newJdbcExceptionTranslator(Object)
方法详细资料
setJdbcExceptionTranslator
public void setJdbcExceptionTranslator(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.
- 参数:
jdbcExceptionTranslator
- exception translator- 另请参阅:
SQLException
,JDOException.getCause()
,SQLErrorCodeSQLExceptionTranslator
,SQLStateSQLExceptionTranslator
getJdbcExceptionTranslator
public SQLExceptionTranslator getJdbcExceptionTranslator()
Return the JDBC exception translator for this dialect, if any.
beginTransaction
public Object beginTransaction(javax.jdo.Transaction transaction, TransactionDefinition definition) throws javax.jdo.JDOException, SQLException, TransactionException
This implementation invokes the standard JDOTransaction.begin()
method and alsoTransaction.setIsolationLevel(String)
if necessary.- 指定者:
beginTransaction
在接口中JdoDialect
- 参数:
transaction
- the JDO transaction to begindefinition
- the Spring transaction definition that defines semantics- 返回:
- an arbitrary object that holds transaction data, if any (to be passed into cleanupTransaction)
- 抛出:
javax.jdo.JDOException
- if thrown by JDO methodsSQLException
- if thrown by JDBC methodsTransactionException
- in case of invalid arguments- 另请参阅:
Transaction.begin()
,InvalidIsolationLevelException
getJdoIsolationLevel
protected String getJdoIsolationLevel(TransactionDefinition definition)
Determine the JDO isolation level String to use for the given Spring transaction definition.- 参数:
definition
- the Spring transaction definition- 返回:
- the corresponding JDO isolation level String, or
null
to indicate that no isolation level should be set explicitly - 另请参阅:
Transaction.setIsolationLevel(String)
,Constants.TX_SERIALIZABLE
,Constants.TX_REPEATABLE_READ
,Constants.TX_READ_COMMITTED
,Constants.TX_READ_UNCOMMITTED
cleanupTransaction
public void cleanupTransaction(Object transactionData)
This implementation does nothing, as the default beginTransaction implementation does not require any cleanup.- 指定者:
cleanupTransaction
在接口中JdoDialect
- 参数:
transactionData
- arbitrary object that holds transaction data, if any (as returned by beginTransaction)- 另请参阅:
beginTransaction(javax.jdo.Transaction, org.springframework.transaction.TransactionDefinition)
getJdbcConnection
public 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
).- 指定者:
getJdbcConnection
在接口中JdoDialect
- 参数:
pm
- the current JDO PersistenceManagerreadOnly
- whether the Connection is only needed for read-only purposes- 返回:
- a handle for the JDBC Connection, to be passed into
releaseJdbcConnection
, ornull
if no JDBC Connection can be retrieved - 抛出:
javax.jdo.JDOException
- if thrown by JDO methodsSQLException
- if thrown by JDBC methods- 另请参阅:
PersistenceManager.getDataStoreConnection()
,NativeJdbcExtractor
,DataSourceUtils.releaseConnection(java.sql.Connection, javax.sql.DataSource)
releaseJdbcConnection
public void releaseJdbcConnection(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.- 指定者:
releaseJdbcConnection
在接口中JdoDialect
- 参数:
conHandle
- the JDBC Connection handle to releasepm
- the current JDO PersistenceManager- 抛出:
javax.jdo.JDOException
- if thrown by JDO methodsSQLException
- if thrown by JDBC methods- 另请参阅:
Connection.close()
translateExceptionIfPossible
public 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.- 指定者:
translateExceptionIfPossible
在接口中PersistenceExceptionTranslator
- 参数:
ex
- a RuntimeException to translate- 返回:
- the corresponding DataAccessException (or
null
if the exception could not be translated, as in this case it may result from user code rather than from an actual persistence problem) - 另请参阅:
PersistenceExceptionTranslationPostProcessor
,translateException(javax.jdo.JDOException)
translateException
public DataAccessException translateException(javax.jdo.JDOException ex)
This implementation delegates to PersistenceManagerFactoryUtils.- 指定者:
translateException
在接口中JdoDialect
- 参数:
ex
- the JDOException thrown- 返回:
- the corresponding DataAccessException (must not be
null
) - 另请参阅:
PersistenceManagerFactoryUtils.convertJdoAccessException(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.- 参数:
ex
- the JDOException, containing a SQLException- 返回:
- the SQL String, or
null
if none found