Example usage for org.hibernate.stat Statistics getCollectionRoleNames

List of usage examples for org.hibernate.stat Statistics getCollectionRoleNames

Introduction

In this page you can find the example usage for org.hibernate.stat Statistics getCollectionRoleNames.

Prototype

String[] getCollectionRoleNames();

Source Link

Document

Get the names of all collection roles

Usage

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

License:Open Source License

/**
 * Refresh stats/*from   www . j a va 2 s.c om*/
 */
private synchronized void refresh() {
    Statistics statistics = HibernateUtil.getSessionFactory().getStatistics();
    generalStatistics.set(0, statistics.getConnectCount());
    generalStatistics.set(1, statistics.getFlushCount());
    generalStatistics.set(2, statistics.getPrepareStatementCount());
    generalStatistics.set(3, statistics.getCloseStatementCount());
    generalStatistics.set(4, statistics.getSessionCloseCount());
    generalStatistics.set(5, statistics.getSessionOpenCount());
    generalStatistics.set(6, statistics.getTransactionCount());
    generalStatistics.set(7, statistics.getSuccessfulTransactionCount());
    generalStatistics.set(8, statistics.getOptimisticFailureCount());
    queryStatistics.clear();
    String[] names = statistics.getQueries();

    if (names != null && names.length > 0) {
        for (int i = 0; i < names.length; i++) {
            queryStatistics.put(names[i], statistics.getQueryStatistics(names[i]));
        }
    }

    entityStatistics.clear();
    names = statistics.getEntityNames();

    if (names != null && names.length > 0) {
        for (int i = 0; i < names.length; i++) {
            entityStatistics.put(names[i], statistics.getEntityStatistics(names[i]));
        }
    }

    collectionStatistics.clear();
    names = statistics.getCollectionRoleNames();

    if (names != null && names.length > 0) {
        for (int i = 0; i < names.length; i++) {
            collectionStatistics.put(names[i], statistics.getCollectionStatistics(names[i]));
        }
    }

    secondLevelCacheStatistics.clear();
    names = statistics.getSecondLevelCacheRegionNames();

    if (names != null && names.length > 0) {
        for (int i = 0; i < names.length; i++) {
            secondLevelCacheStatistics.put(names[i], statistics.getSecondLevelCacheStatistics(names[i]));
        }
    }
}

From source file:com.thoughtworks.go.server.service.support.HibernateInformationProvider.java

License:Apache License

@Override
public Map<String, Object> asJson() {
    LinkedHashMap<String, Object> json = new LinkedHashMap<>();
    Statistics statistics = sessionFactory.getStatistics();
    if (!statistics.isStatisticsEnabled()) {
        return json;
    }/*www .  j a va 2  s. com*/
    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;
}

From source file:de.iew.framework.hibernate.statistics.StatisticsLogger.java

License:Apache License

public void logStatistics() {
    Statistics statistics = this.sessionFactory.getStatistics();
    statistics.setStatisticsEnabled(true);
    StringBuilder sb = new StringBuilder("\nStatistics");
    sb.append("\nCloseStatementCount: ").append(statistics.getCloseStatementCount());

    sb.append("\nEntityDeleteCount: ").append(statistics.getEntityDeleteCount());
    sb.append("\nEntityInsertCount: ").append(statistics.getEntityInsertCount());
    sb.append("\nEntityLoadCount: ").append(statistics.getEntityLoadCount());
    sb.append("\nEntityFetchCount: ").append(statistics.getEntityFetchCount());
    sb.append("\nEntityUpdateCount: ").append(statistics.getEntityUpdateCount());
    sb.append("\nQueryExecutionCount: ").append(statistics.getQueryExecutionCount());
    sb.append("\nQueryExecutionMaxTime: ").append(statistics.getQueryExecutionMaxTime());
    sb.append("\nQueryExecutionMaxTimeQueryString: ").append(statistics.getQueryExecutionMaxTimeQueryString());
    sb.append("\nQueryCacheHitCount: ").append(statistics.getQueryCacheHitCount());
    sb.append("\nQueryCacheMissCount: ").append(statistics.getQueryCacheMissCount());
    sb.append("\nQueryCachePutCount: ").append(statistics.getQueryCachePutCount());
    sb.append("\nNaturalIdQueryExecutionCount: ").append(statistics.getNaturalIdQueryExecutionCount());
    sb.append("\nNaturalIdQueryExecutionMaxTime: ").append(statistics.getNaturalIdQueryExecutionMaxTime());
    sb.append("\nNaturalIdQueryExecutionMaxTimeRegion: ")
            .append(statistics.getNaturalIdQueryExecutionMaxTimeRegion());
    sb.append("\nNaturalIdCacheHitCount: ").append(statistics.getNaturalIdCacheHitCount());
    sb.append("\nNaturalIdCacheMissCount: ").append(statistics.getNaturalIdCacheMissCount());
    sb.append("\nNaturalIdCachePutCount: ").append(statistics.getNaturalIdCachePutCount());
    sb.append("\nUpdateTimestampsCacheHitCount: ").append(statistics.getUpdateTimestampsCacheHitCount());
    sb.append("\nUpdateTimestampsCacheMissCount: ").append(statistics.getUpdateTimestampsCacheMissCount());
    sb.append("\nUpdateTimestampsCachePutCount: ").append(statistics.getUpdateTimestampsCachePutCount());
    sb.append("\nFlushCount: ").append(statistics.getFlushCount());
    sb.append("\nConnectCount: ").append(statistics.getConnectCount());
    sb.append("\nSecondLevelCacheHitCount: ").append(statistics.getSecondLevelCacheHitCount());
    sb.append("\nSecondLevelCacheMissCount: ").append(statistics.getSecondLevelCacheMissCount());
    sb.append("\nSecondLevelCachePutCount: ").append(statistics.getSecondLevelCachePutCount());
    sb.append("\nSessionCloseCount: ").append(statistics.getSessionCloseCount());
    sb.append("\nSessionOpenCount: ").append(statistics.getSessionOpenCount());
    sb.append("\nCollectionLoadCount: ").append(statistics.getCollectionLoadCount());
    sb.append("\nCollectionFetchCount: ").append(statistics.getCollectionFetchCount());
    sb.append("\nCollectionUpdateCount: ").append(statistics.getCollectionUpdateCount());
    sb.append("\nCollectionRemoveCount: ").append(statistics.getCollectionRemoveCount());
    sb.append("\nCollectionRecreateCount: ").append(statistics.getCollectionRecreateCount());
    sb.append("\nStartTime: ").append(statistics.getStartTime());
    sb.append("\nQueries: ").append(statistics.getQueries());
    sb.append("\nEntityNames: ").append(statistics.getEntityNames());
    sb.append("\nCollectionRoleNames: ").append(statistics.getCollectionRoleNames());
    sb.append("\nSecondLevelCacheRegionNames: ").append(statistics.getSecondLevelCacheRegionNames());
    sb.append("\nSuccessfulTransactionCount: ").append(statistics.getSuccessfulTransactionCount());
    sb.append("\nTransactionCount: ").append(statistics.getTransactionCount());
    sb.append("\nPrepareStatementCount: ").append(statistics.getPrepareStatementCount());
    sb.append("\nCloseStatementCount: ").append(statistics.getCloseStatementCount());
    sb.append("\nOptimisticFailureCount: ").append(statistics.getOptimisticFailureCount());

    if (log.isDebugEnabled()) {
        log.debug(sb);//from   w w  w.j  a v a2s .c o  m
    }

}

From source file:net.sf.ehcache.hibernate.management.impl.HibernateStatsImpl.java

License:Apache License

/**
 * {@inheritDoc}/*  ww  w . j av  a2  s  . c o  m*/
 * 
 * @see net.sf.ehcache.hibernate.management.api.HibernateStats#getCollectionStats()
 */
public TabularData getCollectionStats() {
    List<CompositeData> result = new ArrayList<CompositeData>();
    Statistics statistics = getStatistics();
    for (String roleName : statistics.getCollectionRoleNames()) {
        CollectionStats collectionStats = new CollectionStats(roleName,
                statistics.getCollectionStatistics(roleName));
        result.add(collectionStats.toCompositeData());
    }
    TabularData td = CollectionStats.newTabularDataInstance();
    td.putAll(result.toArray(new CompositeData[result.size()]));
    return td;
}

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

License:Open Source License

@Override
public Collection<String> getDynamicChildrenNames(EntityManagerFactoryAccess entityManagerFactoryLookup,
        PathAddress pathAddress) {/*from ww  w.  jav a  2s .  c o  m*/
    org.hibernate.stat.Statistics stats = getBaseStatistics(entityManagerFactoryLookup
            .entityManagerFactory(pathAddress.getValue(HibernateStatistics.PROVIDER_LABEL)));
    if (stats == null) {
        return Collections.emptyList();
    }
    return Collections.unmodifiableCollection(Arrays.asList(stats.getCollectionRoleNames()));
}

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

License:Open Source License

private Set<String> getCollectionNames() {
    final Statistics stats = getStatistics();
    if (stats == null) {
        return Collections.emptySet();
    } else {//from w  w  w .  jav  a2s.  com
        Set<String> result = new HashSet<String>();
        String[] collectionNames = stats.getCollectionRoleNames();
        if (collectionNames != null) {
            for (String entity : collectionNames) {
                result.add(entity);
            }
        }
        return result;
    }
}

From source file:org.keycloak.connections.jpa.HibernateStatsReporter.java

License:Apache License

protected void logCollections(StringBuilder builder, String lineSep, Statistics stats) {
    builder.append("Important collections statistics: ").append(lineSep);
    for (String col : stats.getCollectionRoleNames()) {
        CollectionStatistics collectionStats = stats.getCollectionStatistics(col);
        if (collectionStats.getRecreateCount() > LIMIT || collectionStats.getUpdateCount() > LIMIT
                || collectionStats.getRemoveCount() > LIMIT || collectionStats.getLoadCount() > LIMIT
                || collectionStats.getFetchCount() > LIMIT) {
            builder.append(col).append(" - ").append("recreated: ").append(collectionStats.getRecreateCount())
                    .append(", updated: ").append(collectionStats.getUpdateCount()).append(", removed: ")
                    .append(collectionStats.getRemoveCount()).append(", loaded: ")
                    .append(collectionStats.getLoadCount()).append(", fetched: ")
                    .append(collectionStats.getFetchCount()).append(lineSep);
        }/*w w w. j  a  v a2s .c om*/
    }
    builder.append(lineSep);
}

From source file:org.unitime.commons.hibernate.stats.StatsProvider.java

License:Open Source License

/**
 * Format statistics in HTML/*from   w  w  w .  ja v  a 2  s . co m*/
 * @param sessionFactory Hibernate Session Factory
 * @param summaryOnly true - Display only summary info
 * @return HTML String
 */
