Hey,
  For flexibility reasons (ie not requiring a recompile when changing uname
and password) why not just skip the compare step and wrap
getConnection(String uname, String password) directly to getConnection()?
Attached is a patch that makes that change to PoolingDataSource.  Any
thoughts?

-Chad Johnson

----- Original Message -----
From: [EMAIL PROTECTED]
Reply-To: Jakarta Commons Developers List [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Fri, 19 Apr 2002 08:23:39
Subject: DBCP connection problems with credentials


> Hi,
>
> I'am starting with DBCP and Tomcat because of some pooling
> problems with Tyrex and Poolman.
> First of all, It seems like DBCP works very well.
>
> Now, I've got just a little problem with getConnection method
> and credentials : PoolingDataSource object doesn't support
> getConnection(user, password) method and throw
> an "UnsupportedOperationException".
>
> I understand it as a pooled connections can't be shared among
> multiple database users. My problem is that some application
> still use getConnection(user, password) method even with
> DataSource, so using DBCP with those applications is impossible
> without modifing app. code.
>
> So, here is my proposal : Why not modifing getConection(user,
> password) in BasicDataSource so that :
> - if username/password are good ones, this method forward
> toward getConnection()
> - if not, this method throw a SQLExeption, saying something
> like "Invalid username/password"
>
> I've tried to modify source code and I ask you if it would be
> correct to transform getConnection(username, password) in
> BasicDataSource like this :
>
> -----------------------------------------------------------
> public Connection getConnection(String username, String
> password)
>   throws SQLException {
>
>   if(username.equalsIgnoreCase(this.username) &&
> password.equalsIgnoreCase(this.password)) {
>     return (createDataSource().getConnection());
>   } else {
>     throw new SQLException("DBCP : Invalid username/password");
>   }
> }
> -----------------------------------------------------------
>
> Thanks in advance for your responses
--- PoolingDataSource.java.orig Sun Apr 21 19:21:22 2002
+++ PoolingDataSource.java      Sun Apr 21 22:49:31 2002
@@ -116,11 +116,11 @@
     }

     /**
-     * Throws {@link UnsupportedOperationException}
-     * @throws UnsupportedOperationException
+     * Wraps to {@link #getConnection} ignoring uname and passwd.
+     * User name and password will be specified externally, see documentation for 
+further details.
      */
     public Connection getConnection(String uname, String passwd) throws SQLException {
-        throw new UnsupportedOperationException();
+        return getConnection();
     }

     /**
--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to