📄 sessionfactoryimpl.java
字号:
results.add( testClassName ); } } } } } } return (String[]) results.toArray( new String[ results.size() ] ); } public String getImportedClassName(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 Map getAllClassMetadata() throws HibernateException { return classMetadata; } public Map getAllCollectionMetadata() throws HibernateException { return collectionMetadata; } /** * Closes the session factory, releasing all held resources. * * <ol> * <li>cleans up used cache regions and "stops" the cache provider. * <li>close the JDBC connection * <li>remove the JNDI binding * </ol> * * 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. */ public void close() throws HibernateException { if ( isClosed ) { log.trace( "already closed" ); return; } log.info("closing"); isClosed = true; Iterator iter = entityPersisters.values().iterator(); while ( iter.hasNext() ) { EntityPersister p = (EntityPersister) iter.next(); if ( p.hasCache() ) { p.getCacheAccessStrategy().getRegion().destroy(); } } iter = collectionPersisters.values().iterator(); while ( iter.hasNext() ) { CollectionPersister p = (CollectionPersister) iter.next(); if ( p.hasCache() ) { p.getCacheAccessStrategy().getRegion().destroy(); } } if ( settings.isQueryCacheEnabled() ) { queryCache.destroy(); iter = queryCaches.values().iterator(); while ( iter.hasNext() ) { QueryCache cache = (QueryCache) iter.next(); cache.destroy(); } updateTimestampsCache.destroy(); } settings.getRegionFactory().stop(); try { settings.getConnectionProvider().close(); } finally { SessionFactoryObjectFactory.removeInstance(uuid, name, properties); } if ( settings.isAutoDropSchema() ) { schemaExport.drop( false, true ); } observer.sessionFactoryClosed( this ); eventListeners.destroyListeners(); } public void evictEntity(String entityName, Serializable id) throws HibernateException { 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.getCacheAccessStrategy().evict( cacheKey ); } } public void evictEntity(String entityName) throws HibernateException { EntityPersister p = getEntityPersister( entityName ); if ( p.hasCache() ) { if ( log.isDebugEnabled() ) { log.debug( "evicting second-level cache: " + p.getEntityName() ); } p.getCacheAccessStrategy().evictAll(); } } public void evict(Class persistentClass, Serializable id) throws HibernateException { 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.getCacheAccessStrategy().evict( cacheKey ); } } public void evict(Class persistentClass) throws HibernateException { EntityPersister p = getEntityPersister( persistentClass.getName() ); if ( p.hasCache() ) { if ( log.isDebugEnabled() ) { log.debug( "evicting second-level cache: " + p.getEntityName() ); } p.getCacheAccessStrategy().evictAll(); } } public void evictCollection(String roleName, Serializable id) throws HibernateException { 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.getCacheAccessStrategy().evict( cacheKey ); } } public void evictCollection(String roleName) throws HibernateException { CollectionPersister p = getCollectionPersister( roleName ); if ( p.hasCache() ) { if ( log.isDebugEnabled() ) { log.debug( "evicting second-level cache: " + p.getRole() ); } p.getCacheAccessStrategy().evictAll(); } } public Type getReferencedPropertyType(String className, String propertyName) throws MappingException { return getEntityPersister(className).getPropertyType(propertyName); } public ConnectionProvider getConnectionProvider() { return settings.getConnectionProvider(); } public UpdateTimestampsCache getUpdateTimestampsCache() { return updateTimestampsCache; } public QueryCache getQueryCache() { return queryCache; } public QueryCache getQueryCache(String regionName) throws HibernateException { if ( regionName == null ) { return getQueryCache(); } if ( !settings.isQueryCacheEnabled() ) { return null; } synchronized ( allCacheRegions ) { QueryCache currentQueryCache = ( QueryCache ) queryCaches.get( regionName ); if ( currentQueryCache == null ) { currentQueryCache = settings.getQueryCacheFactory().getQueryCache( regionName, updateTimestampsCache, settings, properties ); queryCaches.put( regionName, currentQueryCache ); allCacheRegions.put( currentQueryCache.getRegion().getName(), currentQueryCache.getRegion() ); } return currentQueryCache; } } public Region getSecondLevelCacheRegion(String regionName) { synchronized ( allCacheRegions ) { return ( Region ) allCacheRegions.get( regionName ); } } public Map getAllSecondLevelCacheRegions() { synchronized ( allCacheRegions ) { return new HashMap( allCacheRegions ); } } public boolean isClosed() { return isClosed; } public Statistics getStatistics() { return statistics; } public StatisticsImplementor getStatisticsImplementor() { return statistics; } public void evictQueries() throws HibernateException { if ( settings.isQueryCacheEnabled() ) { queryCache.clear(); } } public void evictQueries(String cacheRegion) throws HibernateException { 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 FilterDefinition getFilterDefinition(String filterName) throws HibernateException { FilterDefinition def = ( FilterDefinition ) filters.get( filterName ); if ( def == null ) { throw new HibernateException( "No such filter configured [" + filterName + "]" ); } return def; } public Set getDefinedFilterNames() { return filters.keySet(); } public BatcherFactory getBatcherFactory() { return settings.getBatcherFactory(); } public IdentifierGenerator getIdentifierGenerator(String rootEntityName) { return (IdentifierGenerator) identifierGenerators.get(rootEntityName); } private 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; } } } public EventListeners getEventListeners() { return eventListeners; } public EntityNotFoundDelegate getEntityNotFoundDelegate() { return entityNotFoundDelegate; } /** * Custom serialization hook used during Session serialization. * * @param oos The stream to which to write the factory * @throws IOException Indicates problems writing out the serial data stream */ void serialize(ObjectOutputStream oos) throws IOException { oos.writeUTF( uuid ); oos.writeBoolean( name != null ); if ( name != null ) { oos.writeUTF( name ); } } /** * Custom deserialization hook used during Session deserialization. * * @param ois The stream from which to "read" the factory * @return The deserialized factory * @throws IOException indicates problems reading back serial data stream * @throws ClassNotFoundException indicates problems reading back serial data stream */ static SessionFactoryImpl deserialize(ObjectInputStream ois) throws IOException, ClassNotFoundException { 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 SQLFunctionRegistry getSqlFunctionRegistry() { return sqlFunctionRegistry; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -