Gracefully handle the case where getConnection() is called by a non-transactor thread
(merge from helma_1_4)
This commit is contained in:
parent
344c0da36e
commit
1f84ed41ac
1 changed files with 10 additions and 3 deletions
|
@ -61,8 +61,13 @@ public class DbSource {
|
||||||
* @throws SQLException ...
|
* @throws SQLException ...
|
||||||
*/
|
*/
|
||||||
public Connection getConnection() throws ClassNotFoundException, SQLException {
|
public Connection getConnection() throws ClassNotFoundException, SQLException {
|
||||||
Transactor tx = (Transactor) Thread.currentThread();
|
Connection con = null;
|
||||||
Connection con = tx.getConnection(this);
|
Transactor tx = null;
|
||||||
|
if (Thread.currentThread() instanceof Transactor) {
|
||||||
|
tx = (Transactor) Thread.currentThread();
|
||||||
|
con = tx.getConnection(this);
|
||||||
|
}
|
||||||
|
|
||||||
boolean fileUpdated = props.lastModified() > lastRead;
|
boolean fileUpdated = props.lastModified() > lastRead;
|
||||||
|
|
||||||
if (!fileUpdated && (defaultProps != null)) {
|
if (!fileUpdated && (defaultProps != null)) {
|
||||||
|
@ -78,7 +83,9 @@ public class DbSource {
|
||||||
// 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;
|
||||||
// System.err.println ("Created new Connection to "+url);
|
// System.err.println ("Created new Connection to "+url);
|
||||||
tx.registerConnection(this, con);
|
if (tx != null) {
|
||||||
|
tx.registerConnection(this, con);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return con;
|
return con;
|
||||||
|
|
Loading…
Add table
Reference in a new issue