org.hibernate.impl
Class SessionFactoryImpl

java.lang.Object
  extended by org.hibernate.impl.SessionFactoryImpl
All Implemented Interfaces:
Serializable, Referenceable, Mapping, SessionFactoryImplementor, SessionFactory

public final class SessionFactoryImpl
extends Object
implements SessionFactory, SessionFactoryImplementor

Concrete implementation of the SessionFactory interface. Has the following responsibilites

This class must appear immutable to clients, even if it does all kinds of caching and pooling under the covers. It is crucial that the class is not only thread safe, but also highly concurrent. Synchronization must be used extremely sparingly.

Author:
Gavin King
See Also:
ConnectionProvider, Session, QueryTranslator, EntityPersister, CollectionPersister, Serialized Form

Constructor Summary
SessionFactoryImpl(Configuration cfg, Mapping mapping, Settings settings, EventListeners listeners)
           
 
Method Summary
 void close()
          Closes the session factory, releasing all held resources.
 void evict(Class persistentClass)
          Evict all entries from the second-level cache.
 void evict(Class persistentClass, Serializable id)
          Evict an entry from the second-level cache.
 void evictCollection(String roleName)
          Evict all entries from the second-level cache.
 void evictCollection(String roleName, Serializable id)
          Evict an entry from the second-level cache.
 void evictEntity(String entityName)
          Evict all entries from the second-level cache.
 void evictEntity(String entityName, Serializable id)
          Evict an entry from the second-level cache.
 void evictQueries()
          Evict any query result sets cached in the default query cache region.
 void evictQueries(String cacheRegion)
          Evict any query result sets cached in the named query cache region.
 Map getAllClassMetadata()
          Get all ClassMetadata as a Map from entityname String to metadata object
 Map getAllCollectionMetadata()
          Get all CollectionMetadata as a Map from role name to metadata object
 Map getAllSecondLevelCacheRegions()
           
 BatcherFactory getBatcherFactory()
           
 ClassMetadata getClassMetadata(Class persistentClass)
          Get the ClassMetadata associated with the given entity class
 ClassMetadata getClassMetadata(String entityName)
          Get the ClassMetadata associated with the given entity name
 CollectionMetadata getCollectionMetadata(String roleName)
          Get the CollectionMetadata associated with the named collection role
 CollectionPersister getCollectionPersister(String role)
          Get the persister object for a collection role
 Set getCollectionRolesByEntityParticipant(String entityName)
          Retrieves a set of all the collection roles in which the given entity is a participant, as either an index or an element.
 ConnectionProvider getConnectionProvider()
          Get the connection provider
 Session getCurrentSession()
          Obtains the current session.
 Set getDefinedFilterNames()
          Obtain a set of the names of all filters defined on this SessionFactory.
 Dialect getDialect()
          Get the SQL Dialect
 EntityNotFoundDelegate getEntityNotFoundDelegate()
           
 EntityPersister getEntityPersister(String entityName)
          Get the persister for the named entity
 EventListeners getEventListeners()
           
 FilterDefinition getFilterDefinition(String filterName)
          Obtain the definition of a filter by name.
 IdentifierGenerator getIdentifierGenerator(String rootEntityName)
          Get the identifier generator for the hierarchy
 String getIdentifierPropertyName(String className)
           
 Type getIdentifierType(String className)
           
 String[] getImplementors(String className)
          Return the names of all persistent (mapped) classes that extend or implement the given class or interface, accounting for implicit/explicit polymorphism settings and excluding mapped subclasses/joined-subclasses of other classes in the result.
 String getImportedClassName(String className)
          Get a class name, using query language imports
 Interceptor getInterceptor()
           
 NamedQueryDefinition getNamedQuery(String queryName)
           
 NamedSQLQueryDefinition getNamedSQLQuery(String queryName)
           
 QueryCache getQueryCache()
          Get the default query cache
 QueryCache getQueryCache(String cacheRegion)
          Get a particular named query cache, or the default cache
 QueryPlanCache getQueryPlanCache()
           
 Reference getReference()
           
 Type getReferencedPropertyType(String className, String propertyName)
           
 ResultSetMappingDefinition getResultSetMapping(String resultSetName)
           
 String[] getReturnAliases(String queryString)
          Get the return aliases of a query
 Type[] getReturnTypes(String queryString)
          Get the return types of a query
 Cache getSecondLevelCacheRegion(String regionName)
          Get a named second-level cache region
 Settings getSettings()
           
 SQLExceptionConverter getSQLExceptionConverter()
          Retrieves the SQLExceptionConverter in effect for this SessionFactory.
 SQLFunctionRegistry getSqlFunctionRegistry()
           
 Statistics getStatistics()
          Get the statistics for this session factory
 StatisticsImplementor getStatisticsImplementor()
          Statistics SPI
 TransactionFactory getTransactionFactory()
           
 TransactionManager getTransactionManager()
          Get the JTA transaction manager
 UpdateTimestampsCache getUpdateTimestampsCache()
          Get the cache of table update timestamps
 boolean isClosed()
          Was this SessionFactory already closed?
 Session openSession()
          Create database connection and open a Session on it.
 Session openSession(Connection connection)
          Open a Session on the given connection.
 Session openSession(Connection connection, boolean flushBeforeCompletionEnabled, boolean autoCloseSessionEnabled, ConnectionReleaseMode connectionReleaseMode)
          Open a session conforming to the given parameters.
 Session openSession(Connection connection, Interceptor sessionLocalInterceptor)
          Open a Session on the given connection, specifying an interceptor.
 Session openSession(Interceptor sessionLocalInterceptor)
          Create database connection and open a Session on it, specifying an interceptor.
 StatelessSession openStatelessSession()
          Get a new stateless session.
 StatelessSession openStatelessSession(Connection connection)
          Get a new stateless session for the given JDBC connection.
 Session openTemporarySession()
          Get a nontransactional "current" session for Hibernate EntityManager
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SessionFactoryImpl

