Permalink
Browse files

import jdbc-tracer from other repo

  • Loading branch information...
1 parent b7ecf88 commit 49e441a1a58f3fe8774d99c9a2cddd99fa4cbdb1 @tokuhirom committed Apr 8, 2016
View
@@ -2,11 +2,6 @@ apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'idea'
-sourceCompatibility = '1.8'
-targetCompatibility = '1.8'
-
-[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
-
repositories {
mavenCentral()
}
@@ -18,6 +13,11 @@ subprojects {
group 'me.geso.jdbcquerylog'
version '0.1.3'
+ sourceCompatibility = '1.8'
+ targetCompatibility = '1.8'
+
+ [compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
+
repositories {
mavenCentral()
jcenter()
@@ -45,3 +45,6 @@ subprojects {
}
}
+task wrapper(type: Wrapper) {
+ gradleVersion = '2.12'
+}
View
@@ -0,0 +1,23 @@
+checkout:
+ post:
+ - chmod +x ./gradlew
+
+machine:
+ java:
+ version: oraclejdk8
+ environment:
+ GRADLE_OPTS: -Xmx4G -Dorg.gradle.daemon=true
+ post:
+ - sudo service mysql stop
+ - sudo service postgresql stop
+
+dependencies:
+ override:
+ - ./gradlew testClasses --stacktrace
+
+test:
+ override:
+ - ./gradlew --full-stacktrace check
+ post:
+ - mkdir -p $CIRCLE_TEST_REPORTS/junit/
+ - find . -type f -regex ".*/test-results/*/.*xml" -exec cp {} $CIRCLE_TEST_REPORTS/junit/ \;
@@ -37,15 +37,15 @@ uploadArchives {
}
pom.project {
- name 'jdbc-tracer-driver'
+ name 'jdbc-query-log'
packaging 'jar'
- description 'JDBC tracer Driver'
- url 'https://github.com/tokuhirom/jdbc_tracer'
+ description 'JDBC query log'
+ url 'https://github.com/tokuhirom/jdbc_querylog'
scm {
- url "scm:git@github.com:tokuhirom/jdbc_tracer.git"
- connection "scm:git@github.com:tokuhirom/jdbc_tracer.git"
- developerConnection "scm:git@github.com:tokuhirom/jdbc_tracer.git"
+ url "scm:git@github.com:tokuhirom/jdbc_querylog.git"
+ connection "scm:git@github.com:tokuhirom/jdbc_querylog.git"
+ developerConnection "scm:git@github.com:tokuhirom/jdbc_querylog.git"
}
licenses {
license {
@@ -0,0 +1,77 @@
+apply plugin: "maven"
+apply plugin: "signing"
+
+//set build variables based on build type (release, continuous integration, development)
+def isDevBuild
+def isReleaseBuild
+def sonatypeRepositoryUrl
+if (hasProperty("release")) {
+ isReleaseBuild = true
+ sonatypeRepositoryUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
+} else if (hasProperty("ci")) {
+ version += "-SNAPSHOT"
+ sonatypeRepositoryUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
+} else {
+ isDevBuild = true
+ version += "-SNAPSHOT"
+}
+
+signing {
+ required { isReleaseBuild }
+ sign configurations.archives
+}
+
+uploadArchives {
+ repositories {
+ if (isDevBuild) {
+ mavenLocal()
+ }
+ else {
+ mavenDeployer {
+ if(isReleaseBuild) {
+ beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
+ }
+
+ repository(url: sonatypeRepositoryUrl) {
+ authentication(userName: sonatypeUsername, password: sonatypePassword)
+ }
+
+ pom.project {
+ name 'me.geso.jdbctracer'
+ packaging 'jar'
+ description 'JDBC tracer'
+ url 'https://github.com/tokuhirom/jdbc_querylog'
+
+ scm {
+ url "scm:git@github.com:tokuhirom/jdbc_querylog.git"
+ connection "scm:git@github.com:tokuhirom/jdbc_querylog.git"
+ developerConnection "scm:git@github.com:tokuhirom/jdbc_querylog.git"
+ }
+ licenses {
+ license {
+ name 'MIT'
+ url 'https://opensource.org/licenses/MIT'
+ }
+ }
+ developers {
+ developer {
+ id 'tokuhirom'
+ name 'Tokuhiro Matsuno'
+ email 'tokuhirom@gmail.com'
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+dependencies {
+ compile 'org.projectlombok:lombok:1.16.8'
+
+ testCompile 'org.mockito:mockito-core:2.0.44-beta'
+ testCompile 'com.h2database:h2:1.4.191'
+ testCompile 'junit:junit:4.11'
+ testCompile 'org.assertj:assertj-core:3.4.0'
+}
+
@@ -0,0 +1,38 @@
+package me.geso.jdbctracer;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+class ColumnValues {
+ private final Map<Integer, Object> columnValues;
+
+ ColumnValues() {
+ columnValues = new HashMap<>();
+ }
+
+ void put(Integer key, Object value) {
+ columnValues.put(key, value);
+ }
+
+ void clear() {
+ columnValues.clear();
+ }
+
+ @Override
+ public String toString() {
+ return "ColumnValues{" +
+ "columnValues=" + columnValues +
+ '}';
+ }
+
+ List<Object> values() {
+ return columnValues.entrySet()
+ .stream()
+ .sorted((a, b) -> a.getKey() - b.getKey())
+ .map(Map.Entry::getValue)
+ .collect(Collectors.toList());
+ }
+
+}
@@ -0,0 +1,9 @@
+package me.geso.jdbctracer;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.List;
+
+public interface PreparedStatementListener {
+ void trace(Connection connection, long elapsed, String query, List<Object> args) throws SQLException;
+}
@@ -0,0 +1,10 @@
+package me.geso.jdbctracer;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+public interface ResultSetListener {
+ void trace(Connection connection, Statement statement, boolean first, ResultSet resultSet) throws SQLException;
+}
@@ -0,0 +1,69 @@
+package me.geso.jdbctracer;
+
+import lombok.NonNull;
+import me.geso.jdbctracer.util.ExceptionUtil;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.sql.CallableStatement;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.Statement;
+import java.util.Objects;
+
+/**
+ * Traced connection
+ */
+public class TracerConnection implements InvocationHandler {
+ private Connection connection;
+ private final PreparedStatementListener preparedStatementListener;
+ private final ResultSetListener resultSetListener;
+
+ TracerConnection(Connection connection, PreparedStatementListener preparedStatementListener, ResultSetListener resultSetListener) {
+ this.connection = Objects.requireNonNull(connection);
+ this.preparedStatementListener = preparedStatementListener;
+ this.resultSetListener = resultSetListener;
+ }
+
+ /**
+ * Create new instance of traced connection.
+ *
+ * @param connection Target JDBC connection
+ * @param psl Listener for PreparedStatement/Statement
+ * @param rsl Listener for ResultSet
+ * @return Created connection object.
+ */
+ public static Connection newInstance(@NonNull Connection connection,
+ @NonNull PreparedStatementListener psl,
+ @NonNull ResultSetListener rsl) {
+ return (Connection) Proxy.newProxyInstance(
+ TracerConnection.class.getClassLoader(),
+ new Class<?>[]{Connection.class},
+ new TracerConnection(connection, psl, rsl));
+ }
+
+ @Override
+ public Object invoke(Object proxy, Method method, Object[] params) throws Throwable {
+ try {
+ if (Object.class.equals(method.getDeclaringClass())) {
+ return method.invoke(this, params);
+ }
+ if ("prepareStatement".equals(method.getName())) {
+ PreparedStatement stmt = (PreparedStatement) method.invoke(connection, params);
+ return TracerPreparedStatement.newInstance(connection, PreparedStatement.class, stmt, (String) params[0], preparedStatementListener, resultSetListener);
+ } else if ("prepareCall".equals(method.getName())) {
+ PreparedStatement stmt = (PreparedStatement) method.invoke(connection, params);
+ return TracerPreparedStatement.newInstance(connection, CallableStatement.class, stmt, (String) params[0], preparedStatementListener, resultSetListener);
+ } else if ("createStatement".equals(method.getName())) {
+ Statement stmt = (Statement) method.invoke(connection, params);
+ stmt = TracerStatement.newInstance(connection, stmt, preparedStatementListener, resultSetListener);
+ return stmt;
+ } else {
+ return method.invoke(connection, params);
+ }
+ } catch (Throwable t) {
+ throw ExceptionUtil.unwrapThrowable(t);
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit 49e441a

Please sign in to comment.