Commit 9aa957c4 authored by 吴晟's avatar 吴晟
Browse files

1.恢复jdbc-plugin,使用代码替换的模式实现oracle-plugin,代码过于复杂和笨重。

2.移除jdbc-plugin,对于connection.nativeSQL的追踪。
parent a2e7b56c
Loading
Loading
Loading
Loading
+64 −0
Original line number Diff line number Diff line
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>skywalking-sdk-plugin</artifactId>
        <groupId>com.ai.cloud</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>skywalking-jdbc-plugin</artifactId>
    <packaging>jar</packaging>

    <name>jdbc-plugin</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.ai.cloud</groupId>
            <artifactId>skywalking-api</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.36</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <encoding>${project.build.sourceEncoding}</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
            </plugin>
            <plugin>
                <!-- 源码插件 -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <!-- 发布时自动将源码同时发布的配置 -->
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
+32 −0
Original line number Diff line number Diff line
package com.ai.cloud.skywalking.plugin.jdbc;

import com.ai.cloud.skywalking.api.IBuriedPointType;
import com.ai.cloud.skywalking.protocol.CallType;

public class JDBCBuriedPointType implements IBuriedPointType {

    private static JDBCBuriedPointType jdbcBuriedPointType;

    public static IBuriedPointType instance() {
        if (jdbcBuriedPointType == null) {
            jdbcBuriedPointType = new JDBCBuriedPointType();
        }

        return jdbcBuriedPointType;
    }


    @Override
    public String getTypeName() {
        return "J";
    }

    @Override
    public CallType getCallType() {
        return CallType.LOCAL;
    }

    private JDBCBuriedPointType(){
        //Non
    }
}
+1058 −0

File added.

Preview size limit exceeded, changes collapsed.

+326 −0
Original line number Diff line number Diff line
package com.ai.cloud.skywalking.plugin.jdbc;

import java.sql.Array;
import java.sql.Blob;
import java.sql.CallableStatement;
import java.sql.Clob;
import java.sql.DatabaseMetaData;
import java.sql.NClob;
import java.sql.PreparedStatement;
import java.sql.SQLClientInfoException;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.SQLXML;
import java.sql.Savepoint;
import java.sql.Statement;
import java.sql.Struct;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.Executor;

import com.ai.cloud.skywalking.plugin.jdbc.tracing.ConnectionTracing;
import com.ai.cloud.skywalking.plugin.jdbc.tracing.ConnectionTracing.Executable;

public class SWConnection implements java.sql.Connection {
	private String connectInfo;

	private final java.sql.Connection realConnection;

	public SWConnection(String url, Properties info,
			java.sql.Connection realConnection) {
		super();
		this.connectInfo = url + "(" + info.getProperty("user") + ")";
		this.realConnection = realConnection;
	}

	public <T> T unwrap(Class<T> iface) throws SQLException {
		return realConnection.unwrap(iface);
	}

	public boolean isWrapperFor(Class<?> iface) throws SQLException {
		return realConnection.isWrapperFor(iface);
	}

	public Statement createStatement() throws SQLException {
		return new SWStatement(this, realConnection.createStatement(),
				this.connectInfo);
	}

	public PreparedStatement prepareStatement(String sql) throws SQLException {
		return new SWPreparedStatement(this,
				realConnection.prepareStatement(sql), this.connectInfo, sql);
	}

	public CallableStatement prepareCall(String sql) throws SQLException {
		return new SWCallableStatement(this, realConnection.prepareCall(sql),
				this.connectInfo, sql);
	}

	public String nativeSQL(String sql) throws SQLException {
		return ConnectionTracing.execute(realConnection, connectInfo,
				"nativeSQL", sql, new Executable<String>() {
					public String exe(java.sql.Connection realConnection,
							String sql) throws SQLException {
						return realConnection.nativeSQL(sql);
					}
				});
	}

	public void setAutoCommit(boolean autoCommit) throws SQLException {
		realConnection.setAutoCommit(autoCommit);
	}

	public boolean getAutoCommit() throws SQLException {
		return realConnection.getAutoCommit();
	}

	public void commit() throws SQLException {
		ConnectionTracing.execute(realConnection, connectInfo, "commit", "",
				new Executable<String>() {
					public String exe(java.sql.Connection realConnection,
							String sql) throws SQLException {
						realConnection.commit();
						return null;
					}
				});
	}

	public void rollback() throws SQLException {
		ConnectionTracing.execute(realConnection, connectInfo, "rollback", "",
				new Executable<String>() {
					public String exe(java.sql.Connection realConnection,
							String sql) throws SQLException {
						realConnection.rollback();
						return null;
					}
				});
	}

	public void close() throws SQLException {
		ConnectionTracing.execute(realConnection, connectInfo, "close", "",
				new Executable<String>() {
					public String exe(java.sql.Connection realConnection,
							String sql) throws SQLException {
						realConnection.close();
						return null;
					}
				});
	}

	public boolean isClosed() throws SQLException {
		return realConnection.isClosed();
	}

	public DatabaseMetaData getMetaData() throws SQLException {
		return realConnection.getMetaData();
	}

	public void setReadOnly(boolean readOnly) throws SQLException {
		realConnection.setReadOnly(readOnly);
	}

	public boolean isReadOnly() throws SQLException {
		return realConnection.isReadOnly();
	}

	public void setCatalog(String catalog) throws SQLException {
		realConnection.setCatalog(catalog);
	}

	public String getCatalog() throws SQLException {
		return realConnection.getCatalog();
	}

	public void setTransactionIsolation(int level) throws SQLException {
		realConnection.setTransactionIsolation(level);
	}

	public int getTransactionIsolation() throws SQLException {
		return realConnection.getTransactionIsolation();
	}

