Spy SQL

A data source wrapper tha allows to get information about JDBC activity

License

License

GroupId

GroupId

io.blep
ArtifactId

ArtifactId

spy-sql
Last Version

Last Version

0.3
Release Date

Release Date

Type

Type

jar
Description

Description

Spy SQL
A data source wrapper tha allows to get information about JDBC activity
Project URL

Project URL

https://github.com/bleporini/spy-sql
Source Code Management

Source Code Management

https://github.com/bleporini/spy-sql

Download spy-sql

How to add to project

<!-- https://jarcasting.com/artifacts/io.blep/spy-sql/ -->
<dependency>
    <groupId>io.blep</groupId>
    <artifactId>spy-sql</artifactId>
    <version>0.3</version>
</dependency>
// https://jarcasting.com/artifacts/io.blep/spy-sql/
implementation 'io.blep:spy-sql:0.3'
// https://jarcasting.com/artifacts/io.blep/spy-sql/
implementation ("io.blep:spy-sql:0.3")
'io.blep:spy-sql:jar:0.3'
<dependency org="io.blep" name="spy-sql" rev="0.3">
  <artifact name="spy-sql" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.blep', module='spy-sql', version='0.3')
)
libraryDependencies += "io.blep" % "spy-sql" % "0.3"
[io.blep/spy-sql "0.3"]

Dependencies

compile (3)

Group / Artifact Type Version
org.projectlombok : lombok jar 1.12.2
net.jcip : jcip-annotations jar 1.0
org.mockito : mockito-all jar 1.9.5

test (4)

Group / Artifact Type Version
org.easytesting : fest-assert jar 1.4
junit : junit jar 4.11
com.h2database : h2 jar 1.3.164
commons-dbcp : commons-dbcp jar 1.4

Project Modules

There are no modules declared in this project.

Spy SQL

What is it?

Spy SQL is just a datasource wrapper that allows to hook listeners to monitor DB activity. Its original purpose is to programmatically check the number of JDBC roundtrips and the number or the nature of SQL commands executed by JPA application.

How to use it?

Suppose you're using commons-dbcp, just create a new SpyDatasource with the target datasource :

        final BasicDataSource basicDataSource = new BasicDataSource();
        basicDataSource.setDriverClassName("org.h2.Driver");
        basicDataSource.setUrl("jdbc:h2:mem:sample");
        basicDataSource.setUsername("sa");
        basicDataSource.setPassword("");
        final SpyDatasource spyDs = new SpyDatasource(basicDataSource);

Obviously, it can be used with Spring or any other DI framework.

Then you can register any implementation of the simple interface io.blep.spysql.SqlListener, io.blep.spysql.SqlCounter which is provided or your own:

spyDatasource.addListener(listener);

If your datasource is shared accross multiple threads, beware of concurrency issues as listeners are shared as well. If you're just using it in single treaded test cases, just don't care about it.

Versions

Version
0.3
0.2