org.springframework.orm.ojb.support
Class PersistenceBrokerDaoSupport

java.lang.Object
  extended by org.springframework.dao.support.DaoSupport
      extended by org.springframework.orm.ojb.support.PersistenceBrokerDaoSupport
All Implemented Interfaces:
InitializingBean

public abstract class PersistenceBrokerDaoSupport
extends DaoSupport

Convenient super class for OJB PersistenceBroker data access objects.

Allows a JDBC Connection Descriptor alias to be set, providing a PersistenceBrokerTemplate based on it to subclasses. Can alternatively be initialized directly via a PersistenceBrokerTemplate, to reuse the latter's settings like PBKey, DataSource, etc.

This base class is mainly intended for PersistenceBrokerTemplate usage but can also be used when working with OjbFactoryUtils directly. Convenience getPersistenceBroker and releasePersistenceBroker methods are provided for that usage style.

This class will create its own PersistenceBrokerTemplate if no explicit instance is passed in. The allowCreate flag on that PersistenceBrokerTemplate will be true by default. A custom PersistenceBrokerTemplate instance can be used through overriding createHibernateTemplate.

Since:
1.1
Author:
Juergen Hoeller
See Also:
setJcdAlias(java.lang.String), setPersistenceBrokerTemplate(org.springframework.orm.ojb.PersistenceBrokerTemplate), createPersistenceBrokerTemplate(), getPersistenceBroker(boolean), releasePersistenceBroker(org.apache.ojb.broker.PersistenceBroker), PersistenceBrokerTemplate

Field Summary
 
Fields inherited from class org.springframework.dao.support.DaoSupport
logger
 
Constructor Summary
PersistenceBrokerDaoSupport()
           
 
Method Summary
protected  void checkDaoConfig()
          Abstract subclasses must override this to check their configuration.
protected  void closePersistenceBrokerIfNecessary(org.apache.ojb.broker.PersistenceBroker pb)
          Deprecated. in favor of releasePersistenceBroker
protected  DataAccessException convertOjbAccessException(org.apache.ojb.broker.PersistenceBrokerException ex)
          Convert the given PersistenceBrokerException to an appropriate exception from the org.springframework.dao hierarchy.
protected  PersistenceBrokerTemplate createPersistenceBrokerTemplate()
          Create a new default PersistenceBrokerTemplate on initialization.
 String getJcdAlias()
          Return the JDBC Connection Descriptor alias of the PersistenceBroker configuration to use.
protected  org.apache.ojb.broker.PersistenceBroker getPersistenceBroker(boolean allowCreate)
          Get an OJB PersistenceBroker.
 PersistenceBrokerTemplate getPersistenceBrokerTemplate()
          Return the PersistenceBrokerTemplate for this DAO, pre-initialized with the JCD alias or set explicitly.
protected  void releasePersistenceBroker(org.apache.ojb.broker.PersistenceBroker pb)
          Close the given PersistenceBroker if it isn't bound to the thread.
 void setJcdAlias(String jcdAlias)
          Set the JDBC Connection Descriptor alias of the PersistenceBroker configuration to use.
 void setPersistenceBrokerTemplate(PersistenceBrokerTemplate persistenceBrokerTemplate)
          Set the PersistenceBrokerTemplate for this DAO explicitly, as an alternative to specifying a JCD alias.
 
Methods inherited from class org.springframework.dao.support.DaoSupport
afterPropertiesSet, initDao
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PersistenceBrokerDaoSupport

public PersistenceBrokerDaoSupport()
Method Detail

createPersistenceBrokerTemplate

protected PersistenceBrokerTemplate createPersistenceBrokerTemplate()
Create a new default PersistenceBrokerTemplate on initialization. The returned template instance might be populated with a JCD alias, or get overwritten by an explicitly passed-in PersistenceBrokerTemplate.

Can be overridden in subclasses to provide a PersistenceBrokerTemplate instance with different configuration, or a custom PersistenceBrokerTemplate subclass.

Returns:
the new PersistenceBrokerTemplate instance
See Also:
setJcdAlias(java.lang.String), setPersistenceBrokerTemplate(org.springframework.orm.ojb.PersistenceBrokerTemplate)

setJcdAlias

public final void setJcdAlias(String jcdAlias)
Set the JDBC Connection Descriptor alias of the PersistenceBroker configuration to use. Default is the default connection configured for OJB.


getJcdAlias

public final String getJcdAlias()
Return the JDBC Connection Descriptor alias of the PersistenceBroker configuration to use.


setPersistenceBrokerTemplate

public final void setPersistenceBrokerTemplate(PersistenceBrokerTemplate persistenceBrokerTemplate)
Set the PersistenceBrokerTemplate for this DAO explicitly, as an alternative to specifying a JCD alias.


getPersistenceBrokerTemplate

public final PersistenceBrokerTemplate getPersistenceBrokerTemplate()
Return the PersistenceBrokerTemplate for this DAO, pre-initialized with the JCD alias or set explicitly.


checkDaoConfig

protected final void checkDaoConfig()
Description copied from class: DaoSupport
Abstract subclasses must override this to check their configuration.

Implementors should be marked as final, to make it clear that concrete subclasses are not supposed to override this template method themselves.

Specified by:
checkDaoConfig in class DaoSupport

getPersistenceBroker

protected final org.apache.ojb.broker.PersistenceBroker getPersistenceBroker(boolean allowCreate)
                                                                      throws DataAccessResourceFailureException,
                                                                             IllegalStateException
Get an OJB PersistenceBroker. 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:
allowCreate - if a non-transactional PersistenceBroker should be created when no transactional PersistenceBroker can be found for the current thread
Returns:
the PersistenceBroker
Throws:
DataAccessResourceFailureException - if the PersistenceBroker couldn't be created
IllegalStateException - if no thread-bound PersistenceBroker found and allowCreate false

convertOjbAccessException

protected final DataAccessException convertOjbAccessException(org.apache.ojb.broker.PersistenceBrokerException ex)
Convert the given PersistenceBrokerException to an appropriate exception from the org.springframework.dao hierarchy. In case of a wrapped SQLException, the PersistenceBrokerTemplate's SQLExceptionTranslator gets applied.

Parameters:
ex - PersistenceBrokerException that occured
Returns:
the corresponding DataAccessException instance
See Also:
OjbAccessor.convertOjbAccessException(org.apache.ojb.broker.PersistenceBrokerException)

closePersistenceBrokerIfNecessary

protected final void closePersistenceBrokerIfNecessary(org.apache.ojb.broker.PersistenceBroker pb)
Deprecated. in favor of releasePersistenceBroker

Close the given PersistenceBroker if it isn't bound to the thread.

See Also:
releasePersistenceBroker(org.apache.ojb.broker.PersistenceBroker)

releasePersistenceBroker

protected final void releasePersistenceBroker(org.apache.ojb.broker.PersistenceBroker pb)
Close the given PersistenceBroker if it isn't bound to the thread.

Parameters:
pb - PersistenceBroker to close


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