summaryrefslogtreecommitdiffstats
path: root/examples/dummyresource/facade.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2015-05-25 23:14:57 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2015-05-25 23:14:57 +0200
commit3601ee575f833bf204540f4fac41d87a0d977a79 (patch)
tree740e62969ba7cd6384161b40d499fd63b2029f5f /examples/dummyresource/facade.cpp
parent9e3bcbdd45ec05d0a1fd423e6219ac6443feed1c (diff)
downloadsink-3601ee575f833bf204540f4fac41d87a0d977a79.tar.gz
sink-3601ee575f833bf204540f4fac41d87a0d977a79.zip
Centralized type specific code.
Diffstat (limited to 'examples/dummyresource/facade.cpp')
-rw-r--r--examples/dummyresource/facade.cpp61
1 files changed, 10 insertions, 51 deletions
diff --git a/examples/dummyresource/facade.cpp b/examples/dummyresource/facade.cpp
index 9722335..611217f 100644
--- a/examples/dummyresource/facade.cpp
+++ b/examples/dummyresource/facade.cpp
@@ -24,6 +24,8 @@
24 24
25#include "common/resourceaccess.h" 25#include "common/resourceaccess.h"
26#include "common/commands.h" 26#include "common/commands.h"
27#include "common/resultset.h"
28#include "common/domain/event.h"
27#include "dummycalendar_generated.h" 29#include "dummycalendar_generated.h"
28#include "event_generated.h" 30#include "event_generated.h"
29#include "entity_generated.h" 31#include "entity_generated.h"
@@ -126,60 +128,16 @@ void DummyResourceFacade::readValue(const QSharedPointer<Akonadi2::Storage> &sto
126 }); 128 });
127} 129}
128 130
129/*
130 * An iterator to a result set.
131 *
132 * We'll eventually want to lazy load results in next().
133 */
134class ResultSet {
135 public:
136 ResultSet(const QVector<QByteArray> &resultSet)
137 : mResultSet(resultSet),
138 mIt(nullptr)
139 {
140
141 }
142
143 bool next()
144 {
145 if (!mIt) {
146 mIt = mResultSet.constBegin();
147 } else {
148 mIt++;
149 }
150 return mIt != mResultSet.constEnd();
151 }
152
153 QByteArray id()
154 {
155 return *mIt;
156 }
157
158 private:
159 QVector<QByteArray> mResultSet;
160 QVector<QByteArray>::ConstIterator mIt;
161};
162
163static ResultSet getResultSet(const Akonadi2::Query &query, const QSharedPointer<Akonadi2::Storage> &storage) 131static ResultSet getResultSet(const Akonadi2::Query &query, const QSharedPointer<Akonadi2::Storage> &storage)
164{ 132{
165 //Now that the sync is complete we can execute the query 133 auto resultSet = Akonadi2::ApplicationDomain::EventImplementation::queryIndexes(query, "org.kde.dummy");
166 const auto preparedQuery = prepareQuery(query);
167
168 //Index lookups
169 //TODO query standard indexes
170 QVector<QByteArray> keys;
171 if (query.propertyFilter.contains("uid")) {
172 static Index uidIndex(Akonadi2::Store::storageLocation(), "org.kde.dummy.index.uid", Akonadi2::Storage::ReadOnly);
173 uidIndex.lookup(query.propertyFilter.value("uid").toByteArray(), [&](const QByteArray &value) {
174 keys << value;
175 },
176 [](const Index::Error &error) {
177 Warning() << "Error in index: " << error.message;
178 });
179 }
180 134
181 //Scan for where we don't have an index 135 //Scan for where we don't have an index
182 if (keys.isEmpty()) { 136 //TODO: we may want a way for queryIndexes to indicate that the resultSet is not final, and that a scan over the remaining set is required
137 //TODO: the prepared query should be generalized in EventImplementation on top of domain adaptors
138 if (resultSet.isEmpty()) {
139 QVector<QByteArray> keys;
140 const auto preparedQuery = prepareQuery(query);
183 scan(storage, QByteArray(), [preparedQuery, &keys](const QByteArray &key, const Akonadi2::Entity &entity, DummyEvent const *buffer, Akonadi2::ApplicationDomain::Buffer::Event const *local, Akonadi2::Metadata const *metadataBuffer) { 141 scan(storage, QByteArray(), [preparedQuery, &keys](const QByteArray &key, const Akonadi2::Entity &entity, DummyEvent const *buffer, Akonadi2::ApplicationDomain::Buffer::Event const *local, Akonadi2::Metadata const *metadataBuffer) {
184 //TODO use adapter for query and scan? 142 //TODO use adapter for query and scan?
185 if (preparedQuery && preparedQuery(std::string(key.constData(), key.size()), buffer, local)) { 143 if (preparedQuery && preparedQuery(std::string(key.constData(), key.size()), buffer, local)) {
@@ -187,9 +145,10 @@ static ResultSet getResultSet(const Akonadi2::Query &query, const QSharedPointer
187 } 145 }
188 return true; 146 return true;
189 }); 147 });
148 return ResultSet(keys);
190 } 149 }
191 150
192 return ResultSet(keys); 151 return resultSet;
193} 152}
194 153
195KAsync::Job<qint64> DummyResourceFacade::load(const Akonadi2::Query &query, const QSharedPointer<Akonadi2::ResultProvider<Akonadi2::ApplicationDomain::Event::Ptr> > &resultProvider, qint64 oldRevision, qint64 newRevision) 154KAsync::Job<qint64> DummyResourceFacade::load(const Akonadi2::Query &query, const QSharedPointer<Akonadi2::ResultProvider<Akonadi2::ApplicationDomain::Event::Ptr> > &resultProvider, qint64 oldRevision, qint64 newRevision)