diff options
Diffstat (limited to 'common/store.cpp')
-rw-r--r-- | common/store.cpp | 45 |
1 files changed, 36 insertions, 9 deletions
diff --git a/common/store.cpp b/common/store.cpp index 022c40e..ad2bb1c 100644 --- a/common/store.cpp +++ b/common/store.cpp | |||
@@ -195,9 +195,8 @@ template <class DomainType> | |||
195 | KAsync::Job<void> Store::create(const DomainType &domainObject) | 195 | KAsync::Job<void> Store::create(const DomainType &domainObject) |
196 | { | 196 | { |
197 | SinkLog() << "Create: " << domainObject; | 197 | SinkLog() << "Create: " << domainObject; |
198 | // Potentially move to separate thread as well | ||
199 | auto facade = getFacade<DomainType>(domainObject.resourceInstanceIdentifier()); | 198 | auto facade = getFacade<DomainType>(domainObject.resourceInstanceIdentifier()); |
200 | return facade->create(domainObject).addToContext(std::shared_ptr<void>(facade)).onError([](const KAsync::Error &error) { SinkWarning() << "Failed to create"; }); | 199 | return facade->create(domainObject).addToContext(std::shared_ptr<void>(facade)).onError([](const KAsync::Error &error) { SinkWarning() << "Failed to create " << error; }); |
201 | } | 200 | } |
202 | 201 | ||
203 | template <class DomainType> | 202 | template <class DomainType> |
@@ -208,8 +207,15 @@ KAsync::Job<void> Store::modify(const DomainType &domainObject) | |||
208 | return KAsync::null(); | 207 | return KAsync::null(); |
209 | } | 208 | } |
210 | SinkLog() << "Modify: " << domainObject; | 209 | SinkLog() << "Modify: " << domainObject; |
211 | // Potentially move to separate thread as well | ||
212 | auto facade = getFacade<DomainType>(domainObject.resourceInstanceIdentifier()); | 210 | auto facade = getFacade<DomainType>(domainObject.resourceInstanceIdentifier()); |
211 | if (domainObject.isAggregate()) { | ||
212 | return KAsync::value(domainObject.aggregatedIds()) | ||
213 | .addToContext(std::shared_ptr<void>(facade)) | ||
214 | .each([=] (const QByteArray &id) { | ||
215 | auto object = Sink::ApplicationDomain::ApplicationDomainType::createCopy(id, domainObject); | ||
216 | return facade->modify(object).onError([](const KAsync::Error &error) { SinkWarning() << "Failed to modify " << error; }); | ||
217 | }); | ||
218 | } | ||
213 | return facade->modify(domainObject).addToContext(std::shared_ptr<void>(facade)).onError([](const KAsync::Error &error) { SinkWarning() << "Failed to modify"; }); | 219 | return facade->modify(domainObject).addToContext(std::shared_ptr<void>(facade)).onError([](const KAsync::Error &error) { SinkWarning() << "Failed to modify"; }); |
214 | } | 220 | } |
215 | 221 | ||
@@ -235,27 +241,48 @@ template <class DomainType> | |||
235 | KAsync::Job<void> Store::move(const DomainType &domainObject, const QByteArray &newResource) | 241 | KAsync::Job<void> Store::move(const DomainType &domainObject, const QByteArray &newResource) |
236 | { | 242 | { |
237 | SinkLog() << "Move: " << domainObject << newResource; | 243 | SinkLog() << "Move: " << domainObject << newResource; |
238 | // Potentially move to separate thread as well | ||
239 | auto facade = getFacade<DomainType>(domainObject.resourceInstanceIdentifier()); | 244 | auto facade = getFacade<DomainType>(domainObject.resourceInstanceIdentifier()); |
240 | return facade->move(domainObject, newResource).addToContext(std::shared_ptr<void>(facade)).onError([](const KAsync::Error &error) { SinkWarning() << "Failed to move"; }); | 245 | if (domainObject.isAggregate()) { |
246 | return KAsync::value(domainObject.aggregatedIds()) | ||
247 | .addToContext(std::shared_ptr<void>(facade)) | ||
248 | .each([=] (const QByteArray &id) { | ||
249 | auto object = Sink::ApplicationDomain::ApplicationDomainType::createCopy(id, domainObject); | ||
250 | return facade->move(object, newResource).onError([](const KAsync::Error &error) { SinkWarning() << "Failed to move " << error; }); | ||
251 | }); | ||
252 | } | ||
253 | return facade->move(domainObject, newResource).addToContext(std::shared_ptr<void>(facade)).onError([](const KAsync::Error &error) { SinkWarning() << "Failed to move " << error; }); | ||
241 | } | 254 | } |
242 | 255 | ||
243 | template <class DomainType> | 256 | template <class DomainType> |
244 | KAsync::Job<void> Store::copy(const DomainType &domainObject, const QByteArray &newResource) | 257 | KAsync::Job<void> Store::copy(const DomainType &domainObject, const QByteArray &newResource) |
245 | { | 258 | { |
246 | SinkLog() << "Copy: " << domainObject << newResource; | 259 | SinkLog() << "Copy: " << domainObject << newResource; |
247 | // Potentially copy to separate thread as well | ||
248 | auto facade = getFacade<DomainType>(domainObject.resourceInstanceIdentifier()); | 260 | auto facade = getFacade<DomainType>(domainObject.resourceInstanceIdentifier()); |
249 | return facade->copy(domainObject, newResource).addToContext(std::shared_ptr<void>(facade)).onError([](const KAsync::Error &error) { SinkWarning() << "Failed to copy"; }); | 261 | if (domainObject.isAggregate()) { |
262 | return KAsync::value(domainObject.aggregatedIds()) | ||
263 | .addToContext(std::shared_ptr<void>(facade)) | ||
264 | .each([=] (const QByteArray &id) { | ||
265 | auto object = Sink::ApplicationDomain::ApplicationDomainType::createCopy(id, domainObject); | ||
266 | return facade->copy(object, newResource).onError([](const KAsync::Error &error) { SinkWarning() << "Failed to copy " << error; }); | ||
267 | }); | ||
268 | } | ||
269 | return facade->copy(domainObject, newResource).addToContext(std::shared_ptr<void>(facade)).onError([](const KAsync::Error &error) { SinkWarning() << "Failed to copy " << error; }); | ||
250 | } | 270 | } |
251 | 271 | ||
252 | template <class DomainType> | 272 | template <class DomainType> |
253 | KAsync::Job<void> Store::remove(const DomainType &domainObject) | 273 | KAsync::Job<void> Store::remove(const DomainType &domainObject) |
254 | { | 274 | { |
255 | SinkLog() << "Remove: " << domainObject; | 275 | SinkLog() << "Remove: " << domainObject; |
256 | // Potentially move to separate thread as well | ||
257 | auto facade = getFacade<DomainType>(domainObject.resourceInstanceIdentifier()); | 276 | auto facade = getFacade<DomainType>(domainObject.resourceInstanceIdentifier()); |
258 | return facade->remove(domainObject).addToContext(std::shared_ptr<void>(facade)).onError([](const KAsync::Error &error) { SinkWarning() << "Failed to remove"; }); | 277 | if (domainObject.isAggregate()) { |
278 | return KAsync::value(domainObject.aggregatedIds()) | ||
279 | .addToContext(std::shared_ptr<void>(facade)) | ||
280 | .each([=] (const QByteArray &id) { | ||
281 | auto object = Sink::ApplicationDomain::ApplicationDomainType::createCopy(id, domainObject); | ||
282 | return facade->remove(object).onError([](const KAsync::Error &error) { SinkWarning() << "Failed to remove " << error; }); | ||
283 | }); | ||
284 | } | ||
285 | return facade->remove(domainObject).addToContext(std::shared_ptr<void>(facade)).onError([](const KAsync::Error &error) { SinkWarning() << "Failed to remove " << error; }); | ||
259 | } | 286 | } |
260 | 287 | ||
261 | template <class DomainType> | 288 | template <class DomainType> |