diff --git a/src/main/java/io/opentracing/contrib/jdbc/TracingCallableStatement.java b/src/main/java/io/opentracing/contrib/jdbc/TracingCallableStatement.java index 0c24674..ac6074f 100644 --- a/src/main/java/io/opentracing/contrib/jdbc/TracingCallableStatement.java +++ b/src/main/java/io/opentracing/contrib/jdbc/TracingCallableStatement.java @@ -14,6 +14,7 @@ package io.opentracing.contrib.jdbc; import io.opentracing.Tracer; +import io.opentracing.contrib.common.WrapperProxy; import java.io.InputStream; import java.io.Reader; import java.math.BigDecimal; @@ -621,4 +622,22 @@ public T getObject(int parameterIndex, Class type) throws SQLException { public T getObject(String parameterName, Class type) throws SQLException { return statement.getObject(parameterName, type); } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (WrapperProxy.isWrapper(obj, getClass())) { + return obj.equals(this); // trick to get through the WrapperProxy/Proxy instances + } + if (!(obj instanceof CallableStatement)) { + return false; + } + if (obj instanceof TracingCallableStatement) { + return statement.equals(((TracingCallableStatement) obj).statement); + } else { + return statement.equals(obj); + } + } } diff --git a/src/main/java/io/opentracing/contrib/jdbc/TracingConnection.java b/src/main/java/io/opentracing/contrib/jdbc/TracingConnection.java index 77531e9..e696b0b 100644 --- a/src/main/java/io/opentracing/contrib/jdbc/TracingConnection.java +++ b/src/main/java/io/opentracing/contrib/jdbc/TracingConnection.java @@ -360,4 +360,23 @@ public T unwrap(Class iface) throws SQLException { public boolean isWrapperFor(Class iface) throws SQLException { return connection.isWrapperFor(iface); } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (WrapperProxy.isWrapper(obj, getClass())) { + return obj.equals(this); // trick to get through the WrapperProxy/Proxy instances + } + if (!(obj instanceof Connection)) { + return false; + } + if (obj instanceof TracingConnection) { + return connection.equals(((TracingConnection) obj).connection); + } else { + return connection.equals(obj); + } + } + } \ No newline at end of file diff --git a/src/main/java/io/opentracing/contrib/jdbc/TracingDataSource.java b/src/main/java/io/opentracing/contrib/jdbc/TracingDataSource.java index 82f3585..fb65572 100644 --- a/src/main/java/io/opentracing/contrib/jdbc/TracingDataSource.java +++ b/src/main/java/io/opentracing/contrib/jdbc/TracingDataSource.java @@ -134,6 +134,21 @@ public boolean isWrapperFor(final Class iface) throws SQLException { return underlying.isWrapperFor(iface); } + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof DataSource)) { + return false; + } + if (obj instanceof TracingDataSource) { + return underlying.equals(((TracingDataSource) obj).underlying); + } else { + return underlying.equals(obj); + } + } + @Override public void close() throws Exception { if (underlying instanceof AutoCloseable) { diff --git a/src/main/java/io/opentracing/contrib/jdbc/TracingPreparedStatement.java b/src/main/java/io/opentracing/contrib/jdbc/TracingPreparedStatement.java index baad76d..f1bcfaf 100644 --- a/src/main/java/io/opentracing/contrib/jdbc/TracingPreparedStatement.java +++ b/src/main/java/io/opentracing/contrib/jdbc/TracingPreparedStatement.java @@ -15,6 +15,7 @@ import io.opentracing.Tracer; +import io.opentracing.contrib.common.WrapperProxy; import java.io.InputStream; import java.io.Reader; import java.math.BigDecimal; @@ -334,4 +335,22 @@ public void setNClob(int parameterIndex, Reader reader) throws SQLException { preparedStatement.setNClob(parameterIndex, reader); } + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (WrapperProxy.isWrapper(obj, getClass())) { + return obj.equals(this); // trick to get through the WrapperProxy/Proxy instances + } + if (!(obj instanceof PreparedStatement)) { + return false; + } + if (obj instanceof TracingPreparedStatement) { + return preparedStatement.equals(((TracingPreparedStatement) obj).preparedStatement); + } else { + return preparedStatement.equals(obj); + } + } + } diff --git a/src/main/java/io/opentracing/contrib/jdbc/TracingStatement.java b/src/main/java/io/opentracing/contrib/jdbc/TracingStatement.java index e531db1..c3c523e 100644 --- a/src/main/java/io/opentracing/contrib/jdbc/TracingStatement.java +++ b/src/main/java/io/opentracing/contrib/jdbc/TracingStatement.java @@ -15,6 +15,7 @@ import io.opentracing.Tracer; +import io.opentracing.contrib.common.WrapperProxy; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; @@ -289,6 +290,24 @@ public String toString() { return getQuery(); } + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (WrapperProxy.isWrapper(obj, getClass())) { + return obj.equals(this); // trick to get through the WrapperProxy/Proxy instances + } + if (!(obj instanceof Statement)) { + return false; + } + if (obj instanceof TracingStatement) { + return statement.equals(((TracingStatement) obj).statement); + } else { + return statement.equals(obj); + } + } + private String buildSqlForBatch() { StringBuilder sqlBuilder = new StringBuilder(); if (query != null) {