diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-06-03 20:05:13 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-06-03 20:05:13 +0100 |
commit | 4fc6c2e9f70a880f0620e1a3e08f92875e369bab (patch) | |
tree | d84c7a77b6ebe6a2dc7b57e4496e03a6c58db404 /project2/sql/rdbmsDataSource.cpp | |
parent | Close master connection to database when deleting mock (diff) | |
download | project2-4fc6c2e9f70a880f0620e1a3e08f92875e369bab.tar.bz2 project2-4fc6c2e9f70a880f0620e1a3e08f92875e369bab.tar.xz project2-4fc6c2e9f70a880f0620e1a3e08f92875e369bab.zip |
Have RdbmsConnection return a ref counting connection handle so that the client is still valid even if core releases it
Diffstat (limited to 'project2/sql/rdbmsDataSource.cpp')
-rw-r--r-- | project2/sql/rdbmsDataSource.cpp | 35 |
1 files changed, 7 insertions, 28 deletions
diff --git a/project2/sql/rdbmsDataSource.cpp b/project2/sql/rdbmsDataSource.cpp index 5f0d43a..90dd09a 100644 --- a/project2/sql/rdbmsDataSource.cpp +++ b/project2/sql/rdbmsDataSource.cpp @@ -66,7 +66,7 @@ RdbmsDataSource::getWritable() const } LOCK(glock); changedDSNs.insert({name, std::this_thread::get_id()}); - return master.get(); + return master; } RdbmsDataSource::ConnectionRef @@ -76,7 +76,7 @@ RdbmsDataSource::getReadonly() const LOCK(glock); if (changedDSNs.find({name, std::this_thread::get_id()}) != changedDSNs.end()) { glock.unlock(); - return connectTo(masterDsn).get(); + return connectTo(masterDsn); } } LOCK(ilock); @@ -97,9 +97,9 @@ RdbmsDataSource::getReadonly() const if (ro == roDSNs.end()) { Logger()->messagef(LOG_INFO, "%s: No database host matches local host name (%s) Will use master DSN", __PRETTY_FUNCTION__, localhost.c_str()); - return connectTo(masterDsn).get(); + return connectTo(masterDsn); } - return connectTo(ro->second).get(); + return connectTo(ro->second); } catch (...) { // Failed to connect to a preferred DB... carry on and try the others... @@ -107,12 +107,12 @@ RdbmsDataSource::getReadonly() const } for (ReadonlyDSNs::value_type db : roDSNs) { try { - return connectTo(db.second).get(); + return connectTo(db.second); } catch (...) { } } - return connectTo(masterDsn).get(); + return connectTo(masterDsn); } void @@ -262,40 +262,19 @@ RdbmsDataSource::ConnectionInfo::operator<(const RdbmsDataSource::ConnectionInfo return ((typeId < other.typeId) || ((typeId == other.typeId) && (dsn < other.dsn))); } -RdbmsDataSource::ConnectionRef::ConnectionRef() : - conn(NULL) -{ -} - -RdbmsDataSource::ConnectionRef::ConnectionRef(RdbmsConnection * c) : +RdbmsDataSource::ConnectionRef::ConnectionRef(const ConnectionPtr & c) : conn(c) { if (conn) conn->incRef(); } -RdbmsDataSource::ConnectionRef::ConnectionRef(const ConnectionRef & ref) : - conn(ref.conn) -{ - if (conn) - conn->incRef(); -} - RdbmsDataSource::ConnectionRef::~ConnectionRef() { if (conn) conn->decRef(); } -void RdbmsDataSource::ConnectionRef::operator=(const ConnectionRef & ref) -{ - if (conn) - conn->decRef(); - conn = ref.conn; - if (conn) - conn->incRef(); -} - const DB::Connection * RdbmsDataSource::ConnectionRef::operator->() const { |