Skip to content

Commit 9f11206

Browse files
committed
Implements equals method
1 parent 4c225af commit 9f11206

5 files changed

Lines changed: 91 additions & 0 deletions

File tree

src/main/java/io/opentracing/contrib/jdbc/TracingCallableStatement.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package io.opentracing.contrib.jdbc;
1515

1616
import io.opentracing.Tracer;
17+
import io.opentracing.contrib.common.WrapperProxy;
1718
import java.io.InputStream;
1819
import java.io.Reader;
1920
import java.math.BigDecimal;
@@ -621,4 +622,22 @@ public <T> T getObject(int parameterIndex, Class<T> type) throws SQLException {
621622
public <T> T getObject(String parameterName, Class<T> type) throws SQLException {
622623
return statement.getObject(parameterName, type);
623624
}
625+
626+
@Override
627+
public boolean equals(Object obj) {
628+
if (this == obj) {
629+
return true;
630+
}
631+
if (WrapperProxy.isWrapper(obj, getClass())) {
632+
return obj.equals(this); // trick to get through the WrapperProxy/Proxy instances
633+
}
634+
if (!(obj instanceof CallableStatement)) {
635+
return false;
636+
}
637+
if (obj instanceof TracingCallableStatement) {
638+
return statement.equals(((TracingCallableStatement) obj).statement);
639+
} else {
640+
return statement.equals(obj);
641+
}
642+
}
624643
}

src/main/java/io/opentracing/contrib/jdbc/TracingConnection.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,4 +360,23 @@ public <T> T unwrap(Class<T> iface) throws SQLException {
360360
public boolean isWrapperFor(Class<?> iface) throws SQLException {
361361
return connection.isWrapperFor(iface);
362362
}
363+
364+
@Override
365+
public boolean equals(Object obj) {
366+
if (this == obj) {
367+
return true;
368+
}
369+
if (WrapperProxy.isWrapper(obj, getClass())) {
370+
return obj.equals(this); // trick to get through the WrapperProxy/Proxy instances
371+
}
372+
if (!(obj instanceof Connection)) {
373+
return false;
374+
}
375+
if (obj instanceof TracingConnection) {
376+
return connection.equals(((TracingConnection) obj).connection);
377+
} else {
378+
return connection.equals(obj);
379+
}
380+
}
381+
363382
}

src/main/java/io/opentracing/contrib/jdbc/TracingDataSource.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,21 @@ public boolean isWrapperFor(final Class<?> iface) throws SQLException {
154154
return underlying.isWrapperFor(iface);
155155
}
156156

157+
@Override
158+
public boolean equals(Object obj) {
159+
if (this == obj) {
160+
return true;
161+
}
162+
if (!(obj instanceof DataSource)) {
163+
return false;
164+
}
165+
if (obj instanceof TracingDataSource) {
166+
return underlying.equals(((TracingDataSource) obj).underlying);
167+
} else {
168+
return underlying.equals(obj);
169+
}
170+
}
171+
157172
@Override
158173
public void close() throws Exception {
159174
if (underlying instanceof AutoCloseable) {

src/main/java/io/opentracing/contrib/jdbc/TracingPreparedStatement.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import io.opentracing.Scope;
2020
import io.opentracing.Span;
2121
import io.opentracing.Tracer;
22+
import io.opentracing.contrib.common.WrapperProxy;
2223
import java.io.InputStream;
2324
import java.io.Reader;
2425
import java.math.BigDecimal;
@@ -362,4 +363,22 @@ public void setNClob(int parameterIndex, Reader reader) throws SQLException {
362363
preparedStatement.setNClob(parameterIndex, reader);
363364
}
364365

366+
@Override
367+
public boolean equals(Object obj) {
368+
if (this == obj) {
369+
return true;
370+
}
371+
if (WrapperProxy.isWrapper(obj, getClass())) {
372+
return obj.equals(this); // trick to get through the WrapperProxy/Proxy instances
373+
}
374+
if (!(obj instanceof PreparedStatement)) {
375+
return false;
376+
}
377+
if (obj instanceof TracingPreparedStatement) {
378+
return preparedStatement.equals(((TracingPreparedStatement) obj).preparedStatement);
379+
} else {
380+
return preparedStatement.equals(obj);
381+
}
382+
}
383+
365384
}

src/main/java/io/opentracing/contrib/jdbc/TracingStatement.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import io.opentracing.Scope;
2020
import io.opentracing.Span;
2121
import io.opentracing.Tracer;
22+
import io.opentracing.contrib.common.WrapperProxy;
2223
import java.sql.Connection;
2324
import java.sql.ResultSet;
2425
import java.sql.SQLException;
@@ -372,6 +373,24 @@ public String toString() {
372373
return getQuery();
373374
}
374375

376+
@Override
377+
public boolean equals(Object obj) {
378+
if (this == obj) {
379+
return true;
380+
}
381+
if (WrapperProxy.isWrapper(obj, getClass())) {
382+
return obj.equals(this); // trick to get through the WrapperProxy/Proxy instances
383+
}
384+
if (!(obj instanceof Statement)) {
385+
return false;
386+
}
387+
if (obj instanceof TracingStatement) {
388+
return statement.equals(((TracingStatement) obj).statement);
389+
} else {
390+
return statement.equals(obj);
391+
}
392+
}
393+
375394
private Span buildSpanForBatch() {
376395
StringBuilder sqlBuilder = new StringBuilder();
377396
if (query != null) {

0 commit comments

Comments
 (0)