org.springframework.orm.hibernate3
Class SessionFactoryBeanDelegate

java.lang.Object
  extended by org.springframework.orm.hibernate3.SessionFactoryBeanDelegate
All Implemented Interfaces:
Aware, BeanClassLoaderAware, DisposableBean, FactoryBean<org.hibernate.SessionFactory>, InitializingBean, PersistenceExceptionTranslator, SessionFactoryBeanOperations

public class SessionFactoryBeanDelegate
extends Object
implements SessionFactoryBeanOperations

Encapsulates common SessionFactoryBeanOperations behavior in order to avoid multiple-inheritance issues with SessionFactoryBeanOperations implementations that need to extend *SessionFactoryBuilder types.

Maintainer's note: Unless otherwise documented, JavaDoc for all methods is inherited from SessionFactoryBeanOperations.

Since:
3.1
Author:
Chris Beams

Constructor Summary
SessionFactoryBeanDelegate(SessionFactoryBuilderSupport<?> builder)
          Create a new SessionFactoryBeanDelegate
 
Method Summary
 void afterPropertiesSet()
          Build and expose the SessionFactory.
 void destroy()
          Close the SessionFactory on bean factory shutdown.
static org.hibernate.cache.CacheProvider getConfigTimeCacheProvider()
          Deprecated. as of Spring 3.1 in favor of Hibernate's RegionFactory SPI
 org.hibernate.SessionFactory getObject()
          Return the singleton SessionFactory.
 Class<? extends org.hibernate.SessionFactory> getObjectType()
          Return the SessionFactory class used.
 org.hibernate.SessionFactory getSessionFactory()
          Return the SessionFactory maintained by this delegate.
 boolean isSingleton()
          Return true.
 void postBuildSessionFactory()
           
 void preBuildSessionFactory()
           
 void setBeanClassLoader(ClassLoader beanClassLoader)
          Exists for compatibility with BeanClassLoaderAware but simply delegates to setClassLoader.
 void setCacheProvider(org.hibernate.cache.CacheProvider cacheProvider)
          Deprecated. 
 void setJdbcExceptionTranslator(SQLExceptionTranslator jdbcExceptionTranslator)
          Set the JDBC exception translator for the SessionFactory on this instance's underlying HibernateExceptionTranslator.
 void setPersistenceExceptionTranslator(HibernateExceptionTranslator hibernateExceptionTranslator)
          Customize the HibernateExceptionTranslator to be used when translating native HibernateException types to Spring's DataAccessException hierarchy.
 DataAccessException translateExceptionIfPossible(RuntimeException ex)
          Implementation of the PersistenceExceptionTranslator interface, as autodetected by Spring's PersistenceExceptionTranslationPostProcessor.
 org.hibernate.SessionFactory wrapSessionFactoryIfNecessary(org.hibernate.SessionFactory rawSf)
          Override the default DisposableBean proxying behavior in SessionFactoryBuilderSupport.wrapSessionFactoryIfNecessary(SessionFactory) and return the raw SessionFactory instance, as SessionFactory.close() will be called during this FactoryBean's normal destruction lifecycle.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SessionFactoryBeanDelegate

public SessionFactoryBeanDelegate(SessionFactoryBuilderSupport<?> builder)
Create a new SessionFactoryBeanDelegate

Parameters:
builder - the *SessionFactoryBuilder that delegates to this instance.
Method Detail

getSessionFactory

public org.hibernate.SessionFactory getSessionFactory()
Return the SessionFactory maintained by this delegate.


getConfigTimeCacheProvider

@Deprecated
public static org.hibernate.cache.CacheProvider getConfigTimeCacheProvider()
Deprecated. as of Spring 3.1 in favor of Hibernate's RegionFactory SPI

Return the CacheProvider for the currently configured Hibernate SessionFactory, to be used by LocalCacheProviderProxy.

This instance will be set before initialization of the corresponding SessionFactory, and reset immediately afterwards. It is thus only available during configuration.

See Also:
setCacheProvider(org.hibernate.cache.CacheProvider)

setCacheProvider

@Deprecated
public void setCacheProvider(org.hibernate.cache.CacheProvider cacheProvider)
Deprecated. 

Description copied from interface: SessionFactoryBeanOperations
Deprecated. as of Spring 3.0 in favor of setCacheRegionFactory following Hibernate 3.3's deprecation of the CacheProvider SPI.

Set the Hibernate CacheProvider to use for the SessionFactory. Allows for using a Spring-managed CacheProvider instance.

Note: If this is set, the Hibernate settings should not define a cache provider to avoid meaningless double configuration. of the CacheProvider SPI in favor of RegionFactory SPI.

Specified by:
setCacheProvider in interface SessionFactoryBeanOperations

setPersistenceExceptionTranslator

public void setPersistenceExceptionTranslator(HibernateExceptionTranslator hibernateExceptionTranslator)
Description copied from interface: SessionFactoryBeanOperations
Customize the HibernateExceptionTranslator to be used when translating native HibernateException types to Spring's DataAccessException hierarchy.

Specified by:
setPersistenceExceptionTranslator in interface SessionFactoryBeanOperations

setBeanClassLoader

public void setBeanClassLoader(ClassLoader beanClassLoader)
Description copied from interface: SessionFactoryBeanOperations
Exists for compatibility with BeanClassLoaderAware but simply delegates to setClassLoader.

