|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.orm.jdo.DefaultJdoDialect
public class DefaultJdoDialect
Default implementation of the JdoDialect interface. Updated to leverage the JDO 2.0 API when available, as of Spring 1.2. Used as default dialect by JdoAccessor and JdoTransactionManager.
Simply begins a standard JDO transaction in beginTransaction
.
Returns a handle for a JDO2 DataStoreConnection on getJdbcConnection
.
Calls the corresponding JDO2 operations on detachCopy(All)
,
attachCopy(All)
, flush
and newNamedQuery
.
Ignores a given query timeout in applyQueryTimeout
.
Uses a Spring SQLExceptionTranslator for exception translation, if applicable.
Note that, even with JDO2, 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 JDO2's wrapper handle.
setJdbcExceptionTranslator(org.springframework.jdbc.support.SQLExceptionTranslator)
,
JdoAccessor.setJdoDialect(org.springframework.orm.jdo.JdoDialect)
,
JdoTransactionManager.setJdoDialect(org.springframework.orm.jdo.JdoDialect)
Field Summary | |
---|---|
protected Log |
logger
|
Constructor Summary | |
---|---|
DefaultJdoDialect()
Create a new DefaultJdoDialect. |
|
DefaultJdoDialect(javax.jdo.PersistenceManagerFactory pmf)
Create a new DefaultJdoDialect. |
Method Summary | |
---|---|
void |
applyQueryTimeout(javax.jdo.Query query,
int remainingTimeInSeconds)
This implementation logs a warning that it cannot apply a query timeout. |
Object |
attachCopy(javax.jdo.PersistenceManager pm,
Object detachedEntity)
This implementation delegates to JDO 2.0's attachCopy method,
passing in "true" for the "makeTransactional" argument. |
Collection |
attachCopyAll(javax.jdo.PersistenceManager pm,
Collection detachedEntities)
This implementation delegates to JDO 2.0's attachCopyAll method,
passing in "true" for the "makeTransactional" argument. |
Object |
beginTransaction(javax.jdo.Transaction transaction,
TransactionDefinition definition)
This implementation invokes the standard JDO Transaction.begin
method. |
void |
cleanupTransaction(Object transactionData)
This implementation does nothing, as the default beginTransaction implementation does not require any cleanup. |
Object |
detachCopy(javax.jdo.PersistenceManager pm,
Object entity)
This implementation delegates to JDO 2.0's detachCopy method. |
Collection |
detachCopyAll(javax.jdo.PersistenceManager pm,
Collection entities)
This implementation delegates to JDO 2.0's detachCopyAll method. |
protected String |
extractSqlStringFromException(javax.jdo.JDOException ex)
Template method for extracting a SQL String from the given exception. |
void |
flush(javax.jdo.PersistenceManager pm)
This implementation delegates to JDO 2.0's flush method. |
ConnectionHandle |
getJdbcConnection(javax.jdo.PersistenceManager pm,
boolean readOnly)
This implementation returns a DataStoreConnectionHandle for JDO2, which will also work on JDO1 until actually accessing the JDBC Connection. |
SQLExceptionTranslator |
getJdbcExceptionTranslator()
Return the JDBC exception translator for this instance. |
javax.jdo.PersistenceManagerFactory |
getPersistenceManagerFactory()
Return the JDO PersistenceManagerFactory that should be used to create PersistenceManagers. |
javax.jdo.Query |
newNamedQuery(javax.jdo.PersistenceManager pm,
Class entityClass,
String queryName)
This implementation delegates to JDO 2.0's newNamedQuery method. |
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. |
void |
setPersistenceManagerFactory(javax.jdo.PersistenceManagerFactory pmf)
Set the JDO PersistenceManagerFactory, which is used to initialize the default JDBC exception translator if none specified. |
DataAccessException |
translateException(javax.jdo.JDOException ex)
This implementation delegates to PersistenceManagerFactoryUtils. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected Log logger
Constructor Detail |
---|
public DefaultJdoDialect()
public DefaultJdoDialect(javax.jdo.PersistenceManagerFactory pmf)
pmf
- the JDO PersistenceManagerFactory, which is used
to initialize the default JDBC exception translatorMethod Detail |
---|
public void setPersistenceManagerFactory(javax.jdo.PersistenceManagerFactory pmf)
setJdbcExceptionTranslator(org.springframework.jdbc.support.SQLExceptionTranslator)
public javax.jdo.PersistenceManagerFactory getPersistenceManagerFactory()
public void setJdbcExceptionTranslator(SQLExceptionTranslator jdbcExceptionTranslator)
The default exception translator is either a SQLErrorCodeSQLExceptionTranslator if a DataSource is available, or a SQLStateSQLExceptionTranslator else.
jdbcExceptionTranslator
- exception translatorSQLException
,
JDOException.getCause()
,
PersistenceManagerFactoryUtils.newJdbcExceptionTranslator(javax.jdo.PersistenceManagerFactory)
,
SQLErrorCodeSQLExceptionTranslator
,
SQLStateSQLExceptionTranslator
public SQLExceptionTranslator getJdbcExceptionTranslator()
Creates a default SQLErrorCodeSQLExceptionTranslator or SQLStateSQLExceptionTranslator for the specified PersistenceManagerFactory, if no exception translator explicitly specified.
public Object beginTransaction(javax.jdo.Transaction transaction, TransactionDefinition definition) throws javax.jdo.JDOException, SQLException, TransactionException
Transaction.begin
method. Throws an InvalidIsolationLevelException if a non-default isolation
level is set.
beginTransaction
in interface JdoDialect
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 argumentsTransaction.begin()
,
InvalidIsolationLevelException
public void cleanupTransaction(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, SQLException
For pre-JDO2 implementations, override this method to return the
Connection through the corresponding vendor-specific mechanism, or null
if the Connection is not retrievable.
NOTE: A JDO2 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 JDO2 DataStoreConnection is only "borrowed" from the PersistenceManager:
it needs to be returned as early as possible. Effectively, JDO2 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 PersistenceManager
releaseJdbcConnection
, or null
if no JDBC Connection can be retrieved
javax.jdo.JDOException
- if thrown by JDO methods
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, 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 PersistenceManager
javax.jdo.JDOException
- if thrown by JDO methods
SQLException
- if thrown by JDBC methodsConnection.close()
public Object detachCopy(javax.jdo.PersistenceManager pm, Object entity) throws javax.jdo.JDOException
detachCopy
method.
To be overridden for pre-JDO2 implementations, using the corresponding vendor-specific mechanism there.
detachCopy
in interface JdoDialect
pm
- the current JDO PersistenceManagerentity
- the persistent instance to detach
javax.jdo.JDOException
- in case of errorsPersistenceManager.detachCopy(Object)
public Collection detachCopyAll(javax.jdo.PersistenceManager pm, Collection entities) throws javax.jdo.JDOException
detachCopyAll
method.
To be overridden for pre-JDO2 implementations, using the corresponding vendor-specific mechanism there.
detachCopyAll
in interface JdoDialect
pm
- the current JDO PersistenceManagerentities
- the persistent instances to detach
javax.jdo.JDOException
- in case of errorsPersistenceManager.detachCopyAll(java.util.Collection)
public Object attachCopy(javax.jdo.PersistenceManager pm, Object detachedEntity) throws javax.jdo.JDOException
attachCopy
method,
passing in "true" for the "makeTransactional" argument.
To be overridden for pre-JDO2 implementations, using the corresponding vendor-specific mechanism there.
attachCopy
in interface JdoDialect
pm
- the current JDO PersistenceManagerdetachedEntity
- the detached instance to attach
javax.jdo.JDOException
- in case of errorsPersistenceManager.attachCopy(Object, boolean)
public Collection attachCopyAll(javax.jdo.PersistenceManager pm, Collection detachedEntities) throws javax.jdo.JDOException
attachCopyAll
method,
passing in "true" for the "makeTransactional" argument.
To be overridden for pre-JDO2 implementations, using the corresponding vendor-specific mechanism there.
attachCopyAll
in interface JdoDialect
pm
- the current JDO PersistenceManagerdetachedEntities
- the detached instances to reattach
javax.jdo.JDOException
- in case of errorsPersistenceManager.attachCopyAll(java.util.Collection, boolean)
public void flush(javax.jdo.PersistenceManager pm) throws javax.jdo.JDOException
flush
method.
To be overridden for pre-JDO2 implementations, using the corresponding vendor-specific mechanism there.
flush
in interface JdoDialect
pm
- the current JDO PersistenceManager
javax.jdo.JDOException
- in case of errorsPersistenceManager.flush()
public javax.jdo.Query newNamedQuery(javax.jdo.PersistenceManager pm, Class entityClass, String queryName) throws javax.jdo.JDOException
newNamedQuery
method.
To be overridden for pre-JDO2 implementations, using the corresponding vendor-specific mechanism there.
newNamedQuery
in interface JdoDialect
pm
- the current JDO PersistenceManagerentityClass
- a persistent classqueryName
- the name of the query
javax.jdo.JDOException
- in case of errorsPersistenceManager.newNamedQuery(Class, String)
public void applyQueryTimeout(javax.jdo.Query query, int remainingTimeInSeconds) throws javax.jdo.JDOException
applyQueryTimeout
in interface JdoDialect
query
- the JDO query object to apply the timeout toremainingTimeInSeconds
- the timeout value to apply
javax.jdo.JDOException
- if thrown by JDO methodsJdoTemplate.prepareQuery(javax.jdo.Query)
public DataAccessException translateException(javax.jdo.JDOException ex)
translateException
in interface JdoDialect
ex
- the JDOException thrown
null
)PersistenceManagerFactoryUtils.convertJdoAccessException(javax.jdo.JDOException)
protected 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 SQLException
null
if none found
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |