@Override public String toString() { return "QueryResultsCache(" + cacheRegion.getName() + ')'; }
/** * Clear items from the query cache. * * @throws CacheException Indicates a problem delegating to the underlying cache. */ @Override default void clear() throws CacheException { getRegion().clear(); }
private CacheItem getCachedData(QueryKey key, SharedSessionContractImplementor session) { CacheItem cachedItem = null; try { session.getEventListenerManager().cacheGetStart(); cachedItem = (CacheItem) cacheRegion.getFromCache( key, session ); } finally { session.getEventListenerManager().cacheGetEnd( cachedItem != null ); } return cachedItem; }
final SharedSessionContractImplementor session) throws HibernateException { if ( DEBUGGING ) { LOG.debugf( "Caching query results in region: %s; timestamp=%s", cacheRegion.getName(), session.getTransactionStartTimestamp() ); cacheRegion.putIntoCache( key, cacheItem, session );
@SuppressWarnings({ "UnnecessaryBoxing", "unchecked" }) public boolean put( QueryKey key, Type[] returnTypes, List result, boolean isNaturalKeyLookup, SessionImplementor session) throws HibernateException { if ( isNaturalKeyLookup && result.isEmpty() ) { return false; } long ts = cacheRegion.nextTimestamp(); LOG.debugf( "Caching query results in region: %s; timestamp=%s", cacheRegion.getName(), ts ); List cacheable = new ArrayList( result.size() + 1 ); logCachedResultDetails( key, null, returnTypes, cacheable ); cacheable.add( ts ); final boolean singleResult = returnTypes.length == 1; for ( Object aResult : result ) { Serializable cacheItem = singleResult ? returnTypes[0].disassemble( aResult, session, null ) : TypeHelper.disassemble( (Object[]) aResult, returnTypes, null, session, null ); cacheable.add( cacheItem ); logCachedResultRowDetails( returnTypes, aResult ); } cacheRegion.put( key, cacheable ); return true; }
Set spaces, SessionImplementor session) throws HibernateException { LOG.debugf( "Checking cached query results in region: %s", cacheRegion.getName() ); List cacheable = (List) cacheRegion.get( key ); logCachedResultDetails( key, spaces, returnTypes, cacheable ); cacheRegion.evict( key ); return null;
public void clear() throws CacheException { cacheRegion.evictAll(); }
@SuppressWarnings({ "UnnecessaryBoxing", "unchecked" }) public boolean put( QueryKey key, Type[] returnTypes, List result, boolean isNaturalKeyLookup, SessionImplementor session) throws HibernateException { if ( isNaturalKeyLookup && result.isEmpty() ) { return false; } long ts = cacheRegion.nextTimestamp(); LOG.debugf( "Caching query results in region: %s; timestamp=%s", cacheRegion.getName(), ts ); List cacheable = new ArrayList( result.size() + 1 ); logCachedResultDetails( key, null, returnTypes, cacheable ); cacheable.add( ts ); final boolean singleResult = returnTypes.length == 1; for ( Object aResult : result ) { Serializable cacheItem = singleResult ? returnTypes[0].disassemble( aResult, session, null ) : TypeHelper.disassemble( (Object[]) aResult, returnTypes, null, session, null ); cacheable.add( cacheItem ); logCachedResultRowDetails( returnTypes, aResult ); } cacheRegion.put( key, cacheable ); return true; }
Set spaces, SessionImplementor session) throws HibernateException { LOG.debugf( "Checking cached query results in region: %s", cacheRegion.getName() ); List cacheable = (List) cacheRegion.get( key ); logCachedResultDetails( key, spaces, returnTypes, cacheable ); cacheRegion.evict( key ); return null;
@Override @SuppressWarnings({ "unchecked" }) public boolean put( final QueryKey key, final List results, final SharedSessionContractImplementor session) throws HibernateException { if ( DEBUGGING ) { LOG.debugf( "Caching query results in region: %s; timestamp=%s", cacheRegion.getName(), session.getTransactionStartTimestamp() ); } final CacheItem cacheItem = new CacheItem( session.getTransactionStartTimestamp(), deepCopy( results ) ); try { session.getEventListenerManager().cachePutStart(); cacheRegion.putIntoCache( key, cacheItem, session ); } finally { session.getEventListenerManager().cachePutEnd(); } return true; }
public void clear() throws CacheException { cacheRegion.evictAll(); }
private void evictQueryResultRegion(QueryResultsCache cache) { if ( cache == null ) { return; } if ( LOG.isDebugEnabled() ) { LOG.debugf( "Evicting query cache, region: %s", cache.getRegion().getName() ); } cache.clear(); }
private CacheItem getCachedData(QueryKey key, SharedSessionContractImplementor session) { CacheItem cachedItem = null; try { session.getEventListenerManager().cacheGetStart(); cachedItem = (CacheItem) cacheRegion.getFromCache( key, session ); } finally { session.getEventListenerManager().cacheGetEnd( cachedItem != null ); } return cachedItem; }
/** * Clear items from the query cache. * * @throws CacheException Indicates a problem delegating to the underlying cache. */ default void clear() throws CacheException { getRegion().clear(); }
@Override public QueryResultsCache getQueryResultsCache(String regionName) throws HibernateException { if ( !getSessionFactory().getSessionFactoryOptions().isQueryCacheEnabled() ) { return null; } if ( regionName == null || regionName.equals( getDefaultQueryResultsCache().getRegion().getName() ) ) { return getDefaultQueryResultsCache(); } final QueryResultsCache existing = namedQueryResultsCacheMap.get( regionName ); if ( existing != null ) { return existing; } return makeQueryResultsRegionAccess( regionName ); }
final SharedSessionContractImplementor session) { if ( DEBUGGING ) { LOG.debugf( "Checking cached query results in region: %s", cacheRegion.getName() );
protected void putResultInQueryCache( final SharedSessionContractImplementor session, final QueryParameters queryParameters, final Type[] resultTypes, final QueryResultsCache queryCache, final QueryKey key, final List result) { if ( session.getCacheMode().isPutEnabled() ) { boolean put = queryCache.put( key, result, key.getResultTransformer().getCachedResultTypes( resultTypes ), session ); if ( put && factory.getStatistics().isStatisticsEnabled() ) { factory.getStatistics().queryCachePut( getQueryIdentifier(), queryCache.getRegion().getName() ); } } }
public EnabledCaching(SessionFactoryImplementor sessionFactory) { this.sessionFactory = sessionFactory; this.regionFactory = getSessionFactory().getSessionFactoryOptions().getServiceRegistry().getService( RegionFactory.class ); this.regionFactory.start( sessionFactory.getSessionFactoryOptions(), sessionFactory.getProperties() ); if ( getSessionFactory().getSessionFactoryOptions().isQueryCacheEnabled() ) { final TimestampsRegion timestampsRegion = regionFactory.buildTimestampsRegion( RegionFactory.DEFAULT_UPDATE_TIMESTAMPS_REGION_UNQUALIFIED_NAME, sessionFactory ); timestampsCache = sessionFactory.getSessionFactoryOptions() .getTimestampsCacheFactory() .buildTimestampsCache( this, timestampsRegion ); legacySecondLevelCacheNames.add( timestampsRegion.getName() ); final QueryResultsRegion queryResultsRegion = regionFactory.buildQueryResultsRegion( RegionFactory.DEFAULT_QUERY_RESULTS_REGION_UNQUALIFIED_NAME, sessionFactory ); regionsByName.put( queryResultsRegion.getName(), queryResultsRegion ); defaultQueryResultsCache = new QueryResultsCacheImpl( queryResultsRegion, timestampsCache ); } else { timestampsCache = new TimestampsCacheDisabledImpl(); defaultQueryResultsCache = null; } }