For many reasons I prefer not to disclose (long and boring story), I need to capture the interactions of a complex application with the Database. The application builds on top of Spring/JdbcTemplate and I need to find all the SQL sent out by this application. How can I do that in the simplest possible way?
Creating a pseudo mock implementation of JdbcTemplate does not seem reasonable. First off JdbcTemplate is a class and not an interface. Second it has a large interface that makes it tedious to implement. I am thinking along the lines of mocking DataSource
and Connection
to get all the SQL sent out, but maybe there is an easier way to do this?
This kind of problem is very neatly solved be eg. P6Spy. There is a good article on how to get it working with Spring.
Hope that helps.
The only way to capture all SQL going out is to be the touch point between your application and the database. This means, decorating the
DataSource
,Connection
, and all types ofStatement
s from a library implementation that actually handles the JDBC interactions, and note down all the statements being run on your decorated connection from your decorated data source specified in theSimpleJdbcTemplate
bean definition. It would be challenging from a maintainability perspective to capture this at any other point.