下面列出了怎么用org.hibernate.cache.spi.Region的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 CacheRegionStatisticsImpl getCacheRegionStatistics(String regionName) {
if ( sessionFactory == null ) {
return null;
}
if ( ! sessionFactory.getSessionFactoryOptions().isSecondLevelCacheEnabled() ) {
return null;
}
return l2CacheStatsMap.computeIfAbsent(
regionName,
s -> {
Region region = sessionFactory.getCache().getRegion( regionName );
if ( region == null ) {
// this is the pre-5.3 behavior. and since this is a pre-5.3 method it should behave consistently
// NOTE that this method is deprecated
region = sessionFactory.getCache().getQueryResultsCache( regionName ).getRegion();
}
return new CacheRegionStatisticsImpl( region );
}
);
}
@Override
public long getElementCountInMemory() {
long count = 0;
HashSet<Region> processedRegions = null;
for ( NaturalIdDataAccess accessStrategy : accessStrategies ) {
final DomainDataRegion region = accessStrategy.getRegion();
if ( ExtendedStatisticsSupport.class.isInstance( region ) ) {
}
if ( region instanceof ExtendedStatisticsSupport ) {
if ( processedRegions == null ) {
processedRegions = new HashSet<>();
}
if ( processedRegions.add( region ) ) {
count += ( (ExtendedStatisticsSupport) region ).getElementCountInMemory();
}
}
}
if ( count == 0 ) {
return NO_EXTENDED_STAT_SUPPORT_RETURN;
}
return count;
}
@Override
public long getElementCountOnDisk() {
long count = 0;
HashSet<Region> processedRegions = null;
for ( NaturalIdDataAccess accessStrategy : accessStrategies ) {
final DomainDataRegion region = accessStrategy.getRegion();
if ( ExtendedStatisticsSupport.class.isInstance( region ) ) {
}
if ( region instanceof ExtendedStatisticsSupport ) {
if ( processedRegions == null ) {
processedRegions = new HashSet<>();
}
if ( processedRegions.add( region ) ) {
count += ( (ExtendedStatisticsSupport) region ).getElementCountOnDisk();
}
}
}
if ( count == 0 ) {
return NO_EXTENDED_STAT_SUPPORT_RETURN;
}
return count;
}
@Override
public long getSizeInMemory() {
long count = 0;
HashSet<Region> processedRegions = null;
for ( NaturalIdDataAccess accessStrategy : accessStrategies ) {
final DomainDataRegion region = accessStrategy.getRegion();
if ( ExtendedStatisticsSupport.class.isInstance( region ) ) {
}
if ( region instanceof ExtendedStatisticsSupport ) {
if ( processedRegions == null ) {
processedRegions = new HashSet<>();
}
if ( processedRegions.add( region ) ) {
count += ( (ExtendedStatisticsSupport) region ).getElementCountOnDisk();
}
}
}
if ( count == 0 ) {
return NO_EXTENDED_STAT_SUPPORT_RETURN;
}
return count;
}
public AbstractCacheableDataStatistics(Supplier<Region> regionSupplier) {
final Region region = regionSupplier.get();
if ( region == null ) {
this.cacheRegionName = null;
this.cacheHitCount = null;
this.cacheMissCount = null;
this.cachePutCount = null;
}
else {
this.cacheRegionName = region.getName();
this.cacheHitCount = new LongAdder();
this.cacheMissCount = new LongAdder();
this.cachePutCount = new LongAdder();
}
}
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() );
}
/**
* @deprecated No replacement - added just for support of the newly deprecated methods expecting a qualified region name
*/
@Deprecated
default Region getRegionByLegacyName(String legacyName) {
return getRegion( unqualifyRegionName( legacyName ) );
}
CacheRegionStatisticsImpl(Region region) {
this.region = region;
}
@Override
public Region getRegion(String fullRegionName) {
return null;
}
@Override
public Region getRegion(String regionName) {
return regionsByName.get( regionName );
}
@Override
public void close() {
for ( Region region : regionsByName.values() ) {
region.destroy();
}
}
public Region getSecondLevelCacheRegion(String regionName) {
return sessionFactoryImplementor.getSecondLevelCacheRegion(regionName);
}
public Region getNaturalIdCacheRegion(String regionName) {
return sessionFactoryImplementor.getNaturalIdCacheRegion(regionName);
}
/**
* Get a cache Region by name
*
* @apiNote It is only valid to call this method after {@link #prime} has
* been performed
*
* @since 5.3
*/
Region getRegion(String regionName);