Skip to content

Commit

Permalink
Implements equals method
Browse files Browse the repository at this point in the history
  • Loading branch information
quaff committed Sep 15, 2020
1 parent 4c225af commit c5f3d58
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -621,4 +622,22 @@ public <T> T getObject(int parameterIndex, Class<T> type) throws SQLException {
public <T> T getObject(String parameterName, Class<T> 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);
}
}
}
19 changes: 19 additions & 0 deletions src/main/java/io/opentracing/contrib/jdbc/TracingConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -360,4 +360,23 @@ public <T> T unwrap(Class<T> 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);
}
}

}
15 changes: 15 additions & 0 deletions src/main/java/io/opentracing/contrib/jdbc/TracingDataSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
*/
package io.opentracing.contrib.jdbc;


import static io.opentracing.contrib.jdbc.JdbcTracingUtils.buildSpan;

import io.opentracing.Scope;
import io.opentracing.Span;
import io.opentracing.Tracer;
import io.opentracing.contrib.common.WrapperProxy;
import java.io.InputStream;
import java.io.Reader;
import java.math.BigDecimal;
Expand Down Expand Up @@ -362,4 +362,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);
}
}

}
20 changes: 19 additions & 1 deletion src/main/java/io/opentracing/contrib/jdbc/TracingStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
*/
package io.opentracing.contrib.jdbc;


import static io.opentracing.contrib.jdbc.JdbcTracingUtils.buildSpan;

import io.opentracing.Scope;
import io.opentracing.Span;
import io.opentracing.Tracer;
import io.opentracing.contrib.common.WrapperProxy;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
Expand Down Expand Up @@ -372,6 +372,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 Span buildSpanForBatch() {
StringBuilder sqlBuilder = new StringBuilder();
if (query != null) {
Expand Down

0 comments on commit c5f3d58

Please sign in to comment.