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, OutputStream, Charset)
(to stream) to start recording which returns aSqlRecording
. To stop recording, callSqlRecording.close()
.
-
-
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 and clears their recorded messages.java.util.Collection<java.lang.String>
getAllMessages()
Returns all heap SQL logs, across all recording IDs.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
setSqlLogEnabled(boolean sqlLogEnabled)
SqlRecording
startRecording(java.lang.String id)
Starts a heap recording session for the specified ID.SqlRecording
startRecording(java.lang.String id, java.io.OutputStream os, java.nio.charset.Charset charset)
Starts a stream recording session for the specified ID.SqlRecording
stopRecording(java.lang.String id)
Stops the recording with the specified ID and returns it, if existent.
-
-
-
Method Detail
-
setSqlLogEnabled
public void setSqlLogEnabled(boolean sqlLogEnabled)
-
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.OutputStream os, java.nio.charset.Charset charset)
Starts a stream 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 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
-
-