public abstract class

PersistenceManagerFactoryUtils

extends Object
java.lang.Object
   ↳ org.springframework.orm.jdo.PersistenceManagerFactoryUtils

Class Overview

Helper class featuring methods for JDO PersistenceManager handling, allowing for reuse of PersistenceManager instances within transactions. Also provides support for exception translation.

Used internally by JdoTemplate, JdoInterceptor and JdoTransactionManager. Can also be used directly in application code.

Summary

Constants
int PERSISTENCE_MANAGER_SYNCHRONIZATION_ORDER Order value for TransactionSynchronization objects that clean up JDO PersistenceManagers.
Public Constructors
PersistenceManagerFactoryUtils()
Public Methods
static void applyTransactionTimeout(Query query, PersistenceManagerFactory pmf, JdoDialect jdoDialect)
Apply the current transaction timeout, if any, to the given JDO Query object.
static DataAccessException convertJdoAccessException(JDOException ex)
Convert the given JDOException to an appropriate exception from the org.springframework.dao hierarchy.
static PersistenceManager doGetPersistenceManager(PersistenceManagerFactory pmf, boolean allowCreate)
Obtain a JDO PersistenceManager via the given factory.
static void doReleasePersistenceManager(PersistenceManager pm, PersistenceManagerFactory pmf)
Actually release a PersistenceManager for the given factory.
static PersistenceManager getPersistenceManager(PersistenceManagerFactory pmf, boolean allowCreate)
Obtain a JDO PersistenceManager via the given factory.
static boolean isPersistenceManagerTransactional(PersistenceManager pm, PersistenceManagerFactory pmf)
Return whether the given JDO PersistenceManager is transactional, that is, bound to the current thread by Spring's transaction facilities.
static void releasePersistenceManager(PersistenceManager pm, PersistenceManagerFactory pmf)
Close the given PersistenceManager, created via the given factory, if it is not managed externally (i.e.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

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.

Constant Value: 900 (0x00000384)

Public Constructors

public PersistenceManagerFactoryUtils ()

Public Methods

public static void applyTransactionTimeout (Query query, PersistenceManagerFactory pmf, JdoDialect jdoDialect)

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
if thrown by JDO methods
JDOException

public static DataAccessException convertJdoAccessException (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

public static PersistenceManager doGetPersistenceManager (PersistenceManagerFactory pmf, boolean allowCreate)

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
if the PersistenceManager couldn't be created
IllegalStateException if no thread-bound PersistenceManager found and "allowCreate" is false
JDOException
See Also

public static void doReleasePersistenceManager (PersistenceManager pm, PersistenceManagerFactory pmf)

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
if thrown by JDO methods
JDOException

public static PersistenceManager getPersistenceManager (PersistenceManagerFactory pmf, boolean allowCreate)

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

public static boolean isPersistenceManagerTransactional (PersistenceManager pm, 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

public static void releasePersistenceManager (PersistenceManager pm, 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)