下面列出了怎么用org.hibernate.cache.spi.QueryResultsRegion的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public CacheRegionStatisticsImpl getDomainDataRegionStatistics(String regionName) {
if ( sessionFactory == null ) {
return null;
}
return l2CacheStatsMap.computeIfAbsent(
regionName,
s -> {
final Region region = sessionFactory.getCache().getRegion( regionName );
if ( region == null ) {
throw new IllegalArgumentException( "Unknown cache region : " + regionName );
}
if ( region instanceof QueryResultsRegion ) {
throw new IllegalArgumentException(
"Region name [" + regionName + "] referred to a query result region, not a domain data region"
);
}
return new CacheRegionStatisticsImpl( region );
}
);
}
@Override
public QueryResultsRegion buildQueryResultsRegion(
String regionName,
SessionFactoryImplementor sessionFactory) {
verifyStarted();
return new QueryResultsRegionTemplate(
regionName,
this,
createQueryResultsRegionStorageAccess( regionName, sessionFactory )
);
}
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;
}
}
protected QueryResultsCache makeQueryResultsRegionAccess(String regionName) {
final QueryResultsRegion region = (QueryResultsRegion) regionsByName.computeIfAbsent(
regionName,
this::makeQueryResultsRegion
);
final QueryResultsCacheImpl regionAccess = new QueryResultsCacheImpl(
region,
timestampsCache
);
namedQueryResultsCacheMap.put( regionName, regionAccess );
legacySecondLevelCacheNames.add( regionName );
return regionAccess;
}
protected QueryResultsRegion makeQueryResultsRegion(String regionName) {
// make sure there is not an existing domain-data region with that name..
final Region existing = regionsByName.get( regionName );
if ( existing != null ) {
if ( !QueryResultsRegion.class.isInstance( existing ) ) {
throw new IllegalStateException( "Cannot store both domain-data and query-result-data in the same region [" + regionName );
}
throw new IllegalStateException( "Illegal call to create QueryResultsRegion - one already existed" );
}
return regionFactory.buildQueryResultsRegion( regionName, getSessionFactory() );
}
/** {@inheritDoc} */
@Override public QueryResultsRegion buildQueryResultsRegion(String regionName, Properties props)
throws CacheException {
return new HibernateQueryResultsRegion(this,
regionName,
accessStgyFactory.node(),
accessStgyFactory.regionCache(regionName));
}
/** {@inheritDoc} */
@Override public QueryResultsRegion buildQueryResultsRegion(String regionName, Properties props)
throws CacheException {
return new HibernateQueryResultsRegion(this,
regionName,
accessStgyFactory.node(),
accessStgyFactory.regionCache(regionName));
}
@Override
public QueryResultsRegion buildQueryResultsRegion(String regionName, Properties properties) throws CacheException {
log.debug("Building query cache region: " + regionName);
RMapCache<Object, Object> mapCache = getCache(regionName, properties, QUERY_DEF);
return new RedissonQueryRegion(mapCache, ((Redisson)redisson).getConnectionManager(),this, properties, QUERY_DEF);
}
QueryResultsCacheImpl(
QueryResultsRegion cacheRegion,
TimestampsCache timestampsCache) {
this.cacheRegion = cacheRegion;
this.timestampsCache = timestampsCache;
}
@Override
public QueryResultsRegion getRegion() {
return cacheRegion;
}
@Override
public QueryResultsRegion buildQueryResultsRegion(
String regionName, SessionFactoryImplementor sessionFactory) {
throw new NoCacheRegionFactoryAvailableException();
}
/** {@inheritDoc} */
@Override public QueryResultsRegion buildQueryResultsRegion(String regionName, SessionFactoryImplementor sessFactory) {
return new IgniteQueryResultsRegion(this, regionName, accessStgyFactory.node(),
accessStgyFactory.regionCache(regionName));
}