Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implements equals method #97

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

}
19 changes: 19 additions & 0 deletions src/main/java/io/opentracing/contrib/jdbc/TracingStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down