diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-10-20 17:46:10 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-10-21 09:18:50 +0200 |
commit | 0c1f6da51631c0a573a44e2f93eb4012d52dfe5c (patch) | |
tree | cf3cd3bec9fabd44a7107f47e7b0b057880ecb61 /common/storage/entitystore.cpp | |
parent | 9a03eb1a54c6289773bc1b8eb96181ed01553927 (diff) | |
download | sink-0c1f6da51631c0a573a44e2f93eb4012d52dfe5c.tar.gz sink-0c1f6da51631c0a573a44e2f93eb4012d52dfe5c.zip |
Get access to properties in indexes.
Diffstat (limited to 'common/storage/entitystore.cpp')
-rw-r--r-- | common/storage/entitystore.cpp | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/common/storage/entitystore.cpp b/common/storage/entitystore.cpp index f7f235e..dce2fc6 100644 --- a/common/storage/entitystore.cpp +++ b/common/storage/entitystore.cpp | |||
@@ -69,9 +69,8 @@ public: | |||
69 | /* return *index; */ | 69 | /* return *index; */ |
70 | /* } */ | 70 | /* } */ |
71 | 71 | ||
72 | TypeIndex &typeIndex(const QByteArray &type) | 72 | TypeIndex &cachedIndex(const QByteArray &type) |
73 | { | 73 | { |
74 | /* return applyType<typeIndex>(type); */ | ||
75 | if (indexByType.contains(type)) { | 74 | if (indexByType.contains(type)) { |
76 | return *indexByType.value(type); | 75 | return *indexByType.value(type); |
77 | } | 76 | } |
@@ -92,7 +91,19 @@ public: | |||
92 | } | 91 | } |
93 | indexByType.insert(type, index); | 92 | indexByType.insert(type, index); |
94 | return *index; | 93 | return *index; |
94 | TypeIndex &typeIndex(const QByteArray &type) | ||
95 | { | ||
96 | auto &index = cachedIndex(type); | ||
97 | index.mTransaction = &transaction; | ||
98 | return index; | ||
99 | } | ||
100 | |||
101 | ApplicationDomain::ApplicationDomainType createApplicationDomainType(const QByteArray &type, const QByteArray &uid, qint64 revision, const EntityBuffer &buffer) | ||
102 | { | ||
103 | auto adaptor = resourceContext.adaptorFactory(type).createAdaptor(buffer.entity(), &typeIndex(type)); | ||
104 | return ApplicationDomain::ApplicationDomainType{resourceContext.instanceId(), uid, revision, adaptor}; | ||
95 | } | 105 | } |
106 | |||
96 | }; | 107 | }; |
97 | 108 | ||
98 | EntityStore::EntityStore(const ResourceContext &context) | 109 | EntityStore::EntityStore(const ResourceContext &context) |
@@ -373,17 +384,16 @@ void EntityStore::readLatest(const QByteArray &type, const QByteArray &uid, cons | |||
373 | void EntityStore::readLatest(const QByteArray &type, const QByteArray &uid, const std::function<void(const ApplicationDomain::ApplicationDomainType &)> callback) | 384 | void EntityStore::readLatest(const QByteArray &type, const QByteArray &uid, const std::function<void(const ApplicationDomain::ApplicationDomainType &)> callback) |
374 | { | 385 | { |
375 | readLatest(type, uid, [&](const QByteArray &uid, const EntityBuffer &buffer) { | 386 | readLatest(type, uid, [&](const QByteArray &uid, const EntityBuffer &buffer) { |
376 | auto adaptor = d->resourceContext.adaptorFactory(type).createAdaptor(buffer.entity()); | 387 | //TODO cache max revision for the duration of the transaction. |
377 | callback(ApplicationDomain::ApplicationDomainType{d->resourceContext.instanceId(), uid, DataStore::maxRevision(d->getTransaction()), adaptor}); | 388 | callback(d->createApplicationDomainType(type, uid, DataStore::maxRevision(d->getTransaction()), buffer)); |
378 | }); | 389 | }); |
379 | } | 390 | } |
380 | 391 | ||
381 | void EntityStore::readLatest(const QByteArray &type, const QByteArray &uid, const std::function<void(const ApplicationDomain::ApplicationDomainType &, Sink::Operation)> callback) | 392 | void EntityStore::readLatest(const QByteArray &type, const QByteArray &uid, const std::function<void(const ApplicationDomain::ApplicationDomainType &, Sink::Operation)> callback) |
382 | { | 393 | { |
383 | readLatest(type, uid, [&](const QByteArray &uid, const EntityBuffer &buffer) { | 394 | readLatest(type, uid, [&](const QByteArray &uid, const EntityBuffer &buffer) { |
384 | auto adaptor = d->resourceContext.adaptorFactory(type).createAdaptor(buffer.entity()); | ||
385 | //TODO cache max revision for the duration of the transaction. | 395 | //TODO cache max revision for the duration of the transaction. |
386 | callback(ApplicationDomain::ApplicationDomainType{d->resourceContext.instanceId(), uid, DataStore::maxRevision(d->getTransaction()), adaptor}, buffer.operation()); | 396 | callback(d->createApplicationDomainType(type, uid, DataStore::maxRevision(d->getTransaction()), buffer), buffer.operation()); |
387 | }); | 397 | }); |
388 | } | 398 | } |
389 | 399 | ||
@@ -410,8 +420,7 @@ void EntityStore::readEntity(const QByteArray &type, const QByteArray &key, cons | |||
410 | void EntityStore::readEntity(const QByteArray &type, const QByteArray &uid, const std::function<void(const ApplicationDomain::ApplicationDomainType &)> callback) | 420 | void EntityStore::readEntity(const QByteArray &type, const QByteArray &uid, const std::function<void(const ApplicationDomain::ApplicationDomainType &)> callback) |
411 | { | 421 | { |
412 | readEntity(type, uid, [&](const QByteArray &uid, const EntityBuffer &buffer) { | 422 | readEntity(type, uid, [&](const QByteArray &uid, const EntityBuffer &buffer) { |
413 | auto adaptor = d->resourceContext.adaptorFactory(type).createAdaptor(buffer.entity()); | 423 | callback(d->createApplicationDomainType(type, uid, DataStore::maxRevision(d->getTransaction()), buffer)); |
414 | callback(ApplicationDomain::ApplicationDomainType{d->resourceContext.instanceId(), uid, DataStore::maxRevision(d->getTransaction()), adaptor}); | ||
415 | }); | 424 | }); |
416 | } | 425 | } |
417 | 426 | ||
@@ -432,8 +441,7 @@ void EntityStore::readAll(const QByteArray &type, const std::function<void(const | |||
432 | [=](const QByteArray &key, const QByteArray &value) -> bool { | 441 | [=](const QByteArray &key, const QByteArray &value) -> bool { |
433 | auto uid = DataStore::uidFromKey(key); | 442 | auto uid = DataStore::uidFromKey(key); |
434 | auto buffer = Sink::EntityBuffer{value.data(), value.size()}; | 443 | auto buffer = Sink::EntityBuffer{value.data(), value.size()}; |
435 | auto adaptor = d->resourceContext.adaptorFactory(type).createAdaptor(buffer.entity()); | 444 | callback(d->createApplicationDomainType(type, uid, DataStore::maxRevision(d->getTransaction()), buffer)); |
436 | callback(ApplicationDomain::ApplicationDomainType{d->resourceContext.instanceId(), uid, DataStore::maxRevision(d->getTransaction()), adaptor}); | ||
437 | return true; | 445 | return true; |
438 | }, | 446 | }, |
439 | [&](const DataStore::Error &error) { SinkWarning() << "Error during query: " << error.message; }); | 447 | [&](const DataStore::Error &error) { SinkWarning() << "Error during query: " << error.message; }); |
@@ -480,8 +488,7 @@ void EntityStore::readPrevious(const QByteArray &type, const QByteArray &uid, qi | |||
480 | void EntityStore::readPrevious(const QByteArray &type, const QByteArray &uid, qint64 revision, const std::function<void(const ApplicationDomain::ApplicationDomainType &)> callback) | 488 | void EntityStore::readPrevious(const QByteArray &type, const QByteArray &uid, qint64 revision, const std::function<void(const ApplicationDomain::ApplicationDomainType &)> callback) |
481 | { | 489 | { |
482 | readPrevious(type, uid, revision, [&](const QByteArray &uid, const EntityBuffer &buffer) { | 490 | readPrevious(type, uid, revision, [&](const QByteArray &uid, const EntityBuffer &buffer) { |
483 | auto adaptor = d->resourceContext.adaptorFactory(type).createAdaptor(buffer.entity()); | 491 | callback(d->createApplicationDomainType(type, uid, DataStore::maxRevision(d->getTransaction()), buffer)); |
484 | callback(ApplicationDomain::ApplicationDomainType{d->resourceContext.instanceId(), uid, DataStore::maxRevision(d->getTransaction()), adaptor}); | ||
485 | }); | 492 | }); |
486 | } | 493 | } |
487 | 494 | ||