Java Code Examples for org.hibernate.persister.collection.CollectionPersister#getKeyType()

The following examples show how to use org.hibernate.persister.collection.CollectionPersister#getKeyType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BatchFetchQueue.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private boolean isCached(
		Serializable collectionKey,
		CollectionPersister persister,
		EntityMode entityMode) {
	if ( persister.hasCache() ) {
		CacheKey cacheKey = new CacheKey(
				collectionKey,
		        persister.getKeyType(),
		        persister.getRole(),
		        entityMode,
		        context.getSession().getFactory()
		);
		return persister.getCache().getCache().get( cacheKey ) != null;
	}
	return false;
}
 
Example 2
Source File: BatchingCollectionInitializer.java    From webdsl with Apache License 2.0 6 votes vote down vote up
protected static boolean isCached(
		PersistenceContext context,
		Serializable collectionKey,
		CollectionPersister persister,
		EntityMode entityMode) {
	if ( persister.hasCache() ) {
		CacheKey cacheKey = new CacheKey(
				collectionKey,
		        persister.getKeyType(),
		        persister.getRole(),
		        entityMode,
		        context.getSession().getFactory()
		);
		return persister.getCacheAccessStrategy().get( cacheKey, context.getSession().getTimestamp() ) != null;
	}
	return false;
}
 
Example 3
Source File: CollectionKey.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public CollectionKey(CollectionPersister persister, Serializable key) {
	this(
			persister.getRole(),
			key,
			persister.getKeyType(),
			persister.getOwnerEntityPersister().getEntityMetamodel().getEntityMode(),
			persister.getFactory()
	);
}
 
Example 4
Source File: SessionFactoryImpl.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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 );
	}
}
 
Example 5
Source File: CollectionKey.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public CollectionKey(CollectionPersister persister, Serializable key, EntityMode em) {
	this( persister.getRole(), key, persister.getKeyType(), em, persister.getFactory() );
}
 
Example 6
Source File: DefaultCacheKeysFactory.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public static Object staticCreateCollectionKey(Object id, CollectionPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) {
	return new CacheKeyImplementation( id, persister.getKeyType(), persister.getRole(), tenantIdentifier, factory );
}
 
Example 7
Source File: CollectionKey.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public CollectionKey(CollectionPersister persister, Serializable key, EntityMode em) {
	this( persister.getRole(), key, persister.getKeyType(), em, persister.getFactory() );
}
 
Example 8
Source File: CollectionLoadContext.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Add the collection to the second-level cache
 *
 * @param lce The entry representing the collection to add
 * @param persister The persister
 */
private void addCollectionToCache(LoadingCollectionEntry lce, CollectionPersister persister) {
	final SessionImplementor session = getLoadContext().getPersistenceContext().getSession();
	final SessionFactoryImplementor factory = session.getFactory();

	if ( log.isDebugEnabled() ) {
		log.debug( "Caching collection: " + MessageHelper.collectionInfoString( persister, lce.getKey(), factory ) );
	}

	if ( !session.getEnabledFilters().isEmpty() && persister.isAffectedByEnabledFilters( session ) ) {
		// some filters affecting the collection are enabled on the session, so do not do the put into the cache.
		log.debug( "Refusing to add to cache due to enabled filters" );
		// todo : add the notion of enabled filters to the CacheKey to differentiate filtered collections from non-filtered;
		//      but CacheKey is currently used for both collections and entities; would ideally need to define two seperate ones;
		//      currently this works in conjuction with the check on
		//      DefaultInitializeCollectionEventHandler.initializeCollectionFromCache() (which makes sure to not read from
		//      cache with enabled filters).
		return; // EARLY EXIT!!!!!
	}

	final Comparator versionComparator;
	final Object version;
	if ( persister.isVersioned() ) {
		versionComparator = persister.getOwnerEntityPersister().getVersionType().getComparator();
		final Object collectionOwner = getLoadContext().getPersistenceContext().getCollectionOwner( lce.getKey(), persister );
		version = getLoadContext().getPersistenceContext().getEntry( collectionOwner ).getVersion();
	}
	else {
		version = null;
		versionComparator = null;
	}

	CollectionCacheEntry entry = new CollectionCacheEntry( lce.getCollection(), persister );
	CacheKey cacheKey = new CacheKey(
			lce.getKey(),
			persister.getKeyType(),
			persister.getRole(),
			session.getEntityMode(),
			session.getFactory()
	);
	boolean put = persister.getCache().put(
			cacheKey,
			persister.getCacheEntryStructure().structure(entry),
			session.getTimestamp(),
			version,
			versionComparator,
			factory.getSettings().isMinimalPutsEnabled() && session.getCacheMode()!= CacheMode.REFRESH
	);

	if ( put && factory.getStatistics().isStatisticsEnabled() ) {
		factory.getStatisticsImplementor().secondLevelCachePut( persister.getCache().getRegionName() );
	}
}
 
Example 9
Source File: DefaultInitializeCollectionEventListener.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Try to initialize a collection from the cache
 */
private boolean initializeCollectionFromCache(
		Serializable id,
		CollectionPersister persister,
		PersistentCollection collection,
		SessionImplementor source)
throws HibernateException {

	if ( !source.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;
	}
	else {
		
		final SessionFactoryImplementor factory = source.getFactory();

		final CacheKey ck = new CacheKey( 
				id, 
				persister.getKeyType(), 
				persister.getRole(), 
				source.getEntityMode(), 
				source.getFactory() 
			);
		Object ce = persister.getCache().get( ck, source.getTimestamp() );
		
		if ( factory.getStatistics().isStatisticsEnabled() ) {
			if (ce==null) {
				factory.getStatisticsImplementor().secondLevelCacheMiss( 
						persister.getCache().getRegionName() 
					);
			}
			else {
				factory.getStatisticsImplementor().secondLevelCacheHit( 
						persister.getCache().getRegionName() 
					);
			}

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

			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;
		}
		
	}
}