SourceForge.net Logo
Version: 0.27 - Last update: 2004-05-30 Home Page - SourceForge Project Page - Contact

Jodd
  Overview
  News
  Download
  License
  References

Development
  Using Jodd
  Javadoc
  JUnit report

Community
  Contribute
  Report a bug

More reading
  Milestone 0.30



Top 25%

BSD
 

SqlUtilProfiler

Sometimes there is a need to profile SQL queries in the application, i.e. to measure the execution time of executeQuery() and executeUpdate() methods. Jodd makes this possible without any external (and expensive) tool: just instance SqlUtilProfiler instead SqlUtil.

SqlUtilProfiler overloads (i.e. wraps) SqlUtil and measures the execution time of all queries. After query execution is complete and time has been measured, these data will be sent to user-made callback SqlProfilerHandler object. Simple as that.

Here is the example. Instead of the default use of the SqlUtil:

 
	SqlUtil dbsql = new SqlUtil(pool);		 // default code

the SqlUtilProfiler would be used for profiling:

 
	SqlUtil dbsql = new SqlUtilProfiler(pool);	 // profile code

Of course, to be able to collect profiled data, a callback object should be created somewhere during application initialization and assigned to SqlUtilProfiler:

 
	SqlUtilProfiler.handler = new CustomUserProfiler();

To deactivate profiling there is no need to alter the code, it is just enough to set handler to null instead:

 
	SqlUtilProfiler.handler = null;		// turn profiling off

Profiled code obviously runs a bit slower, which mainly depends on the implementation of the SqlProfilerHandler. When profiling is off, the code will run as there is no profiling at all, practically without any additional time delays.

Note:, Jodd currently doesn't provide any implementation of SqlProfilerHandler.



http://jodd.sourceforge.net
najgor at users.sourceforge.net