|
From: Thomas R. <tho...@tr...> - 2004-03-30 02:54:47
|
I have been watching my logs and the constant lookup of the database
product name is bothering me. Colin had the same issue a while ago, but
we never really resolved it. I have a potential solution which entails
storing the hash code of the datasource along with the retreived
database product name in a static HashMap. Next time, before looking up
the name we could check this HashMap and pull the name from there if it
is found. Can anyone see a flaw in this solution? Any chance of two
datasource objects having the same hash code? Any chance of a
datasource switching to a different database while we are running?
Here is the added code:
public SQLErrorCodes getErrorCodes(DataSource ds) {
// Lets avoid looking up database product info if we can.
Integer dataSourceHash = new Integer(ds.hashCode());
if (dataSourceProductName.containsKey(dataSourceHash)) {
String dataSourceDbName =
(String)dataSourceProductName.get(dataSourceHash);
logger.info("Database Product found in cache {" +
dataSourceHash + "}. Name is " + dataSourceDbName);
return getErrorCodes(dataSourceDbName);
}
// We could not find it - got to look it up.
logger.info("Looking up default SQLErrorCodes for DataSource");
... (this part is already there)
Thomas
|