Skip to content

Commit 1938eb8

Browse files
committed
Implements equals method
1 parent f77bb48 commit 1938eb8

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
@@ -134,6 +134,21 @@ public boolean isWrapperFor(final Class<?> iface) throws SQLException {
134134
return underlying.isWrapperFor(iface);
135135
}
136136

137+
@Override
138+
public boolean equals(Object obj) {
139+
if (this == obj) {
140+
return true;
141+
}
142+
if (!(obj instanceof DataSource)) {
143+
return false;
144+
}
145+
if (obj instanceof TracingDataSource) {
146+
return underlying.equals(((TracingDataSource) obj).underlying);
147+
} else {
148+
return underlying.equals(obj);
149+
}
150+
}
151+
137152
@Override
138153
public void close() throws Exception {
139154
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
@@ -15,6 +15,7 @@
1515

1616

1717
import io.opentracing.Tracer;
18+
import io.opentracing.contrib.common.WrapperProxy;
1819
import java.io.InputStream;
1920
import java.io.Reader;
2021
import java.math.BigDecimal;
@@ -334,4 +335,22 @@ public void setNClob(int parameterIndex, Reader reader) throws SQLException {
334335
preparedStatement.setNClob(parameterIndex, reader);
335336
}
336337

338+
@Override
339+
public boolean equals(Object obj) {
340+
if (this == obj) {
341+
return true;
342+
}
343+
if (WrapperProxy.isWrapper(obj, getClass())) {
344+
return obj.equals(this); // trick to get through the WrapperProxy/Proxy instances
345+
}
346+
if (!(obj instanceof PreparedStatement)) {
347+
return false;
348+
}
349+
if (obj instanceof TracingPreparedStatement) {
350+
return preparedStatement.equals(((TracingPreparedStatement) obj).preparedStatement);
351+
} else {
352+
return preparedStatement.equals(obj);
353+
}
354+
}
355+
337356
}

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616

1717
import io.opentracing.Tracer;
18+
import io.opentracing.contrib.common.WrapperProxy;
1819
import java.sql.Connection;
1920
import java.sql.ResultSet;
2021
import java.sql.SQLException;
@@ -289,6 +290,24 @@ public String toString() {
289290
return getQuery();
290291
}
291292

293+
@Override
294+
public boolean equals(Object obj) {
295+
if (this == obj) {
296+
return true;
297+
}
298+
if (WrapperProxy.isWrapper(obj, getClass())) {
299+
return obj.equals(this); // trick to get through the WrapperProxy/Proxy instances
300+
}
301+
if (!(obj instanceof Statement)) {
302+
return false;
303+
}
304+
if (obj instanceof TracingStatement) {
305+
return statement.equals(((TracingStatement) obj).statement);
306+
} else {
307+
return statement.equals(obj);
308+
}
309+
}
310+
292311
private String buildSqlForBatch() {
293312
StringBuilder sqlBuilder = new StringBuilder();
294313
if (query != null) {

0 commit comments

Comments
 (0)