summaryrefslogtreecommitdiffstats
path: root/common/index.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'common/index.cpp')
-rw-r--r--common/index.cpp17
1 files changed, 10 insertions, 7 deletions
diff --git a/common/index.cpp b/common/index.cpp
index 7e3c09e..75ffe3f 100644
--- a/common/index.cpp
+++ b/common/index.cpp
@@ -2,24 +2,27 @@
2#include <QDebug> 2#include <QDebug>
3 3
4Index::Index(const QString &storageRoot, const QString &name, Akonadi2::Storage::AccessMode mode) 4Index::Index(const QString &storageRoot, const QString &name, Akonadi2::Storage::AccessMode mode)
5 : mStorage(storageRoot, name, mode, true) 5 : mTransaction(Akonadi2::Storage(storageRoot, name, mode, true).createTransaction(mode)),
6 mDb(mTransaction.openDatabase(name.toLatin1(), std::function<void(const Akonadi2::Storage::Error &)>(), true))
7{
8
9}
10
11Index::Index(const QByteArray &name, Akonadi2::Storage::Transaction &transaction)
12 : mDb(transaction.openDatabase(name, std::function<void(const Akonadi2::Storage::Error &)>(), true))
6{ 13{
7 14
8} 15}
9 16
10void Index::add(const QByteArray &key, const QByteArray &value) 17void Index::add(const QByteArray &key, const QByteArray &value)
11{ 18{
12 mStorage.createTransaction(Akonadi2::Storage::ReadWrite).write(key, value); 19 mDb.write(key, value);
13} 20}
14 21
15void Index::lookup(const QByteArray &key, const std::function<void(const QByteArray &value)> &resultHandler, 22void Index::lookup(const QByteArray &key, const std::function<void(const QByteArray &value)> &resultHandler,
16 const std::function<void(const Error &error)> &errorHandler) 23 const std::function<void(const Error &error)> &errorHandler)
17{ 24{
18 if (!mStorage.exists()) { 25 mDb.scan(key, [this, resultHandler](const QByteArray &key, const QByteArray &value) -> bool {
19 errorHandler(Error("index", IndexNotAvailable, "Index not existing"));
20 return;
21 }
22 mStorage.createTransaction(Akonadi2::Storage::ReadOnly).scan(key, [this, resultHandler](const QByteArray &key, const QByteArray &value) -> bool {
23 resultHandler(value); 26 resultHandler(value);
24 return true; 27 return true;
25 }, 28 },