summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--project2/sql/rdbmsDataSource.cpp35
-rw-r--r--project2/sql/rdbmsDataSource.h9
2 files changed, 10 insertions, 34 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
{
diff --git a/project2/sql/rdbmsDataSource.h b/project2/sql/rdbmsDataSource.h
index 6d7e623..920ad05 100644
--- a/project2/sql/rdbmsDataSource.h
+++ b/project2/sql/rdbmsDataSource.h
@@ -37,20 +37,18 @@ class RdbmsDataSource : public DataSource {
unsigned int users;
const time_t keepAliveTime;
};
+ typedef boost::shared_ptr<RdbmsConnection> ConnectionPtr;
class ConnectionRef {
public:
- ConnectionRef();
- ConnectionRef(RdbmsConnection *);
- ConnectionRef(const ConnectionRef &);
+ ConnectionRef(const ConnectionPtr &);
~ConnectionRef();
- void operator=(const ConnectionRef &);
const DB::Connection * operator->() const;
const DB::Connection & operator*() const;
const DB::Connection * get() const;
private:
- RdbmsConnection * conn;
+ ConnectionPtr conn;
};
class ConnectionInfo {
@@ -65,7 +63,6 @@ class RdbmsDataSource : public DataSource {
const boost::shared_ptr<ConnectionLoader> typeId;
};
- typedef boost::shared_ptr<RdbmsConnection> ConnectionPtr;
typedef std::map<std::string, ConnectionInfo> ReadonlyDSNs; // Map hostname to DSN string
typedef std::multimap<ConnectionInfo, ConnectionPtr> DBHosts; // Map DSN strings to connections
typedef std::map<ConnectionInfo, const DB::ConnectionError> FailedHosts; // Map DSN strings to failures