What is your reason for wanting a db connection associated with a particular
login?

----- Original Message -----
From: Jian He <[EMAIL PROTECTED]>
To: Turbine <[EMAIL PROTECTED]>
Sent: Wednesday, June 14, 2000 12:08 AM
Subject: DBFactory Patch


> Hi
>
> when i run DBFactory.getInstance().getConnection(driver, url, user1,
pass1) to get the first connection,
> it gives me the right connection.
> but when i run DBFactory.getInstance().getConnection(driver, url, user2,
pass2) to get the second connection,
> it also gives me the first connection, it is not the right connection.
>
> so i changed the DBFactory, ConnectionPool, DBConnection classes to solve
the problem:
>
> bash-2.03$ diff old/DBBroker.java DBBroker.java
> 150c150,153
> <         url = url.trim();
> ---
> >       StringBuffer key = new StringBuffer();
> >       key.append( url.trim() );
> >       key.append( ':' );
> >       key.append( username.trim() );
> 152c155
> <         if ( pools.containsKey(url) )
> ---
> >         if ( pools.containsKey( key ))
> 154c157
> <             pool = (ConnectionPool) pools.get(url);
> ---
> >             pool = (ConnectionPool) pools.get( key );
> 159c162
> <             pools.put( url, pool );
> ---
> >             pools.put( key, pool );
> 259c262,263
> <                 if (pools.containsKey( url ))
> ---
> >               String key = url + ":" + connection.getUsername();
> >                 if (pools.containsKey( key ))
> 261c265
> <                     ConnectionPool pool = (ConnectionPool)
ools.get( url );
> ---
> >                     ConnectionPool pool = (ConnectionPool)
ools.get( key );
>
> bash-2.03$ diff old/ConnectionPool.java ConnectionPool.java
> 175c175
> <         return new DBConnection( db.getConnection(), url );
> ---
> >         return new DBConnection( db.getConnection(), url, username );
>
> bash-2.03$ diff old/DBConnection.java DBConnection.java
> 77a78,79
> >     /** The username of this connection. */
> >     private String username = "";
> 86c88
> <     protected DBConnection(Connection connection, String url)
> ---
> >     protected DBConnection(Connection connection, String url, String
username)
> 89a92
> >       this.username = username;
> 114a118,121
> >     }
> >     public String getUsername()
> >     {
> >       return username;
>
>
> ------------------------------------------------------------
> To subscribe:        [EMAIL PROTECTED]
> To unsubscribe:      [EMAIL PROTECTED]
> Problems?:           [EMAIL PROTECTED]



------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Problems?:           [EMAIL PROTECTED]

Reply via email to