	public SQLWarning getWarnings() throws SQLException {
		return realConnection.getWarnings();
	}

	public void clearWarnings() throws SQLException {
		realConnection.clearWarnings();
	}

	public Statement createStatement(int resultSetType, int resultSetConcurrency)
			throws SQLException {
		return new SWStatement(this, realConnection.createStatement(
				resultSetType, resultSetConcurrency), this.connectInfo);
	}

	public PreparedStatement prepareStatement(String sql, int resultSetType,
			int resultSetConcurrency) throws SQLException {
		return new SWPreparedStatement(this, realConnection.prepareStatement(
				sql, resultSetType, resultSetConcurrency), this.connectInfo,
				sql);
	}

	public CallableStatement prepareCall(String sql, int resultSetType,
			int resultSetConcurrency) throws SQLException {
		return new SWCallableStatement(this, realConnection.prepareCall(sql,
				resultSetType, resultSetConcurrency), this.connectInfo, sql);
	}

	public Map<String, Class<?>> getTypeMap() throws SQLException {
		return realConnection.getTypeMap();
	}

	public void setTypeMap(Map<String, Class<?>> map) throws SQLException {
		realConnection.setTypeMap(map);
	}

	public void setHoldability(int holdability) throws SQLException {
		realConnection.setHoldability(holdability);
	}

	public int getHoldability() throws SQLException {
		return realConnection.getHoldability();
	}

	public Savepoint setSavepoint() throws SQLException {
		return realConnection.setSavepoint();
	}

	public Savepoint setSavepoint(String name) throws SQLException {
		return realConnection.setSavepoint(name);
	}

	public void rollback(final Savepoint savepoint) throws SQLException {
		ConnectionTracing.execute(realConnection, connectInfo,
				"rollback to savepoint", "", new Executable<String>() {
					public String exe(java.sql.Connection realConnection,
							String sql) throws SQLException {
						realConnection.rollback(savepoint);
						return null;
					}
				});
	}

	public void releaseSavepoint(final Savepoint savepoint) throws SQLException {
		ConnectionTracing.execute(realConnection, connectInfo,
				"releaseSavepoint savepoint", "", new Executable<String>() {
					public String exe(java.sql.Connection realConnection,
							String sql) throws SQLException {
						realConnection.releaseSavepoint(savepoint);
						return null;
					}
				});
	}

	public Statement createStatement(int resultSetType,
			int resultSetConcurrency, int resultSetHoldability)
			throws SQLException {
		return new SWStatement(this, realConnection.createStatement(
				resultSetType, resultSetConcurrency, resultSetHoldability),
				this.connectInfo);
	}

	public PreparedStatement prepareStatement(String sql, int resultSetType,
			int resultSetConcurrency, int resultSetHoldability)
			throws SQLException {
		return new SWPreparedStatement(this,
				realConnection.prepareStatement(sql, resultSetType,
						resultSetConcurrency, resultSetHoldability),
				this.connectInfo, sql);
	}

	public CallableStatement prepareCall(String sql, int resultSetType,
			int resultSetConcurrency, int resultSetHoldability)
			throws SQLException {
		return new SWCallableStatement(this, realConnection.prepareCall(sql,
				resultSetType, resultSetConcurrency, resultSetHoldability), this.connectInfo, sql);
	}

	public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys)
			throws SQLException {
		return new SWPreparedStatement(this, realConnection.prepareStatement(
				sql, autoGeneratedKeys), this.connectInfo, sql);
	}

	public PreparedStatement prepareStatement(String sql, int[] columnIndexes)
			throws SQLException {
		return new SWPreparedStatement(this, realConnection.prepareStatement(
				sql, columnIndexes), this.connectInfo, sql);
	}

	public PreparedStatement prepareStatement(String sql, String[] columnNames)
			throws SQLException {
		return new SWPreparedStatement(this, realConnection.prepareStatement(
				sql, columnNames), this.connectInfo, sql);
	}

	public Clob createClob() throws SQLException {
		return realConnection.createClob();
	}

	public Blob createBlob() throws SQLException {
		return realConnection.createBlob();
	}

	public NClob createNClob() throws SQLException {
		return realConnection.createNClob();
	}

	public SQLXML createSQLXML() throws SQLException {
		return realConnection.createSQLXML();
	}

	public boolean isValid(int timeout) throws SQLException {
		return realConnection.isValid(timeout);
	}

	public void setClientInfo(String name, String value)
			throws SQLClientInfoException {
		realConnection.setClientInfo(name, value);
	}

	public void setClientInfo(Properties properties)
			throws SQLClientInfoException {
		realConnection.setClientInfo(properties);
	}

	public String getClientInfo(String name) throws SQLException {
		return realConnection.getClientInfo(name);
	}

	public Properties getClientInfo() throws SQLException {
		return realConnection.getClientInfo();
	}

	public Array createArrayOf(String typeName, Object[] elements)
			throws SQLException {
		return realConnection.createArrayOf(typeName, elements);
	}

	public Struct createStruct(String typeName, Object[] attributes)
			throws SQLException {
		return realConnection.createStruct(typeName, attributes);
	}

	public void setSchema(String schema) throws SQLException {
		realConnection.setSchema(schema);
	}

	public String getSchema() throws SQLException {
		return realConnection.getSchema();
	}

	public void abort(Executor executor) throws SQLException {
		realConnection.abort(executor);
	}

	public void setNetworkTimeout(Executor executor, int milliseconds)
			throws SQLException {
		realConnection.setNetworkTimeout(executor, milliseconds);
	}

	public int getNetworkTimeout() throws SQLException {
		return realConnection.getNetworkTimeout();
	}

}
+537 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading