本文整理汇总了Java中org.hibernate.stat.Statistics类的典型用法代码示例。如果您正苦于以下问题:Java Statistics类的具体用法?Java Statistics怎么用?Java Statistics使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Statistics类属于org.hibernate.stat包,在下文中一共展示了Statistics类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getStatistics
import org.hibernate.stat.Statistics; //导入依赖的package包/类
/**
* Get the {@code Statistics} object from the underlying {@code SessionFactory}. If it isn't hibernate that is
* used return {@code null}.
*
* @param emf an {@code EntityManagerFactory}
* @return the {@code Statistics} from the underlying {@code SessionFactory} or {@code null}.
*/
private Statistics getStatistics(EntityManagerFactory emf) {
try {
SessionFactory sf = emf.unwrap(SessionFactory.class);
return sf.getStatistics();
} catch (PersistenceException pe) {
return null;
}
}
示例2: perfTest
import org.hibernate.stat.Statistics; //导入依赖的package包/类
@Test(enabled = false)
public <T extends ObjectType> void perfTest() throws Exception {
Statistics stats = getFactory().getStatistics();
stats.setStatisticsEnabled(true);
final File OBJECTS_FILE = new File("./src/test/resources/10k-users.xml");
List<PrismObject<? extends Objectable>> elements = prismContext.parserFor(OBJECTS_FILE).parseObjects();
long previousCycle = 0;
long time = System.currentTimeMillis();
for (int i = 0; i < elements.size(); i++) {
if (i % 500 == 0) {
LOGGER.info("Previous cycle time {}. Next cycle: {}", new Object[]{
(System.currentTimeMillis() - time - previousCycle), i});
previousCycle = System.currentTimeMillis() - time;
}
PrismObject<T> object = (PrismObject<T>) elements.get(i);
repositoryService.addObject(object, null, new OperationResult("add performance test"));
}
LOGGER.info("Time to add objects ({}): {}",
new Object[]{elements.size(), (System.currentTimeMillis() - time)});
stats.logSummary();
}
示例3: statisticsAPI
import org.hibernate.stat.Statistics; //导入依赖的package包/类
@Test
public void statisticsAPI() {
log.info("... statisticsAPI ...");
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
List<Author> authors = em.createQuery("SELECT a FROM Author a", Author.class).getResultList();
for (Author a : authors) {
log.info(a.getFirstName() + " " + a.getLastName() + " wrote " + a.getBooks().size());
}
SessionFactory sessionFactory = emf.unwrap(SessionFactory.class);
Statistics stats = sessionFactory.getStatistics();
long queryCount = stats.getQueryExecutionCount();
long collectionFetchCount = stats.getCollectionFetchCount();
log.info("QueryCount: "+queryCount);
log.info("CollectionFetchCount: "+collectionFetchCount);
em.getTransaction().commit();
em.close();
}
示例4: test
import org.hibernate.stat.Statistics; //导入依赖的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());
}
示例5: getStatsValues
import org.hibernate.stat.Statistics; //导入依赖的package包/类
private Map<String, Long> getStatsValues(Collection<Class> entities) {
Statistics stats = getStats();
Map<String, Long> statistics = new HashMap<String, Long>();
statistics.put("Number of connection requests", stats.getConnectCount());
statistics.put("Sessions opened", stats.getSessionOpenCount());
// statistics.put("Sessions closed", stats.getSessionCloseCount());
statistics.put("Transactions", stats.getTransactionCount());
// statistics.put("Successful transactions", stats.getSuccessfulTransactionCount());
// statistics.put("Successful transactions", stats.getSuccessfulTransactionCount());
statistics.put("Queries executed", stats.getQueryExecutionCount());
for(Class entity : entities) {
EntityStatistics eStats = stats.getEntityStatistics(entity.getName());
statistics.put(entity.getSimpleName() + " Fetched", eStats.getFetchCount());
statistics.put(entity.getSimpleName() + " Loaded", eStats.getLoadCount());
statistics.put(entity.getSimpleName() + " Inserted", eStats.getInsertCount());
statistics.put(entity.getSimpleName() + " Deleted", eStats.getDeleteCount());
statistics.put(entity.getSimpleName() + " Updated", eStats.getUpdateCount());
}
return statistics;
}
示例6: 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());
}
示例7: counter
import org.hibernate.stat.Statistics; //导入依赖的package包/类
private void counter(MeterRegistry registry, String name, String description, ToDoubleFunction<Statistics> f, String... extraTags) {
FunctionCounter.builder(name, stats, f)
.tags(tags)
.tags(extraTags)
.description(description)
.register(registry);
}
示例8: createEntityManagerFactoryMock
import org.hibernate.stat.Statistics; //导入依赖的package包/类
private static EntityManagerFactory createEntityManagerFactoryMock(final boolean statsEnabled) {
EntityManagerFactory emf = Mockito.mock(EntityManagerFactory.class);
SessionFactory sf = Mockito.mock(SessionFactory.class);
Statistics stats = Mockito.mock(Statistics.class, invocation -> {
if (invocation.getMethod().getName().equals("isStatisticsEnabled")) {
return statsEnabled;
}
return 42L;
});
when(emf.unwrap(SessionFactory.class)).thenReturn(sf);
when(sf.getStatistics()).thenReturn(stats);
return emf;
}
示例9: verifyQueryCount
import org.hibernate.stat.Statistics; //导入依赖的package包/类
protected void verifyQueryCount(final Statistics stats) {
final long totalQueryCount = Math.max(stats.getQueryExecutionCount(), stats.getPrepareStatementCount());
if (assertions.maxQueries() >= 0 && totalQueryCount > assertions.maxQueries()) {
final StringBuilder msgBuf = new StringBuilder();
msgBuf.append("Statements prepared: ").append(stats.getPrepareStatementCount());
// Create list of queries for debugging purposes
final List<String> queryLines = Stream.of(stats.getQueries())
.map(query -> {
final QueryStatistics qStats = stats.getQueryStatistics(query);
return Tuple.of(qStats.getExecutionCount(), query);
})
.sorted(reverseOrder())
.map(pair -> String.format("%s: %s", StringUtils.leftPad(pair._1.toString(), 3, ' '), pair._2))
.collect(toList());
if (!queryLines.isEmpty()) {
msgBuf.append("\n Queries (ordered by execution count): ")
.append(stats.getQueryExecutionCount())
.append("\n ")
.append(Joiner.on("\n ").join(queryLines));
}
throw new MaximumQueryCountExceededException(String.format("%s\n %s\n",
MaximumQueryCountExceededException.getErrorMessage(assertions.maxQueries(), totalQueryCount),
msgBuf.toString()));
}
if (assertions.queryCount() >= 0 && totalQueryCount != assertions.queryCount()) {
throw new QueryCountAssertionException(assertions.queryCount(), totalQueryCount);
}
}
示例10: jmxService
import org.hibernate.stat.Statistics; //导入依赖的package包/类
@Bean
@DependsOn("statisticsService")
public MBeanExporter jmxService(Statistics statistics) {
MBeanExporter exporter = new MBeanExporter();
exporter.setBeans(ImmutableMap.of("Hibernate:application=Statistics", (Object) statistics));
return exporter;
}
示例11: 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);
}
示例12: 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);
}
示例13: 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() );
}
示例14: scalabilityOnPopulate
import org.hibernate.stat.Statistics; //导入依赖的package包/类
private void scalabilityOnPopulate(String pattern, String teamName, int nbApp, int nbReleasePerApp, int nbEnvPerRelease) throws BusinessException, MalformedURLException {
// Set reference values
Map<HibernateStatsReferenceType, Long> refs = new HashMap<HibernateStatsReferenceType, Long>(14);
refs.put(HibernateStatsReferenceType.DURATION, Long.valueOf(3600000));
refs.put(HibernateStatsReferenceType.QUERY_COUNT, Long.valueOf(1152));
refs.put(HibernateStatsReferenceType.QUERY_MAX_TIME_MS, Long.valueOf(1700));
refs.put(HibernateStatsReferenceType.ENTITY_FETCH_COUNT, Long.valueOf(8016));
refs.put(HibernateStatsReferenceType.ENTITY_LOAD_COUNT, Long.valueOf(43968));
refs.put(HibernateStatsReferenceType.ENTITY_INSERT_COUNT, Long.valueOf(44455));
refs.put(HibernateStatsReferenceType.ENTITY_DELETE_COUNT, Long.valueOf(0));
refs.put(HibernateStatsReferenceType.ENTITY_UPDATE_COUNT, Long.valueOf(3480));
refs.put(HibernateStatsReferenceType.COLLECTION_FETCH_COUNT, Long.valueOf(16360));
refs.put(HibernateStatsReferenceType.COLLECTION_LOAD_COUNT, Long.valueOf(16982));
refs.put(HibernateStatsReferenceType.COLLECTION_RECREATE_COUNT, Long.valueOf(29000));
refs.put(HibernateStatsReferenceType.COLLECTION_REMOVE_COUNT, Long.valueOf(0));
refs.put(HibernateStatsReferenceType.COLLECTION_UPDATE_COUNT, Long.valueOf(75));
// Creation of all paas users, app, app release and env
long startTime = System.currentTimeMillis();
manageScalability.populate(pattern, teamName, nbApp, nbReleasePerApp, nbEnvPerRelease);
long duration = System.currentTimeMillis() - startTime;
Statistics stats = sessionFactory.getStatistics();
logger.info("Test duration : " + duration);
StatisticsHelper.logStats(stats);
// Check stats
// Durations are not ignored as checking durations tends to make this test fragile due to IaaS and DBaaS response time dependencies
HibernateStatsHelper.checkStatsIgnoringDuration(refs, stats);
}
示例15: checkFetchJoin
import org.hibernate.stat.Statistics; //导入依赖的package包/类
@Test
public void checkFetchJoin() {
Statistics statistics = sessionFactory.getStatistics();
statistics.setStatisticsEnabled(true);
DataTablesOutput<A> output = getOutput(input);
assertThat(output.getRecordsFiltered()).isEqualTo(3);
assertThat(statistics.getPrepareStatementCount()).isEqualTo(2);
assertThat(statistics.getEntityLoadCount()).isEqualTo(3 /* A */ + 3 /* C */);
}