#ifndef RDBMSDATASOURCE_H #define RDBMSDATASOURCE_H #include #include #include #include "dataSource.h" #include "../libdbpp/connection.h" #include "../libdbpp/error.h" #include "scriptLoader.h" #include "connectionLoader.h" /// 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(ScriptNodePtr); DB::Connection * connect() const; bool operator<(const ConnectionInfo & o) const; const std::string dsn; const boost::shared_ptr typeId; }; typedef boost::shared_ptr ConnectionPtr; typedef std::map ReadonlyDSNs; // Map hostname to DSN string typedef std::map DBHosts; // Map DSN strings to connections typedef std::map FailedHosts; // Map DSN strings to failures RdbmsDataSource(ScriptNodePtr p); ~RdbmsDataSource(); const DB::Connection & getReadonly() const; const DB::Connection & getWritable() const; 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 DSNSet; static DSNSet changedDSNs; friend class RdbmsDataSourceLoader; }; #endif