diff options
author | Bernard Normier <bernard@zeroc.com> | 2007-01-13 02:01:21 +0000 |
---|---|---|
committer | Bernard Normier <bernard@zeroc.com> | 2007-01-13 02:01:21 +0000 |
commit | ac34961ea546eb517a21e3e8680cad64117bac95 (patch) | |
tree | 3404a26b3c99dddf3d803bffb72c444318cf2ebd /cpp/demo/Database/Oracle/occi/Util.cpp | |
parent | various improvements (diff) | |
download | ice-ac34961ea546eb517a21e3e8680cad64117bac95.tar.bz2 ice-ac34961ea546eb517a21e3e8680cad64117bac95.tar.xz ice-ac34961ea546eb517a21e3e8680cad64117bac95.zip |
Major update
Diffstat (limited to 'cpp/demo/Database/Oracle/occi/Util.cpp')
-rw-r--r-- | cpp/demo/Database/Oracle/occi/Util.cpp | 68 |
1 files changed, 28 insertions, 40 deletions
diff --git a/cpp/demo/Database/Oracle/occi/Util.cpp b/cpp/demo/Database/Oracle/occi/Util.cpp index c7fa42f29f6..840471de51b 100644 --- a/cpp/demo/Database/Oracle/occi/Util.cpp +++ b/cpp/demo/Database/Oracle/occi/Util.cpp @@ -17,74 +17,60 @@ using namespace oracle::occi; ConnectionHolder::ConnectionHolder(StatelessConnectionPool* pool) : _con(pool->getAnyTaggedConnection()), + _txDone(false), _pool(pool) { } -ConnectionHolder::~ConnectionHolder() -{ - if(_con != 0) - { - try - { - rollback(); - } - catch(...) - { - // ignored, to avoid a crash during - // stack unwinding - } - } -} - void ConnectionHolder::commit() { - assert(_con != 0); + _txDone = true; try { _con->commit(); } catch(const SQLException& e) { - release(); throw HR::SqlException(e.what()); } - catch(...) - { - release(); - throw; - } - release(); } void ConnectionHolder::rollback() { - assert(_con != 0); + _txDone = true; try { _con->rollback(); } catch(const SQLException& e) { - release(); throw HR::SqlException(e.what()); } - catch(...) - { - release(); - throw; - } - release(); } -void -ConnectionHolder::release() +ConnectionHolder::~ConnectionHolder() { - Connection* con = _con; - _con = 0; - _pool->releaseConnection(con); + if(!_txDone) + { + _txDone = true; + try + { + _con->rollback(); + } + catch(const std::exception&) + { + } + } + + try + { + _pool->releaseConnection(_con); + } + catch(const std::exception&) + { + } } StatementHolder::StatementHolder(Connection* con) : @@ -93,9 +79,9 @@ StatementHolder::StatementHolder(Connection* con) : { } -StatementHolder::StatementHolder(ConnectionHolder& conh) : - _stmt(conh.connection()->createStatement()), - _con(conh.connection()) +StatementHolder::StatementHolder(const ConnectionHolderPtr& conh) : + _stmt(conh->connection()->createStatement()), + _con(conh->connection()) { } @@ -146,6 +132,8 @@ decodeRef(const string& str, Environment* env, Connection* con) reinterpret_cast<const OraText*>(str.c_str()), str.length(), &ref); + + if(status == OCI_SUCCESS) { OCIHandleFree(error, OCI_HTYPE_ERROR); |