Baloo

database.h
1 /*
2  This file is part of the KDE Baloo project.
3  SPDX-FileCopyrightText: 2015 Vishesh Handa <[email protected]>
4  SPDX-FileCopyrightText: 2016 Christoph Cullmann <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.1-or-later
7 */
8 
9 #ifndef BALOO_DATABASE_H
10 #define BALOO_DATABASE_H
11 
12 #include <QMutex>
13 
14 #include "document.h"
15 #include "databasedbis.h"
16 
17 namespace Baloo {
18 
19 class DatabaseTest;
20 
21 class BALOO_ENGINE_EXPORT Database
22 {
23 public:
24  /**
25  * Init database for given DB path, will not open it.
26  * @param path db path
27  */
28  explicit Database(const QString& path);
29 
30  /**
31  * Destruct db, might close it, if opened.
32  */
33  ~Database();
34 
35  /**
36  * Database open mode
37  */
38  enum OpenMode {
39  /**
40  * Create + open read-write database.
41  */
42  CreateDatabase,
43 
44  /**
45  * Read-Write Database, only works if database exists.
46  */
47  ReadWriteDatabase,
48 
49  /**
50  * Read-Only Database, only works if database exists.
51  */
52  ReadOnlyDatabase,
53  };
54 
55  /**
56  * Open database in given mode.
57  * Nop after open was done (even if mode differs).
58  * There is no close as this would invalidate the database for all threads using it.
59  * @param mode create or open only?
60  * @return success?
61  */
62  bool open(OpenMode mode);
63 
64  /**
65  * Is database open?
66  * @return database open?
67  */
68  bool isOpen() const;
69 
70  /**
71  * Path to database.
72  * @return database path
73  */
74  QString path() const;
75 
76  /**
77  * Is the database available for use?
78  * For example if indexing is disabled or the indexer did never run this is false.
79  * @return database available
80  */
81  bool isAvailable() const;
82 
83 private:
84  /**
85  * serialize access, as open might be called from multiple threads
86  */
87  mutable QMutex m_mutex;
88 
89  /**
90  * database path
91  */
92  const QString m_path;
93 
94  MDB_env* m_env;
95  DatabaseDbis m_dbis;
96 
97  friend class Transaction;
98  friend class DatabaseTest;
99 
100 };
101 }
102 
103 #endif // BALOO_DATABASE_H
QAction * open(const QObject *recvr, const char *slot, QObject *parent)
Implements storage for docIds without any associated data Instantiated for:
Definition: coding.cpp:11
QString path(const QString &relativePath)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Wed Nov 29 2023 03:56:26 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.