站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > Hibernate 2.1.8 正式版 API 英文文档

SessionFactoryImpl (Hibernate API Documentation) - Hibernate 2.1.8 正式版 API 英文文档


net.sf.hibernate.impl
Class SessionFactoryImpl

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

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, ClassPersister, CollectionPersister, Serialized Form

Constructor Summary
SessionFactoryImpl(Configuration cfg, Settings settings)
           
 
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 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 Class to metadata object
 Map getAllCollectionMetadata()
          Get all CollectionMetadata as a Map from role name to metadata object
 ClassMetadata getClassMetadata(Class persistentClass)
          Get the ClassMetadata associated with the given entity class
 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
 ConnectionProvider getConnectionProvider()
          Get the connection provider
 String getDefaultSchema()
          Get the database schema specified in hibernate.default_schema
 Dialect getDialect()
          Get the SQL Dialect
 FilterTranslator getFilter(String filterString, String collectionRole, boolean scalar)
           
 String getIdentifierPropertyName(Class ObjectClass)
           
 Type getIdentifierType(Class ObjectClass)
           
 String[] getImplementors(Class clazz)
          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
 int getJdbcBatchSize()
          Get the JDBC batch size
 Integer getJdbcFetchSize()
          Get the JDBC fetch size
 Integer getMaximumFetchDepth()
          Get the maxmimum depth of outer join fetching
 String getNamedQuery(String queryName)
           
 net.sf.hibernate.impl.SessionFactoryImpl.InternalNamedSQLQuery getNamedSQLQuery(String queryName)
           
 ClassPersister getPersister(Class theClass)
          Get the persister for a class
 ClassPersister getPersister(String className)
          Get the persister for the named class
 Type getPropertyType(Class persistentClass, String propertyName)
           
 QueryTranslator[] getQuery(String queryString, boolean shallow)
           
 QueryCache getQueryCache()
          Get the default query cache
 QueryCache getQueryCache(String cacheRegion)
          Get a particular named query cache, or the default cache
 Reference getReference()
           
 Type[] getReturnTypes(String queryString)
          Get the return types of a query
 SQLExceptionConverter getSQLExceptionConverter()
          Retrieves the SQLExceptionConverter in effect for this SessionFactory.
 TransactionFactory getTransactionFactory()
           
 TransactionManager getTransactionManager()
          Get the JTA transaction manager
 UpdateTimestampsCache getUpdateTimestampsCache()
           
 boolean isGetGeneratedKeysEnabled()
          Is PreparedStatement.getGeneratedKeys supported?
 boolean isJdbcBatchUpdateEnabled()
           
 boolean isJdbcBatchVersionedData()
          Should versioned data be included in jdbc batches?
 boolean isOuterJoinedFetchEnabled()
          Is outerjoin fetching enabled?
 boolean isQueryCacheEnabled()
          If query caching enabled?
 boolean isScrollableResultSetsEnabled()
          Are scrollable ResultSets supported?
 boolean isShowSqlEnabled()
          Are we logging SQL to the console?
 boolean isWrapResultSetsEnabled()
          Should Hibernate wrap result sets in order to speed up column name lookups?
 Databinder openDatabinder()
          Create a new databinder.
 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, Interceptor interceptor)
          Open a Session on the given connection, specifying an interceptor.
 Session openSession(Interceptor interceptor)
          Create database connection and open a Session on it, specifying an interceptor.
 
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,
                          Settings settings)
                   throws HibernateException
Method Detail

getQuery

public QueryTranslator[] getQuery(String queryString,
                                  boolean shallow)
                           throws QueryException,
                                  MappingException
Throws:
QueryException
MappingException

getFilter

public FilterTranslator getFilter(String filterString,
                                  String collectionRole,
                                  boolean scalar)
                           throws QueryException,
                                  MappingException
Throws:
QueryException
MappingException

openSession

public Session openSession(Connection connection,
                           Interceptor interceptor)
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.
interceptor - a session-scoped interceptor
Returns:
Session

openSession

public Session openSession(Interceptor interceptor)
                    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:
interceptor - 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

getPersister

public ClassPersister getPersister(String className)
                            throws MappingException
Description copied from interface: SessionFactoryImplementor
Get the persister for the named class

Specified by:
getPersister in interface SessionFactoryImplementor
Throws:
MappingException

getPersister

public ClassPersister getPersister(Class theClass)
                            throws MappingException
Description copied from interface: SessionFactoryImplementor
Get the persister for a class

