diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-01-12 10:46:47 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-01-12 10:46:47 +0100 |
commit | 7d4784db80284874cd5b7e8e9f1c8694f6985b90 (patch) | |
tree | 0cc70a3ea1eb066ad1c146f42cad42a844ff12cd /common/store.cpp | |
parent | bb529848d4f7037ca92707b4dedbf40ae9c3d673 (diff) | |
download | sink-7d4784db80284874cd5b7e8e9f1c8694f6985b90.tar.gz sink-7d4784db80284874cd5b7e8e9f1c8694f6985b90.zip |
Modifications for multiple entities.
This allows to apply a modification to all entities matching some query.
Diffstat (limited to 'common/store.cpp')
-rw-r--r-- | common/store.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/common/store.cpp b/common/store.cpp index c11e1e8..38445e5 100644 --- a/common/store.cpp +++ b/common/store.cpp | |||
@@ -189,6 +189,20 @@ KAsync::Job<void> Store::modify(const DomainType &domainObject) | |||
189 | } | 189 | } |
190 | 190 | ||
191 | template <class DomainType> | 191 | template <class DomainType> |
192 | KAsync::Job<void> Store::modify(const Query &query, const DomainType &domainObject) | ||
193 | { | ||
194 | SinkLog() << "Modify: " << query << domainObject; | ||
195 | return fetchAll<DomainType>(query) | ||
196 | .each([=] (const typename DomainType::Ptr &entity) { | ||
197 | auto copy = *entity; | ||
198 | for (const auto &p : domainObject.changedProperties()) { | ||
199 | copy.setProperty(p, domainObject.getProperty(p)); | ||
200 | } | ||
201 | return modify(*entity); | ||
202 | }); | ||
203 | } | ||
204 | |||
205 | template <class DomainType> | ||
192 | KAsync::Job<void> Store::move(const DomainType &domainObject, const QByteArray &newResource) | 206 | KAsync::Job<void> Store::move(const DomainType &domainObject, const QByteArray &newResource) |
193 | { | 207 | { |
194 | SinkLog() << "Move: " << domainObject << newResource; | 208 | SinkLog() << "Move: " << domainObject << newResource; |
@@ -215,6 +229,16 @@ KAsync::Job<void> Store::remove(const DomainType &domainObject) | |||
215 | return facade->remove(domainObject).addToContext(std::shared_ptr<void>(facade)).onError([](const KAsync::Error &error) { SinkWarning() << "Failed to remove"; }); | 229 | return facade->remove(domainObject).addToContext(std::shared_ptr<void>(facade)).onError([](const KAsync::Error &error) { SinkWarning() << "Failed to remove"; }); |
216 | } | 230 | } |
217 | 231 | ||
232 | template <class DomainType> | ||
233 | KAsync::Job<void> Store::remove(const Sink::Query &query) | ||
234 | { | ||
235 | SinkLog() << "Remove: " << query; | ||
236 | return fetchAll<DomainType>(query) | ||
237 | .each([] (const typename DomainType::Ptr &entity) { | ||
238 | return remove(*entity); | ||
239 | }); | ||
240 | } | ||
241 | |||
218 | KAsync::Job<void> Store::removeDataFromDisk(const QByteArray &identifier) | 242 | KAsync::Job<void> Store::removeDataFromDisk(const QByteArray &identifier) |
219 | { | 243 | { |
220 | // All databases are going to become invalid, nuke the environments | 244 | // All databases are going to become invalid, nuke the environments |
@@ -368,8 +392,10 @@ QList<DomainType> Store::read(const Sink::Query &query_) | |||
368 | 392 | ||
369 | #define REGISTER_TYPE(T) \ | 393 | #define REGISTER_TYPE(T) \ |
370 | template KAsync::Job<void> Store::remove<T>(const T &domainObject); \ | 394 | template KAsync::Job<void> Store::remove<T>(const T &domainObject); \ |
395 | template KAsync::Job<void> Store::remove<T>(const Query &); \ | ||
371 | template KAsync::Job<void> Store::create<T>(const T &domainObject); \ | 396 | template KAsync::Job<void> Store::create<T>(const T &domainObject); \ |
372 | template KAsync::Job<void> Store::modify<T>(const T &domainObject); \ | 397 | template KAsync::Job<void> Store::modify<T>(const T &domainObject); \ |
398 | template KAsync::Job<void> Store::modify<T>(const Query &, const T &); \ | ||
373 | template KAsync::Job<void> Store::move<T>(const T &domainObject, const QByteArray &newResource); \ | 399 | template KAsync::Job<void> Store::move<T>(const T &domainObject, const QByteArray &newResource); \ |
374 | template KAsync::Job<void> Store::copy<T>(const T &domainObject, const QByteArray &newResource); \ | 400 | template KAsync::Job<void> Store::copy<T>(const T &domainObject, const QByteArray &newResource); \ |
375 | template QSharedPointer<QAbstractItemModel> Store::loadModel<T>(const Query &query); \ | 401 | template QSharedPointer<QAbstractItemModel> Store::loadModel<T>(const Query &query); \ |