org.springframework.orm.jdo
Class PersistenceManagerFactoryUtils

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

public abstract class PersistenceManagerFactoryUtils
extends java.lang.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 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)
           
 
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

getPersistenceManager

public static javax.jdo.PersistenceManager getPersistenceManager(javax.jdo.PersistenceManagerFactory pmf,
                                                                 boolean allowCreate)
                                                          throws DataAccessResourceFailureException
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
java.lang.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
Throws:
DataAccessResourceFailureException

convertJdoAccessException

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

Unfortunately, JDO's JDOUserException covers a lot of distinct causes like unparsable query, optimistic locking failure, etc. Thus, we are not able to convert to Spring's DataAccessException hierarchy in a fine-granular way with standard JDO. JdoAccessor and JdoTransactionManager support more sophisticated translation of exceptions via a JdoDialect.

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

closePersistenceManagerIfNecessary

public static void closePersistenceManagerIfNecessary(javax.jdo.PersistenceManager pm,
                                                      javax.jdo.PersistenceManagerFactory pmf)
                                               throws CleanupFailureDataAccessException
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
Throws:
DataAccessResourceFailureException - if the PersistenceManager couldn't be closed
CleanupFailureDataAccessException


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