public String getStatsHtml(SessionFactory sessionFactory, boolean summaryOnly) {

    StringBuffer hibStats = new StringBuffer();

    try {
        // Get statistics
        Statistics stats = sessionFactory.getStatistics();

        // Checks statistics enabled
        if (!stats.isStatisticsEnabled()) {
            return "<font color='red'><b>Hibernate statistics is not enabled.</b></font>";
        }

        // Row Color for even numbered rows
        String evenRowColor = "#FAFAFA";

        // Generate HTML table
        Table table = new Table();
        table.setWidth("100%");
        table.setBorder(0);
        table.setCellSpacing(0);
        table.setCellPadding(3);

        // Links
        StringBuffer links = new StringBuffer("");

        links.append("<A class=\"l7\" href=\"#Entity\">Entity</A>");
        if (!summaryOnly)
            links.append(" - <A class=\"l7\" href=\"#EntityDetail\">Detail</A>");

        links.append(" | <A class=\"l7\" href=\"#Collection\">Collection</A>");
        if (!summaryOnly)
            links.append(" - <A class=\"l7\" href=\"#CollectionDetail\">Detail</A>");

        links.append(" | <A class=\"l7\" href=\"#SecondLevelCache\">Second Level Cache</A>");
        if (!summaryOnly)
            links.append(" - <A class=\"l7\" href=\"#SecondLevelCacheDetail\">Detail</A>");

        links.append(" | <A class=\"l7\" href=\"#Query\">Query</A>");
        if (!summaryOnly)
            links.append(" - <A class=\"l7\" href=\"#QueryDetail\">Detail</A>");

        TableRow row = new TableRow();
        row.addContent(cell(links.toString(), 1, 2, true, "center", "middle"));
        table.addContent(row);

        // Link to top
        TableRow linkToTop = new TableRow();
        linkToTop.addContent(
                cell("<A class=\"l7\" href=\"#BackToTop\">Back to Top</A>", 1, 2, true, "right", "middle"));

        // ---------------------- Overall Stats ------------------------
        row = new TableRow();
        row.addContent(headerCell("<A name=\"BackToTop\">Metric</A>", 1, 1));
        row.addContent(headerCell("Value", 1, 1));
        table.addContent(row);

        row = new TableRow();
        row.addContent(cell(" &nbsp; Start Time", 1, 1, true));
        row.addContent(cell(new Date(stats.getStartTime()).toString(), 1, 1, false));
        table.addContent(row);

        row = new TableRow();
        row.addContent(cell(" &nbsp; Connect Count", 1, 1, true));
        row.addContent(cell(stats.getConnectCount() + "", 1, 1, false));
        table.addContent(row);

        row = new TableRow();
        row.addContent(cell(" &nbsp; Flush Count", 1, 1, true));
        row.addContent(cell(stats.getFlushCount() + "", 1, 1, false));
        table.addContent(row);

        row = new TableRow();
        row.addContent(cell(" &nbsp; Session Open Count", 1, 1, true));
        row.addContent(cell(stats.getSessionOpenCount() + "", 1, 1, false));
        table.addContent(row);

        row = new TableRow();
        row.addContent(cell(" &nbsp; Session Close Count", 1, 1, true));
        row.addContent(cell(stats.getSessionCloseCount() + "", 1, 1, false));
        table.addContent(row);

        row = new TableRow();
        row.addContent(cell(" &nbsp; Transaction Count", 1, 1, true));
        row.addContent(cell(stats.getTransactionCount() + "", 1, 1, false));
        table.addContent(row);

        row = new TableRow();
        row.addContent(cell(" &nbsp; Successful Transaction Count", 1, 1, true));
        row.addContent(cell(stats.getSuccessfulTransactionCount() + "", 1, 1, false));
        table.addContent(row);

        row = new TableRow();
        row.addContent(cell(" &nbsp; Prepare Statement Count", 1, 1, true));
        row.addContent(cell(stats.getPrepareStatementCount() + "", 1, 1, false));
        table.addContent(row);

        row = new TableRow();
        row.addContent(cell(" &nbsp; Close Statement Count", 1, 1, true));
        row.addContent(cell(stats.getCloseStatementCount() + "", 1, 1, false));
        table.addContent(row);

        row = new TableRow();
        row.addContent(cell(" &nbsp; Optimistic Failure Count", 1, 1, true));
        row.addContent(cell(stats.getOptimisticFailureCount() + "", 1, 1, false));
        table.addContent(row);

        row = new TableRow();
        row.addContent(cell("<hr>", 1, 2, false));
        table.addContent(row);

        // ---------------------- Entity Stats ------------------------
        row = new TableRow();
        row.addContent(headerCell("<A name=\"Entity\">Entity</A>:", 1, 2));
        table.addContent(row);

        row = new TableRow();
        row.addContent(cell(" &nbsp; Fetch Count", 1, 1, true));
        row.addContent(cell(stats.getEntityFetchCount() + "", 1, 1, false));
        table.addContent(row);

        row = new TableRow();
        row.addContent(cell(" &nbsp; Load Count", 1, 1, true));
        row.addContent(cell(stats.getEntityLoadCount() + "", 1, 1, false));
        table.addContent(row);

        row = new TableRow();
        row.addContent(cell(" &nbsp; Insert Count", 1, 1, true));
        row.addContent(cell(stats.getEntityInsertCount() + "", 1, 1, false));
        table.addContent(row);

        row = new TableRow();
        row.addContent(cell(" &nbsp; Update Count", 1, 1, true));
        row.addContent(cell(stats.getEntityUpdateCount() + "", 1, 1, false));
        table.addContent(row);

        row = new TableRow();
        row.addContent(cell(" &nbsp; Delete Count", 1, 1, true));
        row.addContent(cell(stats.getEntityDeleteCount() + "", 1, 1, false));
        table.addContent(row);

        row = new TableRow();
        row.addContent(cell("<hr>", 1, 2, false));
        table.addContent(row);

        table.addContent(linkToTop);

        // ---------------------- Detailed Entity Stats ------------------------

        if (!summaryOnly) {

            row = new TableRow();
            row.addContent(headerCell("<A name=\"EntityDetail\">Entity Statistics Detail</A>:", 1, 2));
            table.addContent(row);

            String[] cEntityNames = stats.getEntityNames();

            if (cEntityNames == null || cEntityNames.length == 0) {
                row = new TableRow();
                row.addContent(cell("No entity names found", 1, 2, false));
                table.addContent(row);
            } else {
                Table subTable = new Table();
                subTable.setCellSpacing(1);
                subTable.setCellPadding(3);

                row = new TableRow();
                row.addContent(headerCell(" &nbsp; ", 1, 1));
                row.addContent(headerCell(" Fetches ", 1, 1));
                row.addContent(headerCell(" Loads ", 1, 1));
                row.addContent(headerCell(" Inserts ", 1, 1));
                row.addContent(headerCell(" Updates ", 1, 1));
                row.addContent(headerCell(" Deletes ", 1, 1));
                subTable.addContent(row);

                for (int i = 0; i < cEntityNames.length; i++) {
                    String entityName = cEntityNames[i];
                    EntityStatistics eStats = stats.getEntityStatistics(entityName);

                    row = new TableRow();
                    if (i % 2 == 0)
                        row.setBgColor(evenRowColor);
                    row.addContent(cell(entityName + " &nbsp;", 1, 1, true));
                    row.addContent(cell(eStats.getFetchCount() + "", 1, 1, false));
                    row.addContent(cell(eStats.getLoadCount() + "", 1, 1, false));
                    row.addContent(cell(eStats.getInsertCount() + "", 1, 1, false));
                    row.addContent(cell(eStats.getUpdateCount() + "", 1, 1, false));
                    row.addContent(cell(eStats.getDeleteCount() + "", 1, 1, false));
                    subTable.addContent(row);
                }

                row = new TableRow();
                row.addContent(cell(subTable.toHtml(), 1, 2, true));
                table.addContent(row);
            }

            row = new TableRow();
            row.addContent(cell("<hr>", 1, 2, false));
            table.addContent(row);

            table.addContent(linkToTop);
        }

        // ---------------------- Collection Stats ------------------------
        row = new TableRow();
        row.addContent(headerCell("<A name=\"Collection\">Collection</A>:", 1, 2));
        table.addContent(row);

        row = new TableRow();
        row.addContent(cell(" &nbsp; Fetch Count", 1, 1, true));
        row.addContent(cell(stats.getCollectionFetchCount() + "", 1, 1, false));
        table.addContent(row);

        row = new TableRow();
        row.addContent(cell(" &nbsp; Load Count", 1, 1, true));
        row.addContent(cell(stats.getCollectionLoadCount() + "", 1, 1, false));
        table.addContent(row);

        row = new TableRow();
        row.addContent(cell(" &nbsp; Update Count", 1, 1, true));
        row.addContent(cell(stats.getCollectionUpdateCount() + "", 1, 1, false));
        table.addContent(row);

        row = new TableRow();
        row.addContent(cell(" &nbsp; Remove Count", 1, 1, true));
        row.addContent(cell(stats.getCollectionRemoveCount() + "", 1, 1, false));
        table.addContent(row);

        row = new TableRow();
        row.addContent(cell(" &nbsp; Recreate Count", 1, 1, true));
        row.addContent(cell(stats.getCollectionRecreateCount() + "", 1, 1, false));
        table.addContent(row);

        row = new TableRow();
        row.addContent(cell("<hr>", 1, 2, false));
        table.addContent(row);

        table.addContent(linkToTop);

        // ---------------------- Detailed Collection Stats ------------------------
        if (!summaryOnly) {

            row = new TableRow();
            row.addContent(headerCell("<A name=\"CollectionDetail\">Collection Statistics Detail</A>:", 1, 2));
            table.addContent(row);

            String[] cRoleNames = stats.getCollectionRoleNames();

            if (cRoleNames == null || cRoleNames.length == 0) {
                row = new TableRow();
                row.addContent(cell("No collection roles found", 1, 2, false));
                table.addContent(row);
            } else {
                Table subTable = new Table();
                subTable.setCellSpacing(1);
                subTable.setCellPadding(3);

                row = new TableRow();
                row.addContent(headerCell(" &nbsp; ", 1, 1));
                row.addContent(headerCell(" Fetches ", 1, 1));
                row.addContent(headerCell(" Loads ", 1, 1));
                row.addContent(headerCell(" Updates ", 1, 1));
                row.addContent(headerCell(" Removes ", 1, 1));
                row.addContent(headerCell(" Recreates ", 1, 1));
                subTable.addContent(row);

                for (int i = 0; i < cRoleNames.length; i++) {
                    String roleName = cRoleNames[i];
                    CollectionStatistics cStats = stats.getCollectionStatistics(roleName);

                    row = new TableRow();
                    if (i % 2 == 0)
                        row.setBgColor(evenRowColor);
                    row.addContent(cell(roleName + " &nbsp;", 1, 1, true));
                    row.addContent(cell(cStats.getFetchCount() + "", 1, 1, false));
                    row.addContent(cell(cStats.getLoadCount() + "", 1, 1, false));
                    row.addContent(cell(cStats.getUpdateCount() + "", 1, 1, false));
                    row.addContent(cell(cStats.getRemoveCount() + "", 1, 1, false));
                    row.addContent(cell(cStats.getRecreateCount() + "", 1, 1, false));
                    subTable.addContent(row);
                }

                row = new TableRow();
                row.addContent(cell(subTable.toHtml(), 1, 2, true));
                table.addContent(row);
            }

            row = new TableRow();
            row.addContent(cell("<hr>", 1, 2, false));
            table.addContent(row);

            table.addContent(linkToTop);
        }

        // ---------------------- Second Level Cache Stats ------------------------
        row = new TableRow();
        row.addContent(headerCell("<A name=\"SecondLevelCache\">Second Level Cache</A>:", 1, 2));
        table.addContent(row);

        row = new TableRow();
        row.addContent(cell(" &nbsp; Hit Count", 1, 1, true));
        row.addContent(cell(stats.getSecondLevelCacheHitCount() + "", 1, 1, false));
        table.addContent(row);

        row = new TableRow();
        row.addContent(cell(" &nbsp; Miss Count", 1, 1, true));
        row.addContent(cell(stats.getSecondLevelCacheMissCount() + "", 1, 1, false));
        table.addContent(row);

        row = new TableRow();
        row.addContent(cell(" &nbsp; Put Count", 1, 1, true));
        row.addContent(cell(stats.getSecondLevelCachePutCount() + "", 1, 1, false));
        table.addContent(row);

        row = new TableRow();
        row.addContent(cell("<hr>", 1, 2, false));
        table.addContent(row);

        table.addContent(linkToTop);

        // ---------------------- Detailed Second Level Cache Stats ------------------------
        if (!summaryOnly) {

            row = new TableRow();
            row.addContent(headerCell(
                    "<A name=\"SecondLevelCacheDetail\">Second Level Cache Statistics Detail</A>:", 1, 2));
            table.addContent(row);

            String[] cRegionNames = stats.getSecondLevelCacheRegionNames();

            if (cRegionNames == null || cRegionNames.length == 0) {
                row = new TableRow();
                row.addContent(cell("No region names found", 1, 2, false));
                table.addContent(row);
            } else {
                Table subTable = new Table();
                subTable.setCellSpacing(1);
                subTable.setCellPadding(3);

                row = new TableRow();
                row.addContent(headerCell(" &nbsp; ", 1, 1));
                row.addContent(headerCell(" Entities ", 1, 1));
                row.addContent(headerCell(" Hits ", 1, 1));
                row.addContent(headerCell(" Misses ", 1, 1));
                row.addContent(headerCell(" Puts ", 1, 1));
                row.addContent(headerCell(" In Memory ", 1, 1));
                row.addContent(headerCell(" On Disk ", 1, 1));
                row.addContent(headerCell(" Memory ", 1, 1));
                subTable.addContent(row);

                long elementsInMem = 0, elementsOnDisk = 0, putCnt = 0, missCnt = 0, hitCnt = 0, size = 0;

                for (int i = 0; i < cRegionNames.length; i++) {
                    String cRegionName = cRegionNames[i];
                    SecondLevelCacheStatistics sStats = stats.getSecondLevelCacheStatistics(cRegionName);

                    row = new TableRow();
                    if (i % 2 == 0)
                        row.setBgColor(evenRowColor);
                    row.addContent(cell(cRegionName + " &nbsp;", 1, 1, true));
                    row.addContent(cell(
                            String.valueOf(sStats.getElementCountInMemory() + sStats.getElementCountOnDisk()),
                            1, 1, false)); //sStats.getEntries().size()
                    row.addContent(cell(sStats.getHitCount() + "", 1, 1, false));
                    row.addContent(cell(sStats.getMissCount() + "", 1, 1, false));
                    row.addContent(cell(sStats.getPutCount() + "", 1, 1, false));
                    row.addContent(cell(sStats.getElementCountInMemory() + "", 1, 1, false));
                    row.addContent(cell(sStats.getElementCountOnDisk() + "", 1, 1, false));
                    row.addContent(cell(sStats.getSizeInMemory() + " bytes", 1, 1, false));
                    elementsInMem += sStats.getElementCountInMemory();
                    elementsOnDisk += sStats.getElementCountOnDisk();
                    putCnt += sStats.getPutCount();
                    missCnt += sStats.getMissCount();
                    hitCnt += sStats.getHitCount();
                    size += sStats.getSizeInMemory();
                    subTable.addContent(row);
                }

                row = new TableRow();
                row.addContent(headerCell("Total &nbsp;", 1, 1));
                row.addContent(headerCell("" + (elementsInMem + elementsOnDisk), 1, 1));
                row.addContent(headerCell("" + hitCnt, 1, 1));
                row.addContent(headerCell("" + missCnt, 1, 1));
                row.addContent(headerCell("" + putCnt, 1, 1));
                row.addContent(headerCell("" + elementsInMem, 1, 1));
                row.addContent(headerCell("" + elementsOnDisk, 1, 1));
                row.addContent(headerCell(size + " bytes", 1, 1));
                subTable.addContent(row);

                row = new TableRow();
                row.addContent(cell(subTable.toHtml(), 1, 2, true));
                table.addContent(row);
            }

            row = new TableRow();
            row.addContent(cell("<hr>", 1, 2, false));
            table.addContent(row);

            table.addContent(linkToTop);
        }

        // ---------------------- Query Stats ------------------------
        row = new TableRow();
        row.addContent(headerCell("<A name=\"Query\">Query</A>:", 1, 2));
        table.addContent(row);

        row = new TableRow();
        row.addContent(cell(" &nbsp; Execution Count", 1, 1, true));
        row.addContent(cell(stats.getQueryExecutionCount() + "", 1, 1, false));
        table.addContent(row);

        row = new TableRow();
        row.addContent(cell(" &nbsp; Execution Max Time", 1, 1, true));
        row.addContent(cell(stats.getQueryExecutionMaxTime() + " ms", 1, 1, false));
        table.addContent(row);

        row = new TableRow();
        row.addContent(cell(" &nbsp; Cache Hit Count", 1, 1, true));
        row.addContent(cell(stats.getQueryCacheHitCount() + " ms", 1, 1, false));
        table.addContent(row);

        row = new TableRow();
        row.addContent(cell(" &nbsp; Cache Miss Count", 1, 1, true));
        row.addContent(cell(stats.getQueryCacheMissCount() + " ms", 1, 1, false));
        table.addContent(row);

        row = new TableRow();
        row.addContent(cell(" &nbsp; Cache Put Count", 1, 1, true));
        row.addContent(cell(stats.getQueryCachePutCount() + "", 1, 1, false));
        table.addContent(row);

        row = new TableRow();
        row.addContent(cell("<hr>", 1, 2, false));
        table.addContent(row);

        table.addContent(linkToTop);

        // ---------------------- Detailed Query Stats ------------------------
        if (!summaryOnly) {

            row = new TableRow();
            row.addContent(headerCell("<A name=\"QueryDetail\">Query Statistics Detail</A>:", 1, 2));
            table.addContent(row);

            String[] cQueryStrings = stats.getQueries();

            if (cQueryStrings == null || cQueryStrings.length == 0) {
                row = new TableRow();
                row.addContent(cell("No query strings found", 1, 2, false));
                table.addContent(row);
            } else {
                Table subTable = new Table();
                subTable.setCellSpacing(1);
                subTable.setCellPadding(3);

                row = new TableRow();
                row.addContent(headerCell(" &nbsp; ", 1, 1));
                row.addContent(headerCell(" Execs ", 1, 1));
                row.addContent(headerCell(" Rows ", 1, 1));
                row.addContent(headerCell(" Max Time ", 1, 1));
                row.addContent(headerCell(" Min Time ", 1, 1));
                row.addContent(headerCell(" Avg Time ", 1, 1));
                row.addContent(headerCell(" Cache Hits ", 1, 1));
                row.addContent(headerCell(" Cache Misses ", 1, 1));
                row.addContent(headerCell(" Cache Puts ", 1, 1));
                subTable.addContent(row);

                for (int i = 0; i < cQueryStrings.length; i++) {
                    String cQueryString = cQueryStrings[i];
                    QueryStatistics qStats = stats.getQueryStatistics(cQueryString);

                    row = new TableRow();
                    if (i % 2 == 0)
                        row.setBgColor(evenRowColor);
                    row.addContent(cell(cQueryString + " &nbsp;", 1, 1, false));
                    row.addContent(cell(qStats.getExecutionCount() + "", 1, 1, false));
                    row.addContent(cell(qStats.getExecutionRowCount() + "", 1, 1, false));
                    row.addContent(cell(qStats.getExecutionMaxTime() + " ms", 1, 1, false));
                    row.addContent(cell(qStats.getExecutionMinTime() + " ms", 1, 1, false));
                    row.addContent(cell(qStats.getExecutionAvgTime() + " ms", 1, 1, false));
                    row.addContent(cell(qStats.getCacheHitCount() + "", 1, 1, false));
                    row.addContent(cell(qStats.getCacheMissCount() + "", 1, 1, false));
                    row.addContent(cell(qStats.getCachePutCount() + "", 1, 1, false));
                    subTable.addContent(row);
                }

                row = new TableRow();
                row.addContent(cell(subTable.toHtml(), 1, 2, true));
                table.addContent(row);
            }

            row = new TableRow();
            row.addContent(cell("<hr>", 1, 2, false));
            table.addContent(row);

            table.addContent(linkToTop);
        }

        // Add to generated HTML
        hibStats.append(table.toHtml());
    } catch (Exception e) {
        hibStats.append("Exception occured: " + e.getMessage());
        e.printStackTrace();
    }

    return hibStats.toString();
}

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

