You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by di...@apache.org on 2003/08/12 01:54:59 UTC
cvs commit: jakarta-commons/dbcp/src/java/org/apache/commons/dbcp DelegatingCallableStatement.java DelegatingConnection.java DelegatingPreparedStatement.java DelegatingResultSet.java DelegatingStatement.java
dirkv 2003/08/11 16:54:59
Modified: dbcp/src/java/org/apache/commons/dbcp
DelegatingCallableStatement.java
DelegatingConnection.java
DelegatingPreparedStatement.java
DelegatingResultSet.java DelegatingStatement.java
Log:
Bugzilla Bug 21458:
Statements and connections don't implement equals()/hashCode
- changes to Delegating*
Revision Changes Path
1.10 +52 -5 jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/DelegatingCallableStatement.java
Index: DelegatingCallableStatement.java
===================================================================
RCS file: /home/cvs/jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/DelegatingCallableStatement.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- DelegatingCallableStatement.java 6 Mar 2003 19:25:34 -0000 1.9
+++ DelegatingCallableStatement.java 11 Aug 2003 23:54:59 -0000 1.10
@@ -125,6 +125,54 @@
return _stmt;
}
+ public boolean equals(Object obj) {
+ CallableStatement delegate = getInnermostDelegate();
+ if (delegate == null) {
+ return false;
+ }
+ if (obj instanceof DelegatingCallableStatement) {
+ DelegatingCallableStatement s = (DelegatingCallableStatement) obj;
+ return delegate.equals(s.getInnermostDelegate());
+ }
+ else {
+ return delegate.equals(obj);
+ }
+ }
+
+ public int hashCode() {
+ Object obj = getInnermostDelegate();
+ if (obj == null) {
+ return 0;
+ }
+ return obj.hashCode();
+ }
+
+ /**
+ * If my underlying {@link CallableStatement} is not a
+ * <tt>DelegatingCallableStatement</tt>, returns it,
+ * otherwise recursively invokes this method on
+ * my delegate.
+ * <p>
+ * Hence this method will return the first
+ * delegate that is not a <tt>DelegatingCallableStatement</tt>,
+ * or <tt>null</tt> when no non-<tt>DelegatingCallableStatement</tt>
+ * delegate can be found by transversing this chain.
+ * <p>
+ * This method is useful when you may have nested
+ * <tt>DelegatingCallableStatement</tt>s, and you want to make
+ * sure to obtain a "genuine" {@link CallableStatement}.
+ */
+ public CallableStatement getInnermostDelegate() {
+ CallableStatement s = _stmt;
+ while(s != null && s instanceof DelegatingPreparedStatement) {
+ s = ((DelegatingCallableStatement)s).getDelegate();
+ if(this == s) {
+ return null;
+ }
+ }
+ return s;
+ }
+
/**
* Close this DelegatingCallableStatement, and close
* any ResultSets that were not explicitly closed.
@@ -557,5 +605,4 @@
}
/* JDBC_3_ANT_KEY_END */
-
}
1.13 +27 -4 jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/DelegatingConnection.java
Index: DelegatingConnection.java
===================================================================
RCS file: /home/cvs/jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/DelegatingConnection.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- DelegatingConnection.java 9 Apr 2003 00:19:37 -0000 1.12
+++ DelegatingConnection.java 11 Aug 2003 23:54:59 -0000 1.13
@@ -131,6 +131,29 @@
return _conn;
}
+ public boolean equals(Object obj) {
+ Connection delegate = getInnermostDelegate();
+ if (delegate == null) {
+ return false;
+ }
+ if (obj instanceof DelegatingConnection) {
+ DelegatingConnection c = (DelegatingConnection) obj;
+ return delegate.equals(c.getInnermostDelegate());
+ }
+ else {
+ return delegate.equals(obj);
+ }
+ }
+
+ public int hashCode() {
+ Object obj = getInnermostDelegate();
+ if (obj == null) {
+ return 0;
+ }
+ return obj.hashCode();
+ }
+
+
/**
* If my underlying {@link Connection} is not a
* <tt>DelegatingConnection</tt>, returns it,
1.13 +26 -4 jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/DelegatingPreparedStatement.java
Index: DelegatingPreparedStatement.java
===================================================================
RCS file: /home/cvs/jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/DelegatingPreparedStatement.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- DelegatingPreparedStatement.java 9 Apr 2003 00:47:01 -0000 1.12
+++ DelegatingPreparedStatement.java 11 Aug 2003 23:54:59 -0000 1.13
@@ -123,6 +123,28 @@
return _stmt;
}
+ public boolean equals(Object obj) {
+ PreparedStatement delegate = getInnermostDelegate();
+ if (delegate == null) {
+ return false;
+ }
+ if (obj instanceof DelegatingPreparedStatement) {
+ DelegatingPreparedStatement s = (DelegatingPreparedStatement) obj;
+ return delegate.equals(s.getInnermostDelegate());
+ }
+ else {
+ return delegate.equals(obj);
+ }
+ }
+
+ public int hashCode() {
+ Object obj = getInnermostDelegate();
+ if (obj == null) {
+ return 0;
+ }
+ return obj.hashCode();
+ }
+
/**
* If my underlying {@link PreparedStatement} is not a
* <tt>DelegatingPreparedStatement</tt>, returns it,
1.8 +51 -3 jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/DelegatingResultSet.java
Index: DelegatingResultSet.java
===================================================================
RCS file: /home/cvs/jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/DelegatingResultSet.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- DelegatingResultSet.java 6 Mar 2003 00:11:32 -0000 1.7
+++ DelegatingResultSet.java 11 Aug 2003 23:54:59 -0000 1.8
@@ -127,6 +127,54 @@
return _res;
}
+ public boolean equals(Object obj) {
+ ResultSet delegate = getInnermostDelegate();
+ if (delegate == null) {
+ return false;
+ }
+ if (obj instanceof DelegatingResultSet) {
+ DelegatingResultSet s = (DelegatingResultSet) obj;
+ return delegate.equals(s.getInnermostDelegate());
+ }
+ else {
+ return delegate.equals(obj);
+ }
+ }
+
+ public int hashCode() {
+ Object obj = getInnermostDelegate();
+ if (obj == null) {
+ return 0;
+ }
+ return obj.hashCode();
+ }
+
+ /**
+ * If my underlying {@link ResultSet} is not a
+ * <tt>DelegatingResultSet</tt>, returns it,
+ * otherwise recursively invokes this method on
+ * my delegate.
+ * <p>
+ * Hence this method will return the first
+ * delegate that is not a <tt>DelegatingResultSet</tt>,
+ * or <tt>null</tt> when no non-<tt>DelegatingResultSet</tt>
+ * delegate can be found by transversing this chain.
+ * <p>
+ * This method is useful when you may have nested
+ * <tt>DelegatingResultSet</tt>s, and you want to make
+ * sure to obtain a "genuine" {@link ResultSet}.
+ */
+ public ResultSet getInnermostDelegate() {
+ ResultSet r = _res;
+ while(r != null && r instanceof DelegatingResultSet) {
+ r = ((DelegatingResultSet)r).getDelegate();
+ if(this == r) {
+ return null;
+ }
+ }
+ return r;
+ }
+
public Statement getStatement() throws SQLException {
return _stmt;
}
1.10 +26 -4 jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/DelegatingStatement.java
Index: DelegatingStatement.java
===================================================================
RCS file: /home/cvs/jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/DelegatingStatement.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- DelegatingStatement.java 6 Mar 2003 19:25:34 -0000 1.9
+++ DelegatingStatement.java 11 Aug 2003 23:54:59 -0000 1.10
@@ -115,6 +115,28 @@
return _stmt;
}
+ public boolean equals(Object obj) {
+ Statement delegate = getInnermostDelegate();
+ if (delegate == null) {
+ return false;
+ }
+ if (obj instanceof DelegatingStatement) {
+ DelegatingStatement s = (DelegatingStatement) obj;
+ return delegate.equals(s.getInnermostDelegate());
+ }
+ else {
+ return delegate.equals(obj);
+ }
+ }
+
+ public int hashCode() {
+ Object obj = getInnermostDelegate();
+ if (obj == null) {
+ return 0;
+ }
+ return obj.hashCode();
+ }
+
/**
* If my underlying {@link Statement} is not a
* <tt>DelegatingStatement</tt>, returns it,