Package org.approvej.database.jdbc
Class RecordingDataSource
java.lang.Object
org.approvej.database.jdbc.RecordingDataSource
- All Implemented Interfaces:
Wrapper,CommonDataSource,DataSource
A
DataSource wrapper that records all SQL statements executed through it.
Wrap your application's DataSource with this to capture the SQL your code sends. Then
approve the recorded queries to catch unintended changes.
This is analogous to the HTTP module's HttpStubServer: instead of intercepting HTTP
requests, it intercepts SQL statements.
SQL is recorded at execution time. For PreparedStatements, the SQL template (with
? placeholders) is recorded each time the statement is executed.
-
Constructor Summary
ConstructorsConstructorDescriptionRecordingDataSource(DataSource delegate) Creates a newRecordingDataSourcewrapping the given delegate. -
Method Summary
Modifier and TypeMethodDescriptiongetConnection(String username, String password) int@Nullable PrintWriterbooleanisWrapperFor(Class<?> iface) Returns the last (most recently) recorded SQL query.Returns theListof recorded SQL queries in the order they were executed.Resets the recorded queries to an empty list.voidsetLoginTimeout(int seconds) voidsetLogWriter(PrintWriter out) <T> TMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface javax.sql.CommonDataSource
createShardingKeyBuilderMethods inherited from interface javax.sql.DataSource
createConnectionBuilder
-
Constructor Details
-
RecordingDataSource
Creates a newRecordingDataSourcewrapping the given delegate.- Parameters:
delegate- the realDataSourceto delegate to
-
-
Method Details
-
recordedQueries
Returns theListof recorded SQL queries in the order they were executed.- Returns:
- the recorded SQL queries
-
lastRecordedQuery
Returns the last (most recently) recorded SQL query.- Returns:
- the last recorded SQL query
-
resetRecordedQueries
Resets the recorded queries to an empty list.- Returns:
- this
-
getConnection
- Specified by:
getConnectionin interfaceDataSource- Throws:
SQLException
-
getConnection
- Specified by:
getConnectionin interfaceDataSource- Throws:
SQLException
-
getLogWriter
- Specified by:
getLogWriterin interfaceCommonDataSource- Specified by:
getLogWriterin interfaceDataSource- Throws:
SQLException
-
setLogWriter
- Specified by:
setLogWriterin interfaceCommonDataSource- Specified by:
setLogWriterin interfaceDataSource- Throws:
SQLException
-
setLoginTimeout
- Specified by:
setLoginTimeoutin interfaceCommonDataSource- Specified by:
setLoginTimeoutin interfaceDataSource- Throws:
SQLException
-
getLoginTimeout
- Specified by:
getLoginTimeoutin interfaceCommonDataSource- Specified by:
getLoginTimeoutin interfaceDataSource- Throws:
SQLException
-
getParentLogger
- Specified by:
getParentLoggerin interfaceCommonDataSource
-
unwrap
- Specified by:
unwrapin interfaceWrapper- Throws:
SQLException
-
isWrapperFor
- Specified by:
isWrapperForin interfaceWrapper- Throws:
SQLException
-