From 156e65909e6fde8ffc19e683f5394dec378df481 Mon Sep 17 00:00:00 2001 From: hns Date: Thu, 8 Mar 2007 15:40:09 +0000 Subject: [PATCH] * Implement switchProperties() to allow to switch db connections at runtime. * Minor cleanup/simplification in getConnection(). --- src/helma/objectmodel/db/DbSource.java | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/helma/objectmodel/db/DbSource.java b/src/helma/objectmodel/db/DbSource.java index 247d06e9..d8a60dfb 100644 --- a/src/helma/objectmodel/db/DbSource.java +++ b/src/helma/objectmodel/db/DbSource.java @@ -72,16 +72,12 @@ public class DbSource { con = tx.getConnection(this); } - boolean fileUpdated = props.lastModified() > lastRead; - if (!fileUpdated && (defaultProps != null)) { - fileUpdated = defaultProps.lastModified() > lastRead; - } + boolean fileUpdated = props.lastModified() > lastRead || + (defaultProps != null && defaultProps.lastModified() > lastRead); if (con == null || con.isClosed() || fileUpdated) { init(); - Class.forName(driver); con = DriverManager.getConnection(url, conProps); - // con = DriverManager.getConnection(url, user, password); // If we wanted to use SQL transactions, we'd set autoCommit to // false here and make commit/rollback invocations in Transactor methods; @@ -94,6 +90,20 @@ public class DbSource { return con; } + /** + * Set the db properties to newProps, and return the old properties. + * @param newProps the new properties to use for this db source + * @return the old properties + * @throws ClassNotFoundException if jdbc driver class couldn't be found + */ + public synchronized ResourceProperties switchProperties(ResourceProperties newProps) + throws ClassNotFoundException { + ResourceProperties oldProps = props; + props = newProps; + init(); + return oldProps; + } + /** * Initialize the db source from the properties *