org.springframework.extensions.jcr.support
Class JcrDaoSupport

java.lang.Object
  extended by org.springframework.dao.support.DaoSupport
      extended by org.springframework.extensions.jcr.support.JcrDaoSupport
All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean

public abstract class JcrDaoSupport
extends org.springframework.dao.support.DaoSupport

Convenient class for accessing Jcr objects.

Author:
Costin Leau, Guillaume Bort , Sergio Bossa, Salvatore Incandela

Field Summary
 
Fields inherited from class org.springframework.dao.support.DaoSupport
logger
 
Constructor Summary
JcrDaoSupport()
           
 
Method Summary
protected  void checkDaoConfig()
           
protected  org.springframework.dao.DataAccessException convertJcrAccessException(javax.jcr.RepositoryException ex)
          Convert the given JCRException to an appropriate exception from the org.springframework.dao hierarchy.
protected  javax.jcr.Session getSession()
          Get a JCR Session, either from the current transaction or a new one.
protected  javax.jcr.Session getSession(boolean allowCreate)
          Get a JCR Session, either from the current transaction or a new one.
 SessionFactory getSessionFactory()
          Return the Jcr SessionFactory used by this DAO.
 JcrTemplate getTemplate()
          Return the JcrTemplate for this DAO, pre-initialized with the SessionFactory or set explicitly.
protected  void releaseSession(javax.jcr.Session session)
          Close the given JCR Session, created via this DAO's SessionFactory, if it isn't bound to the thread.
 void setSessionFactory(SessionFactory sessionFactory)
          Set the JCR SessionFactory to be used by this DAO.
 void setTemplate(JcrTemplate jcrTemplate)
          Set the JcrTemplate for this DAO explicitly, as an alternative to specifying a SessionFactory.
 
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

JcrDaoSupport

public JcrDaoSupport()
Method Detail

setSessionFactory

public final void setSessionFactory(SessionFactory sessionFactory)
Set the JCR SessionFactory to be used by this DAO. Will automatically create a JcrTemplate for the given SessionFactory.

See Also:
#createJcrTemplate, #setJcrTemplate

getSessionFactory

public final SessionFactory getSessionFactory()
Return the Jcr SessionFactory used by this DAO.


setTemplate

public final void setTemplate(JcrTemplate jcrTemplate)
Set the JcrTemplate for this DAO explicitly, as an alternative to specifying a SessionFactory.

See Also:
setSessionFactory(org.springframework.extensions.jcr.SessionFactory)

getTemplate

public final JcrTemplate getTemplate()
Return the JcrTemplate for this DAO, pre-initialized with the SessionFactory or set explicitly.


checkDaoConfig

protected final void checkDaoConfig()
Specified by:
checkDaoConfig in class org.springframework.dao.support.DaoSupport

getSession

protected final javax.jcr.Session getSession()
Get a JCR Session, either from the current transaction or a new one. The latter is only allowed if the "allowCreate" setting of this bean's JcrTemplate is true.

Returns:
the JCR Session
Throws:
org.springframework.dao.DataAccessResourceFailureException - if the Session couldn't be created
java.lang.IllegalStateException - if no thread-bound Session found and allowCreate false
See Also:
SessionFactoryUtils.getSession(org.springframework.extensions.jcr.SessionFactory, boolean)

getSession

protected final javax.jcr.Session getSession(boolean allowCreate)
                                      throws org.springframework.dao.DataAccessResourceFailureException,
                                             java.lang.IllegalStateException
Get a JCR Session, either from the current transaction or a new one. The latter is only allowed if "allowCreate" is true.

Parameters:
allowCreate - if a non-transactional Session should be created when no transactional Session can be found for the current thread
Returns:
the JCR Session
Throws:
org.springframework.dao.DataAccessResourceFailureException - if the Session couldn't be created
java.lang.IllegalStateException - if no thread-bound Session found and allowCreate false
See Also:
SessionFactoryUtils.getSession(org.springframework.extensions.jcr.SessionFactory, boolean)

convertJcrAccessException

protected final org.springframework.dao.DataAccessException convertJcrAccessException(javax.jcr.RepositoryException ex)
Convert the given JCRException to an appropriate exception from the org.springframework.dao hierarchy.

Delegates to the convertJCRAccessException method of this DAO's JCRTemplate.

Parameters:
ex - JCRException that occured
Returns:
the corresponding DataAccessException instance
See Also:
#setJCRTemplate, org.springframework.extensions.jcr.JcrTemplate#convertJCRAccessException

releaseSession

protected final void releaseSession(javax.jcr.Session session)
Close the given JCR Session, created via this DAO's SessionFactory, if it isn't bound to the thread.

Parameters:
pm - Session to close
See Also:
org.springframework.orm.JCR.SessionFactoryUtils#releaseSession


Copyright © 2009. All Rights Reserved.