|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface JdoDialect
SPI strategy that encapsulates certain functionality that standard JDO 1.0 does not offer despite being relevant in the context of O/R mapping, such as access to the underlying JDBC Connection and explicit flushing of changes to the database. Also defines various further hooks that even go beyond standard JDO 2.0.
To be implemented for specific JDO providers such as JPOX, Kodo, Lido, Versant Open Access. Almost every O/R-based JDO provider offers proprietary means to access the underlying JDBC Connection and to explicitly flush changes; hence, this would be the minimum functionality level that should be supported.
JDO 2.0 defines standard ways for most of the functionality covered here. Hence, Spring's DefaultJdoDialect uses the corresponding JDO 2.0 methods by default, to be overridden in a vendor-specific fashion if necessary. Vendor-specific subclasses of DefaultJdoDialect 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) from DefaultJdoDialect, only overriding specific hooks to plug in concrete vendor-specific behavior.
JdoTransactionManager.setJdoDialect(org.springframework.orm.jdo.JdoDialect)
,
JdoAccessor.setJdoDialect(org.springframework.orm.jdo.JdoDialect)
,
DefaultJdoDialect
Method Summary | |
---|---|
void |
applyQueryTimeout(javax.jdo.Query query,
int timeout)
Apply the given timeout to the given JDO query object. |
Object |
attachCopy(javax.jdo.PersistenceManager pm,
Object detachedEntity)
Reattach the given detached instance (for example, a web form object) with the current JDO transaction, merging its changes into the current persistence instance that represents the corresponding entity. |
Collection |
attachCopyAll(javax.jdo.PersistenceManager pm,
Collection detachedEntities)
Reattach the given detached instances (for example, web form objects) with the current JDO transaction, merging their changes into the current persistence instances that represent the corresponding entities. |
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. |
Object |
detachCopy(javax.jdo.PersistenceManager pm,
Object entity)
Detach a copy of the given persistent instance from the current JDO transaction, for use outside a JDO transaction (for example, as web form object). |
Collection |
detachCopyAll(javax.jdo.PersistenceManager pm,
Collection entities)
Detach copies of the given persistent instances from the current JDO transaction, for use outside a JDO transaction (for example, as web form objects). |
void |
flush(javax.jdo.PersistenceManager pm)
Flush the given PersistenceManager, i.e. flush all changes (that have been applied to persistent objects) to the underlying database. |
ConnectionHandle |
getJdbcConnection(javax.jdo.PersistenceManager pm,
boolean readOnly)
Retrieve the JDBC Connection that the given JDO PersistenceManager uses underneath, if accessing a relational database. |
javax.jdo.Query |
newNamedQuery(javax.jdo.PersistenceManager pm,
Class entityClass,
String queryName)
Create a new Query object for the given named query. |
void |
releaseJdbcConnection(ConnectionHandle conHandle,
javax.jdo.PersistenceManager pm)
Release the given JDBC Connection, which has originally been retrieved via getJdbcConnection . |
DataAccessException |
translateException(javax.jdo.JDOException ex)
Translate the given JDOException to a corresponding exception from Spring's generic DataAccessException hierarchy. |
Method Detail |
---|
Object beginTransaction(javax.jdo.Transaction transaction, TransactionDefinition definition) throws javax.jdo.JDOException, SQLException, TransactionException
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
javax.jdo.JDOException
- if thrown by JDO methods
SQLException
- if thrown by JDBC methods
TransactionException
- in case of invalid argumentscleanupTransaction(java.lang.Object)
,
Transaction.begin()
,
DataSourceUtils.prepareConnectionForTransaction(java.sql.Connection, org.springframework.transaction.TransactionDefinition)
void cleanupTransaction(Object transactionData)
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)
ConnectionHandle getJdbcConnection(javax.jdo.PersistenceManager pm, boolean readOnly) throws javax.jdo.JDOException, SQLException
releaseJdbcConnection
method when not needed anymore.
This strategy is necessary as JDO 1.0 does not provide a standard way to retrieve the underlying JDBC Connection (due to the fact that a JDO provider 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
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 PersistenceManager
releaseJdbcConnection
, or null
if no JDBC Connection can be retrieved
javax.jdo.JDOException
- if thrown by JDO methods
SQLException
- if thrown by JDBC methodsreleaseJdbcConnection(org.springframework.jdbc.datasource.ConnectionHandle, javax.jdo.PersistenceManager)
,
ConnectionHandle.getConnection()
,
SimpleConnectionHandle
,
JdoTransactionManager.setDataSource(javax.sql.DataSource)
,
NativeJdbcExtractor
void releaseJdbcConnection(ConnectionHandle conHandle, javax.jdo.PersistenceManager pm) throws javax.jdo.JDOException, SQLException
getJdbcConnection
. 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 methods
SQLException
- if thrown by JDBC methodsgetJdbcConnection(javax.jdo.PersistenceManager, boolean)
Object detachCopy(javax.jdo.PersistenceManager pm, Object entity) throws javax.jdo.JDOException
pm
- the current JDO PersistenceManagerentity
- the persistent instance to detach
javax.jdo.JDOException
- in case of errorsPersistenceManager.detachCopy(Object)
Collection detachCopyAll(javax.jdo.PersistenceManager pm, Collection entities) throws javax.jdo.JDOException
pm
- the current JDO PersistenceManagerentities
- the persistent instances to detach
javax.jdo.JDOException
- in case of errorsPersistenceManager.detachCopyAll(java.util.Collection)
Object attachCopy(javax.jdo.PersistenceManager pm, Object detachedEntity) throws javax.jdo.JDOException
pm
- the current JDO PersistenceManagerdetachedEntity
- the detached instance to attach
javax.jdo.JDOException
- in case of errorsPersistenceManager.attachCopy(Object, boolean)
Collection attachCopyAll(javax.jdo.PersistenceManager pm, Collection detachedEntities) throws javax.jdo.JDOException
pm
- the current JDO PersistenceManagerdetachedEntities
- the detached instances to reattach
javax.jdo.JDOException
- in case of errorsPersistenceManager.attachCopyAll(java.util.Collection, boolean)
void flush(javax.jdo.PersistenceManager pm) throws javax.jdo.JDOException
pm
- the current JDO PersistenceManager
javax.jdo.JDOException
- in case of errorsJdoAccessor.setFlushEager(boolean)
javax.jdo.Query newNamedQuery(javax.jdo.PersistenceManager pm, Class entityClass, String queryName) throws javax.jdo.JDOException
pm
- the current JDO PersistenceManagerentityClass
- a persistent classqueryName
- the name of the query
javax.jdo.JDOException
- in case of errorsPersistenceManager.newNamedQuery(Class, String)
void applyQueryTimeout(javax.jdo.Query query, int timeout) throws javax.jdo.JDOException
Invoked by JdoTemplate with the remaining time of a specified transaction timeout, if any.
query
- the JDO query object to apply the timeout totimeout
- the timeout value to apply
javax.jdo.JDOException
- if thrown by JDO methodsJdoTemplate.prepareQuery(javax.jdo.Query)
DataAccessException translateException(javax.jdo.JDOException ex)
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
null
)JdoAccessor.convertJdoAccessException(javax.jdo.JDOException)
,
JdoTransactionManager.convertJdoAccessException(javax.jdo.JDOException)
,
PersistenceManagerFactoryUtils.convertJdoAccessException(javax.jdo.JDOException)
,
DataIntegrityViolationException
,
SQLExceptionTranslator
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |