Example usage for org.hibernate SessionFactory getStatistics

List of usage examples for org.hibernate SessionFactory getStatistics

Introduction

In this page you can find the example usage for org.hibernate SessionFactory getStatistics.

Prototype

Statistics getStatistics();

Source Link

Document

Retrieve the statistics fopr this factory.

Usage

From source file:org.mzd.shap.spring.orm.Reporting.java

License:Open Source License

public static String reportSecondLevleCacheStatistics(SessionFactory sessionFactory) {
    StringBuffer buffer = new StringBuffer();
    Statistics stats = sessionFactory.getStatistics();

    long cacheHitCount = stats.getSecondLevelCacheHitCount();
    long cacheMissCount = stats.getSecondLevelCacheMissCount();

    System.out.println("Second Level Cache Hits: " + cacheHitCount);
    System.out.println("Second Level Cache Misses: " + cacheMissCount);
    if (cacheHitCount + cacheMissCount > 0) {
        System.out.println("Second Level Cache Hit Ratio: "
                + (double) cacheHitCount / (double) (cacheHitCount + cacheMissCount));
    }/*from  w  w  w .ja  v  a 2 s . c o m*/

    return buffer.toString();
}

From source file:org.rhq.core.domain.server.PersistenceUtility.java

License:Open Source License

/**
 * Enables the hibernate statistics mbean to provide access to information on the ejb3 persistence tier.
 *
 * @param entityManager an inject entity manager whose session factory will be tracked with these statistics
 * @param server        the MBeanServer where the statistics MBean should be registered; if <code>null</code>, the
 *                      first one in the list returned by MBeanServerFactory.findMBeanServer(null) is used
 * @param flag          true if the stats are to be enabled; false to disable the stats
 *//* w  w  w  .j av a 2  s . c  o  m*/
public static void enableHibernateStatistics(EntityManager entityManager, MBeanServer server, boolean flag) {
    SessionFactory sessionFactory = null;
    try {
        sessionFactory = PersistenceUtility.getHibernateSession(entityManager).getSessionFactory();

        if (server == null) {
            ArrayList<MBeanServer> list = MBeanServerFactory.findMBeanServer(null);
            server = list.get(0);
        }

        ObjectName objectName = new ObjectName(HIBERNATE_STATISTICS_MBEAN_OBJECTNAME);
        StatisticsService mBean = new StatisticsService();
        mBean.setSessionFactory(sessionFactory);
        server.registerMBean(mBean, objectName);
    } catch (InstanceAlreadyExistsException iaee) {
        LOG.info("Duplicate mbean registration ignored: " + HIBERNATE_STATISTICS_MBEAN_OBJECTNAME);
    } catch (Exception e) {
        LOG.warn("Couldn't register hibernate statistics mbean", e);
    }

    try {
        if (sessionFactory != null) {
            sessionFactory.getStatistics().setStatisticsEnabled(flag);
            LOG.info("Hibernate statistics enable flag set to [" + flag + "]");
        }
    } catch (Exception e) {
        LOG.warn("Couldn't set the statistics enable flag to [" + flag + "]", e);
    }
}

From source file:org.rhq.core.domain.server.PersistenceUtility.java

License:Open Source License

public static Statistics getStatisticsService(EntityManager entityManager, MBeanServer server) {
    Session hibernateSession = PersistenceUtility.getHibernateSession(entityManager);
    SessionFactory hibernateSessionFactory = hibernateSession.getSessionFactory();
    Statistics hibernateStatistics = hibernateSessionFactory.getStatistics();
    return hibernateStatistics;
}

From source file:org.rhq.core.server.PersistenceUtility.java

License:Open Source License

/**
 * Enables the hibernate statistics mbean to provide access to information on the ejb3 persistence tier.
 *
 * @param entityManager an inject entity manager whose session factory will be tracked with these statistics
 * @param server        the MBeanServer where the statistics MBean should be registered; if <code>null</code>, the
 *                      first one in the list returned by MBeanServerFactory.findMBeanServer(null) is used
 *//*from  w w w .j a v  a  2s.c  om*/
