Methods Summary |
---|
private org.hibernate.context.CurrentSessionContext | buildCurrentSessionContext()
String impl = properties.getProperty( Environment.CURRENT_SESSION_CONTEXT_CLASS );
// for backward-compatability
if ( impl == null && transactionManager != null ) {
impl = "jta";
}
if ( impl == null ) {
return null;
}
else if ( "jta".equals( impl ) ) {
if ( settings.getTransactionFactory().areCallbacksLocalToHibernateTransactions() ) {
log.warn( "JTASessionContext being used with JDBCTransactionFactory; auto-flush will not operate correctly with getCurrentSession()" );
}
return new JTASessionContext( this );
}
else if ( "thread".equals( impl ) ) {
return new ThreadLocalSessionContext( this );
}
else if ( "managed".equals( impl ) ) {
return new ManagedSessionContext( this );
}
else {
try {
Class implClass = ReflectHelper.classForName( impl );
return ( CurrentSessionContext ) implClass
.getConstructor( new Class[] { SessionFactoryImplementor.class } )
.newInstance( new Object[] { this } );
}
catch( Throwable t ) {
log.error( "Unable to construct current session context [" + impl + "]", t );
return null;
}
}
|
private java.util.Map | checkNamedQueries()
Map errors = new HashMap();
// Check named HQL queries
log.debug("Checking " + namedQueries.size() + " named HQL queries");
Iterator itr = namedQueries.entrySet().iterator();
while ( itr.hasNext() ) {
final Map.Entry entry = ( Map.Entry ) itr.next();
final String queryName = ( String ) entry.getKey();
final NamedQueryDefinition qd = ( NamedQueryDefinition ) entry.getValue();
// this will throw an error if there's something wrong.
try {
log.debug("Checking named query: " + queryName);
//TODO: BUG! this currently fails for named queries for non-POJO entities
queryPlanCache.getHQLQueryPlan( qd.getQueryString(), false, CollectionHelper.EMPTY_MAP );
}
catch ( QueryException e ) {
errors.put( queryName, e );
}
catch ( MappingException e ) {
errors.put( queryName, e );
}
}
log.debug("Checking " + namedSqlQueries.size() + " named SQL queries");
itr = namedSqlQueries.entrySet().iterator();
while ( itr.hasNext() ) {
final Map.Entry entry = ( Map.Entry ) itr.next();
final String queryName = ( String ) entry.getKey();
final NamedSQLQueryDefinition qd = ( NamedSQLQueryDefinition ) entry.getValue();
// this will throw an error if there's something wrong.
try {
log.debug("Checking named SQL query: " + queryName);
// TODO : would be really nice to cache the spec on the query-def so as to not have to re-calc the hash;
// currently not doable though because of the resultset-ref stuff...
NativeSQLQuerySpecification spec = null;
if ( qd.getResultSetRef() != null ) {
ResultSetMappingDefinition definition = ( ResultSetMappingDefinition )
sqlResultSetMappings.get( qd.getResultSetRef() );
if ( definition == null ) {
throw new MappingException(
"Unable to find resultset-ref definition: " + qd.getResultSetRef()
);
}
spec = new NativeSQLQuerySpecification(
qd.getQueryString(),
definition.getQueryReturns(),
qd.getQuerySpaces()
);
}
else
{
spec = new NativeSQLQuerySpecification(
qd.getQueryString(),
qd.getQueryReturns(),
qd.getQuerySpaces()
);
}
queryPlanCache.getNativeSQLQueryPlan( spec );
}
catch ( QueryException e ) {
errors.put( queryName, e );
}
catch ( MappingException e ) {
errors.put( queryName, e );
}
}
return errors;
|
public void | close()Closes the session factory, releasing all held resources.
- cleans up used cache regions and "stops" the cache provider.
- close the JDBC connection
- 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.
log.info("closing");
isClosed = true;
Iterator iter = entityPersisters.values().iterator();
while ( iter.hasNext() ) {
EntityPersister p = (EntityPersister) iter.next();
if ( p.hasCache() ) {
p.getCache().destroy();
}
}
iter = collectionPersisters.values().iterator();
while ( iter.hasNext() ) {
CollectionPersister p = (CollectionPersister) iter.next();
if ( p.hasCache() ) {
p.getCache().destroy();
}
}
if ( settings.isQueryCacheEnabled() ) {
queryCache.destroy();
iter = queryCaches.values().iterator();
while ( iter.hasNext() ) {
QueryCache cache = (QueryCache) iter.next();
cache.destroy();
}
updateTimestampsCache.destroy();
}
settings.getCacheProvider().stop();
try {
settings.getConnectionProvider().close();
}
finally {
SessionFactoryObjectFactory.removeInstance(uuid, name, properties);
}
if ( settings.isAutoDropSchema() ) {
schemaExport.drop( false, true );
}
|
static org.hibernate.impl.SessionFactoryImpl | deserialize(java.io.ObjectInputStream ois)Custom deserialization hook used during Session deserialization.
String uuid = ois.readUTF();
boolean isNamed = ois.readBoolean();
String name = null;
if ( isNamed ) {
name = ois.readUTF();
}
Object result = SessionFactoryObjectFactory.getInstance( uuid );
if ( result == null ) {
log.trace( "could not locate session factory by uuid [" + uuid + "] during session deserialization; trying name" );
if ( isNamed ) {
result = SessionFactoryObjectFactory.getNamedInstance( name );
}
if ( result == null ) {
throw new InvalidObjectException( "could not resolve session factory during session deserialization [uuid=" + uuid + ", name=" + name + "]" );
}
}
return ( SessionFactoryImpl ) result;
|
public void | evict(java.lang.Class persistentClass, java.io.Serializable id)
EntityPersister p = getEntityPersister( persistentClass.getName() );
if ( p.hasCache() ) {
if ( log.isDebugEnabled() ) {
log.debug( "evicting second-level cache: " + MessageHelper.infoString(p, id, this) );
}
CacheKey cacheKey = new CacheKey( id, p.getIdentifierType(), p.getRootEntityName(), EntityMode.POJO, this );
p.getCache().remove( cacheKey );
}
|
public void | evict(java.lang.Class persistentClass)
EntityPersister p = getEntityPersister( persistentClass.getName() );
if ( p.hasCache() ) {
if ( log.isDebugEnabled() ) {
log.debug( "evicting second-level cache: " + p.getEntityName() );
}
p.getCache().clear();
}
|
public void | evictCollection(java.lang.String roleName, java.io.Serializable id)
CollectionPersister p = getCollectionPersister(roleName);
if ( p.hasCache() ) {
if ( log.isDebugEnabled() ) {
log.debug( "evicting second-level cache: " + MessageHelper.collectionInfoString(p, id, this) );
}
CacheKey cacheKey = new CacheKey( id, p.getKeyType(), p.getRole(), EntityMode.POJO, this );
p.getCache().remove( cacheKey );
}
|
public void | evictCollection(java.lang.String roleName)
CollectionPersister p = getCollectionPersister(roleName);
if ( p.hasCache() ) {
if ( log.isDebugEnabled() ) {
log.debug( "evicting second-level cache: " + p.getRole() );
}
p.getCache().clear();
}
|
public void | evictEntity(java.lang.String entityName, java.io.Serializable id)
EntityPersister p = getEntityPersister(entityName);
if ( p.hasCache() ) {
if ( log.isDebugEnabled() ) {
log.debug( "evicting second-level cache: " + MessageHelper.infoString(p, id, this) );
}
CacheKey cacheKey = new CacheKey( id, p.getIdentifierType(), p.getRootEntityName(), EntityMode.POJO, this );
p.getCache().remove( cacheKey );
}
|
public void | evictEntity(java.lang.String entityName)
EntityPersister p = getEntityPersister(entityName);
if ( p.hasCache() ) {
if ( log.isDebugEnabled() ) {
log.debug( "evicting second-level cache: " + p.getEntityName() );
}
p.getCache().clear();
}
|
public void | evictQueries()
if ( settings.isQueryCacheEnabled() ) {
queryCache.clear();
}
|
public void | evictQueries(java.lang.String cacheRegion)
if (cacheRegion==null) {
throw new NullPointerException("use the zero-argument form to evict the default query cache");
}
else {
synchronized (allCacheRegions) {
if ( settings.isQueryCacheEnabled() ) {
QueryCache currentQueryCache = (QueryCache) queryCaches.get(cacheRegion);
if ( currentQueryCache != null ) {
currentQueryCache.clear();
}
}
}
}
|
public java.util.Map | getAllClassMetadata()
return classMetadata;
|
public java.util.Map | getAllCollectionMetadata()
return collectionMetadata;
|
public java.util.Map | getAllSecondLevelCacheRegions()
synchronized (allCacheRegions) {
return new HashMap(allCacheRegions);
}
|
public org.hibernate.jdbc.BatcherFactory | getBatcherFactory()
return settings.getBatcherFactory();
|
public org.hibernate.metadata.ClassMetadata | getClassMetadata(java.lang.Class persistentClass)
return getClassMetadata( persistentClass.getName() );
|
public org.hibernate.metadata.ClassMetadata | getClassMetadata(java.lang.String entityName)
return (ClassMetadata) classMetadata.get(entityName);
|
public org.hibernate.metadata.CollectionMetadata | getCollectionMetadata(java.lang.String roleName)
return (CollectionMetadata) collectionMetadata.get(roleName);
|
public org.hibernate.persister.collection.CollectionPersister | getCollectionPersister(java.lang.String role)
CollectionPersister result = (CollectionPersister) collectionPersisters.get(role);
if (result==null) {
throw new MappingException( "Unknown collection role: " + role );
}
return result;
|
public java.util.Set | getCollectionRolesByEntityParticipant(java.lang.String entityName)
return ( Set ) collectionRolesByEntityParticipant.get( entityName );
|
public org.hibernate.connection.ConnectionProvider | getConnectionProvider()
return settings.getConnectionProvider();
|
public org.hibernate.classic.Session | getCurrentSession()
if ( currentSessionContext == null ) {
throw new HibernateException( "No CurrentSessionContext configured!" );
}
return currentSessionContext.currentSession();
|
public java.util.Set | getDefinedFilterNames()
return filters.keySet();
|
public org.hibernate.dialect.Dialect | getDialect()
return settings.getDialect();
|
public org.hibernate.proxy.EntityNotFoundDelegate | getEntityNotFoundDelegate()
return entityNotFoundDelegate;
|
public org.hibernate.persister.entity.EntityPersister | getEntityPersister(java.lang.String entityName)
EntityPersister result = (EntityPersister) entityPersisters.get(entityName);
if (result==null) {
throw new MappingException( "Unknown entity: " + entityName );
}
return result;
|
public org.hibernate.event.EventListeners | getEventListeners()
return eventListeners;
|
public org.hibernate.engine.FilterDefinition | getFilterDefinition(java.lang.String filterName)
FilterDefinition def = ( FilterDefinition ) filters.get( filterName );
if ( def == null ) {
throw new HibernateException( "No such filter configured [" + filterName + "]" );
}
return def;
|
public org.hibernate.id.IdentifierGenerator | getIdentifierGenerator(java.lang.String rootEntityName)
return (IdentifierGenerator) identifierGenerators.get(rootEntityName);
|
public java.lang.String | getIdentifierPropertyName(java.lang.String className)
return getEntityPersister(className).getIdentifierPropertyName();
|
public org.hibernate.type.Type | getIdentifierType(java.lang.String className)
return getEntityPersister(className).getIdentifierType();
|
public java.lang.String[] | getImplementors(java.lang.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.
final Class clazz;
try {
clazz = ReflectHelper.classForName(className);
}
catch (ClassNotFoundException cnfe) {
return new String[] { className }; //for a dynamic-class
}
ArrayList results = new ArrayList();
Iterator iter = entityPersisters.values().iterator();
while ( iter.hasNext() ) {
//test this entity to see if we must query it
EntityPersister testPersister = (EntityPersister) iter.next();
if ( testPersister instanceof Queryable ) {
Queryable testQueryable = (Queryable) testPersister;
String testClassName = testQueryable.getEntityName();
boolean isMappedClass = className.equals(testClassName);
if ( testQueryable.isExplicitPolymorphism() ) {
if ( isMappedClass ) {
return new String[] {className}; //NOTE EARLY EXIT
}
}
else {
if (isMappedClass) {
results.add(testClassName);
}
else {
final Class mappedClass = testQueryable.getMappedClass( EntityMode.POJO );
if ( mappedClass!=null && clazz.isAssignableFrom( mappedClass ) ) {
final boolean assignableSuperclass;
if ( testQueryable.isInherited() ) {
Class mappedSuperclass = getEntityPersister( testQueryable.getMappedSuperclass() ).getMappedClass( EntityMode.POJO);
assignableSuperclass = clazz.isAssignableFrom(mappedSuperclass);
}
else {
assignableSuperclass = false;
}
if ( !assignableSuperclass ) {
results.add( testClassName );
}
}
}
}
}
}
return (String[]) results.toArray( new String[ results.size() ] );
|
public java.lang.String | getImportedClassName(java.lang.String className)
String result = (String) imports.get(className);
if (result==null) {
try {
ReflectHelper.classForName(className);
return className;
}
catch (ClassNotFoundException cnfe) {
return null;
}
}
else {
return result;
}
|
public org.hibernate.Interceptor | getInterceptor()
return interceptor;
|
public org.hibernate.engine.NamedQueryDefinition | getNamedQuery(java.lang.String queryName)
return (NamedQueryDefinition) namedQueries.get(queryName);
|
public org.hibernate.engine.NamedSQLQueryDefinition | getNamedSQLQuery(java.lang.String queryName)
return (NamedSQLQueryDefinition) namedSqlQueries.get(queryName);
|
public org.hibernate.cache.QueryCache | getQueryCache()
return queryCache;
|
public org.hibernate.cache.QueryCache | getQueryCache(java.lang.String cacheRegion)
if (cacheRegion==null) {
return getQueryCache();
}
if ( !settings.isQueryCacheEnabled() ) {
return null;
}
synchronized (allCacheRegions) {
QueryCache currentQueryCache = (QueryCache) queryCaches.get(cacheRegion);
if (currentQueryCache==null) {
currentQueryCache = settings.getQueryCacheFactory()
.getQueryCache(cacheRegion, updateTimestampsCache, settings, properties);
queryCaches.put(cacheRegion, currentQueryCache);
allCacheRegions.put( currentQueryCache.getRegionName(), currentQueryCache.getCache() );
}
return currentQueryCache;
}
|
public org.hibernate.engine.query.QueryPlanCache | getQueryPlanCache()
return queryPlanCache;
|
public javax.naming.Reference | getReference()
log.debug("Returning a Reference to the SessionFactory");
return new Reference(
SessionFactoryImpl.class.getName(),
new StringRefAddr("uuid", uuid),
SessionFactoryObjectFactory.class.getName(),
null
);
|
public org.hibernate.type.Type | getReferencedPropertyType(java.lang.String className, java.lang.String propertyName)
return getEntityPersister(className).getPropertyType(propertyName);
|
public org.hibernate.engine.ResultSetMappingDefinition | getResultSetMapping(java.lang.String resultSetName)
return (ResultSetMappingDefinition) sqlResultSetMappings.get(resultSetName);
|
public java.lang.String[] | getReturnAliases(java.lang.String queryString)
return queryPlanCache.getHQLQueryPlan( queryString, false, CollectionHelper.EMPTY_MAP ).getReturnMetadata().getReturnAliases();
|
public org.hibernate.type.Type[] | getReturnTypes(java.lang.String queryString)
return queryPlanCache.getHQLQueryPlan( queryString, false, CollectionHelper.EMPTY_MAP ).getReturnMetadata().getReturnTypes();
|
public org.hibernate.exception.SQLExceptionConverter | getSQLExceptionConverter()
return settings.getSQLExceptionConverter();
|
public org.hibernate.cache.Cache | getSecondLevelCacheRegion(java.lang.String regionName)
synchronized (allCacheRegions) {
return (Cache) allCacheRegions.get(regionName);
}
|
public org.hibernate.cfg.Settings | getSettings()
return settings;
|
public org.hibernate.dialect.function.SQLFunctionRegistry | getSqlFunctionRegistry()
return sqlFunctionRegistry;
|
public org.hibernate.stat.Statistics | getStatistics()
return statistics;
|
public org.hibernate.stat.StatisticsImplementor | getStatisticsImplementor()
return statistics;
|
public org.hibernate.transaction.TransactionFactory | getTransactionFactory()
return settings.getTransactionFactory();
|
public javax.transaction.TransactionManager | getTransactionManager()
return transactionManager;
|
public org.hibernate.cache.UpdateTimestampsCache | getUpdateTimestampsCache()
return updateTimestampsCache;
|
public boolean | isClosed()
return isClosed;
|
public org.hibernate.classic.Session | openSession()
return openSession(interceptor);
|
public org.hibernate.classic.Session | openSession(java.sql.Connection connection, boolean flushBeforeCompletionEnabled, boolean autoCloseSessionEnabled, org.hibernate.ConnectionReleaseMode connectionReleaseMode)
return new SessionImpl(
connection,
this,
true,
settings.getCacheProvider().nextTimestamp(),
interceptor,
settings.getDefaultEntityMode(),
flushBeforeCompletionEnabled,
autoCloseSessionEnabled,
connectionReleaseMode
);
|
private SessionImpl | openSession(java.sql.Connection connection, boolean autoClose, long timestamp, org.hibernate.Interceptor sessionLocalInterceptor)
return new SessionImpl(
connection,
this,
autoClose,
timestamp,
sessionLocalInterceptor == null ? interceptor : sessionLocalInterceptor,
settings.getDefaultEntityMode(),
settings.isFlushBeforeCompletionEnabled(),
settings.isAutoCloseSessionEnabled(),
settings.getConnectionReleaseMode()
);
|
public org.hibernate.classic.Session | openSession(java.sql.Connection connection, org.hibernate.Interceptor sessionLocalInterceptor)
return openSession(connection, false, Long.MIN_VALUE, sessionLocalInterceptor);
|
public org.hibernate.classic.Session | openSession(org.hibernate.Interceptor sessionLocalInterceptor)
// note that this timestamp is not correct if the connection provider
// returns an older JDBC connection that was associated with a
// transaction that was already begun before openSession() was called
// (don't know any possible solution to this!)
long timestamp = settings.getCacheProvider().nextTimestamp();
return openSession( null, true, timestamp, sessionLocalInterceptor );
|
public org.hibernate.classic.Session | openSession(java.sql.Connection connection)
return openSession(connection, interceptor); //prevents this session from adding things to cache
|
public org.hibernate.StatelessSession | openStatelessSession()
return new StatelessSessionImpl( null, this );
|
public org.hibernate.StatelessSession | openStatelessSession(java.sql.Connection connection)
return new StatelessSessionImpl( connection, this );
|
public org.hibernate.classic.Session | openTemporarySession()
return new SessionImpl(
null,
this,
true,
settings.getCacheProvider().nextTimestamp(),
interceptor,
settings.getDefaultEntityMode(),
false,
false,
ConnectionReleaseMode.AFTER_STATEMENT
);
|
private final void | readObject(java.io.ObjectInputStream in)
log.trace("deserializing");
in.defaultReadObject();
log.debug("deserialized: " + uuid);
|
private java.lang.Object | readResolve()
log.trace("Resolving serialized SessionFactory");
// look for the instance by uuid
Object result = SessionFactoryObjectFactory.getInstance(uuid);
if (result==null) {
// in case we were deserialized in a different JVM, look for an instance with the same name
// (alternatively we could do an actual JNDI lookup here....)
result = SessionFactoryObjectFactory.getNamedInstance(name);
if (result==null) {
throw new InvalidObjectException("Could not find a SessionFactory named: " + name);
}
else {
log.debug("resolved SessionFactory by name");
}
}
else {
log.debug("resolved SessionFactory by uid");
}
return result;
|
void | serialize(java.io.ObjectOutputStream oos)Custom serialization hook used during Session serialization.
oos.writeUTF( uuid );
oos.writeBoolean( name != null );
if ( name != null ) {
oos.writeUTF( name );
}
|
private final void | writeObject(java.io.ObjectOutputStream out)
log.debug("serializing: " + uuid);
out.defaultWriteObject();
log.trace("serialized");
|