diff options
Diffstat (limited to 'examples/dummyresource/facade.cpp')
-rw-r--r-- | examples/dummyresource/facade.cpp | 61 |
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 | */ | ||
134 | class 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 | |||
163 | static ResultSet getResultSet(const Akonadi2::Query &query, const QSharedPointer<Akonadi2::Storage> &storage) | 131 | static 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 | ||
195 | KAsync::Job<qint64> DummyResourceFacade::load(const Akonadi2::Query &query, const QSharedPointer<Akonadi2::ResultProvider<Akonadi2::ApplicationDomain::Event::Ptr> > &resultProvider, qint64 oldRevision, qint64 newRevision) | 154 | KAsync::Job<qint64> DummyResourceFacade::load(const Akonadi2::Query &query, const QSharedPointer<Akonadi2::ResultProvider<Akonadi2::ApplicationDomain::Event::Ptr> > &resultProvider, qint64 oldRevision, qint64 newRevision) |