⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sessionfactoryimpl.java

📁 介绍了hibernate的入门有一些基本常用的事例
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	}	public String[] getReturnAliases(String queryString) throws HibernateException {		return getRepresentativeQuery(queryString).getReturnAliases();	}		private QueryTranslator getRepresentativeQuery(String queryString) throws HibernateException {		String[] queries = QuerySplitter.concreteQueries(queryString, this);		if ( queries.length==0 ) throw new HibernateException("Query does not refer to any persistent classes: " + queryString);		return getQuery( queries[0], true, CollectionHelper.EMPTY_MAP )[0];	}	public ClassMetadata getClassMetadata(Class persistentClass) throws HibernateException {		return getClassMetadata( persistentClass.getName() );	}	public CollectionMetadata getCollectionMetadata(String roleName) throws HibernateException {		return (CollectionMetadata) collectionMetadata.get(roleName);	}	public ClassMetadata getClassMetadata(String entityName) throws HibernateException {		return (ClassMetadata) classMetadata.get(entityName);	}	/**	 * 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.	 */	public String[] getImplementors(String className) throws MappingException {		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 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>	 */	public void close() throws HibernateException {		log.info("closing");		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) );			}			p.getCache().remove( new CacheKey( id, p.getIdentifierType(), p.getRootEntityName(), EntityMode.POJO ) );		}	}	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) );			}			p.getCache().remove( new CacheKey( id, p.getIdentifierType(), p.getRootEntityName(), EntityMode.POJO ) );		}	}	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) );			}			p.getCache().remove( new CacheKey( id, p.getKeyType(), p.getRole(), EntityMode.POJO ) );		}	}	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 getPropertyType(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 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 IllegalArgumentException {		FilterDefinition def = (FilterDefinition) filters.get(filterName);		if (def == null) {			// TODO: what should be the actual type thrown?			throw new IllegalArgumentException("No such filter configured [" + filterName + "]");		}		return def;	}	public BatcherFactory getBatcherFactory() {		return settings.getBatcherFactory();	}		public IdentifierGenerator getIdentifierGenerator(String rootEntityName) {		return (IdentifierGenerator) identifierGenerators.get(rootEntityName);	}	static class CurrentSessionCleanupSynch implements Synchronization {		private Transaction txn;		private SessionFactoryImpl impl;		public CurrentSessionCleanupSynch(Transaction txn, SessionFactoryImpl impl) {			this.txn = txn;			this.impl = impl;		}		public void beforeCompletion() {		}		public void afterCompletion(int i) {			impl.currentSessionMap.remove( txn );		}	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -