private void infoStatistics (SessionFactory sessionFactory) ;

tbase發表於2007-09-06

private void infoStatistics (SessionFactory sessionFactory) {
Statistics stats = sessionFactory.getStatistics();

// total statistics
stats.logSummary();
String[] clazz = stats.getEntityNames();

// entity statistics
if (clazz != null && clazz.length > 0) {
for (int i = 0; i < clazz.length; i++) {
EntityStatistics entityStats = stats
.getEntityStatistics(clazz[i]);

System.out.println(clazz[i]);
System.out.println("inserted : " + entityStats.getInsertCount());
System.out.println("updated : " + entityStats.getUpdateCount());
System.out.println("deleted : " + entityStats.getDeleteCount());
System.out.println("loaded : " + entityStats.getLoadCount());
}
}

String[] queries = stats.getQueries();

// queries statistics
if (queries != null && queries.length > 0) {
for (int i = 0; i < queries.length; i++) {
QueryStatistics queryStats = stats
.getQueryStatistics(queries[i]);
System.out.println(queries[i]);
System.out.println("ExecutionAvgTime : "
+ queryStats.getExecutionAvgTime());
System.out.println("ExecutionMinTime : "
+ queryStats.getExecutionMinTime());
System.out.println("ExecutionMaxTime : "
+ queryStats.getExecutionMaxTime());
System.out.println("ExecutionCount : "
+ queryStats.getExecutionCount());
System.out.println("ExecutionRowCount : "
+ queryStats.getExecutionRowCount());
}
}

// clear
stats.clear();

}

[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/249132/viewspace-968246/,如需轉載,請註明出處,否則將追究法律責任。

相關文章