org.springframework.orm.jdo.support
Class JdoDaoSupport

java.lang.Object
  extended byorg.springframework.orm.jdo.support.JdoDaoSupport
All Implemented Interfaces:
InitializingBean

public abstract class JdoDaoSupport
extends Object
implements InitializingBean

Convenient super class for JDO data access objects.

Requires a PersistenceManagerFactory to be set, providing a JdoTemplate based on it to subclasses. Can alternatively be initialized directly via a JdoTemplate, to reuse the latter's settings like PersistenceManagerFactory, JdoDialect, flush mode, etc.

This base class is mainly intended for JdoTemplate usage but can also be used when working with PersistenceManagerFactoryUtils directly, e.g. in combination with JdoInterceptor-managed PersistenceManagers. Convenience getPersistenceManager and closePersistenceManagerIfNecessary methods are provided for that usage style.

This class will create its own JdoTemplate if only a PersistenceManagerFactory is passed in. The allowCreate flag on that JdoTemplate will be true by default. A custom JdoTemplate instance can be used through overriding createJdoTemplate.

Since:
28.07.2003
Author:
Juergen Hoeller
See Also:
setPersistenceManagerFactory(javax.jdo.PersistenceManagerFactory), setJdoTemplate(org.springframework.orm.jdo.JdoTemplate), getPersistenceManager(), closePersistenceManagerIfNecessary(javax.jdo.PersistenceManager), JdoTemplate, JdoInterceptor

Field Summary
protected  Log logger
           
 
Constructor Summary
JdoDaoSupport()
           
 
Method Summary
 void afterPropertiesSet()
          Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware).
protected  void closePersistenceManagerIfNecessary(javax.jdo.PersistenceManager pm)
          Close the given JDO PersistenceManager if necessary, created via this bean's PersistenceManagerFactory, if it isn't bound to the thread.
protected  DataAccessException convertJdoAccessException(javax.jdo.JDOException ex)
          Convert the given JDOException to an appropriate exception from the org.springframework.dao hierarchy.
protected  JdoTemplate createJdoTemplate(javax.jdo.PersistenceManagerFactory persistenceManagerFactory)
          Create a JdoTemplate for the given PersistenceManagerFactory.
 JdoTemplate getJdoTemplate()
          Return the JdoTemplate for this DAO, pre-initialized with the PersistenceManagerFactory or set explicitly.
protected  javax.jdo.PersistenceManager getPersistenceManager()
          Get a JDO PersistenceManager, either from the current transaction or a new one.
protected  javax.jdo.PersistenceManager getPersistenceManager(boolean allowCreate)
          Get a JDO PersistenceManager, either from the current transaction or a new one.
 javax.jdo.PersistenceManagerFactory getPersistenceManagerFactory()
          Return the JDO PersistenceManagerFactory used by this DAO.
protected  void initDao()
          Subclasses can override this for custom initialization behavior.
 void setJdoTemplate(JdoTemplate jdoTemplate)
          Set the JdoTemplate for this DAO explicitly, as an alternative to specifying a PersistenceManagerFactory.
 void setPersistenceManagerFactory(javax.jdo.PersistenceManagerFactory persistenceManagerFactory)
          Set the JDO PersistenceManagerFactory to be used by this DAO.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final Log logger
Constructor Detail

JdoDaoSupport

public JdoDaoSupport()
Method Detail

setPersistenceManagerFactory

public final void setPersistenceManagerFactory(javax.jdo.PersistenceManagerFactory persistenceManagerFactory)
Set the JDO PersistenceManagerFactory to be used by this DAO. Will automatically create a JdoTemplate for the given PersistenceManagerFactory.

See Also:
createJdoTemplate(javax.jdo.PersistenceManagerFactory), setJdoTemplate(org.springframework.orm.jdo.JdoTemplate)

createJdoTemplate

protected JdoTemplate createJdoTemplate(javax.jdo.PersistenceManagerFactory persistenceManagerFactory)
Create a JdoTemplate for the given PersistenceManagerFactory. Only invoked if populating the DAO with a PersistenceManagerFactory reference!

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

Parameters:
persistenceManagerFactory - the JDO PersistenceManagerFactoryto create a JdoTemplate for
Returns:
the new JdoTemplate instance
See Also:
setPersistenceManagerFactory(javax.jdo.PersistenceManagerFactory)

getPersistenceManagerFactory

public final javax.jdo.PersistenceManagerFactory getPersistenceManagerFactory()
Return the JDO PersistenceManagerFactory used by this DAO.


setJdoTemplate

public final void setJdoTemplate(JdoTemplate jdoTemplate)
Set the JdoTemplate for this DAO explicitly, as an alternative to specifying a PersistenceManagerFactory.

See Also:
setPersistenceManagerFactory(javax.jdo.PersistenceManagerFactory)

getJdoTemplate

public final JdoTemplate getJdoTemplate()
Return the JdoTemplate for this DAO, pre-initialized with the PersistenceManagerFactory or set explicitly.


afterPropertiesSet

public final void afterPropertiesSet()
                              throws Exception
Description copied from interface: InitializingBean
Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware).

This method allows the bean instance to perform initialization only possible when all bean properties have been set and to throw an exception in the event of misconfiguration.

Specified by:
afterPropertiesSet in interface InitializingBean
Throws:
Exception - in the event of misconfiguration (such as failure to set an essential property) or if initialization fails.

initDao

protected void initDao()
                throws Exception
Subclasses can override this for custom initialization behavior. Gets called after population of this instance's bean properties.

Throws:
Exception - if initialization fails

getPersistenceManager

protected final javax.jdo.PersistenceManager getPersistenceManager()
Get a JDO PersistenceManager, either from the current transaction or a new one. The latter is only allowed if the "allowCreate" setting of this bean's JdoTemplate is true.

Returns:
the JDO PersistenceManager
Throws:
DataAccessResourceFailureException - if the PersistenceManager couldn't be created
IllegalStateException - if no thread-bound PersistenceManager found and allowCreate false
See Also:
PersistenceManagerFactoryUtils.getPersistenceManager(javax.jdo.PersistenceManagerFactory, boolean)

getPersistenceManager

protected final javax.jdo.PersistenceManager getPersistenceManager(boolean allowCreate)
                                                            throws DataAccessResourceFailureException
Get a JDO PersistenceManager, either from the current transaction or a new one. The latter is only allowed if "allowCreate" is true.

Parameters:
allowCreate - if a new PersistenceManager should be created if no thread-bound found
Returns:
the JDO PersistenceManager
Throws:
DataAccessResourceFailureException - if the PersistenceManager couldn't be created
IllegalStateException - if no thread-bound PersistenceManager found and allowCreate false
See Also:
PersistenceManagerFactoryUtils.getPersistenceManager(javax.jdo.PersistenceManagerFactory, boolean)

convertJdoAccessException

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

Delegates to the convertJdoAccessException method of this DAO's JdoTemplate.

Parameters:
ex - JDOException that occured
Returns:
the corresponding DataAccessException instance
See Also:
setJdoTemplate(org.springframework.orm.jdo.JdoTemplate), JdoAccessor.convertJdoAccessException(javax.jdo.JDOException)

closePersistenceManagerIfNecessary

protected final void closePersistenceManagerIfNecessary(javax.jdo.PersistenceManager pm)
Close the given JDO PersistenceManager if necessary, created via this bean's PersistenceManagerFactory, if it isn't bound to the thread.

Parameters:
pm - PersistenceManager to close
See Also:
PersistenceManagerFactoryUtils.closePersistenceManagerIfNecessary(javax.jdo.PersistenceManager, javax.jdo.PersistenceManagerFactory)


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