public static void enableHibernateStatistics(EntityManager entityManager, MBeanServer server) {
    try {
        SessionFactory sessionFactory = PersistenceUtility.getHibernateSession(entityManager)
                .getSessionFactory();

        if (server == null) {
            ArrayList<MBeanServer> list = MBeanServerFactory.findMBeanServer(null);
            server = list.get(0);
        }

        ObjectName objectName = new ObjectName(HIBERNATE_STATISTICS_MBEAN_OBJECTNAME);
        StatisticsService mBean = new StatisticsService();
        mBean.setSessionFactory(sessionFactory);
        server.registerMBean(mBean, objectName);
        sessionFactory.getStatistics().setStatisticsEnabled(true);
    } catch (InstanceAlreadyExistsException iaee) {
        LOG.info("Duplicate mbean registration ignored: " + HIBERNATE_STATISTICS_MBEAN_OBJECTNAME);
    } catch (Exception e) {
        LOG.warn("Couldn't register hibernate statistics mbean", e);
    }
}

From source file:org.rhq.enterprise.server.test.AbstractEJB3Test.java

License:Open Source License

@BeforeSuite(alwaysRun = true)
public static void startupEmbeddedJboss() throws Exception {
    // The embeddedDeployment property needs to be set for running tests
    // with the embedded container. It is set in the surefire configuration
    // in pom.xml but setting here makes it easier to run tests directly
    // from your IDE.
    ///*from   www  .j  av  a  2 s .c  om*/
    // jsanda
    System.setProperty("embeddedDeployment", "true");

    // Setting content location to the tmp dir
    System.setProperty(ContentSourceManagerBean.FILESYSTEM_PROPERTY, System.getProperty("java.io.tmpdir"));

    System.out.println("Starting JBoss EJB3 Embedded Container...");
    String deployDir = System.getProperty("deploymentDirectory", "target/classes");
    System.out.println("Loading EJB3 deployments from directory: " + deployDir);
    try {
        EJB3StandaloneBootstrap.boot(null);
        //         EJB3StandaloneBootstrap.scanClasspath();

        System.err.println("...... embedded container booted....");

        deployer = EJB3StandaloneBootstrap.createDeployer();

        deployer.setClassLoader(AbstractEJB3Test.class.getClassLoader());
        System.err.println("...... embedded container classloader set....");

        deployer.getArchivesByResource().add("META-INF/persistence.xml");
        System.err.println("...... embedded container persistence xml deployed....");

        deployer.getArchivesByResource().add("META-INF/ejb-jar.xml");
        System.err.println("...... embedded container ejb-jar xml deployed....");

        EJB3StandaloneBootstrap.deployXmlResource("jboss-jms-beans.xml");
        System.err.println("...... embedded container jboss-jms-beans xml deployed....");

        EJB3StandaloneBootstrap.deployXmlResource("rhq-mdb-beans.xml");
        System.err.println("...... embedded container rhq-mdb-beans xml deployed....");

        /*
         * File core = new File(deployDir, "on-core-domain-ejb.ejb3");      if (!core.exists())
         * System.err.println("Deployment directory does not exist: " + core.getAbsolutePath());
         * deployer.getArchives().add(core.toURI().toURL());
         *
         * File server = new File(deployDir, "on-enterprise-server-ejb.ejb3");      if (!server.exists())
         * System.err.println("Deployment directory does not exist: " + server.getAbsolutePath());
         * deployer.getArchives().add(server.toURI().toURL());
         *
         */

        //deployer.setKernel(EJB3StandaloneBootstrap.getKernel());
        deployer.create();
        System.err.println("...... deployer created....");

        deployer.start();
        System.err.println("...... deployer started....");

        System.err.println("...... start statistics");
        SessionFactory sessionFactory = PersistenceUtility.getHibernateSession(getEntityManager())
                .getSessionFactory();
        stats = sessionFactory.getStatistics();
        stats.setStatisticsEnabled(true);

        System.err.println("...... embedded container initialized and ready for testing....");

    } catch (Throwable t) {
        // Catch RuntimeExceptions and Errors and dump their stack trace, because Surefire will completely swallow them
        // and throw a cryptic NPE (see http://jira.codehaus.org/browse/SUREFIRE-157)!
        t.printStackTrace();
        throw new RuntimeException(t);
    }
}

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

License:Open Source License

/**
 * Format statistics in HTML// www.  ja  va  2s . c o 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();
}