本文整理汇总了Java中org.hibernate.stat.Statistics.clear方法的典型用法代码示例。如果您正苦于以下问题:Java Statistics.clear方法的具体用法?Java Statistics.clear怎么用?Java Statistics.clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hibernate.stat.Statistics
的用法示例。
在下文中一共展示了Statistics.clear方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test
import org.hibernate.stat.Statistics; //导入方法依赖的package包/类
@Test
public void test() {
Cache cache = entityManager.getEntityManagerFactory().getCache();
cache.evictAll();
Statistics statistics = ((Session)(entityManager.getDelegate())).getSessionFactory().getStatistics();
statistics.clear();
CommonCourt commonCourt = testPersistenceObjectFactory.createCcCourt(CommonCourtType.APPEAL);
commonCourtRepository.findOne(commonCourt.getId());
commonCourtRepository.findOne(commonCourt.getId());
Assert.assertTrue(cache.contains(CommonCourt.class, commonCourt.getId()));
Assert.assertTrue(cache.contains(CommonCourtDivision.class, commonCourt.getDivisions().get(0).getId()));
Assert.assertTrue(cache.contains(CommonCourtDivision.class, commonCourt.getDivisions().get(1).getId()));
cache.evict(CommonCourt.class);
cache.evict(CommonCourtDivision.class);
Assert.assertFalse(cache.contains(CommonCourt.class, commonCourt.getId()));
Assert.assertFalse(cache.contains(CommonCourtDivision.class, commonCourt.getDivisions().get(0).getId()));
Assert.assertFalse(cache.contains(CommonCourtDivision.class, commonCourt.getDivisions().get(1).getId()));
Assert.assertEquals(5, statistics.getSecondLevelCachePutCount()); // 1 commonCourt + 2 ccDivision + 2 ccDivisionType
Assert.assertEquals(2, statistics.getSecondLevelCacheHitCount());
Assert.assertEquals(0, statistics.getSecondLevelCacheMissCount());
}
示例2: testSessionStats
import org.hibernate.stat.Statistics; //导入方法依赖的package包/类
public void testSessionStats() throws Exception {
SessionFactory sf = getSessions();
Statistics stats = sf.getStatistics();
boolean isStats = stats.isStatisticsEnabled();
stats.clear();
stats.setStatisticsEnabled(true);
Session s = sf.openSession();
assertEquals( 1, stats.getSessionOpenCount() );
s.close();
assertEquals( 1, stats.getSessionCloseCount() );
s = sf.openSession();
Transaction tx = s.beginTransaction();
A a = new A();
a.setName("mya");
s.save(a);
a.setName("b");
tx.commit();
s.close();
assertEquals( 1, stats.getFlushCount() );
s = sf.openSession();
tx = s.beginTransaction();
String hql = "from " + A.class.getName();
Query q = s.createQuery(hql);
q.list();
tx.commit();
s.close();
assertEquals(1, stats.getQueryExecutionCount() );
assertEquals(1, stats.getQueryStatistics(hql).getExecutionCount() );
stats.setStatisticsEnabled(isStats);
}
示例3: testSessionStatistics
import org.hibernate.stat.Statistics; //导入方法依赖的package包/类
public void testSessionStatistics() throws Exception {
Session s = openSession();
Transaction tx = s.beginTransaction();
Statistics stats = getSessions().getStatistics();
stats.clear();
boolean isStats = stats.isStatisticsEnabled();
stats.setStatisticsEnabled(true);
Continent europe = fillDb(s);
tx.commit();
s.clear();
tx = s.beginTransaction();
SessionStatistics sessionStats = s.getStatistics();
assertEquals( 0, sessionStats.getEntityKeys().size() );
assertEquals( 0, sessionStats.getEntityCount() );
assertEquals( 0, sessionStats.getCollectionKeys().size() );
assertEquals( 0, sessionStats.getCollectionCount() );
europe = (Continent) s.get( Continent.class, europe.getId() );
Hibernate.initialize( europe.getCountries() );
Hibernate.initialize( europe.getCountries().iterator().next() );
assertEquals( 2, sessionStats.getEntityKeys().size() );
assertEquals( 2, sessionStats.getEntityCount() );
assertEquals( 1, sessionStats.getCollectionKeys().size() );
assertEquals( 1, sessionStats.getCollectionCount() );
tx.commit();
s.close();
stats.setStatisticsEnabled( isStats);
}
示例4: testEmptySecondLevelCacheEntry
import org.hibernate.stat.Statistics; //导入方法依赖的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() );
}
示例5: verifyAndClear
import org.hibernate.stat.Statistics; //导入方法依赖的package包/类
public void verifyAndClear() {
final Statistics stats = getStatistics();
verifyQueryCount(stats);
stats.clear();
}
示例6: testJoinedSubclass
import org.hibernate.stat.Statistics; //导入方法依赖的package包/类
public void testJoinedSubclass() {
if ( ! supportsCircularCascadeDelete() ) {
return;
}
Statistics statistics = getSessions().getStatistics();
statistics.clear();
Session s = openSession();
Transaction t = s.beginTransaction();
Salesperson mark = new Salesperson();
mark.setName("Mark");
mark.setTitle("internal sales");
mark.setSex('M');
mark.setAddress("buckhead");
mark.setZip("30305");
mark.setCountry("USA");
Person joe = new Person();
joe.setName("Joe");
joe.setAddress("San Francisco");
joe.setZip("XXXXX");
joe.setCountry("USA");
joe.setSex('M');
joe.setSalesperson(mark);
mark.getCustomers().add(joe);
s.save(mark);
t.commit();
assertEquals( statistics.getEntityInsertCount(), 2 );
assertEquals( statistics.getPrepareStatementCount(), 5 );
statistics.clear();
t = s.beginTransaction();
s.delete(mark);
t.commit();
assertEquals( statistics.getEntityDeleteCount(), 2 );
if ( !(getDialect() instanceof MySQLDialect) || (getDialect() instanceof MySQLInnoDBDialect) ) {
assertEquals( statistics.getPrepareStatementCount(), 1 );
}
t = s.beginTransaction();
List names = s.createQuery("select name from Person").list();
assertTrue( names.isEmpty() );
t.commit();
s.close();
}
示例7: testQueryStatGathering
import org.hibernate.stat.Statistics; //导入方法依赖的package包/类
public void testQueryStatGathering() {
Statistics stats = getSessions().getStatistics();
stats.clear();
Session s = openSession();
Transaction tx = s.beginTransaction();
fillDb(s);
tx.commit();
s.close();
s = openSession();
tx = s.beginTransaction();
final String continents = "from Continent";
int results = s.createQuery( continents ).list().size();
QueryStatistics continentStats = stats.getQueryStatistics( continents );
assertNotNull( "stats were null", continentStats );
assertEquals( "unexpected execution count", 1, continentStats.getExecutionCount() );
assertEquals( "unexpected row count", results, continentStats.getExecutionRowCount() );
long maxTime = continentStats.getExecutionMaxTime();
assertEquals( maxTime, stats.getQueryExecutionMaxTime() );
// assertEquals( continents, stats.getQueryExecutionMaxTimeQueryString() );
Iterator itr = s.createQuery( continents ).iterate();
// iterate() should increment the execution count
assertEquals( "unexpected execution count", 2, continentStats.getExecutionCount() );
// but should not effect the cumulative row count
assertEquals( "unexpected row count", results, continentStats.getExecutionRowCount() );
Hibernate.close( itr );
ScrollableResults scrollableResults = s.createQuery( continents ).scroll();
// same deal with scroll()...
assertEquals( "unexpected execution count", 3, continentStats.getExecutionCount() );
assertEquals( "unexpected row count", results, continentStats.getExecutionRowCount() );
scrollableResults.close();
tx.commit();
s.close();
// explicitly check that statistics for "split queries" get collected
// under the original query
stats.clear();
s = openSession();
tx = s.beginTransaction();
final String localities = "from Locality";
results = s.createQuery( localities ).list().size();
QueryStatistics localityStats = stats.getQueryStatistics( localities );
assertNotNull( "stats were null", localityStats );
// ...one for each split query
assertEquals( "unexpected execution count", 2, localityStats.getExecutionCount() );
assertEquals( "unexpected row count", results, localityStats.getExecutionRowCount() );
maxTime = localityStats.getExecutionMaxTime();
assertEquals( maxTime, stats.getQueryExecutionMaxTime() );
// assertEquals( localities, stats.getQueryExecutionMaxTimeQueryString() );
tx.commit();
s.close();
assertFalse( s.isOpen() );
// native sql queries
stats.clear();
s = openSession();
tx = s.beginTransaction();
final String sql = "select id, name from Country";
results = s.createSQLQuery( sql ).addEntity( Country.class ).list().size();
QueryStatistics sqlStats = stats.getQueryStatistics( sql );
assertNotNull( "sql stats were null", sqlStats );
assertEquals( "unexpected execution count", 1, sqlStats.getExecutionCount() );
assertEquals( "unexpected row count", results, sqlStats.getExecutionRowCount() );
maxTime = sqlStats.getExecutionMaxTime();
assertEquals( maxTime, stats.getQueryExecutionMaxTime() );
// assertEquals( sql, stats.getQueryExecutionMaxTimeQueryString() );
tx.commit();
s.close();
s = openSession();
tx = s.beginTransaction();
cleanDb( s );
tx.commit();
s.close();
}