Class SqlLog
- java.lang.Object
-
- net.ttddyy.dsproxy.listener.NoOpQueryExecutionListener
-
- com.github.chrisgleissner.jutil.sqllog.SqlLog
-
- All Implemented Interfaces:
net.ttddyy.dsproxy.listener.QueryExecutionListener
,org.springframework.beans.factory.config.BeanPostProcessor
public class SqlLog extends net.ttddyy.dsproxy.listener.NoOpQueryExecutionListener implements org.springframework.beans.factory.config.BeanPostProcessor
Records SQL messages either on heap or by writing them to an OutputStream. UsestartRecording(String)
(on heap) orstartRecording(String, File, Charset)
(in file) to start recording. This returns aSqlRecording
. To stop recording, callSqlRecording.close()
.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
DEFAULT_ID
static net.ttddyy.dsproxy.transform.ParameterTransformer
identityParameterTransformer
static net.ttddyy.dsproxy.transform.QueryTransformer
identityQueryTransformer
static net.ttddyy.dsproxy.transform.ParameterTransformer
noOpParameterTransformer
static net.ttddyy.dsproxy.transform.QueryTransformer
noOpQueryTransformer
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
afterQuery(net.ttddyy.dsproxy.ExecutionInfo executionInfo, java.util.List<net.ttddyy.dsproxy.QueryInfo> list)
void
clear()
Stops all ongoing recordings (except the default recording) and clears their recorded messages.java.util.Collection<java.lang.String>
getAllMessages()
Returns all heap SQL logs, across all recording IDs.SqlRecording
getDefaultRecording()
java.util.Collection<java.lang.String>
getMessagesContaining(java.lang.String expectedString)
Returns all recorded heap SQL logs that contain an exact case-sensitive match of the specified string, regardless of recording ID.java.util.Collection<java.lang.String>
getMessagesContainingRegex(java.lang.String regex)
Returns all recorded heap SQL logs that match the specified regular expression, regardless of recording ID.SqlRecording
getRecording(java.lang.String id)
Returns the recording with the specified ID, unless it has been stopped.java.lang.Object
postProcessAfterInitialization(java.lang.Object bean, java.lang.String beanName)
java.lang.Object
postProcessBeforeInitialization(java.lang.Object bean, java.lang.String beanName)
void
setEnabled(boolean sqlLogEnabled)
void
setPropagateCallsToDbEnabled(boolean propagateCallsToDbEnabled)
SqlRecording
startRecording(java.lang.String id)
Starts a heap recording session for the specified ID.SqlRecording
startRecording(java.lang.String id, java.io.File file, java.nio.charset.Charset charset)
Starts a file recording session for the specified ID.SqlRecording
stopRecording(java.lang.String id)
Stops the recording with the specified ID and returns it, if existent.java.lang.String
toString()
-
-
-
Field Detail
-
DEFAULT_ID
public static final java.lang.String DEFAULT_ID
- See Also:
- Constant Field Values
-
identityQueryTransformer
public static final net.ttddyy.dsproxy.transform.QueryTransformer identityQueryTransformer
-
identityParameterTransformer
public static final net.ttddyy.dsproxy.transform.ParameterTransformer identityParameterTransformer
-
noOpQueryTransformer
public static final net.ttddyy.dsproxy.transform.QueryTransformer noOpQueryTransformer
-
noOpParameterTransformer
public static final net.ttddyy.dsproxy.transform.ParameterTransformer noOpParameterTransformer
-
-
Method Detail
-
startRecording
public SqlRecording startRecording(java.lang.String id)
Starts a heap recording session for the specified ID. If a session with this ID is currently in progress, it is stopped first.- Parameters:
id
- under which the recordings will be tracked- Returns:
- recorded heap SQL logs for previous recording of the specified ID, empty if no such recording exists
-
startRecording
public SqlRecording startRecording(java.lang.String id, java.io.File file, java.nio.charset.Charset charset)
Starts a file recording session for the specified ID. If a session with this ID is currently in progress, it is stopped first.- Parameters:
id
- under which the recordings will be tracked- Returns:
- recorded heap SQL logs for previous recording of the specified ID, empty if no such recording exists
-
stopRecording
public SqlRecording stopRecording(java.lang.String id)
Stops the recording with the specified ID and returns it, if existent. Alternatively, callSqlRecording.close()
.
-
getRecording
public SqlRecording getRecording(java.lang.String id)
Returns the recording with the specified ID, unless it has been stopped.- Parameters:
id
- of recording- Returns:
- recording or null if the recording is not known or not in progress
-
getMessagesContainingRegex
public java.util.Collection<java.lang.String> getMessagesContainingRegex(java.lang.String regex)
Returns all recorded heap SQL logs that match the specified regular expression, regardless of recording ID.
-
getMessagesContaining
public java.util.Collection<java.lang.String> getMessagesContaining(java.lang.String expectedString)
Returns all recorded heap SQL logs that contain an exact case-sensitive match of the specified string, regardless of recording ID.
-
getAllMessages
public java.util.Collection<java.lang.String> getAllMessages()
Returns all heap SQL logs, across all recording IDs.
-
clear
public void clear()
Stops all ongoing recordings (except the default recording) and clears their recorded messages.
-
postProcessBeforeInitialization
public java.lang.Object postProcessBeforeInitialization(java.lang.Object bean, java.lang.String beanName) throws org.springframework.beans.BeansException
- Specified by:
postProcessBeforeInitialization
in interfaceorg.springframework.beans.factory.config.BeanPostProcessor
- Throws:
org.springframework.beans.BeansException
-
postProcessAfterInitialization
public java.lang.Object postProcessAfterInitialization(java.lang.Object bean, java.lang.String beanName) throws org.springframework.beans.BeansException
- Specified by:
postProcessAfterInitialization
in interfaceorg.springframework.beans.factory.config.BeanPostProcessor
- Throws:
org.springframework.beans.BeansException
-
afterQuery
public void afterQuery(net.ttddyy.dsproxy.ExecutionInfo executionInfo, java.util.List<net.ttddyy.dsproxy.QueryInfo> list)
- Specified by:
afterQuery
in interfacenet.ttddyy.dsproxy.listener.QueryExecutionListener
- Overrides:
afterQuery
in classnet.ttddyy.dsproxy.listener.NoOpQueryExecutionListener
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
setEnabled
public void setEnabled(boolean sqlLogEnabled)
-
setPropagateCallsToDbEnabled
public void setPropagateCallsToDbEnabled(boolean propagateCallsToDbEnabled)
-
getDefaultRecording
public SqlRecording getDefaultRecording()
-
-