1 /******************************************************************************
3 * Copyright (C) 2012-2018 Icinga Development Team (https://www.icinga.com/) *
5 * This program is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU General Public License *
7 * as published by the Free Software Foundation; either version 2 *
8 * of the License, or (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software Foundation *
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ******************************************************************************/
20 #ifndef IDOPGSQLCONNECTION_H
21 #define IDOPGSQLCONNECTION_H
23 #include "db_ido_pgsql/idopgsqlconnection.thpp"
24 #include "base/array.hpp"
25 #include "base/timer.hpp"
26 #include "base/workqueue.hpp"
32 typedef std::shared_ptr<PGresult> IdoPgsqlResult;
35 * An IDO pgSQL database connection.
39 class IdoPgsqlConnection : public ObjectImpl<IdoPgsqlConnection>
42 DECLARE_OBJECT(IdoPgsqlConnection);
43 DECLARE_OBJECTNAME(IdoPgsqlConnection);
45 IdoPgsqlConnection(void);
47 static void StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata);
49 virtual int GetPendingQueryCount(void) const override;
52 virtual void OnConfigLoaded(void) override;
53 virtual void Resume(void) override;
54 virtual void Pause(void) override;
56 virtual void ActivateObject(const DbObject::Ptr& dbobj) override;
57 virtual void DeactivateObject(const DbObject::Ptr& dbobj) override;
58 virtual void ExecuteQuery(const DbQuery& query) override;
59 virtual void ExecuteMultipleQueries(const std::vector<DbQuery>& queries) override;
60 virtual void CleanUpExecuteQuery(const String& table, const String& time_key, double time_value) override;
61 virtual void FillIDCache(const DbType::Ptr& type) override;
62 virtual void NewTransaction(void) override;
65 DbReference m_InstanceID;
67 WorkQueue m_QueryQueue;
72 Timer::Ptr m_ReconnectTimer;
75 IdoPgsqlResult Query(const String& query);
76 DbReference GetSequenceValue(const String& table, const String& column);
77 int GetAffectedRows(void);
78 String Escape(const String& s);
79 Dictionary::Ptr FetchRow(const IdoPgsqlResult& result, int row);
81 bool FieldToEscapedString(const String& key, const Value& value, Value *result);
82 void InternalActivateObject(const DbObject::Ptr& dbobj);
83 void InternalDeactivateObject(const DbObject::Ptr& dbobj);
85 void Disconnect(void);
86 void InternalNewTransaction(void);
89 void AssertOnWorkQueue(void);
91 void TxTimerHandler(void);
92 void ReconnectTimerHandler(void);
94 void StatsLoggerTimerHandler(void);
96 bool CanExecuteQuery(const DbQuery& query);
98 void InternalExecuteQuery(const DbQuery& query, int typeOverride = -1);
99 void InternalExecuteMultipleQueries(const std::vector<DbQuery>& queries);
100 void InternalCleanUpExecuteQuery(const String& table, const String& time_key, double time_value);
102 void ClearTableBySession(const String& table);
103 void ClearTablesBySession(void);
105 void ExceptionHandler(boost::exception_ptr exp);
107 void FinishConnect(double startTime);
112 #endif /* IDOPGSQLCONNECTION_H */