Java 类org.hibernate.cache.spi.QueryCache 实例源码

项目:lams    文件:Loader.java   
protected void putResultInQueryCache(
        final SessionImplementor session,
        final QueryParameters queryParameters,
        final Type[] resultTypes,
        final QueryCache queryCache,
        final QueryKey key,
        final List result) {
    if ( session.getCacheMode().isPutEnabled() ) {
        boolean put = queryCache.put(
                key,
                key.getResultTransformer().getCachedResultTypes( resultTypes ),
                result,
                queryParameters.isNaturalKeyLookup(),
                session
        );
        if ( put && factory.getStatistics().isStatisticsEnabled() ) {
            factory.getStatisticsImplementor()
                    .queryCachePut( getQueryIdentifier(), queryCache.getRegion().getName() );
        }
    }
}
项目:lams    文件:CacheImpl.java   
public CacheImpl(SessionFactoryImplementor sessionFactory) {
    this.sessionFactory = sessionFactory;
    this.settings = sessionFactory.getSettings();
    //todo should get this from service registry
    this.regionFactory = settings.getRegionFactory();
    regionFactory.start( settings, sessionFactory.getProperties() );
    if ( settings.isQueryCacheEnabled() ) {
        updateTimestampsCache = new UpdateTimestampsCache(
                settings,
                sessionFactory.getProperties(),
                sessionFactory
        );
        queryCache = settings.getQueryCacheFactory()
                .getQueryCache( null, updateTimestampsCache, settings, sessionFactory.getProperties() );
        queryCaches = new ConcurrentHashMap<String, QueryCache>();
        allCacheRegions.put( updateTimestampsCache.getRegion().getName(), updateTimestampsCache.getRegion() );
        allCacheRegions.put( queryCache.getRegion().getName(), queryCache.getRegion() );
    }
    else {
        updateTimestampsCache = null;
        queryCache = null;
        queryCaches = null;
    }
}
项目:lams    文件:CacheImpl.java   
@Override
public void evictQueryRegion(String regionName) {
    if ( regionName == null ) {
        throw new NullPointerException(
                "Region-name cannot be null (use Cache#evictDefaultQueryRegion to evict the default query cache)"
        );
    }
    if ( sessionFactory.getSettings().isQueryCacheEnabled() ) {
        QueryCache namedQueryCache = queryCaches.get( regionName );
        // TODO : cleanup entries in queryCaches + allCacheRegions ?
        if ( namedQueryCache != null ) {
               if ( LOG.isDebugEnabled() ) {
                   LOG.debugf( "Evicting query cache, region: %s", regionName );
               }
            namedQueryCache.clear();
        }
    }
}
项目:lams    文件:CacheImpl.java   
@Override
public void evictQueryRegions() {
    evictDefaultQueryRegion();

    if ( CollectionHelper.isEmpty( queryCaches ) ) {
        return;
    }
       if ( LOG.isDebugEnabled() ) {
           LOG.debug( "Evicting cache of all query regions." );
       }
    for ( QueryCache queryCache : queryCaches.values() ) {
        queryCache.clear();
    }
}
项目:lams    文件:CacheImpl.java   
@Override
public void close() {
    if ( settings.isQueryCacheEnabled() ) {
        queryCache.destroy();

        Iterator iter = queryCaches.values().iterator();
        while ( iter.hasNext() ) {
            QueryCache cache = (QueryCache) iter.next();
            cache.destroy();
        }
        updateTimestampsCache.destroy();
    }

    regionFactory.stop();
}
项目:lams    文件:CacheImpl.java   
@Override
public QueryCache getQueryCache(String regionName) throws HibernateException {
    if ( regionName == null ) {
        return getQueryCache();
    }

    if ( !settings.isQueryCacheEnabled() ) {
        return null;
    }

    QueryCache currentQueryCache = queryCaches.get( regionName );
    if ( currentQueryCache == null ) {
        synchronized ( allCacheRegions ) {
            currentQueryCache = queryCaches.get( regionName );
            if ( currentQueryCache == null ) {
                currentQueryCache = settings.getQueryCacheFactory()
                        .getQueryCache(
                                regionName,
                                updateTimestampsCache,
                                settings,
                                sessionFactory.getProperties()
                        );
                queryCaches.put( regionName, currentQueryCache );
                allCacheRegions.put( currentQueryCache.getRegion().getName(), currentQueryCache.getRegion() );
            }
            else {
                return currentQueryCache;
            }
        }
    }
    return currentQueryCache;
}
项目:lams    文件:StandardQueryCacheFactory.java   
@Override
public QueryCache getQueryCache(
        final String regionName,
        final UpdateTimestampsCache updateTimestampsCache,
        final Settings settings,
        final Properties props) throws HibernateException {
    return new StandardQueryCache(settings, props, updateTimestampsCache, regionName);
}
项目:lemon    文件:SessionFactoryWrapper.java   
public QueryCache getQueryCache() {
    return sessionFactoryImplementor.getQueryCache();
}
项目:lemon    文件:SessionFactoryWrapper.java   
public QueryCache getQueryCache(String regionName)
        throws HibernateException {
    return sessionFactoryImplementor.getQueryCache(regionName);
}
项目:lams    文件:Loader.java   
private List listUsingQueryCache(
        final SessionImplementor session,
        final QueryParameters queryParameters,
        final Set<Serializable> querySpaces,
        final Type[] resultTypes) {

    QueryCache queryCache = factory.getQueryCache( queryParameters.getCacheRegion() );

    QueryKey key = generateQueryKey( session, queryParameters );

    if ( querySpaces == null || querySpaces.size() == 0 )
        LOG.tracev( "Unexpected querySpaces is {0}", ( querySpaces == null ? querySpaces : "empty" ) );
    else {
        LOG.tracev( "querySpaces is {0}", querySpaces );
    }

    List result = getResultFromQueryCache(
            session,
            queryParameters,
            querySpaces,
            resultTypes,
            queryCache,
            key
        );

    if ( result == null ) {
        result = doList( session, queryParameters, key.getResultTransformer() );

        putResultInQueryCache(
                session,
                queryParameters,
                resultTypes,
                queryCache,
                key,
                result
        );
    }

    ResultTransformer resolvedTransformer = resolveResultTransformer( queryParameters.getResultTransformer() );
    if ( resolvedTransformer != null ) {
        result = (
                areResultSetRowsTransformedImmediately() ?
                        key.getResultTransformer().retransformResults(
                                result,
                                getResultRowAliases(),
                                queryParameters.getResultTransformer(),
                                includeInResultRow()
                        ) :
                        key.getResultTransformer().untransformToTuples(
                                result
                        )
        );
    }

    return getResultList( result, queryParameters.getResultTransformer() );
}
项目:lams    文件:Loader.java   
private List getResultFromQueryCache(
        final SessionImplementor session,
        final QueryParameters queryParameters,
        final Set<Serializable> querySpaces,
        final Type[] resultTypes,
        final QueryCache queryCache,
        final QueryKey key) {
    List result = null;

    if ( session.getCacheMode().isGetEnabled() ) {
        boolean isImmutableNaturalKeyLookup =
                queryParameters.isNaturalKeyLookup() &&
                        resultTypes.length == 1 &&
                        resultTypes[0].isEntityType() &&
                        getEntityPersister( EntityType.class.cast( resultTypes[0] ) )
                                .getEntityMetamodel()
                                .hasImmutableNaturalId();

        final PersistenceContext persistenceContext = session.getPersistenceContext();
        boolean defaultReadOnlyOrig = persistenceContext.isDefaultReadOnly();
        if ( queryParameters.isReadOnlyInitialized() ) {
            // The read-only/modifiable mode for the query was explicitly set.
            // Temporarily set the default read-only/modifiable setting to the query's setting.
            persistenceContext.setDefaultReadOnly( queryParameters.isReadOnly() );
        }
        else {
            // The read-only/modifiable setting for the query was not initialized.
            // Use the default read-only/modifiable from the persistence context instead.
            queryParameters.setReadOnly( persistenceContext.isDefaultReadOnly() );
        }
        try {
            result = queryCache.get(
                    key,
                    key.getResultTransformer().getCachedResultTypes( resultTypes ),
                    isImmutableNaturalKeyLookup,
                    querySpaces,
                    session
            );
        }
        finally {
            persistenceContext.setDefaultReadOnly( defaultReadOnlyOrig );
        }

        if ( factory.getStatistics().isStatisticsEnabled() ) {
            if ( result == null ) {
                factory.getStatisticsImplementor()
                        .queryCacheMiss( getQueryIdentifier(), queryCache.getRegion().getName() );
            }
            else {
                factory.getStatisticsImplementor()
                        .queryCacheHit( getQueryIdentifier(), queryCache.getRegion().getName() );
            }
        }
    }

    return result;
}
项目:lams    文件:CacheImpl.java   
@Override
public QueryCache getQueryCache() {
    return queryCache;
}
项目:lams    文件:SessionFactoryImpl.java   
public QueryCache getQueryCache() {
    return cacheAccess.getQueryCache();
}
项目:lams    文件:SessionFactoryImpl.java   
public QueryCache getQueryCache(String regionName) throws HibernateException {
    return cacheAccess.getQueryCache( regionName );
}
项目:hibernate-dynamic-dialects    文件:SessionFactoryImpl.java   
public QueryCache getQueryCache() {
    return cacheAccess.getQueryCache();
}
项目:hibernate-dynamic-dialects    文件:SessionFactoryImpl.java   
public QueryCache getQueryCache(String regionName)
        throws HibernateException {
    return cacheAccess.getQueryCache(regionName);
}
项目:lams    文件:CustomLoader.java   
/**
 * {@link #resultTypes} can be overridden by {@link #autoDiscoverTypes(ResultSet)},
 * *after* {@link #list(SessionImplementor, QueryParameters)} has already been called.  It's a bit of a
 * chicken-and-the-egg issue since {@link #autoDiscoverTypes(ResultSet)} needs the {@link ResultSet}.
 * 
 * As a hacky workaround, override
 * {@link #putResultInQueryCache(SessionImplementor, QueryParameters, Type[], QueryCache, QueryKey, List)} here
 * and provide the {@link #resultTypes}.
 * 
 * @see HHH-3051
 */
