📄 sessionfactoryimpl.java
字号:
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 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 {
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);
}
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.getCache().remove( 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.getCache().clear();
}
}
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.getCache().remove( 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.getCache().clear();
}
}
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.getCache().remove( 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.getCache().clear();
}
}
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 cacheRegion) throws HibernateException {
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 Cache getSecondLevelCacheRegion(String regionName) {
synchronized (allCacheRegions) {
return (Cache) 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 ) ) {
return new JTASessionContext( this );
}
else if ( "thread".equals( impl ) ) {
return new ThreadLocalSessionContext( 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;
}
/**
* Custom serialization hook used during Session serialization.
*
* @param oos The stream to which to write the factory
* @throws IOException
*/
void serialize(ObjectOutputStream oos) throws IOException {
// we are only really concerned with the capability to deserialize
// this reference within the same JVM, so simply writing out the
// uuid is enough
oos.writeUTF( uuid );
}
static SessionFactoryImpl deserialize(ObjectInputStream ois) throws IOException, ClassNotFoundException {
String uuid = ois.readUTF();
Object result = SessionFactoryObjectFactory.getInstance( uuid );
if ( result == null ) {
throw new InvalidObjectException( "could not locate session factory by uuid [" + uuid + "] during session deserialization" );
}
return ( SessionFactoryImpl ) result;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -