FileDocCategorySizeDatePackage
StatisticsImpl.javaAPI DocHibernate 3.2.517100Wed Feb 22 14:40:50 GMT 2006org.hibernate.stat

StatisticsImpl

public class StatisticsImpl extends Object implements StatisticsImplementor, Statistics
see
org.hibernate.stat.Statistics
author
Gavin King

Fields Summary
private static final Log
log
private org.hibernate.engine.SessionFactoryImplementor
sessionFactory
private boolean
isStatisticsEnabled
private long
startTime
private long
sessionOpenCount
private long
sessionCloseCount
private long
flushCount
private long
connectCount
private long
prepareStatementCount
private long
closeStatementCount
private long
entityLoadCount
private long
entityUpdateCount
private long
entityInsertCount
private long
entityDeleteCount
private long
entityFetchCount
private long
collectionLoadCount
private long
collectionUpdateCount
private long
collectionRemoveCount
private long
collectionRecreateCount
private long
collectionFetchCount
private long
secondLevelCacheHitCount
private long
secondLevelCacheMissCount
private long
secondLevelCachePutCount
private long
queryExecutionCount
private long
queryExecutionMaxTime
private String
queryExecutionMaxTimeQueryString
private long
queryCacheHitCount
private long
queryCacheMissCount
private long
queryCachePutCount
private long
commitedTransactionCount
private long
transactionCount
private long
optimisticFailureCount
private final Map
secondLevelCacheStatistics
second level cache statistics per region
private final Map
entityStatistics
entity statistics per name
private final Map
collectionStatistics
collection statistics per name
private final Map
queryStatistics
entity statistics per query string (HQL or SQL)
Constructors Summary
public StatisticsImpl()


	  
		clear();
	
public StatisticsImpl(org.hibernate.engine.SessionFactoryImplementor sessionFactory)

		clear();
		this.sessionFactory = sessionFactory;
	
Methods Summary
public synchronized voidclear()
reset all statistics

		secondLevelCacheHitCount = 0;
		secondLevelCacheMissCount = 0;
		secondLevelCachePutCount = 0;
		
		sessionCloseCount = 0;
		sessionOpenCount = 0;
		flushCount = 0;
		connectCount = 0;
		
		prepareStatementCount = 0;
		closeStatementCount = 0;
		
		entityDeleteCount = 0;
		entityInsertCount = 0;
		entityUpdateCount = 0;
		entityLoadCount = 0;
		entityFetchCount = 0;
		
		collectionRemoveCount = 0;
		collectionUpdateCount = 0;
		collectionRecreateCount = 0;
		collectionLoadCount = 0;
		collectionFetchCount = 0;
		
		queryExecutionCount = 0;
		queryCacheHitCount = 0;
		queryExecutionMaxTime = 0;
		queryExecutionMaxTimeQueryString = null;
		queryCacheMissCount = 0;
		queryCachePutCount = 0;
		
		transactionCount = 0;
		commitedTransactionCount = 0;
		
		optimisticFailureCount = 0;
		
		secondLevelCacheStatistics.clear();
		entityStatistics.clear();
		collectionStatistics.clear();
		queryStatistics.clear();
		
		startTime = System.currentTimeMillis();
	
public synchronized voidcloseSession()

		sessionCloseCount++;
	
public voidcloseStatement()

		closeStatementCount++;
	
public synchronized voidconnect()

		connectCount++;
	
public synchronized voiddeleteEntity(java.lang.String entityName)

		entityDeleteCount++;
		EntityStatistics es = getEntityStatistics(entityName);
		es.deleteCount++;
	
public voidendTransaction(boolean success)

		transactionCount++;
		if (success) commitedTransactionCount++;
	
public synchronized voidfetchCollection(java.lang.String role)

		collectionFetchCount++;
		getCollectionStatistics(role).fetchCount++;
	
public synchronized voidfetchEntity(java.lang.String entityName)

		entityFetchCount++;
		getEntityStatistics(entityName).fetchCount++;
	
public synchronized voidflush()

		flushCount++;
	
public longgetCloseStatementCount()

		return closeStatementCount;
	
public longgetCollectionFetchCount()

return
collection fetching (from DB)

		return collectionFetchCount;
	
public longgetCollectionLoadCount()

return
collection loading (from DB)

		return collectionLoadCount;
	
public longgetCollectionRecreateCount()

return
collection recreation

		return collectionRecreateCount;
	
public longgetCollectionRemoveCount()

return
collection removal FIXME: even if isInverse="true"?

		return collectionRemoveCount;
	
public java.lang.String[]getCollectionRoleNames()
Get the names of all collection roles

		if (sessionFactory==null) {
			return ArrayHelper.toStringArray( collectionStatistics.keySet() );
		}
		else {
			return ArrayHelper.toStringArray( sessionFactory.getAllCollectionMetadata().keySet() );
		}
	
public synchronized CollectionStatisticsgetCollectionStatistics(java.lang.String role)
Get collection statistics per role

param
role collection role
return
CollectionStatistics

		CollectionStatistics cs = (CollectionStatistics) collectionStatistics.get(role);
		if (cs==null) {
			cs = new CollectionStatistics(role);
			collectionStatistics.put(role, cs);
		}
		return cs;
	
public longgetCollectionUpdateCount()

return
collection update

		return collectionUpdateCount;
	
public longgetConnectCount()

return
session connect

		return connectCount;
	
public longgetEntityDeleteCount()

return
entity deletion count

		return entityDeleteCount;
	
public longgetEntityFetchCount()

return
entity fetch (from DB)

		return entityFetchCount;
	
public longgetEntityInsertCount()

return
entity insertion count

		return entityInsertCount;
	
public longgetEntityLoadCount()

return
entity load (from DB)

		return entityLoadCount;
	
public java.lang.String[]getEntityNames()
Get the names of all entities

		if (sessionFactory==null) {
			return ArrayHelper.toStringArray( entityStatistics.keySet() );
		}
		else {
			return ArrayHelper.toStringArray( sessionFactory.getAllClassMetadata().keySet() );
		}
	
public synchronized EntityStatisticsgetEntityStatistics(java.lang.String entityName)
find entity statistics per name

param
entityName entity name
return
EntityStatistics object

		EntityStatistics es = (EntityStatistics) entityStatistics.get(entityName);
		if (es==null) {
			es = new EntityStatistics(entityName);
			entityStatistics.put(entityName, es);
		}
		return es;
	
public longgetEntityUpdateCount()

return
entity update

		return entityUpdateCount;
	
public longgetFlushCount()

return
flush

		return flushCount;
	
public longgetOptimisticFailureCount()

		return optimisticFailureCount;
	
public longgetPrepareStatementCount()

		return prepareStatementCount;
	
public java.lang.String[]getQueries()
Get all executed query strings

		return ArrayHelper.toStringArray( queryStatistics.keySet() );
	
public longgetQueryCacheHitCount()

		return queryCacheHitCount;
	
public longgetQueryCacheMissCount()

		return queryCacheMissCount;
	
public longgetQueryCachePutCount()

		return queryCachePutCount;
	
public longgetQueryExecutionCount()

		return queryExecutionCount;
	
public longgetQueryExecutionMaxTime()

return
Returns the max query execution time, for all queries

		return queryExecutionMaxTime;
	
public java.lang.StringgetQueryExecutionMaxTimeQueryString()

		return queryExecutionMaxTimeQueryString;
	
public synchronized QueryStatisticsgetQueryStatistics(java.lang.String queryString)
Query statistics from query string (HQL or SQL)

param
queryString query string
return
QueryStatistics

		QueryStatistics qs = (QueryStatistics) queryStatistics.get(queryString);
		if (qs==null) {
			qs = new QueryStatistics(queryString);
			queryStatistics.put(queryString, qs);
		}
		return qs;
	
public longgetSecondLevelCacheHitCount()

return
second level cache hit

		return secondLevelCacheHitCount;
	
public longgetSecondLevelCacheMissCount()

return
second level cache miss

		return secondLevelCacheMissCount;
	
public longgetSecondLevelCachePutCount()

return
second level cache put

		return secondLevelCachePutCount;
	
public java.lang.String[]getSecondLevelCacheRegionNames()
Get all second-level cache region names

		if (sessionFactory==null) {
			return ArrayHelper.toStringArray( secondLevelCacheStatistics.keySet() );
		}
		else {
			return ArrayHelper.toStringArray( sessionFactory.getAllSecondLevelCacheRegions().keySet() );
		}
	