@Override
protected void putResultInQueryCache(
        final SessionImplementor session,
        final QueryParameters queryParameters,
        final Type[] resultTypes,
        final QueryCache queryCache,
        final QueryKey key,
        final List result) {
    super.putResultInQueryCache( session, queryParameters, this.resultTypes, queryCache, key, result );
}
项目:lams    文件:SessionFactoryImplementor.java   
/**
 * Get the default query cache
 */
public QueryCache getQueryCache();
项目:lams    文件:SessionFactoryImplementor.java   
/**
 * Get a particular named query cache, or the default cache
 * @param regionName the name of the cache region, or null for the default query cache
 * @return the existing cache, or a newly created cache if none by that region name
 */
public QueryCache getQueryCache(String regionName) throws HibernateException;
项目:lams    文件:CacheImplementor.java   
/**
 * Get query cache by <tt>region name</tt> or create a new one if none exist.
 * <p/>
 * If the region name is null, then default query cache region will be returned.
 *
 * @param regionName Query cache region name.
 * @return The {@code QueryCache} associated with the region name, or default query cache if the region name is <tt>null</tt>.
 * @throws HibernateException {@code HibernateException} maybe thrown when the creation of new QueryCache instance.
 */
public QueryCache getQueryCache(String regionName) throws HibernateException;
项目:lams    文件:CacheImplementor.java   
/**
 * Get the default {@code QueryCache}.
 */
public QueryCache getQueryCache();