当前位置: 首页>>代码示例>>Java>>正文


Java CollectionPersister.hasCache方法代码示例

本文整理汇总了Java中org.hibernate.persister.collection.CollectionPersister.hasCache方法的典型用法代码示例。如果您正苦于以下问题:Java CollectionPersister.hasCache方法的具体用法?Java CollectionPersister.hasCache怎么用?Java CollectionPersister.hasCache使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.hibernate.persister.collection.CollectionPersister的用法示例。


在下文中一共展示了CollectionPersister.hasCache方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isCached

import org.hibernate.persister.collection.CollectionPersister; //导入方法依赖的package包/类
private boolean isCached(Serializable collectionKey, CollectionPersister persister) {
	if ( context.getSession().getCacheMode().isGetEnabled() && persister.hasCache() ) {
		CacheKey cacheKey = context.getSession().generateCacheKey(
				collectionKey,
				persister.getKeyType(),
				persister.getRole()
		);
		return CacheHelper.fromSharedCache( context.getSession(), cacheKey, persister.getCacheAccessStrategy() ) != null;
	}
	return false;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:12,代码来源:BatchFetchQueue.java

示例2: evictCollection

import org.hibernate.persister.collection.CollectionPersister; //导入方法依赖的package包/类
@Override
public void evictCollection(String role, Serializable ownerIdentifier) {
	CollectionPersister p = sessionFactory.getCollectionPersister( role );
	if ( p.hasCache() ) {
		if ( LOG.isDebugEnabled() ) {
			LOG.debugf(
					"Evicting second-level cache: %s",
					MessageHelper.collectionInfoString( p, ownerIdentifier, sessionFactory )
			);
		}
		CacheKey cacheKey = buildCacheKey( ownerIdentifier, p );
		p.getCacheAccessStrategy().evict( cacheKey );
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:15,代码来源:CacheImpl.java

示例3: evictCollectionRegion

import org.hibernate.persister.collection.CollectionPersister; //导入方法依赖的package包/类
@Override
public void evictCollectionRegion(String role) {
	CollectionPersister p = sessionFactory.getCollectionPersister( role );
	if ( p.hasCache() ) {
		if ( LOG.isDebugEnabled() ) {
			LOG.debugf( "Evicting second-level cache: %s", p.getRole() );
		}
		p.getCacheAccessStrategy().evictAll();
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:11,代码来源:CacheImpl.java

示例4: BulkOperationCleanupAction

import org.hibernate.persister.collection.CollectionPersister; //导入方法依赖的package包/类
/**
 * Constructs an action to cleanup "affected cache regions" based on the
 * affected entity persisters.  The affected regions are defined as the
 * region (if any) of the entity persisters themselves, plus the
 * collection regions for any collection in which those entity
 * persisters participate as elements/keys/etc.
 *
 * @param session The session to which this request is tied.
 * @param affectedQueryables The affected entity persisters.
 */
public BulkOperationCleanupAction(SessionImplementor session, Queryable... affectedQueryables) {
	final SessionFactoryImplementor factory = session.getFactory();
	final LinkedHashSet<String> spacesList = new LinkedHashSet<String>();
	for ( Queryable persister : affectedQueryables ) {
		spacesList.addAll( Arrays.asList( (String[]) persister.getQuerySpaces() ) );

		if ( persister.hasCache() ) {
			entityCleanups.add( new EntityCleanup( persister.getCacheAccessStrategy() ) );
		}
		if ( persister.hasNaturalIdentifier() && persister.hasNaturalIdCache() ) {
			naturalIdCleanups.add( new NaturalIdCleanup( persister.getNaturalIdCacheAccessStrategy() ) );
		}

		final Set<String> roles = factory.getCollectionRolesByEntityParticipant( persister.getEntityName() );
		if ( roles != null ) {
			for ( String role : roles ) {
				final CollectionPersister collectionPersister = factory.getCollectionPersister( role );
				if ( collectionPersister.hasCache() ) {
					collectionCleanups.add( new CollectionCleanup( collectionPersister.getCacheAccessStrategy() ) );
				}
			}
		}
	}

	this.affectedTableSpaces = spacesList.toArray( new String[ spacesList.size() ] );
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:37,代码来源:BulkOperationCleanupAction.java

示例5: endLoadingCollection

import org.hibernate.persister.collection.CollectionPersister; //导入方法依赖的package包/类
private void endLoadingCollection(LoadingCollectionEntry lce, CollectionPersister persister) {
		LOG.tracev( "Ending loading collection [{0}]", lce );
		final SessionImplementor session = getLoadContext().getPersistenceContext().getSession();

		// warning: can cause a recursive calls! (proxy initialization)
		final boolean hasNoQueuedAdds = lce.getCollection().endRead();

		if ( persister.getCollectionType().hasHolder() ) {
			getLoadContext().getPersistenceContext().addCollectionHolder( lce.getCollection() );
		}

		CollectionEntry ce = getLoadContext().getPersistenceContext().getCollectionEntry( lce.getCollection() );
		if ( ce == null ) {
			ce = getLoadContext().getPersistenceContext().addInitializedCollection( persister, lce.getCollection(), lce.getKey() );
		}
		else {
			ce.postInitialize( lce.getCollection() );
//			if (ce.getLoadedPersister().getBatchSize() > 1) { // not the best place for doing this, moved into ce.postInitialize
//				getLoadContext().getPersistenceContext().getBatchFetchQueue().removeBatchLoadableCollection(ce); 
//			}
		}


		// add to cache if:
		boolean addToCache =
				// there were no queued additions
				hasNoQueuedAdds
				// and the role has a cache
				&& persister.hasCache()
				// and this is not a forced initialization during flush
				&& session.getCacheMode().isPutEnabled() && !ce.isDoremove();
		if ( addToCache ) {
			addCollectionToCache( lce, persister );
		}

		if ( LOG.isDebugEnabled() ) {
			LOG.debugf(
					"Collection fully initialized: %s",
					MessageHelper.collectionInfoString( persister, lce.getCollection(), lce.getKey(), session )
			);
		}
		if ( session.getFactory().getStatistics().isStatisticsEnabled() ) {
			session.getFactory().getStatisticsImplementor().loadCollection( persister.getRole() );
		}
	}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:46,代码来源:CollectionLoadContext.java

示例6: containsCollection

import org.hibernate.persister.collection.CollectionPersister; //导入方法依赖的package包/类
@Override
public boolean containsCollection(String role, Serializable ownerIdentifier) {
	CollectionPersister p = sessionFactory.getCollectionPersister( role );
	return p.hasCache() &&
			p.getCacheAccessStrategy().getRegion().contains( buildCacheKey( ownerIdentifier, p ) );
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:7,代码来源:CacheImpl.java

示例7: evictCache

import org.hibernate.persister.collection.CollectionPersister; //导入方法依赖的package包/类
private void evictCache(Object entity, EntityPersister persister, EventSource session, Object[] oldState) {
	try {
		SessionFactoryImplementor factory = persister.getFactory();

		Set<String> collectionRoles = factory.getCollectionRolesByEntityParticipant( persister.getEntityName() );
		if ( collectionRoles == null || collectionRoles.isEmpty() ) {
			return;
		}
		for ( String role : collectionRoles ) {
			CollectionPersister collectionPersister = factory.getCollectionPersister( role );
			if ( !collectionPersister.hasCache() ) {
				// ignore collection if no caching is used
				continue;
			}
			// this is the property this OneToMany relation is mapped by
			String mappedBy = collectionPersister.getMappedByProperty();
			if ( mappedBy != null ) {
				int i = persister.getEntityMetamodel().getPropertyIndex( mappedBy );
				Serializable oldId = null;
				if ( oldState != null ) {
					// in case of updating an entity we perhaps have to decache 2 entity collections, this is the
					// old one
					oldId = session.getIdentifier( oldState[i] );
				}
				Object ref = persister.getPropertyValue( entity, i );
				Serializable id = null;
				if ( ref != null ) {
					id = session.getIdentifier( ref );
				}
				// only evict if the related entity has changed
				if ( id != null && !id.equals( oldId ) ) {
					evict( id, collectionPersister, session );
					if ( oldId != null ) {
						evict( oldId, collectionPersister, session );
					}
				}
			}
			else {
				LOG.debug( "Evict CollectionRegion " + role );
				collectionPersister.getCacheAccessStrategy().evictAll();
			}
		}
	}
	catch ( Exception e ) {
		// don't let decaching influence other logic
		LOG.error( "", e );
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:49,代码来源:CollectionCacheInvalidator.java

示例8: initializeCollectionFromCache

import org.hibernate.persister.collection.CollectionPersister; //导入方法依赖的package包/类
/**
 * 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 CacheKey ck = source.generateCacheKey( id, persister.getKeyType(), persister.getRole() );
	final Object ce = CacheHelper.fromSharedCache( source, ck, persister.getCacheAccessStrategy() );

	if ( factory.getStatistics().isStatisticsEnabled() ) {
		if ( ce == null ) {
			factory.getStatisticsImplementor()
					.secondLevelCacheMiss( persister.getCacheAccessStrategy().getRegion().getName() );
		}
		else {
			factory.getStatisticsImplementor()
					.secondLevelCacheHit( persister.getCacheAccessStrategy().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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:60,代码来源:DefaultInitializeCollectionEventListener.java


注:本文中的org.hibernate.persister.collection.CollectionPersister.hasCache方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。