diff options
Diffstat (limited to 'project2/rdbmsDataSource.h')
-rw-r--r-- | project2/rdbmsDataSource.h | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/project2/rdbmsDataSource.h b/project2/rdbmsDataSource.h index ad97624..84c6d03 100644 --- a/project2/rdbmsDataSource.h +++ b/project2/rdbmsDataSource.h @@ -5,35 +5,57 @@ #include <boost/shared_ptr.hpp> #include <map> #include "dataSource.h" -#include "connection.h" +#include "../libdbpp/connection.h" +#include "../libdbpp/error.h" class RdbmsDataSource : public DataSource { public: - class RdbmsConnection : public ODBC::Connection { + class RdbmsConnection { public: - RdbmsConnection(const std::string & dsn, time_t keepAliveTime); + RdbmsConnection(const DB::Connection * connection, time_t kat); + ~RdbmsConnection(); + void touch() const; bool isExpired() const; + const DB::Connection * const connection; + private: mutable time_t lastUsedTime; const time_t keepAliveTime; }; + + class ConnectionInfo { + public: + ConnectionInfo(const xmlpp::Element *); + + DB::Connection * connect() const; + + bool operator<(const ConnectionInfo & o) const; + + private: + std::string dsn; + std::string type; + }; + typedef boost::shared_ptr<RdbmsConnection> ConnectionPtr; - typedef std::map<std::string, std::string> ReadonlyDSNs; // Map hostname to DSN string - typedef std::map<std::string, ConnectionPtr> DBHosts; // Map DSN strings to connections - typedef std::map<std::string, const ODBC::ConnectionError> FailedHosts; // Map DSN strings to failures + typedef std::map<std::string, ConnectionInfo> ReadonlyDSNs; // Map hostname to DSN string + typedef std::map<ConnectionInfo, ConnectionPtr> DBHosts; // Map DSN strings to connections + typedef std::map<ConnectionInfo, const DB::ConnectionError> FailedHosts; // Map DSN strings to failures + RdbmsDataSource(const xmlpp::Element * p); ~RdbmsDataSource(); - ODBC::Connection & getReadonly() const; - ODBC::Connection & getWritable() const; + + const DB::Connection & getReadonly() const; + const DB::Connection & getWritable() const; virtual void loadComplete(const CommonObjects *); virtual void commit(); virtual void rollback(); - const std::string masterDsn; + + const ConnectionInfo masterDsn; const bool preferLocal; protected: - static ConnectionPtr connectTo(const std::string & dsn); + static ConnectionPtr connectTo(const ConnectionInfo & dsn); ReadonlyDSNs roDSNs; private: |