org.springframework.orm.jdo
Class PersistenceManagerFactoryUtils

java.lang.Object
  extended by org.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. Also provides support for exception translation.

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

Field Summary
static int PERSISTENCE_MANAGER_SYNCHRONIZATION_ORDER
          Order value for TransactionSynchronization objects that clean up JDO PersistenceManagers.
 
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)
          Deprecated. in favor of releasePersistenceManager
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 doGetPersistenceManager(javax.jdo.PersistenceManagerFactory pmf, boolean allowCreate)
          Obtain a JDO PersistenceManager via the given factory.
static void doReleasePersistenceManager(javax.jdo.PersistenceManager pm, javax.jdo.PersistenceManagerFactory pmf)
          Actually release a PersistenceManager for the given factory.
static javax.jdo.PersistenceManager getPersistenceManager(javax.jdo.PersistenceManagerFactory pmf, boolean allowCreate)
          Obtain a JDO PersistenceManager via the given factory.
static boolean isPersistenceManagerTransactional(javax.jdo.PersistenceManager pm, javax.jdo.PersistenceManagerFactory pmf)
          Return whether the given JDO PersistenceManager is transactional, that is, bound to the current thread by Spring's transaction facilities.
static SQLExceptionTranslator newJdbcExceptionTranslator(javax.jdo.PersistenceManagerFactory pmf)
          Create an appropriate SQLExceptionTranslator for the given PersistenceManagerFactory.
static void releasePersistenceManager(javax.jdo.PersistenceManager pm, javax.jdo.PersistenceManagerFactory pmf)
          Close the given PersistenceManager, created via the given factory, if it is not managed externally (i.e. not bound to the thread).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PERSISTENCE_MANAGER_SYNCHRONIZATION_ORDER

public static final int PERSISTENCE_MANAGER_SYNCHRONIZATION_ORDER
Order value for TransactionSynchronization objects that clean up JDO PersistenceManagers. Return DataSourceUtils.CONNECTION_SYNCHRONIZATION_ORDER - 100 to execute PersistenceManager cleanup before JDBC Connection cleanup, if any.

See Also:
DataSourceUtils.CONNECTION_SYNCHRONIZATION_ORDER, Constant Field Values
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, creates a SQLErrorCodeSQLExceptionTranslator for the DataSource; else, falls back to a SQLStateSQLExceptionTranslator.

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

getPersistenceManager

public static javax.jdo.PersistenceManager getPersistenceManager(javax.jdo.PersistenceManagerFactory pmf,
                                                                 boolean allowCreate)
                                                          throws DataAccessResourceFailureException,
                                                                 IllegalStateException
Obtain 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 PersistenceManager with
allowCreate - if a non-transactional PersistenceManager should be created when no transactional PersistenceManager can be found for the current thread
Returns:
the PersistenceManager
Throws:
DataAccessResourceFailureException - if the PersistenceManager couldn't be obtained
IllegalStateException - if no thread-bound PersistenceManager found and "allowCreate" is false
See Also:
JdoTransactionManager

doGetPersistenceManager

public static javax.jdo.PersistenceManager doGetPersistenceManager(javax.jdo.PersistenceManagerFactory pmf,
                                                                   boolean allowCreate)
                                                            throws javax.jdo.JDOException,
                                                                   IllegalStateException
Obtain 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.

Same as getPersistenceManager, but throwing the original JDOException.

Parameters:
pmf - PersistenceManagerFactory to create the PersistenceManager with
allowCreate - if a non-transactional PersistenceManager should be created when no transactional PersistenceManager can be found for the current thread
Returns:
the PersistenceManager
Throws:
javax.jdo.JDOException - if the PersistenceManager couldn't be created
IllegalStateException - if no thread-bound PersistenceManager found and "allowCreate" is false
See Also:
getPersistenceManager(javax.jdo.PersistenceManagerFactory, boolean), JdoTransactionManager

isPersistenceManagerTransactional

public static boolean isPersistenceManagerTransactional(javax.jdo.PersistenceManager pm,
                                                        javax.jdo.PersistenceManagerFactory pmf)
Return whether the given JDO PersistenceManager is transactional, that is, bound to the current thread by Spring's transaction facilities.

Parameters:
pm - the JDO PersistenceManager to check
pmf - JDO PersistenceManagerFactory that the PersistenceManager was created with (can be null)
Returns:
whether the PersistenceManager is transactional

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 locking 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)
Deprecated. in favor of releasePersistenceManager

Close the given PersistenceManager, created via the given factory, if it isn't bound to the thread.

See Also:
releasePersistenceManager(javax.jdo.PersistenceManager, javax.jdo.PersistenceManagerFactory)

releasePersistenceManager

public static void releasePersistenceManager(javax.jdo.PersistenceManager pm,
                                             javax.jdo.PersistenceManagerFactory pmf)
Close the given PersistenceManager, created via the given factory, if it is not managed externally (i.e. not bound to the thread).

Parameters:
pm - PersistenceManager to close
pmf - PersistenceManagerFactory that the PersistenceManager was created with (can be null)

doReleasePersistenceManager

public static void doReleasePersistenceManager(javax.jdo.PersistenceManager pm,
                                               javax.jdo.PersistenceManagerFactory pmf)
                                        throws javax.jdo.JDOException
Actually release a PersistenceManager for the given factory. Same as releasePersistenceManager, but throwing the original JDOException.

Parameters:
pm - PersistenceManager to close
pmf - PersistenceManagerFactory that the PersistenceManager was created with (can be null)
Throws:
javax.jdo.JDOException - if thrown by JDO methods


Copyright (c) 2002-2007 The Spring Framework Project.