FileDocCategorySizeDatePackage
StatisticsService.javaAPI DocHibernate 3.2.58674Fri Sep 30 02:48:54 BST 2005org.hibernate.jmx

StatisticsService

public class StatisticsService extends Object implements StatisticsServiceMBean
JMX service for Hibernate statistics

Register this MBean in your JMX server for a specific session factory
//build the ObjectName you want
Hashtable tb = new Hashtable();
tb.put("type", "statistics");
tb.put("sessionFactory", "myFinancialApp");
ObjectName on = new ObjectName("hibernate", tb);
StatisticsService stats = new StatisticsService();
stats.setSessionFactory(sessionFactory);
server.registerMBean(stats, on);
And call the MBean the way you want

Register this MBean in your JMX server with no specific session factory
//build the ObjectName you want
Hashtable tb = new Hashtable();
tb.put("type", "statistics");
tb.put("sessionFactory", "myFinancialApp");
ObjectName on = new ObjectName("hibernate", tb);
StatisticsService stats = new StatisticsService();
server.registerMBean(stats, on);
And call the MBean by providing the SessionFactoryJNDIName first. Then the session factory will be retrieved from JNDI and the statistics loaded.
author
Emmanuel Bernard

Fields Summary
org.hibernate.SessionFactory
sf
String
sfJNDIName
Log
log
org.hibernate.stat.Statistics
stats
Constructors Summary
Methods Summary
public voidclear()

see
StatisticsServiceMBean#clear()

		stats.clear();
	
public longgetCloseStatementCount()

		return stats.getCloseStatementCount();
	
public longgetCollectionFetchCount()

see
StatisticsServiceMBean#getCollectionFetchCount()

		return stats.getCollectionFetchCount();
	
public longgetCollectionLoadCount()

see
StatisticsServiceMBean#getCollectionLoadCount()

		return stats.getCollectionLoadCount();
	
public longgetCollectionRecreateCount()

see
StatisticsServiceMBean#getCollectionRecreateCount()

		return stats.getCollectionRecreateCount();
	
public longgetCollectionRemoveCount()

see
StatisticsServiceMBean#getCollectionRemoveCount()

		return stats.getCollectionRemoveCount();
	
public java.lang.String[]getCollectionRoleNames()

		return stats.getCollectionRoleNames();
	
public org.hibernate.stat.CollectionStatisticsgetCollectionStatistics(java.lang.String role)

see
StatisticsServiceMBean#getCollectionStatistics(java.lang.String)

		return stats.getCollectionStatistics(role);
	
public longgetCollectionUpdateCount()

see
StatisticsServiceMBean#getCollectionUpdateCount()

		return stats.getCollectionUpdateCount();
	
public longgetConnectCount()

see
StatisticsServiceMBean#getConnectCount()

		return stats.getConnectCount();
	
public longgetEntityDeleteCount()

see
StatisticsServiceMBean#getEntityDeleteCount()

		return stats.getEntityDeleteCount();
	
public longgetEntityFetchCount()

see
StatisticsServiceMBean#getEntityFetchCount()

		return stats.getEntityFetchCount();
	
public longgetEntityInsertCount()

see
StatisticsServiceMBean#getEntityInsertCount()

		return stats.getEntityInsertCount();
	
public longgetEntityLoadCount()

see
StatisticsServiceMBean#getEntityLoadCount()

		return stats.getEntityLoadCount();
	
public java.lang.String[]getEntityNames()

		return stats.getEntityNames();
	
public org.hibernate.stat.EntityStatisticsgetEntityStatistics(java.lang.String entityName)

see
StatisticsServiceMBean#getEntityStatistics(java.lang.String)

		return stats.getEntityStatistics(entityName);
	
public longgetEntityUpdateCount()

see
StatisticsServiceMBean#getEntityUpdateCount()

		return stats.getEntityUpdateCount();
	
public longgetFlushCount()

see
StatisticsServiceMBean#getFlushCount()

		return stats.getFlushCount();
	
public longgetOptimisticFailureCount()

		return stats.getOptimisticFailureCount();
	
public longgetPrepareStatementCount()

		return stats.getPrepareStatementCount();
	
public java.lang.String[]getQueries()

		return stats.getQueries();
	
public longgetQueryCacheHitCount()

		return stats.getQueryCacheHitCount();
	
public longgetQueryCacheMissCount()

		return stats.getQueryCacheMissCount();
	
public longgetQueryCachePutCount()

		return stats.getQueryCachePutCount();
	
public longgetQueryExecutionCount()

see
StatisticsServiceMBean#getQueryExecutionCount()

		return stats.getQueryExecutionCount();
	
public longgetQueryExecutionMaxTime()

		return stats.getQueryExecutionMaxTime();
	
public java.lang.StringgetQueryExecutionMaxTimeQueryString()

		return stats.getQueryExecutionMaxTimeQueryString();
	
public org.hibernate.stat.QueryStatisticsgetQueryStatistics(java.lang.String hql)

see
StatisticsServiceMBean#getQueryStatistics(java.lang.String)

		return stats.getQueryStatistics(hql);
	
public longgetSecondLevelCacheHitCount()

see
StatisticsServiceMBean#getSecondLevelCacheHitCount()

		return stats.getSecondLevelCacheHitCount();
	
public longgetSecondLevelCacheMissCount()

see
StatisticsServiceMBean#getSecondLevelCacheMissCount()

		return stats.getSecondLevelCacheMissCount();
	
public longgetSecondLevelCachePutCount()

see
StatisticsServiceMBean#getSecondLevelCachePutCount()

		return stats.getSecondLevelCachePutCount();
	
public java.lang.String[]getSecondLevelCacheRegionNames()

		return stats.getSecondLevelCacheRegionNames();
	
public org.hibernate.stat.SecondLevelCacheStatisticsgetSecondLevelCacheStatistics(java.lang.String regionName)

see
StatisticsServiceMBean#getSecondLevelCacheStatistics(java.lang.String)

		return stats.getSecondLevelCacheStatistics(regionName);
	
public longgetSessionCloseCount()

see
StatisticsServiceMBean#getSessionCloseCount()

		return stats.getSessionCloseCount();
	
public longgetSessionOpenCount()

see
StatisticsServiceMBean#getSessionOpenCount()

		return stats.getSessionOpenCount();
	
public longgetStartTime()

see
StatisticsServiceMBean#getStartTime()

		return stats.getStartTime();
	
public longgetSuccessfulTransactionCount()

		return stats.getSuccessfulTransactionCount();
	
public longgetTransactionCount()

		return stats.getTransactionCount();
	
public booleanisStatisticsEnabled()

see
StatisticsServiceMBean#isStatisticsEnabled()

		return stats.isStatisticsEnabled();
	
public voidlogSummary()

		stats.logSummary();
	
public voidsetSessionFactory(org.hibernate.SessionFactory sf)
Useful to init this MBean wo a JNDI session factory name

param
sf session factory to register

		this.sf = sf;
		if (sf == null) {
			stats = new StatisticsImpl();
		}
		else {
			stats = sf.getStatistics(); 
		}
		
	
public voidsetSessionFactoryJNDIName(java.lang.String sfJNDIName)

see
StatisticsServiceMBean#setSessionFactoryJNDIName(java.lang.String)


	  	 
	    
		this.sfJNDIName = sfJNDIName;
		try {
			Object obj = new InitialContext().lookup(sfJNDIName);
			if (obj instanceof Reference) {
				Reference ref = (Reference) obj;
				setSessionFactory( (SessionFactory) SessionFactoryObjectFactory.getInstance( (String) ref.get(0).getContent() ) );
			}
			else {
				setSessionFactory( (SessionFactory) obj );
			} 
		} 
		catch (NameNotFoundException e) {
			log.error("No session factory with JNDI name " + sfJNDIName, e);
			setSessionFactory(null);
		} 
		catch (NamingException e) {
			log.error("Error while accessing session factory with JNDI name " + sfJNDIName, e);
			setSessionFactory(null);
		} 
		catch (ClassCastException e) {
			log.error("JNDI name " + sfJNDIName + " does not handle a session factory reference", e);
			setSessionFactory(null);
		}
	
public voidsetStatisticsEnabled(boolean enable)

see
StatisticsServiceMBean#setStatisticsEnabled(boolean)

		stats.setStatisticsEnabled(enable);