public synchronized SecondLevelCacheStatisticsgetSecondLevelCacheStatistics(java.lang.String regionName)
Second level cache statistics per region

param
regionName region name
return
SecondLevelCacheStatistics

		SecondLevelCacheStatistics slcs = (SecondLevelCacheStatistics) secondLevelCacheStatistics.get(regionName);
		if (slcs==null) {
			if (sessionFactory == null) return null;
			Cache cache = sessionFactory.getSecondLevelCacheRegion(regionName);
			if (cache==null) return null;
			slcs = new SecondLevelCacheStatistics(cache);
			secondLevelCacheStatistics.put(regionName, slcs);
		}
		return slcs;
	
public longgetSessionCloseCount()

return
session closing

		return sessionCloseCount;
	
public longgetSessionOpenCount()

return
session opening

		return sessionOpenCount;
	
public longgetStartTime()

return
start time in ms (JVM standards {@link System#currentTimeMillis()})

		return startTime;
	
public longgetSuccessfulTransactionCount()

		return commitedTransactionCount;
	
public longgetTransactionCount()

		return transactionCount;
	
public synchronized voidinsertEntity(java.lang.String entityName)

		entityInsertCount++;
		EntityStatistics es = getEntityStatistics(entityName);
		es.insertCount++;
	
public booleanisStatisticsEnabled()
Are statistics logged

		return isStatisticsEnabled;
	
public synchronized voidloadCollection(java.lang.String role)

		collectionLoadCount++;
		getCollectionStatistics(role).loadCount++;
	
public synchronized voidloadEntity(java.lang.String entityName)

		entityLoadCount++;
		getEntityStatistics(entityName).loadCount++;
	
public voidlogSummary()
log in info level the main statistics

		log.info("Logging statistics....");
		log.info("start time: " + startTime);
		log.info("sessions opened: " + sessionOpenCount);
		log.info("sessions closed: " + sessionCloseCount);
		log.info("transactions: " + transactionCount);
		log.info("successful transactions: " + commitedTransactionCount);
		log.info("optimistic lock failures: " + optimisticFailureCount);
		log.info("flushes: " + flushCount);
		log.info("connections obtained: " + connectCount);
		log.info("statements prepared: " + prepareStatementCount);
		log.info("statements closed: " + closeStatementCount);
		log.info("second level cache puts: " + secondLevelCachePutCount);
		log.info("second level cache hits: " + secondLevelCacheHitCount);
		log.info("second level cache misses: " + secondLevelCacheMissCount);
		log.info("entities loaded: " + entityLoadCount);
		log.info("entities updated: " + entityUpdateCount);
		log.info("entities inserted: " + entityInsertCount);
		log.info("entities deleted: " + entityDeleteCount);
		log.info("entities fetched (minimize this): " + entityFetchCount);
		log.info("collections loaded: " + collectionLoadCount);
		log.info("collections updated: " + collectionUpdateCount);
		log.info("collections removed: " + collectionRemoveCount);
		log.info("collections recreated: " + collectionRecreateCount);
		log.info("collections fetched (minimize this): " + collectionFetchCount);
		log.info("queries executed to database: " + queryExecutionCount);
		log.info("query cache puts: " + queryCachePutCount);
		log.info("query cache hits: " + queryCacheHitCount);
		log.info("query cache misses: " + queryCacheMissCount);
		log.info("max query time: " + queryExecutionMaxTime + "ms");
	
public synchronized voidopenSession()

		sessionOpenCount++;
	
public voidoptimisticFailure(java.lang.String entityName)

		optimisticFailureCount++;
		getEntityStatistics(entityName).optimisticFailureCount++;
	
public voidprepareStatement()

		prepareStatementCount++;
	
public synchronized voidqueryCacheHit(java.lang.String hql, java.lang.String regionName)

		queryCacheHitCount++;
		if (hql!=null) {
			QueryStatistics qs = getQueryStatistics(hql);
			qs.cacheHitCount++;
		}
		SecondLevelCacheStatistics slcs = getSecondLevelCacheStatistics(regionName);
		slcs.hitCount++;
	
public synchronized voidqueryCacheMiss(java.lang.String hql, java.lang.String regionName)

		queryCacheMissCount++;
		if (hql!=null) {
			QueryStatistics qs = getQueryStatistics(hql);
			qs.cacheMissCount++;
		}
		SecondLevelCacheStatistics slcs = getSecondLevelCacheStatistics(regionName);
		slcs.missCount++;
	
public synchronized voidqueryCachePut(java.lang.String hql, java.lang.String regionName)

		queryCachePutCount++;
		if (hql!=null) {
			QueryStatistics qs = getQueryStatistics(hql);
			qs.cachePutCount++;
		}
		SecondLevelCacheStatistics slcs = getSecondLevelCacheStatistics(regionName);
		slcs.putCount++;
	
public synchronized voidqueryExecuted(java.lang.String hql, int rows, long time)

		queryExecutionCount++;
		if (queryExecutionMaxTime<time) {
			queryExecutionMaxTime=time;
			queryExecutionMaxTimeQueryString = hql;
		}
		if (hql!=null) {
			QueryStatistics qs = getQueryStatistics(hql);
			qs.executed(rows, time);
		}
	
public synchronized voidrecreateCollection(java.lang.String role)

		collectionRecreateCount++;
		getCollectionStatistics(role).recreateCount++;
	
public synchronized voidremoveCollection(java.lang.String role)

		collectionRemoveCount++;
		getCollectionStatistics(role).removeCount++;
	
public synchronized voidsecondLevelCacheHit(java.lang.String regionName)

		secondLevelCacheHitCount++;
		getSecondLevelCacheStatistics(regionName).hitCount++;
	
public synchronized voidsecondLevelCacheMiss(java.lang.String regionName)

		secondLevelCacheMissCount++;
		getSecondLevelCacheStatistics(regionName).missCount++;
	
public synchronized voidsecondLevelCachePut(java.lang.String regionName)

		secondLevelCachePutCount++;
		getSecondLevelCacheStatistics(regionName).putCount++;
	
public voidsetStatisticsEnabled(boolean b)
Enable statistics logs (this is a dynamic parameter)

		isStatisticsEnabled = b;
	
public java.lang.StringtoString()

		return new StringBuffer()
			.append("Statistics[")
			.append("start time=").append(startTime)
			.append(",sessions opened=").append(sessionOpenCount)
			.append(",sessions closed=").append(sessionCloseCount)
			.append(",transactions=").append(transactionCount)
			.append(",successful transactions=").append(commitedTransactionCount)
			.append(",optimistic lock failures=").append(optimisticFailureCount)
			.append(",flushes=").append(flushCount)
			.append(",connections obtained=").append(connectCount)
			.append(",statements prepared=").append(prepareStatementCount)
			.append(",statements closed=").append(closeStatementCount)
			.append(",second level cache puts=").append(secondLevelCachePutCount)
			.append(",second level cache hits=").append(secondLevelCacheHitCount)
			.append(",second level cache misses=").append(secondLevelCacheMissCount)
			.append(",entities loaded=").append(entityLoadCount)
			.append(",entities updated=").append(entityUpdateCount)
			.append(",entities inserted=").append(entityInsertCount)
			.append(",entities deleted=").append(entityDeleteCount)
			.append(",entities fetched=").append(entityFetchCount)
			.append(",collections loaded=").append(collectionLoadCount)
			.append(",collections updated=").append(collectionUpdateCount)
			.append(",collections removed=").append(collectionRemoveCount)
			.append(",collections recreated=").append(collectionRecreateCount)
			.append(",collections fetched=").append(collectionFetchCount)
			.append(",queries executed to database=").append(queryExecutionCount)
			.append(",query cache puts=").append(queryCachePutCount)
			.append(",query cache hits=").append(queryCacheHitCount)
			.append(",query cache misses=").append(queryCacheMissCount)
			.append(",max query time=").append(queryExecutionMaxTime)
			.append(']")
			.toString();
	
public synchronized voidupdateCollection(java.lang.String role)

		collectionUpdateCount++;
		getCollectionStatistics(role).updateCount++;
	
public synchronized voidupdateEntity(java.lang.String entityName)

		entityUpdateCount++;
		EntityStatistics es = getEntityStatistics(entityName);
		es.updateCount++;