public class JdbcExecuteInterceptor
extends java.lang.Object
implements software.amazon.disco.agent.interception.Installable
| Modifier and Type | Field and Description |
|---|---|
static software.amazon.disco.agent.logging.Logger |
log |
static java.lang.String |
SQL_ORIGIN |
| Constructor and Description |
|---|
JdbcExecuteInterceptor() |
| Modifier and Type | Method and Description |
|---|---|
static software.amazon.disco.agent.event.ServiceRequestEvent |
enter(java.lang.String queryString,
java.lang.String origin,
java.sql.Statement stmt)
This method is inlined at the beginning of all execute methods matched by
buildMethodMatcher(). |
static void |
exit(software.amazon.disco.agent.event.ServiceRequestEvent requestEvent,
java.lang.Object response,
java.lang.Throwable thrown)
This method is inlined with an execute method at the moment it would return or throw a
Throwable. |
net.bytebuddy.agent.builder.AgentBuilder |
install(net.bytebuddy.agent.builder.AgentBuilder agentBuilder)
Installs the Disco SQL interception library into a Java program.
|
static java.lang.String |
parseQueryFromStatement(java.lang.Class<?> preparedStatementClass,
java.lang.Class<?> statementClass,
java.sql.Statement stmt,
java.lang.String queryString)
This helper method attempts to get the query string in two ways before giving up and returning null.
|
public static final software.amazon.disco.agent.logging.Logger log
public static final java.lang.String SQL_ORIGIN
@Advice.OnMethodEnter
public static software.amazon.disco.agent.event.ServiceRequestEvent enter(@Advice.Argument(value=0,optional=true)
java.lang.String queryString,
@Advice.Origin
java.lang.String origin,
@Advice.This
java.sql.Statement stmt)
buildMethodMatcher(). It
extracts some information from the intercepted execute method and calling object, then publishes a SQL query
request event as a ServiceDownstreamRequestEvent. The Query "service" is modeled as:
Origin = "SQL"
Service = Target database name
Operation = SQL query string
Request = JDBC Statement object constructed by user, intercepted by ByteBuddy
Must be public for use in Advice methods https://github.com/raphw/byte-buddy/issues/761queryString - the first parameter of the method, in the case where it is the queryStringorigin - Identifier of the intercepted method, for debugging/loggingstmt - concrete statement class being used to make the query@Advice.OnMethodExit(onThrowable=java.lang.Throwable.class)
public static void exit(@Advice.Enter
software.amazon.disco.agent.event.ServiceRequestEvent requestEvent,
@Advice.Return
java.lang.Object response,
@Advice.Thrown
java.lang.Throwable thrown)
Throwable.
It extracts the response and throwable if any and publishes a ServiceDownstreamResponseEvent.
See enter(java.lang.String, java.lang.String, java.sql.Statement) for Event model.
Must be public for use in Advice methods https://github.com/raphw/byte-buddy/issues/761requestEvent - the returned value of enter(java.lang.String, java.lang.String, java.sql.Statement) method, passed in using the Enter annotationresponse - the response of the JDBC execute method or null if an exception was thrown, passed in using the
Return annotationthrown - the Throwable thrown by the query, or null if query was successful. Passed in using the Thrown
annotation. Typically a SQLException.public net.bytebuddy.agent.builder.AgentBuilder install(net.bytebuddy.agent.builder.AgentBuilder agentBuilder)
install in interface software.amazon.disco.agent.interception.InstallableagentBuilder - - an AgentBuilder to append instructions toAgentBuilder object for chainingpublic static java.lang.String parseQueryFromStatement(java.lang.Class<?> preparedStatementClass,
java.lang.Class<?> statementClass,
java.sql.Statement stmt,
java.lang.String queryString)
throws java.lang.NoSuchMethodException
toString method on their PreparedStatement class to return the pre-loaded SQL query
string. So the second way is to check if the toString method is overridden, and if so we use it.
See: https://stackoverflow.com/questions/2382532/how-can-i-get-the-sql-of-a-preparedstatement
Must be public for use in Advice methods https://github.com/raphw/byte-buddy/issues/761preparedStatementClass - must be literally 'PreparedStatement.class'. Necessary because this method is called from somewhere this class may not be available, so it must be passed instatementClass - must be literally 'Statement.class'. Necessary for the same reason as preparedStatementClassstmt - the JDBC Statement object being used to make the queryqueryString - if the first param of the intercepted method was a queryString, this is not-null.null otherwisejava.lang.NoSuchMethodException