GitHub user ttddyy opened a pull request:
https://github.com/apache/tomcat/pull/18
Add QueryExecutionReportInterceptor and tests to jdbc-pool
Hello,
I wrote a JDBC interceptor, `QueryExecutionReportInterceptor`, and would
like to contribute it to jdbc-pool module.
### About
The `QueryExecutionReportInterceptor` outputs all query execution related
information to JULI log or system.out at the time of query(s) execution.
*Feature:*
- Configurable log level or System.out
- Work with batch executions
- Logs actual query parameters
- Turn on/off query parameters logging
- Support JSON output
*The log includes:*
- Query execution status (success/failure)
- Query execution time
- Statement type
- Batch execution
- Num of batch
- Num of query
- Query
- Query parameter values
### Motivation
I wrote a query reporting framework before,
[datasource-proxy](https://github.com/ttddyy/datasource-proxy), which uses
similar mechanism that jdbc-interceptor uses - using proxy to intercept query
execution and do some logic.
The reporting feature is very useful especially in debugging or trouble
shooting.
I think it would be more beneficial for users if this feature comes from
part of tomcat-jdbc-connection-pool library. So, I rewrote my logic to match
with jdbc-interceptor and enhanced a bit of it.
### Sample Output
Statement:
```
success:true, type:STATEMENT, batch:false, time:2, querySize:1,
batchSize:0, query:[(select * from users)], params:[]
```
Statement (Batched):
```
success:true, type:STATEMENT, batch:true, time:1, querySize:2, batchSize:2,
query:[(insert into users values (200, 'FOO')),(insert into users values (201,
'BAR'))], params:[]
```
PreparedStatement:
```
success:true, type:PREPARED, batch:false, time:3, querySize:1, batchSize:0,
query:[(select 1 from users where id = ? and name = ?)], params:[(1=99,2=foo)]
```
PreparedStatement (Batched):
```
success:true, type:PREPARED, batch:true, time:1, querySize:1, batchSize:2,
query:[(insert into users (id, name) values (?, ?))],
params:[(1=100,2=foo),(1=200,2=bar)]
```
PreparedStatement as JSON:
```
{"success":true, "type":"PREPARED", "batch":true, "timeâ:1,
"querySize":1, "batchSize":1, "query":["insert into users (id, name) values (?,
?)"], "params":[{"1":"100","2":"bar"}]}
```
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/ttddyy/tomcat query-report-interceptor
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/tomcat/pull/18.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #18
----
commit 61350dfa67e7f3414223e0988d4e07cdb66ee2f8
Author: Tadaya Tsuyukubo <[email protected]>
Date: 2015-03-18T05:02:05Z
Add QueryExecutionReportInterceptor and tests to jdbc-pool
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]