Specified by:
getPersister 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

openDatabinder

public Databinder openDatabinder()
                          throws HibernateException
Description copied from interface: SessionFactory
Create a new databinder.

Specified by:
openDatabinder in interface SessionFactory
Returns:
Databinder
Throws:
HibernateException

getDialect

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

Specified by:
getDialect 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: SessionFactory
Retrieves the SQLExceptionConverter in effect for this SessionFactory.

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

getReference

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

isJdbcBatchUpdateEnabled

public boolean isJdbcBatchUpdateEnabled()

getJdbcBatchSize

public int getJdbcBatchSize()
Description copied from interface: SessionFactoryImplementor
Get the JDBC batch size

Specified by:
getJdbcBatchSize in interface SessionFactoryImplementor

isScrollableResultSetsEnabled

public boolean isScrollableResultSetsEnabled()
Description copied from interface: SessionFactoryImplementor
Are scrollable ResultSets supported?

Specified by:
isScrollableResultSetsEnabled in interface SessionFactoryImplementor

isGetGeneratedKeysEnabled

public boolean isGetGeneratedKeysEnabled()
Description copied from interface: SessionFactoryImplementor
Is PreparedStatement.getGeneratedKeys supported?

Specified by:
isGetGeneratedKeysEnabled in interface SessionFactoryImplementor

isOuterJoinedFetchEnabled

public boolean isOuterJoinedFetchEnabled()
Description copied from interface: SessionFactoryImplementor
Is outerjoin fetching enabled?

Specified by:
isOuterJoinedFetchEnabled in interface SessionFactoryImplementor

getNamedQuery

public String getNamedQuery(String queryName)

getNamedSQLQuery

public net.sf.hibernate.impl.SessionFactoryImpl.InternalNamedSQLQuery getNamedSQLQuery(String queryName)

getIdentifierType

public Type getIdentifierType(Class ObjectClass)
                       throws MappingException
Specified by:
getIdentifierType in interface Mapping
Throws:
MappingException

getIdentifierPropertyName

public String getIdentifierPropertyName(Class ObjectClass)
                                 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

getDefaultSchema

public String getDefaultSchema()
Description copied from interface: SessionFactoryImplementor
Get the database schema specified in hibernate.default_schema

Specified by:
getDefaultSchema in interface SessionFactoryImplementor

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

getImplementors

public String[] getImplementors(Class clazz)
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

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 Class to metadata object

Specified by:
getAllClassMetadata in interface SessionFactory
Returns:
a map from Class 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

Specified by:
close 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

getMaximumFetchDepth

public Integer getMaximumFetchDepth()
Description copied from interface: SessionFactoryImplementor
Get the maxmimum depth of outer join fetching

Specified by:
getMaximumFetchDepth in interface SessionFactoryImplementor

getPropertyType

public Type getPropertyType(Class persistentClass,
                            String propertyName)
                     throws MappingException
Specified by:
getPropertyType in interface Mapping
Throws:
MappingException

isShowSqlEnabled

public boolean isShowSqlEnabled()
Description copied from interface: SessionFactoryImplementor
Are we logging SQL to the console?

Specified by:
isShowSqlEnabled in interface SessionFactoryImplementor

getJdbcFetchSize

public Integer getJdbcFetchSize()
Description copied from interface: SessionFactoryImplementor
Get the JDBC fetch size

Specified by:
getJdbcFetchSize in interface SessionFactoryImplementor

getConnectionProvider

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

Specified by:
getConnectionProvider in interface SessionFactoryImplementor

getUpdateTimestampsCache

public UpdateTimestampsCache getUpdateTimestampsCache()

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

isQueryCacheEnabled

public boolean isQueryCacheEnabled()
Description copied from interface: SessionFactoryImplementor
If query caching enabled?

Specified by:
isQueryCacheEnabled in interface SessionFactoryImplementor

isJdbcBatchVersionedData

public boolean isJdbcBatchVersionedData()
Description copied from interface: SessionFactoryImplementor
Should versioned data be included in jdbc batches?

Specified by:
isJdbcBatchVersionedData in interface SessionFactoryImplementor
Returns:
true if versioned data should be batched.

isWrapResultSetsEnabled

public boolean isWrapResultSetsEnabled()
Description copied from interface: SessionFactoryImplementor
Should Hibernate wrap result sets in order to speed up column name lookups?

Specified by:
isWrapResultSetsEnabled in interface SessionFactoryImplementor
Returns:
true if result sets should get wrapped; false otherwise.

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