org.springframework.orm.ojb
Class OjbFactoryUtils

java.lang.Object
  extended byorg.springframework.orm.ojb.OjbFactoryUtils

public abstract class OjbFactoryUtils
extends Object

Helper class featuring methods for OJB PersistenceBroker handling, allowing for reuse of PersistenceBroker instances within transactions.

Used by PersistenceBrokerTemplate and PersistenceBrokerTransactionManager. Can also be used directly in application code.

Since:
1.1
Author:
Juergen Hoeller
See Also:
PersistenceBrokerTemplate, PersistenceBrokerTransactionManager, JtaTransactionManager

Field Summary
static int PERSISTENCE_BROKER_SYNCHRONIZATION_ORDER
          Order value for TransactionSynchronization objects that clean up OJB PersistenceBrokers.
 
Constructor Summary
OjbFactoryUtils()
           
 
Method Summary
static void closePersistenceBrokerIfNecessary(org.apache.ojb.broker.PersistenceBroker pb, org.apache.ojb.broker.PBKey pbKey)
          Close the given PersistenceBroker, created for the given PBKey, if it isn't bound to the thread.
static org.apache.ojb.broker.PersistenceBroker getPersistenceBroker(org.apache.ojb.broker.PBKey pbKey, boolean allowCreate)
          Get an OJB PersistenceBroker for the given PBKey.
static org.apache.ojb.broker.PersistenceBroker getPersistenceBroker(org.apache.ojb.broker.PBKey pbKey, boolean allowCreate, boolean allowSynchronization)
          Get an OJB PersistenceBroker for the given PBKey.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PERSISTENCE_BROKER_SYNCHRONIZATION_ORDER

public static final int PERSISTENCE_BROKER_SYNCHRONIZATION_ORDER
Order value for TransactionSynchronization objects that clean up OJB PersistenceBrokers. Return DataSourceUtils.CONNECTION_SYNCHRONIZATION_ORDER - 100 to execute PersistenceBroker cleanup before JDBC Connection cleanup, if any.

See Also:
DataSourceUtils.CONNECTION_SYNCHRONIZATION_ORDER, Constant Field Values
Constructor Detail

OjbFactoryUtils

public OjbFactoryUtils()
Method Detail

getPersistenceBroker

public static org.apache.ojb.broker.PersistenceBroker getPersistenceBroker(org.apache.ojb.broker.PBKey pbKey,
                                                                           boolean allowCreate)
                                                                    throws DataAccessResourceFailureException,
                                                                           IllegalStateException
Get an OJB PersistenceBroker for the given PBKey. Is aware of a corresponding PersistenceBroker bound to the current thread, for example when using PersistenceBrokerTransactionManager. Will create a new PersistenceBroker else, if allowCreate is true.

Parameters:
pbKey - PBKey to create the PersistenceBroker for
allowCreate - if a new PersistenceBroker should be created if no thread-bound found
Returns:
the PersistenceBroker
Throws:
DataAccessResourceFailureException - if the PersistenceBroker couldn't be created
IllegalStateException - if no thread-bound PersistenceBroker found and allowCreate false

getPersistenceBroker

public static org.apache.ojb.broker.PersistenceBroker getPersistenceBroker(org.apache.ojb.broker.PBKey pbKey,
                                                                           boolean allowCreate,
                                                                           boolean allowSynchronization)
                                                                    throws DataAccessResourceFailureException,
                                                                           IllegalStateException
Get an OJB PersistenceBroker for the given PBKey. Is aware of a corresponding PersistenceBroker bound to the current thread, for example when using PersistenceBrokerTransactionManager. Will create a new PersistenceBroker else.

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

closePersistenceBrokerIfNecessary

public static void closePersistenceBrokerIfNecessary(org.apache.ojb.broker.PersistenceBroker pb,
                                                     org.apache.ojb.broker.PBKey pbKey)
Close the given PersistenceBroker, created for the given PBKey, if it isn't bound to the thread.

Parameters:
pb - PersistenceBroker to close
pbKey - PBKey that the PersistenceBroker was created with


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