From 1f84ed41acf23159b5ad59f224b8def9c251aefb Mon Sep 17 00:00:00 2001 From: hns Date: Fri, 11 Mar 2005 15:37:32 +0000 Subject: [PATCH] Gracefully handle the case where getConnection() is called by a non-transactor thread (merge from helma_1_4) --- src/helma/objectmodel/db/DbSource.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/helma/objectmodel/db/DbSource.java b/src/helma/objectmodel/db/DbSource.java index 2f76bdbd..b6e451f7 100644 --- a/src/helma/objectmodel/db/DbSource.java +++ b/src/helma/objectmodel/db/DbSource.java @@ -61,8 +61,13 @@ public class DbSource { * @throws SQLException ... */ public Connection getConnection() throws ClassNotFoundException, SQLException { - Transactor tx = (Transactor) Thread.currentThread(); - Connection con = tx.getConnection(this); + Connection con = null; + Transactor tx = null; + if (Thread.currentThread() instanceof Transactor) { + tx = (Transactor) Thread.currentThread(); + con = tx.getConnection(this); + } + boolean fileUpdated = props.lastModified() > lastRead; if (!fileUpdated && (defaultProps != null)) { @@ -78,7 +83,9 @@ public class DbSource { // If we wanted to use SQL transactions, we'd set autoCommit to // false here and make commit/rollback invocations in Transactor methods; // System.err.println ("Created new Connection to "+url); - tx.registerConnection(this, con); + if (tx != null) { + tx.registerConnection(this, con); + } } return con;