Akonadi

dbconfig.h
1 /*
2  SPDX-FileCopyrightText: 2010 Tobias Koenig <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #pragma once
8 
9 #include <QSettings>
10 #include <QSqlDatabase>
11 
12 namespace Akonadi
13 {
14 namespace Server
15 {
16 /**
17  * A base class that provides an unique access layer to configuration
18  * and initialization of different database backends.
19  */
20 class DbConfig
21 {
22 public:
23  virtual ~DbConfig();
24 
25  /**
26  * Returns whether database have been configured.
27  */
28  static bool isConfigured();
29 
30  /**
31  * Returns the DbConfig instance for the database the user has
32  * configured.
33  */
34  static DbConfig *configuredDatabase();
35 
36  /**
37  * Returns the name of the used driver.
38  */
39  virtual QString driverName() const = 0;
40 
41  /**
42  * Returns the database name.
43  */
44  virtual QString databaseName() const = 0;
45 
46  /**
47  * This method is called whenever the Akonadi server is started
48  * and before the initial database connection is set up.
49  *
50  * At this point the default settings should be determined, merged
51  * with the given @p settings and written back if @p storeSettings is true.
52  */
53  virtual bool init(QSettings &settings, bool storeSettings = true) = 0;
54 
55  /**
56  * This method checks if the requirements for this database connection are met
57  * in the system (i.e. QMYSQL driver is available, mysqld binary is found, etc.).
58  */
59  virtual bool isAvailable(QSettings &settings) = 0;
60 
61  /**
62  * This method applies the configured settings to the QtSql @p database
63  * instance.
64  */
65  virtual void apply(QSqlDatabase &database) = 0;
66 
67  /**
68  * Do session setup/initialization work on @p database.
69  * An example would be to run some SQL commands on every new session,
70  * typically stuff like setting encodings, transaction isolation levels, etc.
71  */
72  virtual void initSession(const QSqlDatabase &database);
73 
74  /**
75  * Returns whether an internal server needs to be used.
76  */
77  virtual bool useInternalServer() const = 0;
78 
79  /**
80  * This method is called to start an external server.
81  */
82  virtual bool startInternalServer();
83 
84  /**
85  * This method is called to stop the external server.
86  */
87  virtual void stopInternalServer();
88 
89  /**
90  * Payload data bigger than this value will be stored in separate files, instead of the database. Valid
91  *
92  * @return the size threshold in bytes, defaults to 4096.
93  */
94  virtual qint64 sizeThreshold() const;
95 
96  /**
97  * This method is called to setup initial database settings after a connection is established.
98  */
99  virtual void setup();
100 
101 protected:
102  DbConfig();
103 
104  /**
105  * Returns the suggested default database name, if none is specified in the configuration already.
106  * This includes instance namespaces, so usually this is not necessary to use in combination
107  * with internal databases (in process or using our own server instance).
108  */
109  static QString defaultDatabaseName();
110 
111  /*
112  * Returns the Database backend we should use by default. Usually it should be the same value
113  * configured as AKONADI_DATABASE_BACKEND at build time, but this method checks if that
114  * backend is really available and if it's not, it falls back to returning "QSQLITE3".
115  */
116  static QString defaultAvailableDatabaseBackend(QSettings &settings);
117 
118  /**
119  * Calls QProcess::execute() and also prints the command and arguments via qCDebug()
120  */
121  int execute(const QString &cmd, const QStringList &args) const;
122 
123 private:
124  Q_DISABLE_COPY(DbConfig)
125 
126  qint64 mSizeThreshold;
127 };
128 
129 } // namespace Server
130 } // namespace Akonadi
131 
virtual bool startInternalServer()
This method is called to start an external server.
Definition: dbconfig.cpp:112
virtual void apply(QSqlDatabase &database)=0
This method applies the configured settings to the QtSql database instance.
static DbConfig * configuredDatabase()
Returns the DbConfig instance for the database the user has configured.
Definition: dbconfig.cpp:73
virtual QString driverName() const =0
Returns the name of the used driver.
virtual QString databaseName() const =0
Returns the database name.
virtual bool init(QSettings &settings, bool storeSettings=true)=0
This method is called whenever the Akonadi server is started and before the initial database connecti...
virtual qint64 sizeThreshold() const
Payload data bigger than this value will be stored in separate files, instead of the database.
Definition: dbconfig.cpp:128
static QString defaultDatabaseName()
Returns the suggested default database name, if none is specified in the configuration already.
Definition: dbconfig.cpp:133
virtual bool useInternalServer() const =0
Returns whether an internal server needs to be used.
virtual void setup()
This method is called to setup initial database settings after a connection is established.
Definition: dbconfig.cpp:123
int execute(const QString &cmd, const QStringList &args) const
Calls QProcess::execute() and also prints the command and arguments via qCDebug()
Definition: dbconfig.cpp:147
virtual bool isAvailable(QSettings &settings)=0
This method checks if the requirements for this database connection are met in the system (i....
static bool isConfigured()
Returns whether database have been configured.
Definition: dbconfig.cpp:49
virtual void initSession(const QSqlDatabase &database)
Do session setup/initialization work on database.
Definition: dbconfig.cpp:142
A base class that provides an unique access layer to configuration and initialization of different da...
Definition: dbconfig.h:20
virtual void stopInternalServer()
This method is called to stop the external server.
Definition: dbconfig.cpp:118
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Jun 25 2022 06:00:32 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.