本文整理汇总了Java中org.hibernate.stat.SecondLevelCacheStatistics类的典型用法代码示例。如果您正苦于以下问题:Java SecondLevelCacheStatistics类的具体用法?Java SecondLevelCacheStatistics怎么用?Java SecondLevelCacheStatistics使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SecondLevelCacheStatistics类属于org.hibernate.stat包,在下文中一共展示了SecondLevelCacheStatistics类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSecondLevelCacheStatistics
import org.hibernate.stat.SecondLevelCacheStatistics; //导入依赖的package包/类
/**
* Second level cache statistics per region
*
* @param regionName region name
*
* @return SecondLevelCacheStatistics
*/
public SecondLevelCacheStatistics getSecondLevelCacheStatistics(String regionName) {
ConcurrentSecondLevelCacheStatisticsImpl slcs
= (ConcurrentSecondLevelCacheStatisticsImpl) secondLevelCacheStatistics.get( regionName );
if ( slcs == null ) {
if ( sessionFactory == null ) {
return null;
}
Region region = sessionFactory.getSecondLevelCacheRegion( regionName );
if ( region == null ) {
return null;
}
slcs = new ConcurrentSecondLevelCacheStatisticsImpl( region );
ConcurrentSecondLevelCacheStatisticsImpl previous;
if ( ( previous = (ConcurrentSecondLevelCacheStatisticsImpl) secondLevelCacheStatistics.putIfAbsent(
regionName, slcs
) ) != null ) {
slcs = previous;
}
}
return slcs;
}
示例2: testUpdateEventuallyInvalidatesObject
import org.hibernate.stat.SecondLevelCacheStatistics; //导入依赖的package包/类
@Test
public void testUpdateEventuallyInvalidatesObject() {
insertDummyEntities(10, 4);
//all 10 entities and 40 properties are cached
SecondLevelCacheStatistics dummyEntityCacheStats = sf.getStatistics().getSecondLevelCacheStatistics(CACHE_ENTITY);
SecondLevelCacheStatistics dummyPropertyCacheStats = sf.getStatistics().getSecondLevelCacheStatistics(CACHE_PROPERTY);
sf.getCache().evictEntityRegions();
sf.getCache().evictCollectionRegions();
//miss 10 entities
getDummyEntities(sf, 10);
//hit 1 entity and 4 properties
updateDummyEntityName(sf, 2, "updated");
assertSizeEventually(9, dummyEntityCacheStats.getEntries());
}
示例3: testGetUpdateRemoveGet
import org.hibernate.stat.SecondLevelCacheStatistics; //导入依赖的package包/类
@Test
public void testGetUpdateRemoveGet()
throws Exception {
insertDummyEntities(10, 4);
//all 10 entities and 40 properties are cached
SecondLevelCacheStatistics dummyEntityCacheStats = sf.getStatistics().getSecondLevelCacheStatistics(CACHE_ENTITY);
SecondLevelCacheStatistics dummyPropertyCacheStats = sf.getStatistics().getSecondLevelCacheStatistics(CACHE_PROPERTY);
sf.getCache().evictEntityRegions();
sf.getCache().evictCollectionRegions();
//miss 10 entities
getDummyEntities(sf, 10);
//hit 1 entity and 4 properties
deleteDummyEntity(sf, 1);
assertEquals(4, dummyPropertyCacheStats.getHitCount());
assertEquals(0, dummyPropertyCacheStats.getMissCount());
assertEquals(1, dummyEntityCacheStats.getHitCount());
assertEquals(10, dummyEntityCacheStats.getMissCount());
}
示例4: testUpdateShouldNotInvalidateEntryInCache
import org.hibernate.stat.SecondLevelCacheStatistics; //导入依赖的package包/类
@Test
public void testUpdateShouldNotInvalidateEntryInCache() {
insertDummyEntities(10, 4);
//all 10 entities and 40 properties are cached
SecondLevelCacheStatistics dummyEntityCacheStats = sf.getStatistics().getSecondLevelCacheStatistics(CACHE_ENTITY);
sf.getCache().evictEntityRegions();
sf.getCache().evictCollectionRegions();
//miss 10 entities, 10 entities are cached
getDummyEntities(sf, 10);
//updates cache entity
updateDummyEntityName(sf, 2, "updated");
assertEquals(10, dummyEntityCacheStats.getElementCountInMemory());
}
示例5: test
import org.hibernate.stat.SecondLevelCacheStatistics; //导入依赖的package包/类
@Test
public void test() {
SessionFactory factory = SessionFactoryProvider
.getInstance().provide(Context.class);
Statistics statistics = factory.getStatistics();
SecondLevelCacheStatistics secondStat = factory.getStatistics().getSecondLevelCacheStatistics(GameUser.class.getName());
deleteAll();
logger.info("==========>>>deleteAll: second level cache hits: " + statistics.getSecondLevelCacheHitCount());
logger.info("==========>>>deleteAll: query execution hits: " + statistics.getQueryExecutionCount());
logger.info("==========>>>deleteAll: element count in mem: " + secondStat.getElementCountInMemory());
intsert5();
logger.info("==========>>>intsert5: second level cache hits: " + statistics.getSecondLevelCacheHitCount());
logger.info("==========>>>intsert5: query execution hits: " + statistics.getQueryExecutionCount());
logger.info("==========>>>intsert5: element count in mem: " + secondStat.getElementCountInMemory());
doSomeThing();
logger.info("==========>>>doSomeThing: second level cache hits: " + statistics.getSecondLevelCacheHitCount());
logger.info("==========>>>doSomeThing: query execution hits: " + statistics.getQueryExecutionCount());
logger.info("==========>>>doSomeThing: element count in mem: " + secondStat.getElementCountInMemory());
deleteAll();
logger.info("==========>>>deleteAll: second level cache hits: " + statistics.getSecondLevelCacheHitCount());
logger.info("==========>>>deleteAll: query execution hits: " + statistics.getQueryExecutionCount());
logger.info("==========>>>deleteAll: element count in mem: " + secondStat.getElementCountInMemory());
}
示例6: testUpdateEventuallyInvalidatesObject
import org.hibernate.stat.SecondLevelCacheStatistics; //导入依赖的package包/类
@Test
public void testUpdateEventuallyInvalidatesObject() {
insertDummyEntities(10, 4);
//all 10 entities and 40 properties are cached
final SecondLevelCacheStatistics dummyEntityCacheStats = sf.getStatistics().getSecondLevelCacheStatistics(CACHE_ENTITY);
SecondLevelCacheStatistics dummyPropertyCacheStats = sf.getStatistics().getSecondLevelCacheStatistics(CACHE_PROPERTY);
sf.getCache().evictEntityRegions();
sf.getCache().evictCollectionRegions();
//miss 10 entities
getDummyEntities(sf, 10);
//hit 1 entity and 4 properties
updateDummyEntityName(sf, 2, "updated");
assertSizeEventually(9, dummyEntityCacheStats.getEntries());
}
示例7: assertCollectionCache
import org.hibernate.stat.SecondLevelCacheStatistics; //导入依赖的package包/类
/**
* @param sesFactory Session factory.
* @param idToChildCnt Number of children per entity.
* @param expHit Expected cache hits.
* @param expMiss Expected cache misses.
*/
@SuppressWarnings("unchecked")
private void assertCollectionCache(SessionFactory sesFactory, Map<Integer, Integer> idToChildCnt, int expHit,
int expMiss) {
sesFactory.getStatistics().clear();
Session ses = sesFactory.openSession();
try {
for(Map.Entry<Integer, Integer> e : idToChildCnt.entrySet()) {
Entity entity = (Entity)ses.load(Entity.class, e.getKey());
assertEquals((int)e.getValue(), entity.getChildren().size());
}
}
finally {
ses.close();
}
SecondLevelCacheStatistics stats =
sesFactory.getStatistics().getSecondLevelCacheStatistics(CHILD_COLLECTION_REGION);
assertEquals(expHit, stats.getHitCount());
assertEquals(expMiss, stats.getMissCount());
}
示例8: printStats
import org.hibernate.stat.SecondLevelCacheStatistics; //导入依赖的package包/类
/**
* Prints Hibernate L2 cache statistics to standard output.
*
* @param sesFactory Hibernate {@link SessionFactory}, for which to print
* statistics.
*/
private static void printStats(SessionFactory sesFactory) {
System.out.println("=== Hibernate L2 cache statistics ===");
for (String entityName : ENTITY_NAMES) {
System.out.println("\tEntity: " + entityName);
SecondLevelCacheStatistics stats =
sesFactory.getStatistics().getSecondLevelCacheStatistics(entityName);
System.out.println("\t\tPuts: " + stats.getPutCount());
System.out.println("\t\tHits: " + stats.getHitCount());
System.out.println("\t\tMisses: " + stats.getMissCount());
}
System.out.println("=====================================");
}
示例9: testGetUpdateRemoveGet
import org.hibernate.stat.SecondLevelCacheStatistics; //导入依赖的package包/类
@Test
public void testGetUpdateRemoveGet()
throws Exception {
insertDummyEntities(10, 4);
//all 10 entities and 40 properties are cached
SecondLevelCacheStatistics dummyEntityCacheStats = sf.getStatistics().getSecondLevelCacheStatistics(CACHE_ENTITY);
SecondLevelCacheStatistics dummyPropertyCacheStats = sf.getStatistics().getSecondLevelCacheStatistics(CACHE_PROPERTY);
sf.getCache().evictEntityRegions();
sf.getCache().evictCollectionRegions();
//miss 10 entities
getDummyEntities(sf, 10);
//hit 1 entity and 4 properties
updateDummyEntityName(sf, 2, "updated");
//entity 2 and its properties are invalidated
//miss updated entity, hit 4 properties(they are still the same)
getPropertiesOfEntity(sf, 2);
//hit 1 entity and 4 properties
deleteDummyEntity(sf, 1);
assertEquals(12, dummyPropertyCacheStats.getHitCount());
assertEquals(0, dummyPropertyCacheStats.getMissCount());
assertEquals(2, dummyEntityCacheStats.getHitCount());
assertEquals(11, dummyEntityCacheStats.getMissCount());
}
示例10: testUpdateQueryCausesInvalidationOfEntireRegion
import org.hibernate.stat.SecondLevelCacheStatistics; //导入依赖的package包/类
@Test
public void testUpdateQueryCausesInvalidationOfEntireRegion() {
insertDummyEntities(10);
executeUpdateQuery(sf, "UPDATE DummyEntity set name = 'manually-updated' where id=2");
sf.getStatistics().clear();
getDummyEntities(sf, 10);
SecondLevelCacheStatistics dummyEntityCacheStats = sf.getStatistics().getSecondLevelCacheStatistics(CACHE_ENTITY);
assertEquals(10, dummyEntityCacheStats.getMissCount());
assertEquals(0, dummyEntityCacheStats.getHitCount());
}
示例11: testUpdateQueryCausesInvalidationOfEntireCollectionRegion
import org.hibernate.stat.SecondLevelCacheStatistics; //导入依赖的package包/类
@Test
public void testUpdateQueryCausesInvalidationOfEntireCollectionRegion() {
insertDummyEntities(1, 10);
//properties reference in DummyEntity is evicted because of custom SQL query on Collection region
executeUpdateQuery(sf, "update DummyProperty ent set ent.key='manually-updated'");
sf.getStatistics().clear();
//property reference missed in cache.
getPropertiesOfEntity(sf, 0);
SecondLevelCacheStatistics dummyPropertyCacheStats = sf.getStatistics().getSecondLevelCacheStatistics(CACHE_ENTITY + ".properties");
assertEquals(0, dummyPropertyCacheStats.getHitCount());
assertEquals(1, dummyPropertyCacheStats.getMissCount());
}
示例12: testGetUpdateRemoveGet
import org.hibernate.stat.SecondLevelCacheStatistics; //导入依赖的package包/类
@Test
public void testGetUpdateRemoveGet()
throws Exception {
insertDummyEntities(10, 4);
//all 10 entities and 40 properties are cached
SecondLevelCacheStatistics dummyEntityCacheStats = sf.getStatistics().getSecondLevelCacheStatistics(CACHE_ENTITY);
SecondLevelCacheStatistics dummyPropertyCacheStats = sf.getStatistics().getSecondLevelCacheStatistics(CACHE_PROPERTY);
sf.getCache().evictEntityRegions();
sf.getCache().evictCollectionRegions();
//miss 10 entities
getDummyEntities(sf, 10);
//hit 1 entity and 4 properties
updateDummyEntityName(sf, 2, "updated");
//hit 1 entity, hit 4 properties
getPropertiesOfEntity(sf, 2);
//hit 1 entity and 4 properties
deleteDummyEntity(sf, 1);
assertEquals(12, dummyPropertyCacheStats.getHitCount());
assertEquals(0, dummyPropertyCacheStats.getMissCount());
assertEquals(3, dummyEntityCacheStats.getHitCount());
assertEquals(10, dummyEntityCacheStats.getMissCount());
}
示例13: testGetUpdateRemoveGet
import org.hibernate.stat.SecondLevelCacheStatistics; //导入依赖的package包/类
@Test
public void testGetUpdateRemoveGet()
throws Exception {
insertDummyEntities(10, 4);
//all 10 entities and 40 properties are cached
SecondLevelCacheStatistics dummyEntityCacheStats = sf.getStatistics().getSecondLevelCacheStatistics(CACHE_ENTITY);
SecondLevelCacheStatistics dummyPropertyCacheStats = sf.getStatistics().getSecondLevelCacheStatistics(CACHE_PROPERTY);
sf.getCache().evictEntityRegions();
sf.getCache().evictCollectionRegions();
//miss 10 entities
getDummyEntities(sf, 10);
//hit 1 entity and 4 properties
updateDummyEntityName(sf, 2, "updated");
//invalidation is not synchronized, so we have to wait
//entity 2 and its properties are invalidated
//miss updated entity, hit 4 properties(they are still the same)
getPropertiesOfEntity(sf, 2);
//hit 1 entity and 4 properties
deleteDummyEntity(sf, 1);
assertEquals(12, dummyPropertyCacheStats.getHitCount());
assertEquals(0, dummyPropertyCacheStats.getMissCount());
assertEquals(2, dummyEntityCacheStats.getHitCount());
assertEquals(11, dummyEntityCacheStats.getMissCount());
}
示例14: testEmptySecondLevelCacheEntry
import org.hibernate.stat.SecondLevelCacheStatistics; //导入依赖的package包/类
public void testEmptySecondLevelCacheEntry() throws Exception {
getSessions().evictEntity( Item.class.getName() );
Statistics stats = getSessions().getStatistics();
stats.clear();
SecondLevelCacheStatistics statistics = stats.getSecondLevelCacheStatistics( Item.class.getName() );
Map cacheEntries = statistics.getEntries();
assertEquals( 0, cacheEntries.size() );
}
示例15: printEntityCacheStats
import org.hibernate.stat.SecondLevelCacheStatistics; //导入依赖的package包/类
protected void printEntityCacheStats(String region, boolean printEntries) {
SecondLevelCacheStatistics stats = getCacheStats(region);
LOGGER.info(region + " Stats: \n\n\t" + stats + "\n");
if (printEntries) {
@SuppressWarnings("rawtypes")
Map cacheEntries = stats.getEntries();
LOGGER.info(Arrays.toString(cacheEntries.entrySet().toArray()));
}
}