diff options
Diffstat (limited to 'project2/sql/rdbmsDataSource.h')
-rw-r--r-- | project2/sql/rdbmsDataSource.h | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/project2/sql/rdbmsDataSource.h b/project2/sql/rdbmsDataSource.h new file mode 100644 index 0000000..fdcfbe7 --- /dev/null +++ b/project2/sql/rdbmsDataSource.h @@ -0,0 +1,78 @@ +#ifndef RDBMSDATASOURCE_H +#define RDBMSDATASOURCE_H + +#include <libxml/tree.h> +#include <boost/shared_ptr.hpp> +#include <map> +#include <set> +#include "dataSource.h" +#include "../libdbpp/connection.h" +#include "../libdbpp/error.h" +#include "xmlObjectLoader.h" + +class ConnectionLoader; + +/// Project2 component to provide access to transactional RDBMS data sources +class RdbmsDataSource : public DataSource { + public: + class RdbmsConnection { + public: + RdbmsConnection(const DB::Connection * connection, time_t kat); + ~RdbmsConnection(); + + void touch() const; + bool isExpired() const; + const DB::Connection * const connection; + bool txOpen; + + 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; + 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::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(); + + const DB::Connection & getReadonly() const; + const DB::Connection & getWritable() const; + virtual void loadComplete(const CommonObjects *); + virtual void commit(); + virtual void rollback(); + + const ConnectionInfo masterDsn; + const bool preferLocal; + + protected: + static ConnectionPtr connectTo(const ConnectionInfo & dsn); + ReadonlyDSNs roDSNs; + + private: + mutable std::string localhost; + static DBHosts dbhosts; + static FailedHosts failedhosts; + typedef std::set<std::string> DSNSet; + static DSNSet changedDSNs; + + friend class RdbmsDataSourceLoader; +}; + +#endif + |