[Biojava-dev] Frederik Decouttere's BioSQL/Ontology bug
Len Trigg
len at reeltwo.com
Thu Feb 19 16:46:15 EST 2004
I have looked into the previously mentioned problem with Ontologies in
the BioSQL binding. It boils down to the fact that each
BioSQLSequenceDB has it's own copy of the ontologies contained in the
database, and since it's possible to have more than one
BioSQLSequenceDB pointing at the database (e.g.: each corresponding to
a different biodatabase), they get their own Ontology handling.
Frederik's problem arose when his code ended up inserting a term via
one BioSQLSequenceDB, and then attempting to insert again via the
second BioSQLSequenceDB (which wasn't aware of the first set of
ontology changes). This was then caught by the database constraints.
Dealing with two separate BioSQLSequenceDB's in the same database at
the same time certainly doesn't seem unreasonable (some of my apps do
it, and it's probably only chance that I haven't bumped into the
problem myself). What I have done is basically the simplest thing
that would work: OntologySQL now has a static method that
BioSQLSequenceDB's use to request an OntologySQL object. This method
uses a static hashmap that is keyed off the DataSource to return the
appropriate OntologySQL object. Now the two BioSQLSequenceDB's end up
sharing the same OntologySQL object and things are basically fine.
There are a couple of minor issues though. The first is that in order
to use the DataSource as a key, I've extended the PoolingDataSource to
use the database url and username as the basis for equals and
hashcode. The Ontology retrieval won't work if you create
BioSQLSequenceDB's with other DataSources, or if the DataSource
somehow begins to point to another database (the javadocs for
DataSource alluded to this somehow being possible). I imagine that
neither of these will actually be a problem in practise.
The other issue is that the cache of OntologySQL's can under come
circumstances become invalid -- this happened in the unit tests when
the database was entirely removed between unit tests! :-). To get
around this (pretty unreasonable really) behaviour, I just added a
package level method to clear the cache, just for use by the tests.
If this all sounds OK, I'll check in the changes. I'll also take no
response as approval :-)
Cheers,
Len.
More information about the biojava-dev
mailing list