接口 JdoDialect
- 所有已知实现类:
DefaultJdoDialect
public interface JdoDialect
SPI strategy that allows for customizing integration with a specific JDO provider, in particular regarding transaction management and exception translation. To be implemented for specific JDO providers such as JPOX, Kodo, Lido, Versant Open Access.JDO 3.0 defines standard ways for most of the functionality covered here. Hence, Spring's
DefaultJdoDialect
uses the corresponding JDO 3.0 methods by default, to be overridden in a vendor-specific fashion if necessary. Vendor-specific subclasses ofDefaultJdoDialect
are still required for special transaction semantics and more sophisticated exception translation (if needed).In general, it is recommended to derive from
DefaultJdoDialect
instead of implementing this interface directly. This allows for inheriting common behavior (present and future) fromDefaultJdoDialect
, only overriding specific hooks to plug in concrete vendor-specific behavior.- 从以下版本开始:
- 02.11.2003
- 作者:
- Juergen Hoeller
- 另请参阅:
JdoTransactionManager.setJdoDialect(org.springframework.orm.jdo.JdoDialect)
,DefaultJdoDialect
方法概要
所有方法 实例方法 抽象方法 修饰符和类型 方法 说明 Object
beginTransaction(javax.jdo.Transaction transaction, TransactionDefinition definition)
Begin the given JDO transaction, applying the semantics specified by the given Spring transaction definition (in particular, an isolation level and a timeout).void
cleanupTransaction(Object transactionData)
Clean up the transaction via the given transaction data.ConnectionHandle
getJdbcConnection(javax.jdo.PersistenceManager pm, boolean readOnly)
Retrieve the JDBC Connection that the given JDO PersistenceManager uses underneath, if accessing a relational database.void
releaseJdbcConnection(ConnectionHandle conHandle, javax.jdo.PersistenceManager pm)
Release the given JDBC Connection, which has originally been retrieved viagetJdbcConnection
.DataAccessException
translateException(javax.jdo.JDOException ex)
Translate the given JDOException to a corresponding exception from Spring's generic DataAccessException hierarchy.
方法详细资料
beginTransaction
Object beginTransaction(javax.jdo.Transaction transaction, TransactionDefinition definition) throws javax.jdo.JDOException, SQLException, TransactionException
Begin the given JDO transaction, applying the semantics specified by the given Spring transaction definition (in particular, an isolation level and a timeout). Invoked by JdoTransactionManager on transaction begin.An implementation can configure the JDO Transaction object and then invoke
begin
, or invoke a special begin method that takes, for example, an isolation level.An implementation can also apply read-only flag and isolation level to the underlying JDBC Connection before beginning the transaction. In that case, a transaction data object can be returned that holds the previous isolation level (and possibly other data), to be reset in
cleanupTransaction
.Implementations can also use the Spring transaction name, as exposed by the passed-in TransactionDefinition, to optimize for specific data access use cases (effectively using the current transaction name as use case identifier).
- 参数:
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- 另请参阅:
cleanupTransaction(java.lang.Object)
,Transaction.begin()
,DataSourceUtils.prepareConnectionForTransaction(java.sql.Connection, org.springframework.transaction.TransactionDefinition)
cleanupTransaction
void cleanupTransaction(Object transactionData)
Clean up the transaction via the given transaction data. Invoked by JdoTransactionManager on transaction cleanup.An implementation can, for example, reset read-only flag and isolation level of the underlying JDBC Connection. Furthermore, an exposed data access use case can be reset here.
- 参数:
transactionData
- arbitrary object that holds transaction data, if any (as returned by beginTransaction)- 另请参阅:
beginTransaction(javax.jdo.Transaction, org.springframework.transaction.TransactionDefinition)
,DataSourceUtils.resetConnectionAfterTransaction(java.sql.Connection, java.lang.Integer)
getJdbcConnection
ConnectionHandle getJdbcConnection(javax.jdo.PersistenceManager pm, boolean readOnly) throws javax.jdo.JDOException, SQLException
Retrieve the JDBC Connection that the given JDO PersistenceManager 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 JDO transaction (for example, by JdoTransactionManager). The returned handle will be passed into thereleaseJdbcConnection
method when not needed anymore.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 PersistenceManager 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.- 参数:
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- 另请参阅:
releaseJdbcConnection(org.springframework.jdbc.datasource.ConnectionHandle, javax.jdo.PersistenceManager)
,ConnectionHandle.getConnection()
,SimpleConnectionHandle
,JdoTransactionManager.setDataSource(javax.sql.DataSource)
,NativeJdbcExtractor
releaseJdbcConnection
void releaseJdbcConnection(ConnectionHandle conHandle, javax.jdo.PersistenceManager pm) throws javax.jdo.JDOException, SQLException
Release the given JDBC Connection, which has originally been retrieved viagetJdbcConnection
. This should be invoked in any case, to allow for proper release of the retrieved Connection handle.An implementation might simply do nothing, if the Connection returned by
getJdbcConnection
will be implicitly closed when the JDO transaction completes or when the PersistenceManager is closed.- 参数:
conHandle
- the JDBC Connection handle to releasepm
- the current JDO PersistenceManager- 抛出:
javax.jdo.JDOException
- if thrown by JDO methodsSQLException
- if thrown by JDBC methods- 另请参阅:
getJdbcConnection(javax.jdo.PersistenceManager, boolean)
translateException
DataAccessException translateException(javax.jdo.JDOException ex)
Translate the given JDOException to a corresponding exception from Spring's generic DataAccessException hierarchy. An implementation should apply PersistenceManagerFactoryUtils' standard exception translation if can't do anything more specific.Of particular importance is the correct translation to DataIntegrityViolationException, for example on constraint violation. Unfortunately, standard JDO does not allow for portable detection of this.
Can use a SQLExceptionTranslator for translating underlying SQLExceptions in a database-specific fashion.
- 参数:
ex
- the JDOException thrown- 返回:
- the corresponding DataAccessException (must not be
null
) - 另请参阅:
JdoTransactionManager.convertJdoAccessException(javax.jdo.JDOException)
,PersistenceManagerFactoryUtils.convertJdoAccessException(javax.jdo.JDOException)
,DataIntegrityViolationException
,SQLExceptionTranslator