Example usage for org.hibernate.stat EntityStatistics getOptimisticFailureCount

List of usage examples for org.hibernate.stat EntityStatistics getOptimisticFailureCount

Introduction

In this page you can find the example usage for org.hibernate.stat EntityStatistics getOptimisticFailureCount.

Prototype

long getOptimisticFailureCount();

Source Link

Document

Number of times (since last Statistics clearing) this entity has experienced an optimistic lock failure.

Usage

From source file:com.openkm.servlet.admin.HibernateStatsServlet.java

License:Open Source License

/**
 * View log/*w  ww .  ja va2 s  .co m*/
 */
private void view(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    log.debug("view({}, {})", request, response);
    refresh();

    // Query Statistics
    List<Map<String, String>> qStats = new ArrayList<Map<String, String>>();
    for (String query : queryStatistics.keySet()) {
        QueryStatistics queryStats = queryStatistics.get(query);
        Map<String, String> stat = new HashMap<String, String>();
        stat.put("query", query);
        //stat.put("tquery", HibernateUtil.toSql(query));
        stat.put("executionCount", Long.toString(queryStats.getExecutionCount()));
        stat.put("executionRowCount", Long.toString(queryStats.getExecutionRowCount()));
        stat.put("executionMaxTime", Long.toString(queryStats.getExecutionMaxTime()));
        stat.put("executionMinTime", Long.toString(queryStats.getExecutionMinTime()));
        stat.put("executionAvgTime", Long.toString(queryStats.getExecutionAvgTime()));
        stat.put("executionTotalTime",
                Long.toString(queryStats.getExecutionAvgTime() * queryStats.getExecutionCount()));
        stat.put("cacheHitCount", Long.toString(queryStats.getCacheHitCount()));
        stat.put("cacheMissCount", Long.toString(queryStats.getCacheMissCount()));
        stat.put("cachePutCount", Long.toString(queryStats.getCachePutCount()));
        qStats.add(stat);
    }

    // Entity Statistics
    List<Map<String, String>> eStats = new ArrayList<Map<String, String>>();
    for (String entity : entityStatistics.keySet()) {
        EntityStatistics entityStats = entityStatistics.get(entity);
        Map<String, String> stat = new HashMap<String, String>();
        stat.put("entity", entity);
        stat.put("loadCount", Long.toString(entityStats.getLoadCount()));
        stat.put("fetchCount", Long.toString(entityStats.getFetchCount()));
        stat.put("insertCount", Long.toString(entityStats.getInsertCount()));
        stat.put("updateCount", Long.toString(entityStats.getUpdateCount()));
        stat.put("deleteCount", Long.toString(entityStats.getDeleteCount()));
        stat.put("optimisticFailureCount", Long.toString(entityStats.getOptimisticFailureCount()));
        eStats.add(stat);
    }

    // Collection Statistics
    List<Map<String, String>> cStats = new ArrayList<Map<String, String>>();
    for (String collection : collectionStatistics.keySet()) {
        CollectionStatistics collectionStats = collectionStatistics.get(collection);
        Map<String, String> stat = new HashMap<String, String>();
        stat.put("collection", collection);
        stat.put("loadCount", Long.toString(collectionStats.getLoadCount()));
        stat.put("fetchCount", Long.toString(collectionStats.getFetchCount()));
        stat.put("updateCount", Long.toString(collectionStats.getUpdateCount()));
        stat.put("recreateCount", Long.toString(collectionStats.getRecreateCount()));
        stat.put("removeCount", Long.toString(collectionStats.getRemoveCount()));
        cStats.add(stat);
    }

    // 2nd Level Cache Statistics
    long totalSizeInMemory = 0;
    List<Map<String, String>> slcStats = new ArrayList<Map<String, String>>();
    for (String cache : secondLevelCacheStatistics.keySet()) {
        SecondLevelCacheStatistics cacheStats = secondLevelCacheStatistics.get(cache);
        totalSizeInMemory += cacheStats.getSizeInMemory();
        Map<String, String> stat = new HashMap<String, String>();
        stat.put("cache", cache);
        stat.put("putCount", Long.toString(cacheStats.getPutCount()));
        stat.put("hitCount", Long.toString(cacheStats.getHitCount()));
        stat.put("missCount", Long.toString(cacheStats.getMissCount()));
        stat.put("elementCountInMemory", Long.toString(cacheStats.getElementCountInMemory()));
        stat.put("sizeInMemory", Long.toString(cacheStats.getSizeInMemory()));
        stat.put("elementCountOnDisk", Long.toString(cacheStats.getElementCountOnDisk()));
        slcStats.add(stat);
    }

    ServletContext sc = getServletContext();
    sc.setAttribute("generalStats", generalStatistics);
    sc.setAttribute("queryStats", qStats);
    sc.setAttribute("entityStats", eStats);
    sc.setAttribute("collectionStats", cStats);
    sc.setAttribute("secondLevelCacheStats", slcStats);
    sc.setAttribute("totalSizeInMemory", totalSizeInMemory);
    sc.setAttribute("statsEnabled", HibernateUtil.getSessionFactory().getStatistics().isStatisticsEnabled());
    sc.getRequestDispatcher("/admin/hibernate_stats.jsp").forward(request, response);

    // Activity log
    UserActivity.log(request.getRemoteUser(), "ADMIN_HIBERNATE_STATS", null, null, null);

    log.debug("view: void");
}

From source file:org.jboss.as.jpa.hibernate4.management.EntityMetricsHandler.java

License:Open Source License

static final EntityMetricsHandler getOptimisticFailureCount(
        final PersistenceUnitServiceRegistry persistenceUnitRegistry) {
    return new EntityMetricsHandler(persistenceUnitRegistry) {
        @Override/*from  w w w.j  av  a 2 s.  c  om*/
        protected void handle(EntityStatistics statistics, OperationContext context, String attributeName) {
            long count = statistics.getOptimisticFailureCount();
            context.getResult().set(count);
        }
    };
}

From source file:org.yawlfoundation.yawl.util.HibernateStatistics.java

License:Open Source License

private XNode getEntities(Statistics stats) {
    XNode node = new XNode("Entities");
    node.addChild("total_fetches", stats.getEntityFetchCount());
    node.addChild("total_deletes", stats.getEntityDeleteCount());
    node.addChild("total_inserts", stats.getEntityInsertCount());
    node.addChild("total_loads", stats.getEntityLoadCount());
    node.addChild("total_updates", stats.getEntityUpdateCount());
    node.addChild("total_optimistic_failures", stats.getOptimisticFailureCount());
    for (String entity : stats.getEntityNames()) {
        EntityStatistics entityStats = stats.getEntityStatistics(entity);
        XNode queryNode = node.addChild("entity");
        queryNode.addChild("entity", entity);
        queryNode.addChild("fetches", entityStats.getFetchCount());
        queryNode.addChild("deletes", entityStats.getDeleteCount());
        queryNode.addChild("inserts", entityStats.getInsertCount());
        queryNode.addChild("loads", entityStats.getLoadCount());
        queryNode.addChild("updates", entityStats.getUpdateCount());
        queryNode.addChild("optimistic_failures", entityStats.getOptimisticFailureCount());
    }//from   w  w  w  .j  av a  2s .  co m
    return node;
}