Specified by:
setBeanClassLoader in interface BeanClassLoaderAware
Specified by:
setBeanClassLoader in interface SessionFactoryBeanOperations
Parameters:
beanClassLoader - the owning class loader; may be null in which case a default ClassLoader must be used, for example the ClassLoader obtained via ClassUtils.getDefaultClassLoader()

getObject

public org.hibernate.SessionFactory getObject()
Description copied from interface: SessionFactoryBeanOperations
Return the singleton SessionFactory.

Specified by:
getObject in interface FactoryBean<org.hibernate.SessionFactory>
Specified by:
getObject in interface SessionFactoryBeanOperations
Returns:
an instance of the bean (can be null)
See Also:
FactoryBeanNotInitializedException

getObjectType

public Class<? extends org.hibernate.SessionFactory> getObjectType()
Description copied from interface: SessionFactoryBeanOperations
Return the SessionFactory class used.

Specified by:
getObjectType in interface FactoryBean<org.hibernate.SessionFactory>
Specified by:
getObjectType in interface SessionFactoryBeanOperations
Returns:
the type of object that this FactoryBean creates, or null if not known at the time of the call
See Also:
ListableBeanFactory.getBeansOfType(java.lang.Class)

isSingleton

public boolean isSingleton()
Description copied from interface: SessionFactoryBeanOperations
Return true.

Specified by:
isSingleton in interface FactoryBean<org.hibernate.SessionFactory>
Specified by:
isSingleton in interface SessionFactoryBeanOperations
Returns:
whether the exposed object is a singleton
See Also:
FactoryBean.getObject(), SmartFactoryBean.isPrototype()

afterPropertiesSet

public void afterPropertiesSet()
                        throws Exception
Description copied from interface: SessionFactoryBeanOperations
Build and expose the SessionFactory.

Specified by:
afterPropertiesSet in interface InitializingBean
Specified by:
afterPropertiesSet in interface SessionFactoryBeanOperations
Throws:
Exception - in the event of misconfiguration (such as failure to set an essential property) or if initialization fails.
See Also:
SessionFactoryBuilderSupport.buildSessionFactory(), SessionFactoryBuilderSupport.doBuildSessionFactory(), SessionFactoryBuilderSupport.wrapSessionFactoryIfNecessary(org.hibernate.SessionFactory), SessionFactoryBuilderSupport.afterSessionFactoryCreation()

destroy

public void destroy()
             throws org.hibernate.HibernateException
Description copied from interface: SessionFactoryBeanOperations
Close the SessionFactory on bean factory shutdown.

Specified by:
destroy in interface DisposableBean
Specified by:
destroy in interface SessionFactoryBeanOperations
Throws:
org.hibernate.HibernateException

setJdbcExceptionTranslator

public void setJdbcExceptionTranslator(SQLExceptionTranslator jdbcExceptionTranslator)
Description copied from interface: SessionFactoryBeanOperations
Set the JDBC exception translator for the SessionFactory on this instance's underlying HibernateExceptionTranslator.

Applied to any SQLException root cause of a Hibernate JDBCException, overriding Hibernate's default SQLException translation (which is based on Hibernate's Dialect for a specific target database).

Specified by:
setJdbcExceptionTranslator in interface SessionFactoryBeanOperations
Parameters:
jdbcExceptionTranslator - the exception translator
See Also:
SessionFactoryBeanOperations.setPersistenceExceptionTranslator(HibernateExceptionTranslator), HibernateExceptionTranslator.setJdbcExceptionTranslator(org.springframework.jdbc.support.SQLExceptionTranslator), SQLException, JDBCException, SQLErrorCodeSQLExceptionTranslator, SQLStateSQLExceptionTranslator, PersistenceExceptionTranslator

translateExceptionIfPossible

public DataAccessException translateExceptionIfPossible(RuntimeException ex)
Description copied from interface: SessionFactoryBeanOperations
Implementation of the PersistenceExceptionTranslator interface, as autodetected by Spring's PersistenceExceptionTranslationPostProcessor.

Converts the exception if it is a HibernateException; else returns null to indicate an unknown exception.

Specified by:
translateExceptionIfPossible in interface PersistenceExceptionTranslator
Specified by:
translateExceptionIfPossible in interface SessionFactoryBeanOperations
Parameters:
ex - a RuntimeException thrown
Returns:
the corresponding DataAccessException (or null if the exception could not be translated, as in this case it may result from user code rather than an actual persistence problem)
See Also:
PersistenceExceptionTranslationPostProcessor, #convertHibernateAccessException

wrapSessionFactoryIfNecessary

public org.hibernate.SessionFactory wrapSessionFactoryIfNecessary(org.hibernate.SessionFactory rawSf)
Description copied from interface: SessionFactoryBeanOperations
Override the default DisposableBean proxying behavior in SessionFactoryBuilderSupport.wrapSessionFactoryIfNecessary(SessionFactory) and return the raw SessionFactory instance, as SessionFactory.close() will be called during this FactoryBean's normal destruction lifecycle.

Specified by:
wrapSessionFactoryIfNecessary in interface SessionFactoryBeanOperations

preBuildSessionFactory

public void preBuildSessionFactory()
See Also:
SessionFactoryBuilderSupport.preBuildSessionFactory()

postBuildSessionFactory

public void postBuildSessionFactory()
See Also:
SessionFactoryBuilderSupport.postBuildSessionFactory()