public class DefaultJdoDialect extends java.lang.Object implements JdoDialect, PersistenceExceptionTranslator
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.
Constructor and Description |
---|
DefaultJdoDialect()
Create a new DefaultJdoDialect.
|
DefaultJdoDialect(java.lang.Object connectionFactory)
Create a new DefaultJdoDialect.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
beginTransaction(javax.jdo.Transaction transaction,
TransactionDefinition definition)
This implementation invokes the standard JDO
Transaction.begin()
method and also Transaction.setIsolationLevel(String) if necessary. |
void |
cleanupTransaction(java.lang.Object transactionData)
This implementation does nothing, as the default beginTransaction implementation
does not require any cleanup.
|
protected java.lang.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 java.lang.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(java.lang.RuntimeException ex)
Implementation of the PersistenceExceptionTranslator interface,
as autodetected by Spring's PersistenceExceptionTranslationPostProcessor.
|
public DefaultJdoDialect()
public DefaultJdoDialect(java.lang.Object connectionFactory)
connectionFactory
- the connection factory of the JDO PersistenceManagerFactory,
which is used to initialize the default JDBC exception translatorPersistenceManagerFactory.getConnectionFactory()
,
PersistenceManagerFactoryUtils.newJdbcExceptionTranslator(Object)
public void setJdbcExceptionTranslator(SQLExceptionTranslator jdbcExceptionTranslator)
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 translatorSQLException
,
JDOException.getCause()
,
SQLErrorCodeSQLExceptionTranslator
,
SQLStateSQLExceptionTranslator
public SQLExceptionTranslator getJdbcExceptionTranslator()
public java.lang.Object beginTransaction(javax.jdo.Transaction transaction, TransactionDefinition definition) throws javax.jdo.JDOException, java.sql.SQLException, TransactionException
Transaction.begin()
method and also Transaction.setIsolationLevel(String)
if necessary.beginTransaction
in interface JdoDialect
transaction
- the JDO transaction to begindefinition
- the Spring transaction definition that defines semanticsjavax.jdo.JDOException
- if thrown by JDO methodsjava.sql.SQLException
- if thrown by JDBC methodsTransactionException
- in case of invalid argumentsTransaction.begin()
,
InvalidIsolationLevelException
protected java.lang.String getJdoIsolationLevel(TransactionDefinition definition)
definition
- the Spring transaction definitionnull
to indicate that no isolation level should be set explicitlyTransaction.setIsolationLevel(String)
,
Constants.TX_SERIALIZABLE
,
Constants.TX_REPEATABLE_READ
,
Constants.TX_READ_COMMITTED
,
Constants.TX_READ_UNCOMMITTED
public void cleanupTransaction(java.lang.Object transactionData)
cleanupTransaction
in interface JdoDialect
transactionData
- arbitrary object that holds transaction data, if any
(as returned by beginTransaction)beginTransaction(javax.jdo.Transaction, org.springframework.transaction.TransactionDefinition)
public ConnectionHandle getJdbcConnection(javax.jdo.PersistenceManager pm, boolean readOnly) throws javax.jdo.JDOException, java.sql.SQLException
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
in interface JdoDialect
pm
- the current JDO PersistenceManagerreadOnly
- whether the Connection is only needed for read-only purposesreleaseJdbcConnection
, or null
if no JDBC Connection can be retrievedjavax.jdo.JDOException
- if thrown by JDO methodsjava.sql.SQLException
- if thrown by JDBC methodsPersistenceManager.getDataStoreConnection()
,
NativeJdbcExtractor
,
DataSourceUtils.releaseConnection(java.sql.Connection, javax.sql.DataSource)
public void releaseJdbcConnection(ConnectionHandle conHandle, javax.jdo.PersistenceManager pm) throws javax.jdo.JDOException, java.sql.SQLException
If the JDO provider returns a Connection handle that it
expects the application to close, the dialect needs to invoke
Connection.close
here.
releaseJdbcConnection
in interface JdoDialect
conHandle
- the JDBC Connection handle to releasepm
- the current JDO PersistenceManagerjavax.jdo.JDOException
- if thrown by JDO methodsjava.sql.SQLException
- if thrown by JDBC methodsConnection.close()
public DataAccessException translateExceptionIfPossible(java.lang.RuntimeException ex)
Converts the exception if it is a JDOException, using this JdoDialect.
Else returns null
to indicate an unknown exception.
translateExceptionIfPossible
in interface PersistenceExceptionTranslator
ex
- a RuntimeException to translatenull
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)
public DataAccessException translateException(javax.jdo.JDOException ex)
translateException
in interface JdoDialect
ex
- the JDOException thrownnull
)PersistenceManagerFactoryUtils.convertJdoAccessException(javax.jdo.JDOException)
protected java.lang.String extractSqlStringFromException(javax.jdo.JDOException ex)
Default implementation always returns null
. Can be overridden in
subclasses to extract SQL Strings for vendor-specific exception classes.
ex
- the JDOException, containing a SQLExceptionnull
if none found