org.hibernate.cache.spi.entry.CollectionCacheEntry#assemble ( )源码实例Demo

下面列出了org.hibernate.cache.spi.entry.CollectionCacheEntry#assemble ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

/**
 * Try to initialize a collection from the cache
 *
 * @param id The id of the collection to initialize
 * @param persister The collection persister
 * @param collection The collection to initialize
 * @param source The originating session
 *
 * @return true if we were able to initialize the collection from the cache;
 *         false otherwise.
 */
private boolean initializeCollectionFromCache(
		Serializable id,
		CollectionPersister persister,
		PersistentCollection collection,
		SessionImplementor source) {

	if ( source.getLoadQueryInfluencers().hasEnabledFilters() && persister.isAffectedByEnabledFilters( source ) ) {
		LOG.trace( "Disregarding cached version (if any) of collection due to enabled filters" );
		return false;
	}

	final boolean useCache = persister.hasCache() && source.getCacheMode().isGetEnabled();

	if ( !useCache ) {
		return false;
	}

	final SessionFactoryImplementor factory = source.getFactory();
	final CollectionDataAccess cacheAccessStrategy = persister.getCacheAccessStrategy();
	final Object ck = cacheAccessStrategy.generateCacheKey( id, persister, factory, source.getTenantIdentifier() );
	final Object ce = CacheHelper.fromSharedCache( source, ck, cacheAccessStrategy );

	final StatisticsImplementor statistics = factory.getStatistics();
	if ( statistics.isStatisticsEnabled() ) {
		if ( ce == null ) {
			statistics.collectionCacheMiss( persister.getNavigableRole(), cacheAccessStrategy.getRegion().getName() );
		}
		else {
			statistics.collectionCacheHit( persister.getNavigableRole(), cacheAccessStrategy.getRegion().getName() );
		}
	}

	if ( ce == null ) {
		return false;
	}

	CollectionCacheEntry cacheEntry = (CollectionCacheEntry) persister.getCacheEntryStructure().destructure( ce, factory );

	final PersistenceContext persistenceContext = source.getPersistenceContextInternal();
	cacheEntry.assemble( collection, persister, persistenceContext.getCollectionOwner( id, persister ) );
	persistenceContext.getCollectionEntry( collection ).postInitialize( collection );
	return true;
}
 
/**
 * Try to initialize a collection from the cache
 *
 * @param id The id of the collection of initialize
 * @param persister The collection persister
 * @param collection The collection to initialize
 * @param source The originating session
 *
 * @return true if we were able to initialize the collection from the cache;
 *         false otherwise.
 */
private boolean initializeCollectionFromCache(
		Serializable id,
		CollectionPersister persister,
		PersistentCollection collection,
		SessionImplementor source) {

	if ( !source.getLoadQueryInfluencers().getEnabledFilters().isEmpty()
			&& persister.isAffectedByEnabledFilters( source ) ) {
		LOG.trace( "Disregarding cached version (if any) of collection due to enabled filters" );
		return false;
	}

	final boolean useCache = persister.hasCache() && source.getCacheMode().isGetEnabled();

	if ( !useCache ) {
		return false;
	}

	final SessionFactoryImplementor factory = source.getFactory();
	final CollectionDataAccess cacheAccessStrategy = persister.getCacheAccessStrategy();
	final Object ck = cacheAccessStrategy.generateCacheKey( id, persister, factory, source.getTenantIdentifier() );
	final Object ce = CacheHelper.fromSharedCache( source, ck, persister.getCacheAccessStrategy() );

	if ( factory.getStatistics().isStatisticsEnabled() ) {
		if ( ce == null ) {
			factory.getStatistics().collectionCacheMiss(
					persister.getNavigableRole(),
					cacheAccessStrategy.getRegion().getName()
			);
		}
		else {
			factory.getStatistics().collectionCacheHit(
					persister.getNavigableRole(),
					cacheAccessStrategy.getRegion().getName()
			);
		}
	}

	if ( ce == null ) {
		return false;
	}

	CollectionCacheEntry cacheEntry = (CollectionCacheEntry) persister.getCacheEntryStructure().destructure(
			ce,
			factory
	);

	final PersistenceContext persistenceContext = source.getPersistenceContext();
	cacheEntry.assemble( collection, persister, persistenceContext.getCollectionOwner( id, persister ) );
	persistenceContext.getCollectionEntry( collection ).postInitialize( collection );
	// addInitializedCollection(collection, persister, id);
	return true;
}