public SessionFactoryImpl(Configuration cfg,
                          Mapping mapping,
                          Settings settings,
                          EventListeners listeners)
                   throws HibernateException
Throws:
HibernateException
Method Detail

getQueryPlanCache

public QueryPlanCache getQueryPlanCache()
Specified by:
getQueryPlanCache in interface SessionFactoryImplementor

openStatelessSession

public StatelessSession openStatelessSession()
Description copied from interface: SessionFactory
Get a new stateless session.

Specified by:
openStatelessSession in interface SessionFactory

openStatelessSession

public StatelessSession openStatelessSession(Connection connection)
Description copied from interface: SessionFactory
Get a new stateless session for the given JDBC connection.

Specified by:
openStatelessSession in interface SessionFactory

openSession

public Session openSession(Connection connection,
                           Interceptor sessionLocalInterceptor)
Description copied from interface: SessionFactory
Open a Session on the given connection, specifying an interceptor.

Note that the second-level cache will be disabled if you supply a JDBC connection. Hibernate will not be able to track any statements you might have executed in the same transaction. Consider implementing your own ConnectionProvider.

Specified by:
openSession in interface SessionFactory
Parameters:
connection - a connection provided by the application.
sessionLocalInterceptor - a session-scoped interceptor
Returns:
Session

openSession

public Session openSession(Interceptor sessionLocalInterceptor)
                    throws HibernateException
Description copied from interface: SessionFactory
Create database connection and open a Session on it, specifying an interceptor.

Specified by:
openSession in interface SessionFactory
Parameters:
sessionLocalInterceptor - a session-scoped interceptor
Returns:
Session
Throws:
HibernateException

openSession

public Session openSession(Connection connection)
Description copied from interface: SessionFactory
Open a Session on the given connection.

Note that the second-level cache will be disabled if you supply a JDBC connection. Hibernate will not be able to track any statements you might have executed in the same transaction. Consider implementing your own ConnectionProvider.

Specified by:
openSession in interface SessionFactory
Parameters:
connection - a connection provided by the application.
Returns:
Session

openSession

public Session openSession()
                    throws HibernateException
Description copied from interface: SessionFactory
Create database connection and open a Session on it.

Specified by:
openSession in interface SessionFactory
Returns:
Session
Throws:
HibernateException

openTemporarySession

public Session openTemporarySession()
                             throws HibernateException
Description copied from interface: SessionFactoryImplementor
Get a nontransactional "current" session for Hibernate EntityManager

Specified by:
openTemporarySession in interface SessionFactoryImplementor
Throws:
HibernateException

openSession

public Session openSession(Connection connection,
                           boolean flushBeforeCompletionEnabled,
                           boolean autoCloseSessionEnabled,
                           ConnectionReleaseMode connectionReleaseMode)
                    throws HibernateException
Description copied from interface: SessionFactoryImplementor
Open a session conforming to the given parameters. Used mainly by JTASessionContext for current session processing.

Specified by:
openSession in interface SessionFactoryImplementor
Parameters:
connection - The external jdbc connection to use, if one (i.e., optional).
flushBeforeCompletionEnabled - Should the session be auto-flushed prior to transaction completion?
autoCloseSessionEnabled - Should the session be auto-closed after transaction completion?
connectionReleaseMode - The release mode for managed jdbc connections.
Returns:
An appropriate session.
Throws:
HibernateException

getCurrentSession

public Session getCurrentSession()
                          throws HibernateException
Description copied from interface: SessionFactory
Obtains the current session. The definition of what exactly "current" means controlled by the CurrentSessionContext impl configured for use.

Note that for backwards compatibility, if a CurrentSessionContext is not configured but a JTA TransactionManagerLookup is configured this will default to the JTASessionContext impl.

Specified by:
getCurrentSession in interface SessionFactory
Returns:
The current session.
Throws:
HibernateException - Indicates an issue locating a suitable current session.

getEntityPersister

public EntityPersister getEntityPersister(String entityName)
                                   throws MappingException
Description copied from interface: SessionFactoryImplementor
Get the persister for the named entity

Specified by:
getEntityPersister in interface SessionFactoryImplementor
Throws:
MappingException

getCollectionPersister

public CollectionPersister getCollectionPersister(String role)
                                           throws MappingException
Description copied from interface: SessionFactoryImplementor
Get the persister object for a collection role

Specified by:
getCollectionPersister in interface SessionFactoryImplementor
Throws:
MappingException

getSettings

public Settings getSettings()
Specified by:
getSettings in interface SessionFactoryImplementor

getDialect

public Dialect getDialect()
Description copied from interface: SessionFactoryImplementor
Get the SQL Dialect

Specified by:
getDialect in interface SessionFactoryImplementor

getInterceptor

public Interceptor getInterceptor()
Specified by:
getInterceptor in interface SessionFactoryImplementor

getTransactionFactory

public TransactionFactory getTransactionFactory()

getTransactionManager

public TransactionManager getTransactionManager()
Description copied from interface: SessionFactoryImplementor
Get the JTA transaction manager

Specified by:
getTransactionManager in interface SessionFactoryImplementor

getSQLExceptionConverter

public SQLExceptionConverter getSQLExceptionConverter()
Description copied from interface: SessionFactoryImplementor
Retrieves the SQLExceptionConverter in effect for this SessionFactory.

Specified by:
getSQLExceptionConverter in interface SessionFactoryImplementor
Returns:
The SQLExceptionConverter for this SessionFactory.

getCollectionRolesByEntityParticipant

public Set getCollectionRolesByEntityParticipant(String entityName)
Description copied from interface: SessionFactoryImplementor
Retrieves a set of all the collection roles in which the given entity is a participant, as either an index or an element.

Specified by:
getCollectionRolesByEntityParticipant in interface SessionFactoryImplementor
Parameters:
entityName - The entity name for which to get the collection roles.
Returns:
set of all the collection roles in which the given entityName participates.

getReference

public Reference getReference()
                       throws NamingException
Specified by:
getReference in interface Referenceable
Throws:
NamingException

getNamedQuery

public NamedQueryDefinition getNamedQuery(String queryName)
Specified by:
getNamedQuery in interface SessionFactoryImplementor

getNamedSQLQuery

public NamedSQLQueryDefinition getNamedSQLQuery(String queryName)
Specified by:
getNamedSQLQuery in interface SessionFactoryImplementor

getResultSetMapping

public ResultSetMappingDefinition getResultSetMapping(String resultSetName)
Specified by:
getResultSetMapping in interface SessionFactoryImplementor

getIdentifierType

public Type getIdentifierType(String className)
                       throws MappingException
Specified by:
getIdentifierType in interface Mapping
Throws:
MappingException

getIdentifierPropertyName

public String getIdentifierPropertyName(String className)
                                 throws MappingException
Specified by:
getIdentifierPropertyName in interface Mapping
Throws:
MappingException

getReturnTypes

public Type[] getReturnTypes(String queryString)
                      throws HibernateException
Description copied from interface: SessionFactoryImplementor
Get the return types of a query

Specified by:
getReturnTypes in interface SessionFactoryImplementor
Throws:
HibernateException

getReturnAliases

public String[] getReturnAliases(String queryString)
                          throws HibernateException
Description copied from interface: SessionFactoryImplementor
Get the return aliases of a query

Specified by:
getReturnAliases in interface SessionFactoryImplementor
Throws:
HibernateException

getClassMetadata

public ClassMetadata getClassMetadata(Class persistentClass)
                               throws HibernateException
Description copied from interface: SessionFactory
Get the ClassMetadata associated with the given entity class

Specified by:
getClassMetadata in interface SessionFactory
Throws:
HibernateException
See Also:
ClassMetadata

getCollectionMetadata

public CollectionMetadata getCollectionMetadata(String roleName)
                                         throws HibernateException
Description copied from interface: SessionFactory
Get the CollectionMetadata associated with the named collection role

Specified by:
getCollectionMetadata in interface SessionFactory
Throws:
HibernateException
See Also:
CollectionMetadata

getClassMetadata

public ClassMetadata getClassMetadata(String entityName)
                               throws HibernateException
Description copied from interface: SessionFactory
Get the ClassMetadata associated with the given entity name

Specified by:
getClassMetadata in interface SessionFactory
Throws:
HibernateException
See Also:
ClassMetadata

getImplementors

public String[] getImplementors(String className)
                         throws MappingException
Return the names of all persistent (mapped) classes that extend or implement the given class or interface, accounting for implicit/explicit polymorphism settings and excluding mapped subclasses/joined-subclasses of other classes in the result.

Specified by:
getImplementors in interface SessionFactoryImplementor
Throws:
MappingException

getImportedClassName

public String getImportedClassName(String className)
Description copied from interface: SessionFactoryImplementor
Get a class name, using query language imports

Specified by:
getImportedClassName in interface SessionFactoryImplementor

getAllClassMetadata

public Map getAllClassMetadata()
                        throws HibernateException
Description copied from interface: SessionFactory
Get all ClassMetadata as a Map from entityname String to metadata object

Specified by:
getAllClassMetadata in interface SessionFactory
Returns:
a map from String an entity name to ClassMetaData
Throws:
HibernateException
See Also:
ClassMetadata

getAllCollectionMetadata

public Map getAllCollectionMetadata()
                             throws HibernateException
Description copied from interface: SessionFactory
Get all CollectionMetadata as a Map from role name to metadata object

Specified by:
getAllCollectionMetadata in interface SessionFactory
Returns:
a map from String to CollectionMetadata
Throws:
HibernateException
See Also:
CollectionMetadata

close

public void close()
           throws HibernateException
Closes the session factory, releasing all held resources.
  1. cleans up used cache regions and "stops" the cache provider.
  2. close the JDBC connection
  3. remove the JNDI binding
Note: Be aware that the sessionfactory instance still can be a "heavy" object memory wise after close() has been called. Thus it is important to not keep referencing the instance to let the garbage collector release the memory.

Specified by:
close in interface SessionFactory
Throws:
HibernateException

evictEntity

public void evictEntity(String entityName,
                        Serializable id)
                 throws HibernateException
Description copied from interface: SessionFactory
Evict an entry from the second-level cache. This method occurs outside of any transaction; it performs an immediate "hard" remove, so does not respect any transaction isolation semantics of the usage strategy. Use with care.

Specified by:
evictEntity in interface SessionFactory
Throws:
HibernateException

evictEntity

public void evictEntity(String entityName)
                 throws HibernateException
Description copied from interface: SessionFactory
Evict all entries from the second-level cache. This method occurs outside of any transaction; it performs an immediate "hard" remove, so does not respect any transaction isolation semantics of the usage strategy. Use with care.

Specified by:
evictEntity in interface SessionFactory
Throws:
HibernateException

evict

public void evict(Class persistentClass,
                  Serializable id)
           throws HibernateException
Description copied from interface: SessionFactory
Evict an entry from the second-level cache. This method occurs outside of any transaction; it performs an immediate "hard" remove, so does not respect any transaction isolation semantics of the usage strategy. Use with care.

Specified by:
evict in interface SessionFactory
Throws:
HibernateException

evict

public void evict(Class persistentClass)
           throws HibernateException
Description copied from interface: SessionFactory
Evict all entries from the second-level cache. This method occurs outside of any transaction; it performs an immediate "hard" remove, so does not respect any transaction isolation semantics of the usage strategy. Use with care.

Specified by:
evict in interface SessionFactory
Throws:
HibernateException

evictCollection

public void evictCollection(String roleName,
                            Serializable id)
                     throws HibernateException
Description copied from interface: SessionFactory
Evict an entry from the second-level cache. This method occurs outside of any transaction; it performs an immediate "hard" remove, so does not respect any transaction isolation semantics of the usage strategy. Use with care.

Specified by:
evictCollection in interface SessionFactory
Throws:
HibernateException

evictCollection

public void evictCollection(String roleName)
                     throws HibernateException
Description copied from interface: SessionFactory
Evict all entries from the second-level cache. This method occurs outside of any transaction; it performs an immediate "hard" remove, so does not respect any transaction isolation semantics of the usage strategy. Use with care.

Specified by:
evictCollection in interface SessionFactory
Throws:
HibernateException

getReferencedPropertyType

public Type getReferencedPropertyType(String className,
                                      String propertyName)
                               throws MappingException
Specified by:
getReferencedPropertyType in interface Mapping
Throws:
MappingException

getConnectionProvider

public ConnectionProvider getConnectionProvider()
Description copied from interface: SessionFactoryImplementor
Get the connection provider

Specified by:
getConnectionProvider in interface SessionFactoryImplementor

getUpdateTimestampsCache

public UpdateTimestampsCache getUpdateTimestampsCache()
Description copied from interface: SessionFactoryImplementor
Get the cache of table update timestamps

Specified by:
getUpdateTimestampsCache in interface SessionFactoryImplementor

getQueryCache

public QueryCache getQueryCache()
Description copied from interface: SessionFactoryImplementor
Get the default query cache

Specified by:
getQueryCache in interface SessionFactoryImplementor

getQueryCache

public QueryCache getQueryCache(String cacheRegion)
                         throws HibernateException
Description copied from interface: SessionFactoryImplementor
Get a particular named query cache, or the default cache

Specified by:
getQueryCache in interface SessionFactoryImplementor
Parameters:
cacheRegion - the name of the cache region, or null for the default query cache
Returns:
the existing cache, or a newly created cache if none by that region name
Throws:
HibernateException

getSecondLevelCacheRegion

public Cache getSecondLevelCacheRegion(String regionName)
Description copied from interface: SessionFactoryImplementor
Get a named second-level cache region

Specified by:
getSecondLevelCacheRegion in interface SessionFactoryImplementor

getAllSecondLevelCacheRegions

public Map getAllSecondLevelCacheRegions()
Specified by:
getAllSecondLevelCacheRegions in interface SessionFactoryImplementor

isClosed

public boolean isClosed()
Description copied from interface: SessionFactory
Was this SessionFactory already closed?

Specified by:
isClosed in interface SessionFactory

getStatistics

public Statistics getStatistics()
Description copied from interface: SessionFactory
Get the statistics for this session factory

Specified by:
getStatistics in interface SessionFactory

getStatisticsImplementor

public StatisticsImplementor getStatisticsImplementor()
Description copied from interface: SessionFactoryImplementor
Statistics SPI

Specified by:
getStatisticsImplementor in interface SessionFactoryImplementor

evictQueries

public void evictQueries()
                  throws HibernateException
Description copied from interface: SessionFactory
Evict any query result sets cached in the default query cache region.

Specified by:
evictQueries in interface SessionFactory
Throws:
HibernateException

evictQueries

public void evictQueries(String cacheRegion)
                  throws HibernateException
Description copied from interface: SessionFactory
Evict any query result sets cached in the named query cache region.

Specified by:
evictQueries in interface SessionFactory
Throws:
HibernateException

getFilterDefinition

public FilterDefinition getFilterDefinition(String filterName)
                                     throws HibernateException
Description copied from interface: SessionFactory
Obtain the definition of a filter by name.

Specified by:
getFilterDefinition in interface SessionFactory
Parameters:
filterName - The name of the filter for which to obtain the definition.
Returns:
The filter definition.
Throws:
HibernateException - If no filter defined with the given name.

getDefinedFilterNames

public Set getDefinedFilterNames()
Description copied from interface: SessionFactory
Obtain a set of the names of all filters defined on this SessionFactory.

Specified by:
getDefinedFilterNames in interface SessionFactory
Returns:
The set of filter names.

getBatcherFactory

public BatcherFactory getBatcherFactory()

getIdentifierGenerator

public IdentifierGenerator getIdentifierGenerator(String rootEntityName)
Description copied from interface: SessionFactoryImplementor
Get the identifier generator for the hierarchy

Specified by:
getIdentifierGenerator in interface SessionFactoryImplementor

getEventListeners

public EventListeners getEventListeners()

getEntityNotFoundDelegate

public EntityNotFoundDelegate getEntityNotFoundDelegate()
Specified by:
getEntityNotFoundDelegate in interface SessionFactoryImplementor

getSqlFunctionRegistry

public SQLFunctionRegistry getSqlFunctionRegistry()
Specified by:
getSqlFunctionRegistry in interface SessionFactoryImplementor