Akonadi

dbconfigpostgresql.h
1/*
2 SPDX-FileCopyrightText: 2010 Tobias Koenig <tokoe@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "dbconfig.h"
10
11#include <optional>
12
13namespace Akonadi
14{
15namespace Server
16{
17class DbConfigPostgresql : public DbConfig
18{
19public:
20 /**
21 * Constructs a new DbConfig for PostgreSQL reading configuration from the standard akonadiserverrc config file.
22 */
23 explicit DbConfigPostgresql() = default;
24
25 /**
26 * Constructs a new DbConfig for PostgreSQL reading configuration from the @p configFile.
27 */
28 explicit DbConfigPostgresql(const QString &configFile);
29
30 /**
31 * Returns the name of the used driver.
32 */
33 QString driverName() const override;
34
35 /**
36 * Returns the database name.
37 */
38 QString databaseName() const override;
39
40 /**
41 * Return path to the database file or directory.
42 */
43 QString databasePath() const override;
44
45 /**
46 * Sets path to the database file or directory.
47 */
48 void setDatabasePath(const QString &path, QSettings &settings) override;
49
50 /**
51 * This method is called whenever the Akonadi server is started
52 * and before the initial database connection is set up.
53 *
54 * At this point the default settings should be determined, merged
55 * with the given @p settings and written back if @p storeSettings is true.
56 */
57 bool init(QSettings &settings, bool storeSettings = true, const QString &dbPathOverride = {}) override;
58
59 /**
60 * This method checks if the requirements for this database connection are
61 * met in the system (QPOSTGRESQL driver is available, postgresql binary is
62 * found, etc.).
63 */
64 bool isAvailable(QSettings &settings) override;
65
66 /**
67 * This method applies the configured settings to the QtSql @p database
68 * instance.
69 */
70 void apply(QSqlDatabase &database) override;
71
72 /**
73 * Returns whether an internal server needs to be used.
74 */
75 bool useInternalServer() const override;
76
77 /**
78 * This method is called to start an external server.
79 */
80 bool startInternalServer() override;
81
82 /**
83 * This method is called to stop the external server.
84 */
85 void stopInternalServer() override;
86
87 /// reimpl
88 bool disableConstraintChecks(const QSqlDatabase &db) override;
89
90 /// reimpl
91 bool enableConstraintChecks(const QSqlDatabase &db) override;
92
93protected:
94 QStringList postgresSearchPaths(const QString &versionedPath) const;
95
96private:
97 struct Versions {
98 int clusterVersion = 0;
99 int pgServerVersion = 0;
100 };
101 std::optional<Versions> checkPgVersion() const;
102 bool upgradeCluster(int clusterVersion);
103 bool runInitDb(const QString &dbDataPath);
104
105 bool checkServerIsRunning();
106
107 QString mDatabaseName;
108 QString mHostName;
109 int mHostPort = 0;
110 QString mUserName;
111 QString mPassword;
112 QString mConnectionOptions;
113 QString mServerPath;
114 QString mInitDbPath;
115 QString mPgData;
116 QString mPgUpgradePath;
117 bool mInternalServer = true;
118};
119
120} // namespace Server
121} // namespace Akonadi
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:31:59 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.