org.springframework.orm.jdo
Class PersistenceManagerFactoryUtils

java.lang.Object
  extended byorg.springframework.orm.jdo.PersistenceManagerFactoryUtils

public abstract class PersistenceManagerFactoryUtils
extends Object

Helper class featuring methods for JDO PersistenceManager handling, allowing for reuse of PersistenceManager instances within transactions.

Used by JdoTemplate, JdoInterceptor, and JdoTransactionManager. Can also be used directly in application code, e.g. in combination with JdoInterceptor.

Since:
03.06.2003
Author:
Juergen Hoeller
See Also:
JdoTemplate, JdoInterceptor, JdoTransactionManager

Constructor Summary
PersistenceManagerFactoryUtils()
           
 
Method Summary
static void applyTransactionTimeout(javax.jdo.Query query, javax.jdo.PersistenceManagerFactory pmf, JdoDialect jdoDialect)
          Apply the current transaction timeout, if any, to the given JDO Query object.
static void closePersistenceManagerIfNecessary(javax.jdo.PersistenceManager pm, javax.jdo.PersistenceManagerFactory pmf)
          Close the given PersistenceManager, created via the given factory, if it isn't bound to the thread.
static DataAccessException convertJdoAccessException(javax.jdo.JDOException ex)
          Convert the given JDOException to an appropriate exception from the org.springframework.dao hierarchy.
static javax.jdo.PersistenceManager getPersistenceManager(javax.jdo.PersistenceManagerFactory pmf, boolean allowCreate)
          Get a JDO PersistenceManager via the given factory.
static javax.jdo.PersistenceManager getPersistenceManager(javax.jdo.PersistenceManagerFactory pmf, boolean allowCreate, boolean allowSynchronization)
          Get a JDO PersistenceManager via the given factory.
static SQLExceptionTranslator newJdbcExceptionTranslator(javax.jdo.PersistenceManagerFactory pmf)
          Create an appropriate SQLExceptionTranslator for the given PersistenceManagerFactory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PersistenceManagerFactoryUtils

public PersistenceManagerFactoryUtils()
Method Detail

newJdbcExceptionTranslator

public static SQLExceptionTranslator newJdbcExceptionTranslator(javax.jdo.PersistenceManagerFactory pmf)
Create an appropriate SQLExceptionTranslator for the given PersistenceManagerFactory. If a DataSource is found, create a SQLErrorCodeSQLExceptionTranslator for the DataSource; else, fall back to a SQLStateSQLExceptionTranslator.

Parameters:
pmf - the PersistenceManagerFactory to create the translator for
Returns:
the SQLExceptionTranslator
See Also:
PersistenceManagerFactory.getConnectionFactory(), SQLErrorCodeSQLExceptionTranslator, SQLStateSQLExceptionTranslator

getPersistenceManager

public static javax.jdo.PersistenceManager getPersistenceManager(javax.jdo.PersistenceManagerFactory pmf,
                                                                 boolean allowCreate)
                                                          throws DataAccessResourceFailureException,
                                                                 IllegalStateException
Get a JDO PersistenceManager via the given factory. Is aware of a corresponding PersistenceManager bound to the current thread, for example when using JdoTransactionManager. Will create a new PersistenceManager else, if allowCreate is true.

Parameters:
pmf - PersistenceManagerFactory to create the session with
allowCreate - if a new PersistenceManager should be created if no thread-bound found
Returns:
the PersistenceManager
Throws:
DataAccessResourceFailureException - if the PersistenceManager couldn't be created
IllegalStateException - if no thread-bound PersistenceManager found and allowCreate false

getPersistenceManager

public static javax.jdo.PersistenceManager getPersistenceManager(javax.jdo.PersistenceManagerFactory pmf,
                                                                 boolean allowCreate,
                                                                 boolean allowSynchronization)
                                                          throws DataAccessResourceFailureException,
                                                                 IllegalStateException
Get a JDO PersistenceManager via the given factory. Is aware of a corresponding PersistenceManager bound to the current thread, for example when using JdoTransactionManager. Will create a new PersistenceManager else, if allowCreate is true.

Parameters:
pmf - PersistenceManagerFactory to create the session with
allowCreate - if a new PersistenceManager should be created if no thread-bound found
allowSynchronization - if a new JDO PersistenceManager is supposed to be registered with transaction synchronization (if synchronization is active). This will always be true for typical data access code.
Returns:
the PersistenceManager
Throws:
DataAccessResourceFailureException - if the PersistenceManager couldn't be created
IllegalStateException - if no thread-bound PersistenceManager found and allowCreate false

applyTransactionTimeout

public static void applyTransactionTimeout(javax.jdo.Query query,
                                           javax.jdo.PersistenceManagerFactory pmf,
                                           JdoDialect jdoDialect)
                                    throws javax.jdo.JDOException
Apply the current transaction timeout, if any, to the given JDO Query object.

Parameters:
query - the JDO Query object
pmf - JDO PersistenceManagerFactory that the Query was created for
jdoDialect - the JdoDialect to use for applying a query timeout (must not be null)
Throws:
javax.jdo.JDOException
See Also:
JdoDialect.applyQueryTimeout(javax.jdo.Query, int)

convertJdoAccessException

public static DataAccessException convertJdoAccessException(javax.jdo.JDOException ex)
Convert the given JDOException to an appropriate exception from the org.springframework.dao hierarchy.

The most important cases like object not found or optimistic verification failure are covered here. For more fine-granular conversion, JdoAccessor and JdoTransactionManager support sophisticated translation of exceptions via a JdoDialect.

Parameters:
ex - JDOException that occured
Returns:
the corresponding DataAccessException instance
See Also:
JdoAccessor.convertJdoAccessException(javax.jdo.JDOException), JdoTransactionManager.convertJdoAccessException(javax.jdo.JDOException), JdoDialect.translateException(javax.jdo.JDOException)

closePersistenceManagerIfNecessary

public static void closePersistenceManagerIfNecessary(javax.jdo.PersistenceManager pm,
                                                      javax.jdo.PersistenceManagerFactory pmf)
Close the given PersistenceManager, created via the given factory, if it isn't bound to the thread.

Parameters:
pm - PersistenceManager to close
pmf - PersistenceManagerFactory that the PersistenceManager was created with


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