提交 8716bb0d 编写于 作者: L li.can 提交者: wu-sheng

Fix Mysql 6.x plugin (#2803)

* fix NPE

* fix 6.x

* optimize

* add final

* fix ci

* Update apm-sniffer/apm-sdk-plugin/jdbc-commons/src/main/java/org/apache/skywalking/apm/plugin/jdbc/JDBCDriverInterceptor.java

add not null
Co-Authored-By: NXin,Zhang <zhangxin@apache.org>
上级 f803a2ad
......@@ -45,6 +45,7 @@ public class ConnectionServiceMethodInterceptor implements InstanceMethodsAround
Class<?>[] argumentsTypes,
MethodInterceptResult result) throws Throwable {
ConnectionInfo connectInfo = (ConnectionInfo)objInst.getSkyWalkingDynamicField();
if (connectInfo != null) {
AbstractSpan span = ContextManager.createExitSpan(connectInfo.getDBType() + "/JDBI/Connection/" + method.getName(), connectInfo.getDatabasePeer());
Tags.DB_TYPE.set(span, "sql");
Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName());
......@@ -52,12 +53,16 @@ public class ConnectionServiceMethodInterceptor implements InstanceMethodsAround
span.setComponent(connectInfo.getComponent());
SpanLayer.asDB(span);
}
}
@Override
public final Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
Class<?>[] argumentsTypes,
Object ret) throws Throwable {
ConnectionInfo connectInfo = (ConnectionInfo)objInst.getSkyWalkingDynamicField();
if (connectInfo != null) {
ContextManager.stopSpan();
}
return ret;
}
......
......@@ -41,7 +41,7 @@ public class JDBCDriverInterceptor implements InstanceMethodsAroundInterceptor {
@Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
Class<?>[] argumentsTypes, Object ret) throws Throwable {
if (ret != null) {
if (ret != null && ret instanceof EnhancedInstance) {
((EnhancedInstance)ret).setSkyWalkingDynamicField(URLParser.parser((String)allArguments[0]));
}
......
......@@ -84,12 +84,12 @@ public class MysqlURLParser extends AbstractURLParser {
StringBuilder sb = new StringBuilder();
for (String host : hostSegment) {
if (host.split(":").length == 1) {
sb.append(host + ":" + DEFAULT_PORT + ",");
sb.append(host).append(":").append(DEFAULT_PORT).append(",");
} else {
sb.append(host + ",");
sb.append(host).append(",");
}
}
return new ConnectionInfo(ComponentsDefine.MYSQL_JDBC_DRIVER, DB_TYPE, sb.toString(), fetchDatabaseNameFromURL());
return new ConnectionInfo(ComponentsDefine.MYSQL_JDBC_DRIVER, DB_TYPE, sb.substring(0, sb.length() - 1), fetchDatabaseNameFromURL());
} else {
String[] hostAndPort = hostSegment[0].split(":");
if (hostAndPort.length != 1) {
......
......@@ -55,7 +55,7 @@ public class URLParserTest {
ConnectionInfo connectionInfo = new URLParser().parser("jdbc:mysql//primaryhost:3307,secondaryhost1,secondaryhost2/test?profileSQL=true");
assertThat(connectionInfo.getDBType(), is("Mysql"));
assertThat(connectionInfo.getDatabaseName(), is("test"));
assertThat(connectionInfo.getDatabasePeer(), is("primaryhost:3307,secondaryhost1:3306,secondaryhost2:3306,"));
assertThat(connectionInfo.getDatabasePeer(), is("primaryhost:3307,secondaryhost1:3306,secondaryhost2:3306"));
}
@Test
......@@ -63,7 +63,7 @@ public class URLParserTest {
ConnectionInfo connectionInfo = new URLParser().parser("jdbc:mysql:replication://master,slave1,slave2,slave3/test");
assertThat(connectionInfo.getDBType(), is("Mysql"));
assertThat(connectionInfo.getDatabaseName(), is("test"));
assertThat(connectionInfo.getDatabasePeer(), is("master:3306,slave1:3306,slave2:3306,slave3:3306,"));
assertThat(connectionInfo.getDatabasePeer(), is("master:3306,slave1:3306,slave2:3306,slave3:3306"));
}
@Test
......
......@@ -22,6 +22,7 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedI
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.StaticMethodsAroundInterceptor;
import org.apache.skywalking.apm.plugin.jdbc.connectionurl.parser.URLParser;
import org.apache.skywalking.apm.plugin.jdbc.mysql.ConnectionCache;
import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo;
import java.lang.reflect.Method;
......
......@@ -26,6 +26,7 @@ import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch;
import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.DRIVER_CONNECT_INTERCEPTOR;
/**
* @author: dingshaocheng
......@@ -35,7 +36,6 @@ public class CacheIpsInstrumentation extends AbstractMysqlInstrumentation {
private static final String ENHANCE_CLASS_NON_REG_REP = "com.mysql.jdbc.NonRegisteringReplicationDriver";
private static final String ENHANCE_CLASS = "com.mysql.jdbc.Driver";
private static final String ENHANCE_CLASS_NON_REG = "com.mysql.jdbc.NonRegisteringDriver";
private static final String METHOD_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.jdbc.mysql.v5.DriverConnectInterceptor";
@Override
......@@ -54,7 +54,7 @@ public class CacheIpsInstrumentation extends AbstractMysqlInstrumentation {
@Override
public String getMethodsInterceptor() {
return METHOD_INTERCEPTOR_CLASS;
return DRIVER_CONNECT_INTERCEPTOR;
}
@Override
......
......@@ -13,42 +13,44 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.plugin.jdbc.mysql.v6;
import com.mysql.cj.api.jdbc.JdbcConnection;
import com.mysql.cj.core.conf.url.ConnectionUrl;
import com.mysql.cj.core.conf.url.HostInfo;
import java.lang.reflect.Method;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.StaticMethodsAroundInterceptor;
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
import org.apache.skywalking.apm.plugin.jdbc.mysql.v6.wrapper.JdbcConnectionWrapper;
import org.apache.skywalking.apm.plugin.jdbc.connectionurl.parser.URLParser;
import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo;
public class CreateJdbcConnectionProxyInstanceInterceptor implements StaticMethodsAroundInterceptor {
import java.lang.reflect.Method;
/**
* for mysql connector java 6.0.4+
* @author lican
*/
public class ConnectionCreateNewInterceptor implements StaticMethodsAroundInterceptor {
@Override
public void beforeMethod(Class clazz, Method method, Object[] allArguments, Class<?>[] parameterTypes,
MethodInterceptResult result) {
public void beforeMethod(Class clazz, Method method, Object[] allArguments, Class<?>[] parameterTypes, MethodInterceptResult result) {
}
@Override
public Object afterMethod(Class clazz, Method method, Object[] allArguments, Class<?>[] parameterTypes,
Object ret) {
ConnectionUrl connectionUrl = (ConnectionUrl)allArguments[0];
StringBuilder hosts = new StringBuilder();
for (HostInfo info : connectionUrl.getHostsList()) {
hosts.append(info.getHost()).append(":").append(info.getPort()).append(",");
public Object afterMethod(Class clazz, Method method, Object[] allArguments, Class<?>[] parameterTypes, Object ret) {
if (ret instanceof EnhancedInstance) {
final HostInfo hostInfo = (HostInfo) allArguments[0];
ConnectionInfo connectionInfo = URLParser.parser(hostInfo.getDatabaseUrl());
((EnhancedInstance) ret).setSkyWalkingDynamicField(connectionInfo);
}
ConnectionInfo connectionInfo = new ConnectionInfo(ComponentsDefine.MYSQL_JDBC_DRIVER, "Mysql", hosts.toString(), connectionUrl.getDatabase());
return new JdbcConnectionWrapper((JdbcConnection)ret, connectionInfo);
return ret;
}
@Override
public void handleMethodException(Class clazz, Method method, Object[] allArguments, Class<?>[] parameterTypes,
Throwable t) {
public void handleMethodException(Class clazz, Method method, Object[] allArguments, Class<?>[] parameterTypes, Throwable t) {
}
}
......@@ -13,41 +13,42 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.plugin.jdbc.mysql.v6;
import com.mysql.cj.api.jdbc.ha.ReplicationConnection;
import com.mysql.cj.core.conf.url.ConnectionUrl;
import com.mysql.cj.core.conf.url.HostInfo;
import java.lang.reflect.Method;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.StaticMethodsAroundInterceptor;
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
import org.apache.skywalking.apm.plugin.jdbc.mysql.v6.wrapper.ReplicationConnectionWrapper;
import org.apache.skywalking.apm.plugin.jdbc.mysql.ConnectionCache;
import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo;
public class CreateReplicationConnectionProxyInstanceInterceptor implements StaticMethodsAroundInterceptor {
@Override public void beforeMethod(Class clazz, Method method, Object[] allArguments, Class<?>[] parameterTypes,
MethodInterceptResult result) {
import java.lang.reflect.Method;
}
/**
* for mysql connector java 6.0.2,6.0.3
* @author lican
*/
public class ConnectionCreateOldInterceptor implements StaticMethodsAroundInterceptor {
@Override public Object afterMethod(Class clazz, Method method, Object[] allArguments, Class<?>[] parameterTypes,
Object ret) {
ConnectionUrl connectionUrl = (ConnectionUrl)allArguments[0];
StringBuilder hosts = new StringBuilder();
for (HostInfo info : connectionUrl.getHostsList()) {
hosts.append(info.getHost()).append(":").append(info.getPort()).append(",");
@Override
public void beforeMethod(Class clazz, Method method, Object[] allArguments, Class<?>[] parameterTypes, MethodInterceptResult result) {
}
@Override
public Object afterMethod(Class clazz, Method method, Object[] allArguments, Class<?>[] parameterTypes, Object ret) {
if (ret instanceof EnhancedInstance) {
ConnectionInfo connectionInfo = ConnectionCache.get(allArguments[1].toString(), allArguments[2].toString());
((EnhancedInstance) ret).setSkyWalkingDynamicField(connectionInfo);
}
ConnectionInfo connectionInfo = new ConnectionInfo(ComponentsDefine.MYSQL_JDBC_DRIVER, "Mysql", hosts.toString(), connectionUrl.getDatabase());
return new ReplicationConnectionWrapper((ReplicationConnection)ret, connectionInfo);
return ret;
}
@Override
public void handleMethodException(Class clazz, Method method, Object[] allArguments, Class<?>[] parameterTypes,
Throwable t) {
public void handleMethodException(Class clazz, Method method, Object[] allArguments, Class<?>[] parameterTypes, Throwable t) {
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.skywalking.apm.plugin.jdbc.mysql.v6;
import com.mysql.cj.api.jdbc.ha.LoadBalancedConnection;
import com.mysql.cj.core.conf.url.ConnectionUrl;
import com.mysql.cj.core.conf.url.HostInfo;
import java.lang.reflect.Method;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.StaticMethodsAroundInterceptor;
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
import org.apache.skywalking.apm.plugin.jdbc.mysql.v6.wrapper.LoadBalancedConnectionWrapper;
import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo;
public class CreateLoadBalancedConnectionProxyInstanceInterceptor implements StaticMethodsAroundInterceptor {
@Override public void beforeMethod(Class clazz, Method method, Object[] allArguments, Class<?>[] parameterTypes,
MethodInterceptResult result) {
}
@Override public Object afterMethod(Class clazz, Method method, Object[] allArguments, Class<?>[] parameterTypes,
Object ret) {
ConnectionUrl connectionUrl = (ConnectionUrl)allArguments[0];
StringBuilder hosts = new StringBuilder();
for (HostInfo info : connectionUrl.getHostsList()) {
hosts.append(info.getHost()).append(":").append(info.getPort()).append(",");
}
ConnectionInfo connectionInfo = new ConnectionInfo(ComponentsDefine.MYSQL_JDBC_DRIVER, "Mysql", hosts.toString(), connectionUrl.getDatabase());
return new LoadBalancedConnectionWrapper((LoadBalancedConnection)ret, connectionInfo);
}
@Override
public void handleMethodException(Class clazz, Method method, Object[] allArguments, Class<?>[] parameterTypes,
Throwable t) {
}
}
......@@ -13,36 +13,49 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.plugin.jdbc.mysql.v6.define;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.StaticMethodsInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch;
import static org.apache.skywalking.apm.plugin.jdbc.mysql.Constants.DRIVER_CONNECT_INTERCEPTOR;
/**
* @author dingshaocheng lican
*/
public class CacheIpsInstrumentation extends AbstractMysqlInstrumentation {
public class FailoverConnectionProxyInstrumentation extends AbstractMysqlInstrumentation {
private static final String ENHANCE_CLASS_NON_REG = "com.mysql.cj.jdbc.NonRegisteringDriver";
public static final String METHOD_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jdbc.mysql.v6.CreateJdbcConnectionProxyInstanceInterceptor";
public static final String INTERCEPT_CLASS = "com.mysql.cj.jdbc.ha.FailoverConnectionProxy";
@Override
protected StaticMethodsInterceptPoint[] getStaticMethodsInterceptPoints() {
return new StaticMethodsInterceptPoint[] {
new StaticMethodsInterceptPoint() {
@Override public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named("createProxyInstance");
protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
return new ConstructorInterceptPoint[0];
}
@Override
protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
return new InstanceMethodsInterceptPoint[]{new InstanceMethodsInterceptPoint() {
@Override
public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named("connect");
}
@Override public String getMethodsInterceptor() {
return METHOD_INTERCEPTOR;
@Override
public String getMethodsInterceptor() {
return DRIVER_CONNECT_INTERCEPTOR;
}
@Override public boolean isOverrideArgs() {
@Override
public boolean isOverrideArgs() {
return false;
}
}
......@@ -51,7 +64,6 @@ public class FailoverConnectionProxyInstrumentation extends AbstractMysqlInstrum
@Override
protected ClassMatch enhanceClass() {
return byName(INTERCEPT_CLASS);
return byMultiClassMatch(ENHANCE_CLASS_NON_REG);
}
}
......@@ -13,8 +13,10 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.plugin.jdbc.mysql.v6.define;
import net.bytebuddy.description.method.MethodDescription;
......@@ -23,33 +25,65 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.StaticMethodsInte
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
public class LoadBalancedConnectionProxyInstrumentation extends AbstractMysqlInstrumentation {
/**
* interceptor the method {@link com.mysql.cj.jdbc.ConnectionImpl#getInstance} for mysql client version 6.x
*
* @author dingshaocheng lican
*/
public class ConnectionImplCreateInstrumentation extends AbstractMysqlInstrumentation {
private static final String JDBC_ENHANCE_CLASS = "com.mysql.cj.jdbc.ConnectionImpl";
private static final String CONNECT_METHOD = "getInstance";
private static final String GET_INSTANCE_NEW_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jdbc.mysql.v6.ConnectionCreateNewInterceptor";
private static final String GET_INSTANCE_OLD_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jdbc.mysql.v6.ConnectionCreateOldInterceptor";
public static final String METHOD_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jdbc.mysql.v6.CreateLoadBalancedConnectionProxyInstanceInterceptor";
public static final String INTERCEPT_CLASS = "com.mysql.cj.jdbc.ha.LoadBalancedConnectionProxy";
@Override protected StaticMethodsInterceptPoint[] getStaticMethodsInterceptPoints() {
return new StaticMethodsInterceptPoint[] {
@Override
protected StaticMethodsInterceptPoint[] getStaticMethodsInterceptPoints() {
return new StaticMethodsInterceptPoint[]{
new StaticMethodsInterceptPoint() {
@Override public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named("createProxyInstance");
@Override
public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named(CONNECT_METHOD).and(takesArguments(1));
}
@Override public String getMethodsInterceptor() {
return METHOD_INTERCEPTOR;
@Override
public String getMethodsInterceptor() {
return GET_INSTANCE_NEW_INTERCEPTOR;
}
@Override public boolean isOverrideArgs() {
@Override
public boolean isOverrideArgs() {
return false;
}
},
new StaticMethodsInterceptPoint() {
@Override
public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named(CONNECT_METHOD).and(takesArguments(4));
}
};
@Override
public String getMethodsInterceptor() {
return GET_INSTANCE_OLD_INTERCEPTOR;
}
@Override protected ClassMatch enhanceClass() {
return byName(INTERCEPT_CLASS);
@Override
public boolean isOverrideArgs() {
return false;
}
}
};
}
@Override
protected ClassMatch enhanceClass() {
return byName(JDBC_ENHANCE_CLASS);
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.skywalking.apm.plugin.jdbc.mysql.v6.define;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.StaticMethodsInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
public class ReplicationConnectionProxyInstrumentation extends AbstractMysqlInstrumentation {
public static final String METHOD_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jdbc.mysql.v6.CreateReplicationConnectionProxyInstanceInterceptor";
public static final String INTERCEPT_CLASS = "com.mysql.cj.jdbc.ha.ReplicationConnectionProxy";
@Override protected StaticMethodsInterceptPoint[] getStaticMethodsInterceptPoints() {
return new StaticMethodsInterceptPoint[] {
new StaticMethodsInterceptPoint() {
@Override public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named("createProxyInstance");
}
@Override public String getMethodsInterceptor() {
return METHOD_INTERCEPTOR;
}
@Override public boolean isOverrideArgs() {
return false;
}
}
};
}
@Override protected ClassMatch enhanceClass() {
return byName(INTERCEPT_CLASS);
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.skywalking.apm.plugin.jdbc.mysql.v6.wrapper;
import java.io.InputStream;
import java.io.Reader;
import java.math.BigDecimal;
import java.net.URL;
import java.sql.Array;
import java.sql.Blob;
import java.sql.CallableStatement;
import java.sql.Clob;
import java.sql.Date;
import java.sql.NClob;
import java.sql.Ref;
import java.sql.RowId;
import java.sql.SQLException;
import java.sql.SQLType;
import java.sql.SQLXML;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Map;
import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo;
public class CallableStatementWrapper extends PreparedStatementWrapper implements CallableStatement {
@Override public void registerOutParameter(int parameterIndex, int sqlType) throws SQLException {
call.registerOutParameter(parameterIndex, sqlType);
}
@Override public void registerOutParameter(int parameterIndex, int sqlType, int scale) throws SQLException {
call.registerOutParameter(parameterIndex, sqlType, scale);
}
@Override public boolean wasNull() throws SQLException {
return call.wasNull();
}
@Override public String getString(int parameterIndex) throws SQLException {
return call.getString(parameterIndex);
}
@Override public boolean getBoolean(int parameterIndex) throws SQLException {
return call.getBoolean(parameterIndex);
}
@Override public byte getByte(int parameterIndex) throws SQLException {
return call.getByte(parameterIndex);
}
@Override public short getShort(int parameterIndex) throws SQLException {
return call.getShort(parameterIndex);
}
@Override public int getInt(int parameterIndex) throws SQLException {
return call.getInt(parameterIndex);
}
@Override public long getLong(int parameterIndex) throws SQLException {
return call.getLong(parameterIndex);
}
@Override public float getFloat(int parameterIndex) throws SQLException {
return call.getFloat(parameterIndex);
}
@Override public double getDouble(int parameterIndex) throws SQLException {
return call.getDouble(parameterIndex);
}
@Override @Deprecated public BigDecimal getBigDecimal(int parameterIndex, int scale) throws SQLException {
return call.getBigDecimal(parameterIndex, scale);
}
@Override public byte[] getBytes(int parameterIndex) throws SQLException {
return call.getBytes(parameterIndex);
}
@Override public Date getDate(int parameterIndex) throws SQLException {
return call.getDate(parameterIndex);
}
@Override public Time getTime(int parameterIndex) throws SQLException {
return call.getTime(parameterIndex);
}
@Override public Timestamp getTimestamp(int parameterIndex) throws SQLException {
return call.getTimestamp(parameterIndex);
}
@Override public Object getObject(int parameterIndex) throws SQLException {
return call.getObject(parameterIndex);
}
@Override public BigDecimal getBigDecimal(int parameterIndex) throws SQLException {
return call.getBigDecimal(parameterIndex);
}
@Override public Object getObject(int parameterIndex, Map<String, Class<?>> map) throws SQLException {
return call.getObject(parameterIndex, map);
}
@Override public Ref getRef(int parameterIndex) throws SQLException {
return call.getRef(parameterIndex);
}
@Override public Blob getBlob(int parameterIndex) throws SQLException {
return call.getBlob(parameterIndex);
}
@Override public Clob getClob(int parameterIndex) throws SQLException {
return call.getClob(parameterIndex);
}
@Override public Array getArray(int parameterIndex) throws SQLException {
return call.getArray(parameterIndex);
}
@Override public Date getDate(int parameterIndex, Calendar cal) throws SQLException {
return call.getDate(parameterIndex, cal);
}
@Override public Time getTime(int parameterIndex, Calendar cal) throws SQLException {
return call.getTime(parameterIndex, cal);
}
@Override public Timestamp getTimestamp(int parameterIndex, Calendar cal) throws SQLException {
return call.getTimestamp(parameterIndex, cal);
}
@Override public void registerOutParameter(int parameterIndex, int sqlType, String typeName) throws SQLException {
call.registerOutParameter(parameterIndex, sqlType, typeName);
}
@Override public void registerOutParameter(String parameterName, int sqlType) throws SQLException {
call.registerOutParameter(parameterName, sqlType);
}
@Override public void registerOutParameter(String parameterName, int sqlType, int scale) throws SQLException {
call.registerOutParameter(parameterName, sqlType, scale);
}
@Override public void registerOutParameter(String parameterName, int sqlType, String typeName) throws SQLException {
call.registerOutParameter(parameterName, sqlType, typeName);
}
@Override public URL getURL(int parameterIndex) throws SQLException {
return call.getURL(parameterIndex);
}
@Override public void setURL(String parameterName, URL val) throws SQLException {
call.setURL(parameterName, val);
}
@Override public void setNull(String parameterName, int sqlType) throws SQLException {
call.setNull(parameterName, sqlType);
}
@Override public void setBoolean(String parameterName, boolean x) throws SQLException {
call.setBoolean(parameterName, x);
}
@Override public void setByte(String parameterName, byte x) throws SQLException {
call.setByte(parameterName, x);
}
@Override public void setShort(String parameterName, short x) throws SQLException {
call.setShort(parameterName, x);
}
@Override public void setInt(String parameterName, int x) throws SQLException {
call.setInt(parameterName, x);
}
@Override public void setLong(String parameterName, long x) throws SQLException {
call.setLong(parameterName, x);
}
@Override public void setFloat(String parameterName, float x) throws SQLException {
call.setFloat(parameterName, x);
}
@Override public void setDouble(String parameterName, double x) throws SQLException {
call.setDouble(parameterName, x);
}
@Override public void setBigDecimal(String parameterName, BigDecimal x) throws SQLException {
call.setBigDecimal(parameterName, x);
}
@Override public void setString(String parameterName, String x) throws SQLException {
call.setString(parameterName, x);
}
@Override public void setBytes(String parameterName, byte[] x) throws SQLException {
call.setBytes(parameterName, x);
}
@Override public void setDate(String parameterName, Date x) throws SQLException {
call.setDate(parameterName, x);
}
@Override public void setTime(String parameterName, Time x) throws SQLException {
call.setTime(parameterName, x);
}
@Override public void setTimestamp(String parameterName, Timestamp x) throws SQLException {
call.setTimestamp(parameterName, x);
}
@Override public void setAsciiStream(String parameterName, InputStream x, int length) throws SQLException {
call.setAsciiStream(parameterName, x, length);
}
@Override public void setBinaryStream(String parameterName, InputStream x, int length) throws SQLException {
call.setBinaryStream(parameterName, x, length);
}
@Override public void setObject(String parameterName, Object x, int targetSqlType, int scale) throws SQLException {
call.setObject(parameterName, x, targetSqlType, scale);
}
@Override public void setObject(String parameterName, Object x, int targetSqlType) throws SQLException {
call.setObject(parameterName, x, targetSqlType);
}
@Override public void setObject(String parameterName, Object x) throws SQLException {
call.setObject(parameterName, x);
}
@Override public void setCharacterStream(String parameterName, Reader reader, int length) throws SQLException {
call.setCharacterStream(parameterName, reader, length);
}
@Override public void setDate(String parameterName, Date x, Calendar cal) throws SQLException {
call.setDate(parameterName, x, cal);
}
@Override public void setTime(String parameterName, Time x, Calendar cal) throws SQLException {
call.setTime(parameterName, x, cal);
}
@Override public void setTimestamp(String parameterName, Timestamp x, Calendar cal) throws SQLException {
call.setTimestamp(parameterName, x, cal);
}
@Override public void setNull(String parameterName, int sqlType, String typeName) throws SQLException {
call.setNull(parameterName, sqlType, typeName);
}
@Override public String getString(String parameterName) throws SQLException {
return call.getString(parameterName);
}
@Override public boolean getBoolean(String parameterName) throws SQLException {
return call.getBoolean(parameterName);
}
@Override public byte getByte(String parameterName) throws SQLException {
return call.getByte(parameterName);
}
@Override public short getShort(String parameterName) throws SQLException {
return call.getShort(parameterName);
}
@Override public int getInt(String parameterName) throws SQLException {
return call.getInt(parameterName);
}
@Override public long getLong(String parameterName) throws SQLException {
return call.getLong(parameterName);
}
@Override public float getFloat(String parameterName) throws SQLException {
return call.getFloat(parameterName);
}
@Override public double getDouble(String parameterName) throws SQLException {
return call.getDouble(parameterName);
}
@Override public byte[] getBytes(String parameterName) throws SQLException {
return call.getBytes(parameterName);
}
@Override public Date getDate(String parameterName) throws SQLException {
return call.getDate(parameterName);
}
@Override public Time getTime(String parameterName) throws SQLException {
return call.getTime(parameterName);
}
@Override public Timestamp getTimestamp(String parameterName) throws SQLException {
return call.getTimestamp(parameterName);
}
@Override public Object getObject(String parameterName) throws SQLException {
return call.getObject(parameterName);
}
@Override public BigDecimal getBigDecimal(String parameterName) throws SQLException {
return call.getBigDecimal(parameterName);
}
@Override public Object getObject(String parameterName, Map<String, Class<?>> map) throws SQLException {
return call.getObject(parameterName, map);
}
@Override public Ref getRef(String parameterName) throws SQLException {
return call.getRef(parameterName);
}
@Override public Blob getBlob(String parameterName) throws SQLException {
return call.getBlob(parameterName);
}
@Override public Clob getClob(String parameterName) throws SQLException {
return call.getClob(parameterName);
}
@Override public Array getArray(String parameterName) throws SQLException {
return call.getArray(parameterName);
}
@Override public Date getDate(String parameterName, Calendar cal) throws SQLException {
return call.getDate(parameterName, cal);
}
@Override public Time getTime(String parameterName, Calendar cal) throws SQLException {
return call.getTime(parameterName, cal);
}
@Override public Timestamp getTimestamp(String parameterName, Calendar cal) throws SQLException {
return call.getTimestamp(parameterName, cal);
}
@Override public URL getURL(String parameterName) throws SQLException {
return call.getURL(parameterName);
}
@Override public RowId getRowId(int parameterIndex) throws SQLException {
return call.getRowId(parameterIndex);
}
@Override public RowId getRowId(String parameterName) throws SQLException {
return call.getRowId(parameterName);
}
@Override public void setRowId(String parameterName, RowId x) throws SQLException {
call.setRowId(parameterName, x);
}
@Override public void setNString(String parameterName, String value) throws SQLException {
call.setNString(parameterName, value);
}
@Override public void setNCharacterStream(String parameterName, Reader value, long length) throws SQLException {
call.setNCharacterStream(parameterName, value, length);
}
@Override public void setNClob(String parameterName, NClob value) throws SQLException {
call.setNClob(parameterName, value);
}
@Override public void setClob(String parameterName, Reader reader, long length) throws SQLException {
call.setClob(parameterName, reader, length);
}
@Override public void setBlob(String parameterName, InputStream inputStream, long length) throws SQLException {
call.setBlob(parameterName, inputStream, length);
}
@Override public void setNClob(String parameterName, Reader reader, long length) throws SQLException {
call.setNClob(parameterName, reader, length);
}
@Override public NClob getNClob(int parameterIndex) throws SQLException {
return call.getNClob(parameterIndex);
}
@Override public NClob getNClob(String parameterName) throws SQLException {
return call.getNClob(parameterName);
}
@Override public void setSQLXML(String parameterName, SQLXML xmlObject) throws SQLException {
call.setSQLXML(parameterName, xmlObject);
}
@Override public SQLXML getSQLXML(int parameterIndex) throws SQLException {
return call.getSQLXML(parameterIndex);
}
@Override public SQLXML getSQLXML(String parameterName) throws SQLException {
return call.getSQLXML(parameterName);
}
@Override public String getNString(int parameterIndex) throws SQLException {
return call.getNString(parameterIndex);
}
@Override public String getNString(String parameterName) throws SQLException {
return call.getNString(parameterName);
}
@Override public Reader getNCharacterStream(int parameterIndex) throws SQLException {
return call.getNCharacterStream(parameterIndex);
}
@Override public Reader getNCharacterStream(String parameterName) throws SQLException {
return call.getNCharacterStream(parameterName);
}
@Override public Reader getCharacterStream(int parameterIndex) throws SQLException {
return call.getCharacterStream(parameterIndex);
}
@Override public Reader getCharacterStream(String parameterName) throws SQLException {
return call.getCharacterStream(parameterName);
}
@Override public void setBlob(String parameterName, Blob x) throws SQLException {
call.setBlob(parameterName, x);
}
@Override public void setClob(String parameterName, Clob x) throws SQLException {
call.setClob(parameterName, x);
}
@Override public void setAsciiStream(String parameterName, InputStream x, long length) throws SQLException {
call.setAsciiStream(parameterName, x, length);
}
@Override public void setBinaryStream(String parameterName, InputStream x, long length) throws SQLException {
call.setBinaryStream(parameterName, x, length);
}
@Override public void setCharacterStream(String parameterName, Reader reader, long length) throws SQLException {
call.setCharacterStream(parameterName, reader, length);
}
@Override public void setAsciiStream(String parameterName, InputStream x) throws SQLException {
call.setAsciiStream(parameterName, x);
}
@Override public void setBinaryStream(String parameterName, InputStream x) throws SQLException {
call.setBinaryStream(parameterName, x);
}
@Override public void setCharacterStream(String parameterName, Reader reader) throws SQLException {
call.setCharacterStream(parameterName, reader);
}
@Override public void setNCharacterStream(String parameterName, Reader value) throws SQLException {
call.setNCharacterStream(parameterName, value);
}
@Override public void setClob(String parameterName, Reader reader) throws SQLException {
call.setClob(parameterName, reader);
}
@Override public void setBlob(String parameterName, InputStream inputStream) throws SQLException {
call.setBlob(parameterName, inputStream);
}
@Override public void setNClob(String parameterName, Reader reader) throws SQLException {
call.setNClob(parameterName, reader);
}
@Override public <T> T getObject(int parameterIndex, Class<T> type) throws SQLException {
return call.getObject(parameterIndex, type);
}
@Override public <T> T getObject(String parameterName, Class<T> type) throws SQLException {
return call.getObject(parameterName, type);
}
@Override public void setObject(String parameterName, Object x, SQLType targetSqlType,
int scaleOrLength) throws SQLException {
call.setObject(parameterName, x, targetSqlType, scaleOrLength);
}
@Override public void setObject(String parameterName, Object x, SQLType targetSqlType) throws SQLException {
call.setObject(parameterName, x, targetSqlType);
}
@Override public void registerOutParameter(int parameterIndex, SQLType sqlType) throws SQLException {
call.registerOutParameter(parameterIndex, sqlType);
}
@Override public void registerOutParameter(int parameterIndex, SQLType sqlType, int scale) throws SQLException {
call.registerOutParameter(parameterIndex, sqlType, scale);
}
@Override
public void registerOutParameter(int parameterIndex, SQLType sqlType, String typeName) throws SQLException {
call.registerOutParameter(parameterIndex, sqlType, typeName);
}
@Override public void registerOutParameter(String parameterName, SQLType sqlType) throws SQLException {
call.registerOutParameter(parameterName, sqlType);
}
@Override public void registerOutParameter(String parameterName, SQLType sqlType, int scale) throws SQLException {
call.registerOutParameter(parameterName, sqlType, scale);
}
@Override
public void registerOutParameter(String parameterName, SQLType sqlType, String typeName) throws SQLException {
call.registerOutParameter(parameterName, sqlType, typeName);
}
private final CallableStatement call;
private final String sql;
public CallableStatementWrapper(CallableStatement call, ConnectionInfo connectionInfo, String sql) {
super(call, connectionInfo, sql, "Callable");
this.call = call;
this.sql = sql;
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.skywalking.apm.plugin.jdbc.mysql.v6.wrapper;
import com.mysql.cj.api.jdbc.ha.LoadBalancedConnection;
import java.sql.SQLException;
import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo;
public class LoadBalancedConnectionWrapper extends JdbcConnectionWrapper implements LoadBalancedConnection {
@Override
public boolean addHost(String s) throws SQLException {
return delegate.addHost(s);
}
@Override public void removeHost(String s) throws SQLException {
delegate.removeHost(s);
}
@Override public void removeHostWhenNotInUse(String s) throws SQLException {
delegate.removeHostWhenNotInUse(s);
}
@Override public void ping(boolean b) throws SQLException {
delegate.ping(b);
}
private LoadBalancedConnection delegate;
public LoadBalancedConnectionWrapper(LoadBalancedConnection delegate, ConnectionInfo info) {
super(delegate, info);
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.skywalking.apm.plugin.jdbc.mysql.v6.wrapper;
import java.io.InputStream;
import java.io.Reader;
import java.math.BigDecimal;
import java.net.URL;
import java.sql.Array;
import java.sql.Blob;
import java.sql.Clob;
import java.sql.Date;
import java.sql.NClob;
import java.sql.ParameterMetaData;
import java.sql.PreparedStatement;
import java.sql.Ref;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.RowId;
import java.sql.SQLException;
import java.sql.SQLType;
import java.sql.SQLXML;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.Calendar;
import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo;
public class PreparedStatementWrapper extends StatementWrapper implements PreparedStatement {
public PreparedStatementWrapper(PreparedStatement statement, ConnectionInfo connectionInfo, String sql,
String statementType) {
super(statement, connectionInfo, statementType);
this.statement = statement;
this.sql = sql;
}
public PreparedStatementWrapper(PreparedStatement statement, ConnectionInfo connectionInfo, String sql) {
this(statement, connectionInfo, sql, "PreparedStatement");
}
@Override public ResultSet executeQuery() throws SQLException {
return TracingUtils.trace(connectionInfo, "executeQuery", sql, stateType, new TracingUtils.Executable<ResultSet>() {
@Override public ResultSet exe(String sql) throws SQLException {
return statement.executeQuery();
}
});
}
@Override public int executeUpdate() throws SQLException {
return TracingUtils.trace(connectionInfo, "executeUpdate", sql, stateType, new TracingUtils.Executable<Integer>() {
@Override public Integer exe(String sql) throws SQLException {
return statement.executeUpdate();
}
});
}
@Override public void setNull(int parameterIndex, int sqlType) throws SQLException {
statement.setNull(parameterIndex, sqlType);
}
@Override public void setBoolean(int parameterIndex, boolean x) throws SQLException {
statement.setBoolean(parameterIndex, x);
}
@Override public void setByte(int parameterIndex, byte x) throws SQLException {
statement.setByte(parameterIndex, x);
}
@Override public void setShort(int parameterIndex, short x) throws SQLException {
statement.setShort(parameterIndex, x);
}
@Override public void setInt(int parameterIndex, int x) throws SQLException {
statement.setInt(parameterIndex, x);
}
@Override public void setLong(int parameterIndex, long x) throws SQLException {
statement.setLong(parameterIndex, x);
}
@Override public void setFloat(int parameterIndex, float x) throws SQLException {
statement.setFloat(parameterIndex, x);
}
@Override public void setDouble(int parameterIndex, double x) throws SQLException {
statement.setDouble(parameterIndex, x);
}
@Override public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException {
statement.setBigDecimal(parameterIndex, x);
}
@Override public void setString(int parameterIndex, String x) throws SQLException {
statement.setString(parameterIndex, x);
}
@Override public void setBytes(int parameterIndex, byte[] x) throws SQLException {
statement.setBytes(parameterIndex, x);
}
@Override public void setDate(int parameterIndex, Date x) throws SQLException {
statement.setDate(parameterIndex, x);
}
@Override public void setTime(int parameterIndex, Time x) throws SQLException {
statement.setTime(parameterIndex, x);
}
@Override public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException {
statement.setTimestamp(parameterIndex, x);
}
@Override public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException {
statement.setAsciiStream(parameterIndex, x, length);
}
@Override @Deprecated
public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException {
statement.setUnicodeStream(parameterIndex, x, length);
}
@Override public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException {
statement.setBinaryStream(parameterIndex, x, length);
}
@Override public void clearParameters() throws SQLException {
statement.clearParameters();
}
@Override public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException {
statement.setObject(parameterIndex, x, targetSqlType);
}
@Override public void setObject(int parameterIndex, Object x) throws SQLException {
statement.setObject(parameterIndex, x);
}
@Override public boolean execute() throws SQLException {
return TracingUtils.trace(connectionInfo, "execute", sql, stateType, new TracingUtils.Executable<Boolean>() {
@Override public Boolean exe(String sql) throws SQLException {
return statement.execute();
}
});
}
@Override public void addBatch() throws SQLException {
statement.addBatch();
}
@Override public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException {
statement.setCharacterStream(parameterIndex, reader, length);
}
@Override public void setRef(int parameterIndex, Ref x) throws SQLException {
statement.setRef(parameterIndex, x);
}
@Override public void setBlob(int parameterIndex, Blob x) throws SQLException {
statement.setBlob(parameterIndex, x);
}
@Override public void setClob(int parameterIndex, Clob x) throws SQLException {
statement.setClob(parameterIndex, x);
}
@Override public void setArray(int parameterIndex, Array x) throws SQLException {
statement.setArray(parameterIndex, x);
}
@Override public ResultSetMetaData getMetaData() throws SQLException {
return statement.getMetaData();
}
@Override public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException {
statement.setDate(parameterIndex, x, cal);
}
@Override public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException {
statement.setTime(parameterIndex, x, cal);
}
@Override public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException {
statement.setTimestamp(parameterIndex, x, cal);
}
@Override public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException {
statement.setNull(parameterIndex, sqlType, typeName);
}
@Override public void setURL(int parameterIndex, URL x) throws SQLException {
statement.setURL(parameterIndex, x);
}
@Override public ParameterMetaData getParameterMetaData() throws SQLException {
return statement.getParameterMetaData();
}
@Override public void setRowId(int parameterIndex, RowId x) throws SQLException {
statement.setRowId(parameterIndex, x);
}
@Override public void setNString(int parameterIndex, String value) throws SQLException {
statement.setNString(parameterIndex, value);
}
@Override public void setNCharacterStream(int parameterIndex, Reader value, long length) throws SQLException {
statement.setNCharacterStream(parameterIndex, value, length);
}
@Override public void setNClob(int parameterIndex, NClob value) throws SQLException {
statement.setNClob(parameterIndex, value);
}
@Override public void setClob(int parameterIndex, Reader reader, long length) throws SQLException {
statement.setClob(parameterIndex, reader, length);
}
@Override public void setBlob(int parameterIndex, InputStream inputStream, long length) throws SQLException {
statement.setBlob(parameterIndex, inputStream, length);
}
@Override public void setNClob(int parameterIndex, Reader reader, long length) throws SQLException {
statement.setNClob(parameterIndex, reader, length);
}
@Override public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException {
statement.setSQLXML(parameterIndex, xmlObject);
}
@Override
public void setObject(int parameterIndex, Object x, int targetSqlType, int scaleOrLength) throws SQLException {
statement.setObject(parameterIndex, x, targetSqlType, scaleOrLength);
}
@Override public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException {
statement.setAsciiStream(parameterIndex, x, length);
}
@Override public void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException {
statement.setBinaryStream(parameterIndex, x, length);
}
@Override public void setCharacterStream(int parameterIndex, Reader reader, long length) throws SQLException {
statement.setCharacterStream(parameterIndex, reader, length);
}
@Override public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException {
statement.setAsciiStream(parameterIndex, x);
}
@Override public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException {
statement.setBinaryStream(parameterIndex, x);
}
@Override public void setCharacterStream(int parameterIndex, Reader reader) throws SQLException {
statement.setCharacterStream(parameterIndex, reader);
}
@Override public void setNCharacterStream(int parameterIndex, Reader value) throws SQLException {
statement.setNCharacterStream(parameterIndex, value);
}
@Override public void setClob(int parameterIndex, Reader reader) throws SQLException {
statement.setClob(parameterIndex, reader);
}
@Override public void setBlob(int parameterIndex, InputStream inputStream) throws SQLException {
statement.setBlob(parameterIndex, inputStream);
}
@Override public void setNClob(int parameterIndex, Reader reader) throws SQLException {
statement.setNClob(parameterIndex, reader);
}
@Override
public void setObject(int parameterIndex, Object x, SQLType targetSqlType, int scaleOrLength) throws SQLException {
statement.setObject(parameterIndex, x, targetSqlType, scaleOrLength);
}
@Override
public void setObject(int parameterIndex, Object x, SQLType targetSqlType) throws SQLException {
statement.setObject(parameterIndex, x, targetSqlType);
}
private final PreparedStatement statement;
private final String sql;
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.skywalking.apm.plugin.jdbc.mysql.v6.wrapper;
import com.mysql.cj.api.jdbc.JdbcConnection;
import com.mysql.cj.api.jdbc.ha.ReplicationConnection;
import java.sql.SQLException;
import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo;
public class ReplicationConnectionWrapper extends JdbcConnectionWrapper implements ReplicationConnection {
public ReplicationConnectionWrapper(JdbcConnection delegate, ConnectionInfo connectionInfo) {
super(delegate, connectionInfo);
}
@Override public long getConnectionGroupId() {
return replicationConnection.getConnectionGroupId();
}
@Override public JdbcConnection getCurrentConnection() {
return replicationConnection.getCurrentConnection();
}
@Override public JdbcConnection getMasterConnection() {
return replicationConnection.getMasterConnection();
}
@Override public void promoteSlaveToMaster(String s) throws SQLException {
replicationConnection.promoteSlaveToMaster(s);
}
@Override public void removeMasterHost(String s) throws SQLException {
replicationConnection.removeMasterHost(s);
}
@Override public void removeMasterHost(String s, boolean b) throws SQLException {
replicationConnection.removeMasterHost(s, b);
}
@Override public boolean isHostMaster(String s) {
return replicationConnection.isHostMaster(s);
}
@Override public JdbcConnection getSlavesConnection() {
return replicationConnection.getSlavesConnection();
}
@Override public void addSlaveHost(String s) throws SQLException {
replicationConnection.addSlaveHost(s);
}
@Override public void removeSlave(String s) throws SQLException {
replicationConnection.removeSlave(s);
}
@Override public void removeSlave(String s, boolean b) throws SQLException {
replicationConnection.removeSlave(s, b);
}
@Override public boolean isHostSlave(String s) {
return replicationConnection.isHostSlave(s);
}
private ReplicationConnection replicationConnection;
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.skywalking.apm.plugin.jdbc.mysql.v6.wrapper;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.Statement;
import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo;
public class StatementWrapper implements Statement {
@Override
public ResultSet executeQuery(String sql) throws SQLException {
return TracingUtils.trace(connectionInfo, "executeQuery", sql, stateType, new TracingUtils.Executable<ResultSet>() {
@Override public ResultSet exe(String sql) throws SQLException {
return statement.executeQuery(sql);
}
});
}
@Override public int executeUpdate(String sql) throws SQLException {
return TracingUtils.trace(connectionInfo, "executeUpdate", sql, stateType, new TracingUtils.Executable<Integer>() {
@Override public Integer exe(String sql) throws SQLException {
return statement.executeUpdate(sql);
}
});
}
@Override public void close() throws SQLException {
statement.close();
}
@Override public int getMaxFieldSize() throws SQLException {
return statement.getMaxFieldSize();
}
@Override public void setMaxFieldSize(int max) throws SQLException {
statement.setMaxFieldSize(max);
}
@Override public int getMaxRows() throws SQLException {
return statement.getMaxRows();
}
@Override public void setMaxRows(int max) throws SQLException {
statement.setMaxRows(max);
}
@Override public void setEscapeProcessing(boolean enable) throws SQLException {
statement.setEscapeProcessing(enable);
}
@Override public int getQueryTimeout() throws SQLException {
return statement.getQueryTimeout();
}
@Override public void setQueryTimeout(int seconds) throws SQLException {
statement.setQueryTimeout(seconds);
}
@Override public void cancel() throws SQLException {
statement.cancel();
}
@Override public SQLWarning getWarnings() throws SQLException {
return statement.getWarnings();
}
@Override public void clearWarnings() throws SQLException {
statement.clearWarnings();
}
@Override public void setCursorName(String name) throws SQLException {
statement.setCursorName(name);
}
@Override public boolean execute(String sql) throws SQLException {
return TracingUtils.trace(connectionInfo, "execute", sql, stateType, new TracingUtils.Executable<Boolean>() {
@Override public Boolean exe(String sql) throws SQLException {
return statement.execute(sql);
}
});
}
@Override public ResultSet getResultSet() throws SQLException {
return statement.getResultSet();
}
@Override public int getUpdateCount() throws SQLException {
return statement.getUpdateCount();
}
@Override public boolean getMoreResults() throws SQLException {
return statement.getMoreResults();
}
@Override public void setFetchDirection(int direction) throws SQLException {
statement.setFetchDirection(direction);
}
@Override public int getFetchDirection() throws SQLException {
return statement.getFetchDirection();
}
@Override public void setFetchSize(int rows) throws SQLException {
statement.setFetchSize(rows);
}
@Override public int getFetchSize() throws SQLException {
return statement.getFetchSize();
}
@Override public int getResultSetConcurrency() throws SQLException {
return statement.getResultSetConcurrency();
}
@Override public int getResultSetType() throws SQLException {
return statement.getResultSetType();
}
@Override public void addBatch(String sql) throws SQLException {
statement.addBatch(sql);
}
@Override public void clearBatch() throws SQLException {
statement.clearBatch();
}
@Override public int[] executeBatch() throws SQLException {
return TracingUtils.trace(connectionInfo, "executeBatch", null, stateType, new TracingUtils.Executable<int[]>() {
@Override public int[] exe(String sql) throws SQLException {
return statement.executeBatch();
}
});
}
@Override public Connection getConnection() throws SQLException {
return statement.getConnection();
}
@Override public boolean getMoreResults(int current) throws SQLException {
return statement.getMoreResults(current);
}
@Override public ResultSet getGeneratedKeys() throws SQLException {
return statement.getGeneratedKeys();
}
@Override public int executeUpdate(String sql, final int autoGeneratedKeys) throws SQLException {
return TracingUtils.trace(connectionInfo, "executeUpdate", sql, stateType, new TracingUtils.Executable<Integer>() {
@Override public Integer exe(String sql) throws SQLException {
return statement.executeUpdate(sql, autoGeneratedKeys);
}
});
}
@Override public int executeUpdate(String sql, final int[] columnIndexes) throws SQLException {
return TracingUtils.trace(connectionInfo, "executeUpdate", sql, stateType, new TracingUtils.Executable<Integer>() {
@Override public Integer exe(String sql) throws SQLException {
return statement.executeUpdate(sql, columnIndexes);
}
});
}
@Override public int executeUpdate(String sql, final String[] columnNames) throws SQLException {
return TracingUtils.trace(connectionInfo, "executeUpdate", sql, stateType, new TracingUtils.Executable<Integer>() {
@Override public Integer exe(String sql) throws SQLException {
return statement.executeUpdate(sql, columnNames);
}
});
}
@Override public boolean execute(String sql, final int autoGeneratedKeys) throws SQLException {
return TracingUtils.trace(connectionInfo, "execute", sql, stateType, new TracingUtils.Executable<Boolean>() {
@Override public Boolean exe(String sql) throws SQLException {
return statement.execute(sql, autoGeneratedKeys);
}
});
}
@Override public boolean execute(String sql, final int[] columnIndexes) throws SQLException {
return TracingUtils.trace(connectionInfo, "execute", sql, stateType, new TracingUtils.Executable<Boolean>() {
@Override public Boolean exe(String sql) throws SQLException {
return statement.execute(sql, columnIndexes);
}
});
}
@Override public boolean execute(String sql, final String[] columnNames) throws SQLException {
return TracingUtils.trace(connectionInfo, "execute", sql, stateType, new TracingUtils.Executable<Boolean>() {
@Override public Boolean exe(String sql) throws SQLException {
return statement.execute(sql, columnNames);
}
});
}
@Override public int getResultSetHoldability() throws SQLException {
return statement.getResultSetHoldability();
}
@Override public boolean isClosed() throws SQLException {
return statement.isClosed();
}
@Override public void setPoolable(boolean poolable) throws SQLException {
statement.setPoolable(poolable);
}
@Override public boolean isPoolable() throws SQLException {
return statement.isPoolable();
}
@Override public void closeOnCompletion() throws SQLException {
statement.closeOnCompletion();
}
@Override public boolean isCloseOnCompletion() throws SQLException {
return statement.isCloseOnCompletion();
}
@Override public long getLargeUpdateCount() throws SQLException {
return statement.getLargeUpdateCount();
}
@Override public void setLargeMaxRows(long max) throws SQLException {
statement.setLargeMaxRows(max);
}
@Override public long getLargeMaxRows() throws SQLException {
return statement.getLargeMaxRows();
}
@Override public long[] executeLargeBatch() throws SQLException {
return statement.executeLargeBatch();
}
@Override public long executeLargeUpdate(String sql) throws SQLException {
return TracingUtils.trace(connectionInfo, "executeLargeUpdate", sql, stateType, new TracingUtils.Executable<Long>() {
@Override public Long exe(String sql) throws SQLException {
return statement.executeLargeUpdate(sql);
}
});
}
@Override public long executeLargeUpdate(String sql, final int autoGeneratedKeys) throws SQLException {
return TracingUtils.trace(connectionInfo, "executeLargeUpdate", sql, stateType, new TracingUtils.Executable<Long>() {
@Override public Long exe(String sql) throws SQLException {
return statement.executeLargeUpdate(sql, autoGeneratedKeys);
}
});
}
@Override public long executeLargeUpdate(String sql, final int[] columnIndexes) throws SQLException {
return TracingUtils.trace(connectionInfo, "executeLargeUpdate", sql, stateType, new TracingUtils.Executable<Long>() {
@Override public Long exe(String sql) throws SQLException {
return statement.executeLargeUpdate(sql, columnIndexes);
}
});
}
@Override public long executeLargeUpdate(String sql, final String[] columnNames) throws SQLException {
return TracingUtils.trace(connectionInfo, "executeLargeUpdate", sql, stateType, new TracingUtils.Executable<Long>() {
@Override public Long exe(String sql) throws SQLException {
return statement.executeLargeUpdate(sql, columnNames);
}
});
}
private final Statement statement;
protected final ConnectionInfo connectionInfo;
protected final String stateType;
public StatementWrapper(Statement statement, ConnectionInfo connectionInfo, String stateType) {
this.statement = statement;
this.connectionInfo = connectionInfo;
this.stateType = stateType;
}
public StatementWrapper(Statement statement, ConnectionInfo connectionInfo) {
this(statement, connectionInfo, "Statement");
}
@Override public <T> T unwrap(Class<T> iface) throws SQLException {
return statement.unwrap(iface);
}
@Override public boolean isWrapperFor(Class<?> iface) throws SQLException {
return statement.isWrapperFor(iface);
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.skywalking.apm.plugin.jdbc.mysql.v6.wrapper;
import java.sql.SQLException;
import org.apache.skywalking.apm.agent.core.context.ContextManager;
import org.apache.skywalking.apm.agent.core.context.tag.Tags;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer;
import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo;
public class TracingUtils {
public static <R> R trace(ConnectionInfo connectInfo, String method, String sql, String statementType,
TracingUtils.Executable<R> exec)
throws SQLException {
try {
AbstractSpan span = ContextManager.createExitSpan(connectInfo.getDBType() + "/JDBI/" + statementType + "/" + method, connectInfo.getDatabasePeer());
Tags.DB_TYPE.set(span, "sql");
Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName());
Tags.DB_STATEMENT.set(span, sql);
span.setComponent(connectInfo.getComponent());
SpanLayer.asDB(span);
return exec.exe(sql);
} catch (SQLException e) {
AbstractSpan span = ContextManager.activeSpan();
span.errorOccurred();
span.log(e);
throw e;
} finally {
ContextManager.stopSpan();
}
}
public interface Executable<R> {
R exe(String sql) throws SQLException;
}
}
......@@ -19,6 +19,5 @@ mysql-6.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v6.define.ConnectionInstru
mysql-6.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v6.define.CallableInstrumentation
mysql-6.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v6.define.PreparedStatementInstrumentation
mysql-6.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v6.define.StatementInstrumentation
mysql-6.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v6.define.FailoverConnectionProxyInstrumentation
mysql-6.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v6.define.LoadBalancedConnectionProxyInstrumentation
mysql-6.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v6.define.ReplicationConnectionProxyInstrumentation
mysql-6.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v6.define.CacheIpsInstrumentation
mysql-6.x=org.apache.skywalking.apm.plugin.jdbc.mysql.v6.define.ConnectionImplCreateInstrumentation
......@@ -32,7 +32,7 @@ import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMa
public class PreparedStatementInstrumentation extends AbstractMysqlInstrumentation {
private static final String PREPARED_STATEMENT_CLASS_NAME = "com.mysql.cj.jdbc.ClientPreparedStatement";
private static final String PREPARED_STATEMENT_SERVERSIDE_CLASS_NAME = "com.mysql.cj.jdbc.ServerPreparedStatement";
private static final String PREPARED_STATEMENT_SERVER_SIDE_CLASS_NAME = "com.mysql.cj.jdbc.ServerPreparedStatement";
private static final String SERVICE_METHOD_INTERCEPTOR = Constants.PREPARED_STATEMENT_EXECUTE_METHODS_INTERCEPTOR;
......@@ -62,6 +62,6 @@ public class PreparedStatementInstrumentation extends AbstractMysqlInstrumentati
}
@Override protected ClassMatch enhanceClass() {
return byMultiClassMatch(PREPARED_STATEMENT_CLASS_NAME,PREPARED_STATEMENT_SERVERSIDE_CLASS_NAME);
return byMultiClassMatch(PREPARED_STATEMENT_CLASS_NAME, PREPARED_STATEMENT_SERVER_SIDE_CLASS_NAME);
}
}
......@@ -16,7 +16,7 @@
*
*/
package org.apache.skywalking.apm.plugin.jdbc.mysql.v5;
package org.apache.skywalking.apm.plugin.jdbc.mysql;
import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo;
import org.apache.skywalking.apm.util.StringUtil;
......@@ -27,9 +27,9 @@ import java.util.concurrent.ConcurrentHashMap;
* @author: dingshaocheng
*/
public class ConnectionCache {
private static ConcurrentHashMap<String, ConnectionInfo> CONNECTIONS_MAP = new ConcurrentHashMap<String, ConnectionInfo>();
private static final ConcurrentHashMap<String, ConnectionInfo> CONNECTIONS_MAP = new ConcurrentHashMap<String, ConnectionInfo>();
private static String CONNECTION_SPLIT_STR = ",";
private static final String CONNECTION_SPLIT_STR = ",";
public static ConnectionInfo get(String host, String port) {
final String connStr = String.format("%s:%s", host, port);
......
......@@ -28,4 +28,5 @@ public class Constants {
public static final String PREPARED_STATEMENT_EXECUTE_METHODS_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jdbc.mysql.PreparedStatementExecuteMethodsInterceptor";
public static final String SET_CATALOG_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jdbc.mysql.SetCatalogInterceptor";
public static final String STATEMENT_EXECUTE_METHODS_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jdbc.mysql.StatementExecuteMethodsInterceptor";
public static final String DRIVER_CONNECT_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jdbc.mysql.DriverConnectInterceptor";
}
......@@ -16,7 +16,7 @@
*
*/
package org.apache.skywalking.apm.plugin.jdbc.mysql.v5;
package org.apache.skywalking.apm.plugin.jdbc.mysql;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册