[Biojava-dev] JDBCPooledDataSource regression

Richard Holland holland at ebi.ac.uk
Wed Jan 31 13:07:58 UTC 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I've committed your changes Andy.

Thomas, I wouldn't worry about OntologySQL. It's highly deprecated and
not supported - the whole biojavax/Hibernate thing made that code redundant.

Richard.

Andy Yates wrote:
> Okay I've attached the fix here.
> 
> I just did this in a text editor but I believe that the imports are
> okay. If you can just do a quick scan as well to make sure I haven't
> deleted anything that was very important.
> 
> I'll get on to the helpdesk now as well :)
> 
> Andy
> 
> Richard Holland wrote:
> Andy could you make the change to your local copy of the source file and
> email the file to me, that way I can make sure I don't get it wrong when
> I commit it.
> 
> Richard.
> 
> PS. You should probably have your own CVS account - email the OBF
> helpdesk and ask for one, saying I told you to. :)
> 
> 
> Andy Yates wrote:
>>>> Thomas Down wrote:
>>>>> On 31 Jan 2007, at 12:06, Andy Yates wrote:
>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> Sorry I was meaning if that if that method just becomes:
>>>>>>
>>>>>> public static DataSource getDataSource(final String driver,
>>>>>>                                          final String url,
>>>>>>                                          final String user,
>>>>>>                                          final String pass)
>>>>>>     throws Exception {
>>>>>>
>>>>>>     BasicDataSource ds = new BasicDataSource();
>>>>>>     ds.setUrl(url);
>>>>>>     ds.setDriverClassName(driver);
>>>>>>     ds.setUsername(user);
>>>>>>     ds.setPassword(pass);
>>>>>>     // Set BasicDataSource properties such as maxActive and
>>>>>> maxIdle, as described in
>>>>>>     //
>>>>>> http://jakarta.apache.org/commons/dbcp/api/org/apache/commons/dbcp/BasicDataSource.html
>>>>>>
>>>>>>     ds.setMaxActive(10);
>>>>>>     ds.setMaxIdle(5);
>>>>>>     ds.setMaxWait(10000);
>>>>>>
>>>>>>     return ds;
>>>>>>   }
>>>>>>
>>>>>> Does that still work?
>>>>> Hmmm, I was assuming that BasicDataSource didn't actually do any
>>>>> pooling itself, and that you needed another layer on top to manage a
>>>>> connection pool -- that seems to be how all previous revisions of
>>>>> JDBCConnectionPool worked, so I guess I wasn't alone in thinking
>>>>> this.  But yes, BasicDataSource does seem to do pooling itself
>>>>> (confirmed by reading the source), so maybe your simpler version is
>>>>> a better idea.  It certainly works okay for me.
>>>>>
>>>>>            Thomas.
>>>> That's what I thought should have happened :). Can I suggest that
>>>> this revised version goes into CVS? Anyone got any objections?
>>>>
>>>> Andy
>>>> _______________________________________________
>>>> biojava-dev mailing list
>>>> biojava-dev at lists.open-bio.org
>>>> http://lists.open-bio.org/mailman/listinfo/biojava-dev
>>>>

> ------------------------------------------------------------------------

> /*
>  *                    BioJava development code
>  *
>  * This code may be freely distributed and modified under the
>  * terms of the GNU Lesser General Public Licence.  This should
>  * be distributed with the code.  If you do not have a copy,
>  * see:
>  *
>  *      http://www.gnu.org/copyleft/lesser.html
>  *
>  * Copyright for this code is held jointly by the individual
>  * authors.  These should be listed in @author doc comments.
>  *
>  * For more information on the BioJava project and its aims,
>  * or to join the biojava-l mailing list, visit the home page
>  * at:
>  *
>  *      http://www.biojava.org/
>  *
>  */
> package org.biojava.utils;

> import javax.sql.DataSource;

> import org.apache.commons.dbcp.BasicDataSource;
> import org.apache.commons.dbcp.PoolingDataSource;
> import org.apache.commons.pool.ObjectPool;

> /**
> * Returns a DataSource that implements connection pooling
> *
> * Uses Jakarta Commons DBCP and Pool packages.
> * See the description of the dbcp package at 
> * http://jakarta.apache.org/commons/dbcp/api/overview-summary.html#overview_description
> *
> * @author Simon Foote
> * @author Len Trigg
> */

> public class JDBCPooledDataSource {

>   public static DataSource getDataSource(final String driver, 
>                                          final String url,
>                                          final String user,
>                                          final String pass)
>     throws Exception {

>     BasicDataSource ds = new BasicDataSource();
>     ds.setUrl(url);
>     ds.setDriverClassName(driver);
>     ds.setUsername(user);
>     ds.setPassword(pass);
>     // Set BasicDataSource properties such as maxActive and maxIdle, as described in
>     // http://jakarta.apache.org/commons/dbcp/api/org/apache/commons/dbcp/BasicDataSource.html
>     ds.setMaxActive(10);
>     ds.setMaxIdle(5);
>     ds.setMaxWait(10000);

>     return dataSource;
>   }


>   // Adds simple equals and hashcode methods so that we can compare if
>   // two connections are to the same database. This will fail if the
>   // DataSource is redirected to another database etc (I doubt this is
>   // ever likely to be used).
>   /**
>    * @depercated This is no longer used in favor of {@link BasicDataSource}
>    * from DBCP
>    */
>   static class MyPoolingDataSource extends PoolingDataSource {
>     final String source;
>     public MyPoolingDataSource(ObjectPool connectionPool, String source) {
>       super(connectionPool);
>       this.source = source;
>     }
>     public boolean equals(Object o2) {
>       if ((o2 == null) || !(o2 instanceof MyPoolingDataSource)) {
>         return false;
>       }
>       MyPoolingDataSource b2 = (MyPoolingDataSource) o2;
>       return source.equals(b2.source);
>     }
>     public int hashCode() {
>       return source.hashCode();
>     }
>   }


>   public static void main(String[] args) {
>     try {
>       DataSource ds1 = getDataSource("org.hsqldb.jdbcDriver", "jdbc:hsqldb:/tmp/hsqldb/biosql", "sa", "");
>       DataSource ds2 = getDataSource("org.hsqldb.jdbcDriver", "jdbc:hsqldb:/tmp/hsqldb/biosql", "sa", "");
>       System.err.println(ds1);
>       System.err.println(ds2);
>       System.err.println(ds1.equals(ds2));
>     } catch (Exception e) {
>       e.printStackTrace();
>     }
>   }
> }
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFwJSu4C5LeMEKA/QRAgt1AJ9dtk3SBbDwtah469igyc9DYWGzMwCgqAad
X1KXpdlqqhBfuL1MisMj/yo=
=nlGe
-----END PGP SIGNATURE-----



More information about the biojava-dev mailing list