当前位置: 首页>>代码示例>>Java>>正文


Java Statistics类代码示例

本文整理汇总了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;
    }
}
 
开发者ID:micrometer-metrics,项目名称:micrometer,代码行数:16,代码来源:HibernateMetrics.java

示例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();
}
 
开发者ID:Pardus-Engerek,项目名称:engerek,代码行数:26,代码来源:AddGetObjectTest.java

示例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();
}
 
开发者ID:thjanssen,项目名称:HibernateTips,代码行数:24,代码来源:TestStatistics.java

示例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());
}
 
开发者ID:youngmonkeys,项目名称:ezyfox-db,代码行数:24,代码来源:BaseDbTest.java

示例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;
}
 
开发者ID:orange-cloudfoundry,项目名称:elpaaso-core,代码行数:21,代码来源:ManageStatisticsImpl.java

示例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());
    
}
 
开发者ID:CeON,项目名称:saos,代码行数:27,代码来源:SecondLevelCacheTest.java

示例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);
}
 
开发者ID:micrometer-metrics,项目名称:micrometer,代码行数:8,代码来源:HibernateMetrics.java

示例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;
}
 
开发者ID:micrometer-metrics,项目名称:micrometer,代码行数:14,代码来源:HibernateMetricsTest.java

示例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);
    }
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:35,代码来源:HibernateStatisticsVerifier.java

示例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;
}
 
开发者ID:przodownikR1,项目名称:springJpaKata,代码行数:8,代码来源:JmxConfig.java

示例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);
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:33,代码来源:StatisticsTest.java

示例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);

}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:30,代码来源:SessionStatsTest.java

示例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() );
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:9,代码来源:BaseCacheProviderTestCase.java

示例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);
}
 
开发者ID:orange-cloudfoundry,项目名称:elpaaso-core,代码行数:33,代码来源:PaasServicesScalabilityIT.java

示例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 */);
}
 
开发者ID:darrachequesne,项目名称:spring-data-jpa-datatables,代码行数:12,代码来源:RelationshipsRepositoryTest.java


注:本文中的org.hibernate.stat.Statistics类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。