* Implement switchProperties() to allow to switch db connections at runtime.
* Minor cleanup/simplification in getConnection().
This commit is contained in:
parent
eb692b71ec
commit
156e65909e
1 changed files with 16 additions and 6 deletions
|
@ -72,16 +72,12 @@ public class DbSource {
|
||||||
con = tx.getConnection(this);
|
con = tx.getConnection(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean fileUpdated = props.lastModified() > lastRead;
|
boolean fileUpdated = props.lastModified() > lastRead ||
|
||||||
if (!fileUpdated && (defaultProps != null)) {
|
(defaultProps != null && defaultProps.lastModified() > lastRead);
|
||||||
fileUpdated = defaultProps.lastModified() > lastRead;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (con == null || con.isClosed() || fileUpdated) {
|
if (con == null || con.isClosed() || fileUpdated) {
|
||||||
init();
|
init();
|
||||||
Class.forName(driver);
|
|
||||||
con = DriverManager.getConnection(url, conProps);
|
con = DriverManager.getConnection(url, conProps);
|
||||||
// con = DriverManager.getConnection(url, user, password);
|
|
||||||
|
|
||||||
// If we wanted to use SQL transactions, we'd set autoCommit to
|
// If we wanted to use SQL transactions, we'd set autoCommit to
|
||||||
// false here and make commit/rollback invocations in Transactor methods;
|
// false here and make commit/rollback invocations in Transactor methods;
|
||||||
|
@ -94,6 +90,20 @@ public class DbSource {
|
||||||
return con;
|
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
|
* Initialize the db source from the properties
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue