diff options
-rw-r--r-- | common/index.cpp | 4 | ||||
-rw-r--r-- | common/index.h | 4 | ||||
-rw-r--r-- | examples/dummyresource/resourcefactory.cpp | 21 |
3 files changed, 17 insertions, 12 deletions
diff --git a/common/index.cpp b/common/index.cpp index 9bb467b..a8de697 100644 --- a/common/index.cpp +++ b/common/index.cpp | |||
@@ -17,6 +17,10 @@ void Index::add(const QByteArray &key, const QByteArray &value) | |||
17 | void Index::lookup(const QByteArray &key, const std::function<void(const QByteArray &value)> &resultHandler, | 17 | void Index::lookup(const QByteArray &key, const std::function<void(const QByteArray &value)> &resultHandler, |
18 | const std::function<void(const Error &error)> &errorHandler) | 18 | const std::function<void(const Error &error)> &errorHandler) |
19 | { | 19 | { |
20 | if (!mStorage.exists()) { | ||
21 | errorHandler(Error("index", IndexNotAvailable, "Index not existing")); | ||
22 | return; | ||
23 | } | ||
20 | mStorage.scan(key, [this, resultHandler](void *keyPtr, int keySize, void *valuePtr, int valueSize) -> bool { | 24 | mStorage.scan(key, [this, resultHandler](void *keyPtr, int keySize, void *valuePtr, int valueSize) -> bool { |
21 | resultHandler(QByteArray(static_cast<char*>(valuePtr), valueSize)); | 25 | resultHandler(QByteArray(static_cast<char*>(valuePtr), valueSize)); |
22 | return true; | 26 | return true; |
diff --git a/common/index.h b/common/index.h index 3cd7cc8..08b499f 100644 --- a/common/index.h +++ b/common/index.h | |||
@@ -11,6 +11,10 @@ | |||
11 | class Index | 11 | class Index |
12 | { | 12 | { |
13 | public: | 13 | public: |
14 | enum ErrorCodes { | ||
15 | IndexNotAvailable = -1 | ||
16 | }; | ||
17 | |||
14 | class Error | 18 | class Error |
15 | { | 19 | { |
16 | public: | 20 | public: |
diff --git a/examples/dummyresource/resourcefactory.cpp b/examples/dummyresource/resourcefactory.cpp index b9123d5..c7a3eef 100644 --- a/examples/dummyresource/resourcefactory.cpp +++ b/examples/dummyresource/resourcefactory.cpp | |||
@@ -66,22 +66,20 @@ void DummyResource::configurePipeline(Akonadi2::Pipeline *pipeline) | |||
66 | KAsync::Job<void> DummyResource::synchronizeWithSource(Akonadi2::Pipeline *pipeline) | 66 | KAsync::Job<void> DummyResource::synchronizeWithSource(Akonadi2::Pipeline *pipeline) |
67 | { | 67 | { |
68 | return KAsync::start<void>([this, pipeline](KAsync::Future<void> &f) { | 68 | return KAsync::start<void>([this, pipeline](KAsync::Future<void> &f) { |
69 | auto storage = QSharedPointer<Akonadi2::Storage>::create(Akonadi2::Store::storageLocation(), mResourceInstanceIdentifier); | 69 | //TODO start transaction on index |
70 | storage->startTransaction(Akonadi2::Storage::ReadOnly); | ||
71 | |||
72 | Index uidIndex(Akonadi2::Store::storageLocation(), mResourceInstanceIdentifier + ".index.uid", Akonadi2::Storage::ReadOnly); | 70 | Index uidIndex(Akonadi2::Store::storageLocation(), mResourceInstanceIdentifier + ".index.uid", Akonadi2::Storage::ReadOnly); |
73 | 71 | ||
74 | const auto data = DummyStore::instance().data(); | 72 | const auto data = DummyStore::instance().data(); |
75 | for (auto it = data.constBegin(); it != data.constEnd(); it++) { | 73 | for (auto it = data.constBegin(); it != data.constEnd(); it++) { |
76 | bool isNew = true; | 74 | bool isNew = true; |
77 | if (storage->exists()) { | 75 | uidIndex.lookup(it.key().toLatin1(), [&](const QByteArray &value) { |
78 | uidIndex.lookup(it.key().toLatin1(), [&](const QByteArray &value) { | 76 | isNew = false; |
79 | isNew = false; | 77 | }, |
80 | }, | 78 | [](const Index::Error &error) { |
81 | [](const Index::Error &error) { | 79 | if (error.code != Index::IndexNotAvailable) { |
82 | Warning() << "Error in index: " << error.message; | 80 | Warning() << "Error in uid index: " << error.message; |
83 | }); | 81 | } |
84 | } | 82 | }); |
85 | if (isNew) { | 83 | if (isNew) { |
86 | m_fbb.Clear(); | 84 | m_fbb.Clear(); |
87 | 85 | ||
@@ -117,7 +115,6 @@ KAsync::Job<void> DummyResource::synchronizeWithSource(Akonadi2::Pipeline *pipel | |||
117 | //TODO diff and create modification if necessary | 115 | //TODO diff and create modification if necessary |
118 | } | 116 | } |
119 | } | 117 | } |
120 | storage->abortTransaction(); | ||
121 | //TODO find items to remove | 118 | //TODO find items to remove |
122 | f.setFinished(); | 119 | f.setFinished(); |
123 | }); | 120 | }); |