You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by dg...@apache.org on 2003/04/15 03:32:43 UTC
cvs commit: jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/jdbc2pool Jdbc2PoolDataSource.java UserPassKey.java
dgraham 2003/04/14 18:32:43
Modified: dbcp/src/java/org/apache/commons/dbcp/jdbc2pool
Jdbc2PoolDataSource.java UserPassKey.java
Log:
Changed how connections are retrieved for username and password pairs
for PR# 18905.
Revision Changes Path
1.10 +22 -14 jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/jdbc2pool/Jdbc2PoolDataSource.java
Index: Jdbc2PoolDataSource.java
===================================================================
RCS file: /home/cvs/jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/jdbc2pool/Jdbc2PoolDataSource.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- Jdbc2PoolDataSource.java 7 Mar 2003 00:24:09 -0000 1.9
+++ Jdbc2PoolDataSource.java 15 Apr 2003 01:32:42 -0000 1.10
@@ -1,9 +1,12 @@
-package org.apache.commons.dbcp.jdbc2pool;
-
-/* ====================================================================
+/*
+ * $Header$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * Copyright (c) 2001-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -54,6 +57,8 @@
* <http://www.apache.org/>.
*/
+package org.apache.commons.dbcp.jdbc2pool;
+
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -1117,12 +1122,6 @@
throw new SQLException(e.getMessage());
}
}
- if(!(null == password ? null == info.getPassword() : password.equals(info.getPassword())))
- {
- closeDueToException(info);
- throw new SQLException("Given password did not match password used "
- + "to create the PooledConnection.");
- }
PooledConnection pc = info.getPooledConnection();
boolean defaultAutoCommit = isDefaultAutoCommit();
@@ -1206,11 +1205,20 @@
private UserPassKey getUserPassKey(String username, String password)
{
- UserPassKey key = (UserPassKey)userKeys.get(username);
- if (key == null)
- {
+ UserPassKey key = (UserPassKey) userKeys.get(username);
+ if (key == null) {
key = new UserPassKey(username, password);
userKeys.put(username, key);
+
+ } else {
+ String foundPass = key.getPassword();
+ boolean passwordsEqual =
+ (foundPass == null ? password == null : foundPass.equals(password));
+
+ if (!passwordsEqual) {
+ key = new UserPassKey(username, password);
+ userKeys.put(username, key);
+ }
}
return key;
}
1.4 +43 -22 jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/jdbc2pool/UserPassKey.java
Index: UserPassKey.java
===================================================================
RCS file: /home/cvs/jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/jdbc2pool/UserPassKey.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- UserPassKey.java 7 Mar 2003 00:24:09 -0000 1.3
+++ UserPassKey.java 15 Apr 2003 01:32:42 -0000 1.4
@@ -1,9 +1,13 @@
-package org.apache.commons.dbcp.jdbc2pool;
-
-/* ====================================================================
+/*
+ * $Header$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * Copyright (c) 2001-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -53,11 +57,15 @@
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
-
+
+package org.apache.commons.dbcp.jdbc2pool;
+
import java.io.Serializable;
-class UserPassKey
- implements Serializable
+/**
+ * Holds a username, password pair.
+ */
+class UserPassKey implements Serializable
{
private String password;
private String username;
@@ -86,27 +94,40 @@
return username;
}
+ /**
+ * @return <code>true</code> if the username and password fields for both
+ * objects are equal.
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
public boolean equals(Object obj)
{
- if ( obj instanceof UserPassKey )
- {
- UserPassKey upk = (UserPassKey)obj;
- return null == username ? null == upk.username : username.equals(upk.username);
- }
- else
- {
- return false;
- }
+ if (obj == null)
+ return false;
+
+ if (obj == this)
+ return true;
+
+ if (!(obj instanceof UserPassKey))
+ return false;
+
+ UserPassKey key = (UserPassKey) obj;
+
+ boolean usersEqual =
+ (this.username == null
+ ? key.username == null
+ : this.username.equals(key.username));
+
+ boolean passwordsEqual =
+ (this.password == null
+ ? key.password == null
+ : this.password.equals(key.password));
+
+ return (usersEqual && passwordsEqual);
}
public int hashCode()
{
- int h = 0;
- if (username != null)
- {
- h = username.hashCode();
- }
- return h;
+ return (this.username != null ? this.username.hashCode() : 0);
}
public String toString()
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org