License:Open Source License

private XNode getCollections(Statistics stats) {
    XNode node = new XNode("Collections");
    node.addChild("total_fetches", stats.getCollectionFetchCount());
    node.addChild("total_loads", stats.getCollectionLoadCount());
    node.addChild("total_recreates", stats.getCollectionRecreateCount());
    node.addChild("total_removes", stats.getCollectionRemoveCount());
    node.addChild("total_updates", stats.getCollectionUpdateCount());
    for (String name : stats.getCollectionRoleNames()) {
        CollectionStatistics collStats = stats.getCollectionStatistics(name);
        XNode collNode = node.addChild("collection");
        collNode.addChild("name", name);
        collNode.addChild("fetches", collStats.getFetchCount());
        collNode.addChild("loads", collStats.getLoadCount());
        collNode.addChild("recreates", collStats.getRecreateCount());
        collNode.addChild("removes", collStats.getRemoveCount());
        collNode.addChild("updates", collStats.getUpdateCount());
    }/* www  .j a v a  2s.  c o  m*/
    return node;
}

From source file:ubic.gemma.persistence.util.monitor.HibernateMonitorImpl.java

License:Apache License

@Override
public String getStats(boolean showEntityStats, boolean showCollectionStats,
        boolean showSecondLevelCacheDetails) {

    Statistics stats = sessionFactory.getStatistics();

    StringBuilder buf = new StringBuilder();
    buf.append("Statistics started at: ").append(new Date(stats.getStartTime())).append("\n");
    long flushes = stats.getFlushCount();
    long trans = stats.getTransactionCount();
    long prep = stats.getPrepareStatementCount();
    long open = stats.getSessionOpenCount();
    long close = stats.getSessionCloseCount();
    long ex = stats.getQueryExecutionCount();

    buf.append("Queries executed: ").append(ex).append("\n");

    buf.append(open).append(" sessions opened, ").append(close).append(" closed\n");
    buf.append(prep).append(" statements prepared, ").append(trans).append(" transactions completed, ")
            .append(flushes).append(" flushes.\n");
    String slowQuery = stats.getQueryExecutionMaxTimeQueryString();
    long queryExecutionMaxTime = stats.getQueryExecutionMaxTime();
    if (queryExecutionMaxTime > 1000) {
        buf.append("Slowest query [").append(queryExecutionMaxTime).append("ms]: ")
                .append(StringUtils.abbreviate(slowQuery, 150)).append("\n");
    }/*from   ww  w.  j av  a2  s .c om*/
    buf.append("\n------------------- Query Cache stats -----------------------\n");
    long queryCacheHitCount = stats.getQueryCacheHitCount();
    long queryCacheMissCount = stats.getQueryCacheMissCount();
    long queryCachePutCount = stats.getQueryCachePutCount();

    buf.append("Puts: ").append(queryCachePutCount).append("\n");
    buf.append("Hits: ").append(queryCacheHitCount).append("\n");
    buf.append("Misses: ").append(queryCacheMissCount).append("\n");

    buf.append("\n------------------- Second Level Cache stats -----------------------\n");
    long secCacheHits = stats.getSecondLevelCacheHitCount();
    long secCacheMiss = stats.getSecondLevelCacheMissCount();
    long secCachePut = stats.getSecondLevelCachePutCount();
    buf.append("Puts: ").append(secCachePut).append("\n");
    buf.append("Hits: ").append(secCacheHits).append("\n");
    buf.append("Misses: ").append(secCacheMiss).append("\n");

    if (showSecondLevelCacheDetails) {
        String[] regions = stats.getSecondLevelCacheRegionNames();
        Arrays.sort(regions);
        for (String region : regions) {
            SecondLevelCacheStatistics secondLevelCacheStatistics = stats.getSecondLevelCacheStatistics(region);
            long hitCount = secondLevelCacheStatistics.getHitCount();
            long missCount = secondLevelCacheStatistics.getMissCount();
            long putCount = secondLevelCacheStatistics.getPutCount();
            long size = secondLevelCacheStatistics.getSizeInMemory();
            long count = secondLevelCacheStatistics.getElementCountInMemory();
            long diskCount = secondLevelCacheStatistics.getElementCountOnDisk();

            if (putCount > 0 || hitCount > 0 || missCount > 0) {
                buf.append(region).append(": ").append(hitCount).append(" hits; ").append(missCount)
                        .append(" misses; ").append(putCount).append(" puts; Memcount=").append(count)
                        .append("; Diskcount=").append(diskCount).append(" MemSizeBytes=").append(size)
                        .append("\n");
            }
        }
    }

    if (showCollectionStats) {
        buf.append("\n------------------- Collection stats -----------------------\n");
        String[] collectionRoleNames = stats.getCollectionRoleNames();
        Arrays.sort(collectionRoleNames);
        for (String string : collectionRoleNames) {
            CollectionStatistics collectionStatistics = stats.getCollectionStatistics(string);
            long fetchCount = collectionStatistics.getFetchCount();
            long loadCount = collectionStatistics.getLoadCount();
            long updateCount = collectionStatistics.getUpdateCount();
            if (fetchCount > 0 || loadCount > 0 || updateCount > 0) {
                buf.append(string).append(": ").append(fetchCount).append(" fetches, ").append(loadCount)
                        .append(" loads, ").append(updateCount).append(" updates\n");
            }
        }
    }

    if (showEntityStats) {
        buf.append("\n------------------- Entity stats -----------------------\n");
        String[] entityNames = stats.getEntityNames();
        Arrays.sort(entityNames);
        for (String string : entityNames) {
            EntityStatistics entityStats = stats.getEntityStatistics(string);
            long changes = entityStats.getInsertCount() + entityStats.getUpdateCount()
                    + entityStats.getDeleteCount();
            if (changes > 0) {
                String shortName;
                try {
                    shortName = Class.forName(string).getSimpleName().replaceFirst("Impl", "");
                    buf.append(shortName).append(" updates: ").append(changes).append(" \n");
                } catch (ClassNotFoundException e) {
                    HibernateMonitorImpl.log.error(e, e);
                }
            }
            long reads = entityStats.getLoadCount();
            if (reads > 0) {
                String shortName;
                try {
                    shortName = Class.forName(string).getSimpleName().replaceFirst("Impl", "");
                    buf.append(shortName).append(" read: ").append(reads).append(" \n");
                } catch (ClassNotFoundException e) {
                    HibernateMonitorImpl.log.error(e, e);
                }
            }

        }
    }
    return buf.toString();
}