org.springframework.extensions.jcr
Class SessionFactoryUtils

java.lang.Object
  extended by org.springframework.extensions.jcr.SessionFactoryUtils

public abstract class SessionFactoryUtils
extends java.lang.Object

FactoryBean for instantiating a Java Content Repository. This abstract class adds custom functionality subclasses handling only the configuration issues.

Author:
Costin Leau, Sergio Bossa, Salvatore Incandela

Constructor Summary
SessionFactoryUtils()
           
 
Method Summary
static javax.jcr.Session doGetSession(SessionFactory sessionFactory, boolean allowCreate)
          Get a JCR Session for the given Repository.
static javax.jcr.Session getSession(SessionFactory sessionFactory, boolean allowCreate)
          Get a JCR Session for the given Repository.
static boolean isSessionThreadBound(javax.jcr.Session session, SessionFactory sessionFactory)
          Return whether the given JCR Session is thread-bound that is, bound to the current thread by Spring's transaction facilities (which is used as a thread-bounding utility class).
static void releaseSession(javax.jcr.Session session, SessionFactory sessionFactory)
          Close the given Session, created via the given repository, if it is not managed externally (i.e.
static org.springframework.dao.DataAccessException translateException(java.io.IOException ex)
          Jcr exception translator - it converts specific JSR-170 checked exceptions into unchecked Spring DA exception.
static org.springframework.dao.DataAccessException translateException(javax.jcr.RepositoryException ex)
          Jcr exception translator - it converts specific JSR-170 checked exceptions into unchecked Spring DA exception.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SessionFactoryUtils

public SessionFactoryUtils()
Method Detail

doGetSession

public static javax.jcr.Session doGetSession(SessionFactory sessionFactory,
                                             boolean allowCreate)
                                      throws javax.jcr.RepositoryException
Get a JCR Session for the given Repository. Is aware of and will return any existing corresponding Session bound to the current thread, for example when using JcrTransactionManager. Same as getSession but throws the original Repository.

Parameters:
sessionFactory - Jcr Repository to create session with
allowCreate - if a non-transactional Session should be created when no transactional Session can be found for the current thread
Returns:
Throws:
javax.jcr.RepositoryException

getSession

public static javax.jcr.Session getSession(SessionFactory sessionFactory,
                                           boolean allowCreate)
                                    throws org.springframework.dao.DataAccessException
Get a JCR Session for the given Repository. Is aware of and will return any existing corresponding Session bound to the current thread, for example when using JcrTransactionManager. Will create a new Session otherwise, if allowCreate is true. This is the getSession method used by typical data access code, in combination with releaseSession called when done with the Session. Note that JcrTemplate allows to write data access code without caring about such resource handling. Supports synchronization with both Spring-managed JTA transactions (i.e. JtaTransactionManager) and non-Spring JTA transactions (i.e. plain JTA or EJB CMT).

Parameters:
sessionFactory - JCR Repository to create session with
allowCreate - if a non-transactional Session should be created when no transactional Session can be found for the current thread
Returns:
Throws:
org.springframework.dao.DataAccessException

isSessionThreadBound

public static boolean isSessionThreadBound(javax.jcr.Session session,
                                           SessionFactory sessionFactory)
Return whether the given JCR Session is thread-bound that is, bound to the current thread by Spring's transaction facilities (which is used as a thread-bounding utility class).

Parameters:
session - the JCR Session to check
sessionFactory - the JCR SessionFactory that the Session was created with (can be null)
Returns:
whether the Session is transactional

releaseSession

public static void releaseSession(javax.jcr.Session session,
                                  SessionFactory sessionFactory)
Close the given Session, created via the given repository, if it is not managed externally (i.e. not bound to the thread).

Parameters:
session - the Jcr Session to close
sessionFactory - JcrSessionFactory that the Session was created with (can be null)

translateException

public static org.springframework.dao.DataAccessException translateException(javax.jcr.RepositoryException ex)
Jcr exception translator - it converts specific JSR-170 checked exceptions into unchecked Spring DA exception.

Parameters:
ex -
Returns:

translateException

public static org.springframework.dao.DataAccessException translateException(java.io.IOException ex)
Jcr exception translator - it converts specific JSR-170 checked exceptions into unchecked Spring DA exception.

Parameters:
ex -
Returns:


Copyright © 2009. All Rights Reserved.