org.springframework.orm.jdo
Class DefaultJdoDialect

java.lang.Object
  extended byorg.springframework.orm.jdo.DefaultJdoDialect
All Implemented Interfaces:
InitializingBean, JdoDialect

public class DefaultJdoDialect
extends Object
implements JdoDialect, InitializingBean

Default implementation of the JdoDialect interface. Used by JdoAccessor and JdoTransactionManager as default.

Simply begins a standard JDO transaction in beginTransaction. Returns null on getJdbcConnection. Ignores a given query timeout in applyQueryTimeout. Throws a JDOUnsupportedOptionException on flush. Delegates to PersistenceManagerFactoryUtils for exception translation.

This class will be adapted to JDO 2.0 as soon as the latter is available. JDBC Connection retrieval and flushing will then default to the respective JDO 2.0 methods. Vendor-specific subclasses will still be necessary for special transaction semantics and more sophisticated exception translation.

Since:
1.1
Author:
Juergen Hoeller
See Also:
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 afterPropertiesSet()
          Eagerly initialize the exception translator, creating a default one for the specified PersistenceManagerFactory if none set.
 void applyQueryTimeout(javax.jdo.Query query, int remainingTimeInSeconds)
          This implementation logs a warning that it cannot apply a query timeout.
 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.
 void flush(javax.jdo.PersistenceManager pm)
          This implementation throws a JDOUnsupportedOptionException.
 ConnectionHandle getJdbcConnection(javax.jdo.PersistenceManager pm, boolean readOnly)
          This implementation returns null, to indicate that JDBC Connection retrieval is not supported.
 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.
 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

logger

protected Log logger
Constructor Detail

DefaultJdoDialect

public DefaultJdoDialect()
Create a new DefaultJdoDialect.


DefaultJdoDialect

public DefaultJdoDialect(javax.jdo.PersistenceManagerFactory pmf)
Create a new DefaultJdoDialect.

Parameters:
pmf - the JDO PersistenceManagerFactory, which is used to initialize the default JDBC exception translator
Method Detail

setPersistenceManagerFactory

public void setPersistenceManagerFactory(javax.jdo.PersistenceManagerFactory pmf)
Set the JDO PersistenceManagerFactory, which is used to initialize the default JDBC exception translator if none specified.

See Also:
setJdbcExceptionTranslator(org.springframework.jdbc.support.SQLExceptionTranslator)

getPersistenceManagerFactory

public javax.jdo.PersistenceManagerFactory getPersistenceManagerFactory()
Return the JDO PersistenceManagerFactory that should be used to create PersistenceManagers.


setJdbcExceptionTranslator

public void setJdbcExceptionTranslator(SQLExceptionTranslator jdbcExceptionTranslator)
Set the JDBC exception translator for this dialect. Applied to SQLExceptions that are the cause of JDOExceptions.

The default exception translator is either a SQLErrorCodeSQLExceptionTranslator if a DataSource is available, or a SQLStateSQLExceptionTranslator else.

Parameters:
jdbcExceptionTranslator - exception translator
See Also:
SQLException, JDOException.getCause(), PersistenceManagerFactoryUtils.newJdbcExceptionTranslator(javax.jdo.PersistenceManagerFactory), SQLErrorCodeSQLExceptionTranslator, SQLStateSQLExceptionTranslator

getJdbcExceptionTranslator

public SQLExceptionTranslator getJdbcExceptionTranslator()
Return the JDBC exception translator for this instance. Creates a default one for the specified PersistenceManagerFactory if none set.


afterPropertiesSet

public void afterPropertiesSet()
Eagerly initialize the exception translator, creating a default one for the specified PersistenceManagerFactory if none set.

Specified by:
afterPropertiesSet in interface InitializingBean

beginTransaction

public Object beginTransaction(javax.jdo.Transaction transaction,
                               TransactionDefinition definition)
                        throws javax.jdo.JDOException,
                               SQLException,
                               TransactionException
This implementation invokes the standard JDO Transaction.begin method. Throws an InvalidIsolationLevelException if a non-default isolation level is set.

Specified by:
beginTransaction in interface JdoDialect
Parameters:
transaction - the JDO transaction to begin
definition - the Spring transaction definition that defines semantics
Returns:
an arbitrary object that holds transaction data, if any (to be passed into cleanupTransaction)
Throws:
TransactionException - in case of invalid arguments
javax.jdo.JDOException - if thrown by JDO methods
SQLException - if thrown by JDBC methods
See Also:
Transaction.begin(), InvalidIsolationLevelException

cleanupTransaction

public void cleanupTransaction(Object transactionData)
This implementation does nothing, as the default beginTransaction implementation does not require any cleanup.

Specified by:
cleanupTransaction in interface JdoDialect
Parameters:
transactionData - arbitrary object that holds transaction data, if any (as returned by beginTransaction)
See Also:
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 null, to indicate that JDBC Connection retrieval is not supported.

Specified by:
getJdbcConnection in interface JdoDialect
Parameters:
pm - the current JDO PersistenceManager
Returns:
a handle for the JDBC Connection, to be passed into releaseJdbcConnection, or null if no JDBC Connection can be retrieved
Throws:
javax.jdo.JDOException - if thrown by JDO methods
SQLException - if thrown by JDBC methods
See Also:
JdoDialect.releaseJdbcConnection(org.springframework.jdbc.datasource.ConnectionHandle, javax.jdo.PersistenceManager), ConnectionHandle.getConnection(), SimpleConnectionHandle, JdoTransactionManager.setDataSource(javax.sql.DataSource), NativeJdbcExtractor

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 implementation returns a Connection handle that it expects the application to close, the dialect needs to invoke Connection.close here.

Specified by:
releaseJdbcConnection in interface JdoDialect
Parameters:
conHandle - the JDBC Connection handle to release
pm - the current JDO PersistenceManager
Throws:
javax.jdo.JDOException - if thrown by JDO methods
SQLException - if thrown by JDBC methods
See Also:
Connection.close()

applyQueryTimeout

public void applyQueryTimeout(javax.jdo.Query query,
                              int remainingTimeInSeconds)
                       throws javax.jdo.JDOException
This implementation logs a warning that it cannot apply a query timeout.

Specified by:
applyQueryTimeout in interface JdoDialect
Parameters:
query - the JDO query object to apply the timeout to
remainingTimeInSeconds - the timeout value to apply
Throws:
javax.jdo.JDOException - if thrown by JDO methods
See Also:
JdoTemplate.prepareQuery(javax.jdo.Query)

flush

public void flush(javax.jdo.PersistenceManager pm)
           throws javax.jdo.JDOException
This implementation throws a JDOUnsupportedOptionException.

Specified by:
flush in interface JdoDialect
Parameters:
pm - the current JDO PersistenceManager
Throws:
javax.jdo.JDOException - in case of errors
See Also:
JDOUnsupportedOptionException

translateException

public DataAccessException translateException(javax.jdo.JDOException ex)
This implementation delegates to PersistenceManagerFactoryUtils.

Specified by:
translateException in interface JdoDialect
Parameters:
ex - the JDOException thrown
Returns:
the corresponding DataAccessException (must not be null)
See Also:
PersistenceManagerFactoryUtils.convertJdoAccessException(javax.jdo.JDOException)


Copyright (C) 2003-2004 The Spring Framework Project.