Search in sources :

Example 36 with Statistics

use of org.hibernate.stat.Statistics in project gocd by gocd.

the class HibernateInformationProvider method asJson.

@Override
public Map<String, Object> asJson() {
    LinkedHashMap<String, Object> json = new LinkedHashMap<>();
    Statistics statistics = sessionFactory.getStatistics();
    if (!statistics.isStatisticsEnabled()) {
        return json;
    }
    json.put("EntityDeleteCount", statistics.getEntityDeleteCount());
    json.put("EntityInsertCount", statistics.getEntityInsertCount());
    json.put("EntityLoadCount", statistics.getEntityLoadCount());
    json.put("EntityFetchCount", statistics.getEntityFetchCount());
    json.put("EntityUpdateCount", statistics.getEntityUpdateCount());
    json.put("QueryExecutionCount", statistics.getQueryExecutionCount());
    json.put("QueryExecutionMaxTime", statistics.getQueryExecutionMaxTime());
    json.put("QueryExecutionMaxTimeQueryString", statistics.getQueryExecutionMaxTimeQueryString());
    json.put("QueryCacheHitCount", statistics.getQueryCacheHitCount());
    json.put("QueryCacheMissCount", statistics.getQueryCacheMissCount());
    json.put("QueryCachePutCount", statistics.getQueryCachePutCount());
    json.put("FlushCount", statistics.getFlushCount());
    json.put("ConnectCount", statistics.getConnectCount());
    json.put("SecondLevelCacheHitCount", statistics.getSecondLevelCacheHitCount());
    json.put("SecondLevelCacheMissCount", statistics.getSecondLevelCacheMissCount());
    json.put("SecondLevelCachePutCount", statistics.getSecondLevelCachePutCount());
    json.put("SessionCloseCount", statistics.getSessionCloseCount());
    json.put("SessionOpenCount", statistics.getSessionOpenCount());
    json.put("CollectionLoadCount", statistics.getCollectionLoadCount());
    json.put("CollectionFetchCount", statistics.getCollectionFetchCount());
    json.put("CollectionUpdateCount", statistics.getCollectionUpdateCount());
    json.put("CollectionRemoveCount", statistics.getCollectionRemoveCount());
    json.put("CollectionRecreateCount", statistics.getCollectionRecreateCount());
    json.put("StartTime", statistics.getStartTime());
    json.put("SecondLevelCacheRegionNames", statistics.getSecondLevelCacheRegionNames());
    json.put("SuccessfulTransactionCount", statistics.getSuccessfulTransactionCount());
    json.put("TransactionCount", statistics.getTransactionCount());
    json.put("PrepareStatementCount", statistics.getPrepareStatementCount());
    json.put("CloseStatementCount", statistics.getCloseStatementCount());
    json.put("OptimisticFailureCount", statistics.getOptimisticFailureCount());
    LinkedHashMap<String, Object> queryStats = new LinkedHashMap<>();
    json.put("Queries", queryStats);
    String[] queries = statistics.getQueries();
    for (String query : queries) {
        queryStats.put(query, statistics.getQueryStatistics(query));
    }
    LinkedHashMap<String, Object> entityStatistics = new LinkedHashMap<>();
    json.put("EntityStatistics", entityStatistics);
    String[] entityNames = statistics.getEntityNames();
    for (String entityName : entityNames) {
        entityStatistics.put(entityName, statistics.getEntityStatistics(entityName));
    }
    LinkedHashMap<String, Object> roleStatistics = new LinkedHashMap<>();
    json.put("RoleStatistics", roleStatistics);
    String[] roleNames = statistics.getCollectionRoleNames();
    for (String roleName : roleNames) {
        roleStatistics.put(roleName, statistics.getCollectionStatistics(roleName));
    }
    return json;
}
Also used : Statistics(org.hibernate.stat.Statistics) LinkedHashMap(java.util.LinkedHashMap)

Example 37 with Statistics

use of org.hibernate.stat.Statistics in project OpenClinica by OpenClinica.

the class RuleSetRuleDao method findByRuleSetStudyIdAndStatusAvail.

/**
     * Use this method carefully as we force an eager fetch. It is also annotated with 
     * Transactional so it can be called from Quartz threads. 
     * @param studyId
     * @return List of RuleSetRuleBeans 
     */
@SuppressWarnings("unchecked")
@Transactional
public ArrayList<RuleSetRuleBean> findByRuleSetStudyIdAndStatusAvail(Integer studyId) {
    String query = "from " + getDomainClassName() + " ruleSetRule  where ruleSetRule.ruleSetBean.studyId = :studyId and status = :status ";
    org.hibernate.Query q = getCurrentSession().createQuery(query);
    q.setInteger("studyId", studyId);
    q.setParameter("status", org.akaza.openclinica.domain.Status.AVAILABLE);
    q.setCacheable(true);
    q.setCacheRegion(getDomainClassName());
    //JN: enabling statistics for hibernate queries etc... to monitor the performance
    Statistics stats = getSessionFactory().getStatistics();
    logger.info("EntityRuleSet" + stats.getEntityInsertCount());
    logger.info(stats.getQueryExecutionMaxTimeQueryString());
    logger.info("hit count" + stats.getSecondLevelCacheHitCount());
    stats.logSummary();
    ArrayList<RuleSetRuleBean> ruleSetRules = (ArrayList<RuleSetRuleBean>) q.list();
    // Forcing eager fetch of actions & their properties
    for (RuleSetRuleBean ruleSetRuleBean : ruleSetRules) {
        for (RuleActionBean action : ruleSetRuleBean.getActions()) {
            if (action instanceof RandomizeActionBean) {
                ((RandomizeActionBean) action).getProperties().size();
            }
            if (action instanceof InsertActionBean) {
                ((InsertActionBean) action).getProperties().size();
            }
            if (action instanceof ShowActionBean) {
                ((ShowActionBean) action).getProperties().size();
            }
            if (action instanceof HideActionBean) {
                ((HideActionBean) action).getProperties().size();
            }
            if (action instanceof EventActionBean) {
                ((EventActionBean) action).getProperties().size();
            }
        }
    }
    return ruleSetRules;
}
Also used : ShowActionBean(org.akaza.openclinica.domain.rule.action.ShowActionBean) HideActionBean(org.akaza.openclinica.domain.rule.action.HideActionBean) RuleActionBean(org.akaza.openclinica.domain.rule.action.RuleActionBean) RuleSetRuleBean(org.akaza.openclinica.domain.rule.RuleSetRuleBean) InsertActionBean(org.akaza.openclinica.domain.rule.action.InsertActionBean) ArrayList(java.util.ArrayList) Statistics(org.hibernate.stat.Statistics) EventActionBean(org.akaza.openclinica.domain.rule.action.EventActionBean) RandomizeActionBean(org.akaza.openclinica.domain.rule.action.RandomizeActionBean) Transactional(org.springframework.transaction.annotation.Transactional)

Example 38 with Statistics

use of org.hibernate.stat.Statistics in project hibernate-orm by hibernate.

the class HibernateStatsImpl method getEntityStats.

@Override
public TabularData getEntityStats() {
    final List<CompositeData> result = new ArrayList<CompositeData>();
    final Statistics statistics = getStatistics();
    for (String entity : statistics.getEntityNames()) {
        final EntityStats entityStats = new EntityStats(entity, statistics.getEntityStatistics(entity));
        result.add(entityStats.toCompositeData());
    }
    final TabularData td = EntityStats.newTabularDataInstance();
    td.putAll(result.toArray(new CompositeData[result.size()]));
    return td;
}
Also used : CompositeData(javax.management.openmbean.CompositeData) ArrayList(java.util.ArrayList) Statistics(org.hibernate.stat.Statistics) TabularData(javax.management.openmbean.TabularData)

Example 39 with Statistics

use of org.hibernate.stat.Statistics in project hibernate-orm by hibernate.

the class HibernateStatsImpl method getCollectionStats.

@Override
public TabularData getCollectionStats() {
    final List<CompositeData> result = new ArrayList<CompositeData>();
    final Statistics statistics = getStatistics();
    for (String roleName : statistics.getCollectionRoleNames()) {
        final CollectionStats collectionStats = new CollectionStats(roleName, statistics.getCollectionStatistics(roleName));
        result.add(collectionStats.toCompositeData());
    }
    final TabularData td = CollectionStats.newTabularDataInstance();
    td.putAll(result.toArray(new CompositeData[result.size()]));
    return td;
}
Also used : CompositeData(javax.management.openmbean.CompositeData) ArrayList(java.util.ArrayList) Statistics(org.hibernate.stat.Statistics) TabularData(javax.management.openmbean.TabularData)

Example 40 with Statistics

use of org.hibernate.stat.Statistics in project hibernate-orm by hibernate.

the class EhCacheTest method testEmptySecondLevelCacheEntry.

@Test
public void testEmptySecondLevelCacheEntry() throws Exception {
    sessionFactory().getCache().evictEntityRegion(Item.class.getName());
    Statistics stats = sessionFactory().getStatistics();
    stats.clear();
    SecondLevelCacheStatistics statistics = stats.getSecondLevelCacheStatistics(Item.class.getName());
    Map cacheEntries = statistics.getEntries();
    assertEquals(0, cacheEntries.size());
}
Also used : SecondLevelCacheStatistics(org.hibernate.stat.SecondLevelCacheStatistics) SecondLevelCacheStatistics(org.hibernate.stat.SecondLevelCacheStatistics) Statistics(org.hibernate.stat.Statistics) Map(java.util.Map) Test(org.junit.Test)

Aggregations

Statistics (org.hibernate.stat.Statistics)61 Test (org.junit.Test)44 SecondLevelCacheStatistics (org.hibernate.stat.SecondLevelCacheStatistics)28 Session (org.hibernate.Session)16 EntityManager (javax.persistence.EntityManager)15 Item (org.hibernate.test.cache.infinispan.functional.entities.Item)14 Transaction (org.hibernate.Transaction)12 VersionedItem (org.hibernate.test.cache.infinispan.functional.entities.VersionedItem)11 OtherItem (org.hibernate.test.cache.infinispan.functional.entities.OtherItem)10 QueryStatistics (org.hibernate.stat.QueryStatistics)9 ByRef (org.infinispan.commons.util.ByRef)8 ArrayList (java.util.ArrayList)7 List (java.util.List)7 Map (java.util.Map)4 CompositeData (javax.management.openmbean.CompositeData)4 TabularData (javax.management.openmbean.TabularData)4 Criteria (org.hibernate.Criteria)4 NaturalIdLoadAccess (org.hibernate.NaturalIdLoadAccess)4 SessionFactory (org.hibernate.SessionFactory)4 TestForIssue (org.hibernate.testing.TestForIssue)4