org.hibernate.cache.spi.Region Java Examples

The following examples show how to use org.hibernate.cache.spi.Region. 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: StatisticsImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@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 );
			}
	);
}
 
Example #2
Source File: StatisticsImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@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 );
			}
	);
}
 
Example #3
Source File: DeprecatedNaturalIdCacheStatisticsImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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;
}
 
Example #4
Source File: DeprecatedNaturalIdCacheStatisticsImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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;
}
 
Example #5
Source File: DeprecatedNaturalIdCacheStatisticsImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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;
}
 
Example #6
Source File: AbstractCacheableDataStatistics.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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();
	}
}
 
Example #7
Source File: EnabledCaching.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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() );
}
 
Example #8
Source File: CacheImplementor.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @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 ) );
}
 
Example #9
Source File: CacheRegionStatisticsImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
CacheRegionStatisticsImpl(Region region) {
	this.region = region;
}
 
Example #10
Source File: DisabledCaching.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Region getRegion(String fullRegionName) {
	return null;
}
 
Example #11
Source File: EnabledCaching.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Region getRegion(String regionName) {
	return regionsByName.get( regionName );
}
 
Example #12
Source File: EnabledCaching.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void close() {
	for ( Region region : regionsByName.values() ) {
		region.destroy();
	}
}
 
Example #13
Source File: SessionFactoryWrapper.java    From lemon with Apache License 2.0 4 votes vote down vote up
public Region getSecondLevelCacheRegion(String regionName) {
    return sessionFactoryImplementor.getSecondLevelCacheRegion(regionName);
}
 
Example #14
Source File: SessionFactoryWrapper.java    From lemon with Apache License 2.0 4 votes vote down vote up
public Region getNaturalIdCacheRegion(String regionName) {
    return sessionFactoryImplementor.getNaturalIdCacheRegion(regionName);
}
 
Example #15
Source File: CacheImplementor.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * 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);