diff options
author | Minijackson <minijackson@riseup.net> | 2018-07-13 17:15:53 +0200 |
---|---|---|
committer | Minijackson <minijackson@riseup.net> | 2018-07-13 17:15:53 +0200 |
commit | 1b5499770273913ad26b213406df4208b10e2b3c (patch) | |
tree | 85e13a65e7c6e702db3e6c433b95e718e7072148 | |
parent | d0ab46b20b74acef104038cbc5c1b769be863cd3 (diff) | |
download | sink-1b5499770273913ad26b213406df4208b10e2b3c.tar.gz sink-1b5499770273913ad26b213406df4208b10e2b3c.zip |
Finish converting DataStoreQuery to new Key API
-rw-r--r-- | common/datastorequery.cpp | 59 | ||||
-rw-r--r-- | common/datastorequery.h | 20 | ||||
-rw-r--r-- | common/storage/entitystore.cpp | 39 | ||||
-rw-r--r-- | common/storage/entitystore.h | 10 | ||||
-rw-r--r-- | common/storage/key.h | 3 | ||||
-rw-r--r-- | common/typeindex.cpp | 10 | ||||
-rw-r--r-- | common/typeindex.h | 2 |
7 files changed, 75 insertions, 68 deletions
diff --git a/common/datastorequery.cpp b/common/datastorequery.cpp index fd910f8..8bfc49b 100644 --- a/common/datastorequery.cpp +++ b/common/datastorequery.cpp | |||
@@ -41,17 +41,23 @@ class Source : public FilterBase { | |||
41 | public: | 41 | public: |
42 | typedef QSharedPointer<Source> Ptr; | 42 | typedef QSharedPointer<Source> Ptr; |
43 | 43 | ||
44 | QVector<QByteArray> mIds; | 44 | QVector<Identifier> mIds; |
45 | QVector<QByteArray>::ConstIterator mIt; | 45 | QVector<Identifier>::ConstIterator mIt; |
46 | QVector<QByteArray> mIncrementalIds; | 46 | QVector<Identifier> mIncrementalIds; |
47 | QVector<QByteArray>::ConstIterator mIncrementalIt; | 47 | QVector<Identifier>::ConstIterator mIncrementalIt; |
48 | 48 | ||
49 | Source (const QVector<QByteArray> &ids, DataStoreQuery *store) | 49 | Source (const QVector<QByteArray> &ids, DataStoreQuery *store) |
50 | : FilterBase(store), | 50 | : FilterBase(store), |
51 | mIds(ids), | 51 | mIds() |
52 | mIt(mIds.constBegin()) | ||
53 | { | 52 | { |
54 | 53 | // Use reserve + append instead of QVector constructor with size here | |
54 | // to avoid default construction, which would generate a new random | ||
55 | // Uuid | ||
56 | mIds.reserve(ids.size()); | ||
57 | for (const auto &id : ids) { | ||
58 | mIds.append(Identifier::fromDisplayByteArray(id)); | ||
59 | } | ||
60 | mIt = mIds.constBegin(); | ||
55 | } | 61 | } |
56 | 62 | ||
57 | virtual ~Source(){} | 63 | virtual ~Source(){} |
@@ -63,9 +69,15 @@ class Source : public FilterBase { | |||
63 | } | 69 | } |
64 | }; | 70 | }; |
65 | 71 | ||
66 | void add(const QVector<QByteArray> &ids) | 72 | void add(const QVector<Key> &keys) |
67 | { | 73 | { |
68 | mIncrementalIds = ids; | 74 | // Use clear + reserve + append instead of resize here to avoid default |
75 | // construction | ||
76 | mIncrementalIds.clear(); | ||
77 | mIncrementalIds.reserve(keys.size()); | ||
78 | for (const auto &key : keys) { | ||
79 | mIncrementalIds.append(key.identifier()); | ||
80 | } | ||
69 | mIncrementalIt = mIncrementalIds.constBegin(); | 81 | mIncrementalIt = mIncrementalIds.constBegin(); |
70 | } | 82 | } |
71 | 83 | ||
@@ -284,7 +296,7 @@ public: | |||
284 | if (!matchesFilter(entity)) { | 296 | if (!matchesFilter(entity)) { |
285 | return; | 297 | return; |
286 | } | 298 | } |
287 | reducedAndFilteredResults << r; | 299 | reducedAndFilteredResults << r.toDisplayByteArray(); |
288 | Q_ASSERT(operation != Sink::Operation_Removal); | 300 | Q_ASSERT(operation != Sink::Operation_Removal); |
289 | for (auto &aggregator : mAggregators) { | 301 | for (auto &aggregator : mAggregators) { |
290 | if (!aggregator.property.isEmpty()) { | 302 | if (!aggregator.property.isEmpty()) { |
@@ -318,7 +330,8 @@ public: | |||
318 | if (v.isNull() && result.operation == Sink::Operation_Removal) { | 330 | if (v.isNull() && result.operation == Sink::Operation_Removal) { |
319 | //For removals we have to read the last revision to get a value, and thus be able to find the correct thread. | 331 | //For removals we have to read the last revision to get a value, and thus be able to find the correct thread. |
320 | QVariant reductionValue; | 332 | QVariant reductionValue; |
321 | readPrevious(result.entity.identifier(), [&] (const ApplicationDomain::ApplicationDomainType &prev) { | 333 | const auto id = Identifier::fromDisplayByteArray(result.entity.identifier()); |
334 | readPrevious(id, [&] (const ApplicationDomain::ApplicationDomainType &prev) { | ||
322 | Q_ASSERT(result.entity.identifier() == prev.identifier()); | 335 | Q_ASSERT(result.entity.identifier() == prev.identifier()); |
323 | reductionValue = prev.getProperty(mReductionProperty); | 336 | reductionValue = prev.getProperty(mReductionProperty); |
324 | }); | 337 | }); |
@@ -345,7 +358,7 @@ public: | |||
345 | return; | 358 | return; |
346 | } | 359 | } |
347 | mSelectedValues.insert(reductionValueBa, reductionResult.selection); | 360 | mSelectedValues.insert(reductionValueBa, reductionResult.selection); |
348 | readEntity(reductionResult.selection, [&](const Sink::ApplicationDomain::ApplicationDomainType &entity, Sink::Operation operation) { | 361 | readEntity(Identifier::fromDisplayByteArray(reductionResult.selection), [&](const Sink::ApplicationDomain::ApplicationDomainType &entity, Sink::Operation operation) { |
349 | callback({entity, operation, reductionResult.aggregateValues, reductionResult.aggregateIds}); | 362 | callback({entity, operation, reductionResult.aggregateValues, reductionResult.aggregateIds}); |
350 | foundValue = true; | 363 | foundValue = true; |
351 | }); | 364 | }); |
@@ -368,13 +381,13 @@ public: | |||
368 | if (oldSelectionResult == selectionResult.selection) { | 381 | if (oldSelectionResult == selectionResult.selection) { |
369 | mSelectedValues.insert(reductionValueBa, selectionResult.selection); | 382 | mSelectedValues.insert(reductionValueBa, selectionResult.selection); |
370 | Q_ASSERT(!selectionResult.selection.isEmpty()); | 383 | Q_ASSERT(!selectionResult.selection.isEmpty()); |
371 | readEntity(selectionResult.selection, [&](const Sink::ApplicationDomain::ApplicationDomainType &entity, Sink::Operation) { | 384 | readEntity(Identifier::fromDisplayByteArray(selectionResult.selection), [&](const Sink::ApplicationDomain::ApplicationDomainType &entity, Sink::Operation) { |
372 | callback({entity, Sink::Operation_Modification, selectionResult.aggregateValues, selectionResult.aggregateIds}); | 385 | callback({entity, Sink::Operation_Modification, selectionResult.aggregateValues, selectionResult.aggregateIds}); |
373 | }); | 386 | }); |
374 | } else { | 387 | } else { |
375 | //remove old result | 388 | //remove old result |
376 | Q_ASSERT(!oldSelectionResult.isEmpty()); | 389 | Q_ASSERT(!oldSelectionResult.isEmpty()); |
377 | readEntity(oldSelectionResult, [&](const Sink::ApplicationDomain::ApplicationDomainType &entity, Sink::Operation) { | 390 | readEntity(Identifier::fromDisplayByteArray(oldSelectionResult), [&](const Sink::ApplicationDomain::ApplicationDomainType &entity, Sink::Operation) { |
378 | callback({entity, Sink::Operation_Removal}); | 391 | callback({entity, Sink::Operation_Removal}); |
379 | }); | 392 | }); |
380 | 393 | ||
@@ -383,7 +396,7 @@ public: | |||
383 | //add new result | 396 | //add new result |
384 | mSelectedValues.insert(reductionValueBa, selectionResult.selection); | 397 | mSelectedValues.insert(reductionValueBa, selectionResult.selection); |
385 | Q_ASSERT(!selectionResult.selection.isEmpty()); | 398 | Q_ASSERT(!selectionResult.selection.isEmpty()); |
386 | readEntity(selectionResult.selection, [&](const Sink::ApplicationDomain::ApplicationDomainType &entity, Sink::Operation) { | 399 | readEntity(Identifier::fromDisplayByteArray(selectionResult.selection), [&](const Sink::ApplicationDomain::ApplicationDomainType &entity, Sink::Operation) { |
387 | callback({entity, Sink::Operation_Creation, selectionResult.aggregateValues, selectionResult.aggregateIds}); | 400 | callback({entity, Sink::Operation_Creation, selectionResult.aggregateValues, selectionResult.aggregateIds}); |
388 | }); | 401 | }); |
389 | } | 402 | } |
@@ -477,17 +490,17 @@ DataStoreQuery::State::Ptr DataStoreQuery::getState() | |||
477 | return state; | 490 | return state; |
478 | } | 491 | } |
479 | 492 | ||
480 | void DataStoreQuery::readEntity(const QByteArray &key, const BufferCallback &resultCallback) | 493 | void DataStoreQuery::readEntity(const Identifier &id, const BufferCallback &resultCallback) |
481 | { | 494 | { |
482 | mStore.readLatest(mType, key, resultCallback); | 495 | mStore.readLatest(mType, id, resultCallback); |
483 | } | 496 | } |
484 | 497 | ||
485 | void DataStoreQuery::readPrevious(const QByteArray &key, const std::function<void (const ApplicationDomain::ApplicationDomainType &)> &callback) | 498 | void DataStoreQuery::readPrevious(const Identifier &id, const std::function<void (const ApplicationDomain::ApplicationDomainType &)> &callback) |
486 | { | 499 | { |
487 | mStore.readPrevious(mType, key, mStore.maxRevision(), callback); | 500 | mStore.readPrevious(mType, id, mStore.maxRevision(), callback); |
488 | } | 501 | } |
489 | 502 | ||
490 | QVector<QByteArray> DataStoreQuery::indexLookup(const QByteArray &property, const QVariant &value) | 503 | QVector<Identifier> DataStoreQuery::indexLookup(const QByteArray &property, const QVariant &value) |
491 | { | 504 | { |
492 | return mStore.indexLookup(mType, property, value); | 505 | return mStore.indexLookup(mType, property, value); |
493 | } | 506 | } |
@@ -654,10 +667,10 @@ void DataStoreQuery::setupQuery(const Sink::QueryBase &query_) | |||
654 | mCollector = Collector::Ptr::create(baseSet, this); | 667 | mCollector = Collector::Ptr::create(baseSet, this); |
655 | } | 668 | } |
656 | 669 | ||
657 | QVector<QByteArray> DataStoreQuery::loadIncrementalResultSet(qint64 baseRevision) | 670 | QVector<Key> DataStoreQuery::loadIncrementalResultSet(qint64 baseRevision) |
658 | { | 671 | { |
659 | QVector<QByteArray> changedKeys; | 672 | QVector<Key> changedKeys; |
660 | mStore.readRevisions(baseRevision, mType, [&](const QByteArray &key) { | 673 | mStore.readRevisions(baseRevision, mType, [&](const Key &key) { |
661 | changedKeys << key; | 674 | changedKeys << key; |
662 | }); | 675 | }); |
663 | return changedKeys; | 676 | return changedKeys; |
diff --git a/common/datastorequery.h b/common/datastorequery.h index 2311585..a224e64 100644 --- a/common/datastorequery.h +++ b/common/datastorequery.h | |||
@@ -22,7 +22,7 @@ | |||
22 | #include "resultset.h" | 22 | #include "resultset.h" |
23 | #include "log.h" | 23 | #include "log.h" |
24 | #include "storage/entitystore.h" | 24 | #include "storage/entitystore.h" |
25 | 25 | #include "storage/key.h" | |
26 | 26 | ||
27 | class Source; | 27 | class Source; |
28 | class Bloom; | 28 | class Bloom; |
@@ -59,13 +59,13 @@ private: | |||
59 | typedef std::function<bool(const Sink::ApplicationDomain::ApplicationDomainType &entity, Sink::Operation)> FilterFunction; | 59 | typedef std::function<bool(const Sink::ApplicationDomain::ApplicationDomainType &entity, Sink::Operation)> FilterFunction; |
60 | typedef std::function<void(const Sink::ApplicationDomain::ApplicationDomainType &entity, Sink::Operation)> BufferCallback; | 60 | typedef std::function<void(const Sink::ApplicationDomain::ApplicationDomainType &entity, Sink::Operation)> BufferCallback; |
61 | 61 | ||
62 | QVector<QByteArray> indexLookup(const QByteArray &property, const QVariant &value); | 62 | QVector<Sink::Storage::Identifier> indexLookup(const QByteArray &property, const QVariant &value); |
63 | 63 | ||
64 | void readEntity(const QByteArray &key, const BufferCallback &resultCallback); | 64 | void readEntity(const Sink::Storage::Identifier &id, const BufferCallback &resultCallback); |
65 | void readPrevious(const QByteArray &key, const std::function<void (const Sink::ApplicationDomain::ApplicationDomainType &)> &callback); | 65 | void readPrevious(const Sink::Storage::Identifier &id, const std::function<void (const Sink::ApplicationDomain::ApplicationDomainType &)> &callback); |
66 | 66 | ||
67 | ResultSet createFilteredSet(ResultSet &resultSet, const FilterFunction &); | 67 | ResultSet createFilteredSet(ResultSet &resultSet, const FilterFunction &); |
68 | QVector<QByteArray> loadIncrementalResultSet(qint64 baseRevision); | 68 | QVector<Sink::Storage::Key> loadIncrementalResultSet(qint64 baseRevision); |
69 | 69 | ||
70 | void setupQuery(const Sink::QueryBase &query_); | 70 | void setupQuery(const Sink::QueryBase &query_); |
71 | QByteArrayList executeSubquery(const Sink::QueryBase &subquery); | 71 | QByteArrayList executeSubquery(const Sink::QueryBase &subquery); |
@@ -96,22 +96,22 @@ public: | |||
96 | 96 | ||
97 | virtual ~FilterBase(){} | 97 | virtual ~FilterBase(){} |
98 | 98 | ||
99 | void readEntity(const QByteArray &key, const std::function<void(const Sink::ApplicationDomain::ApplicationDomainType &entity, Sink::Operation)> &callback) | 99 | void readEntity(const Sink::Storage::Identifier &id, const std::function<void(const Sink::ApplicationDomain::ApplicationDomainType &entity, Sink::Operation)> &callback) |
100 | { | 100 | { |
101 | Q_ASSERT(mDatastore); | 101 | Q_ASSERT(mDatastore); |
102 | mDatastore->readEntity(key, callback); | 102 | mDatastore->readEntity(id, callback); |
103 | } | 103 | } |
104 | 104 | ||
105 | QVector<QByteArray> indexLookup(const QByteArray &property, const QVariant &value) | 105 | QVector<Sink::Storage::Identifier> indexLookup(const QByteArray &property, const QVariant &value) |
106 | { | 106 | { |
107 | Q_ASSERT(mDatastore); | 107 | Q_ASSERT(mDatastore); |
108 | return mDatastore->indexLookup(property, value); | 108 | return mDatastore->indexLookup(property, value); |
109 | } | 109 | } |
110 | 110 | ||
111 | void readPrevious(const QByteArray &key, const std::function<void (const Sink::ApplicationDomain::ApplicationDomainType &)> &callback) | 111 | void readPrevious(const Sink::Storage::Identifier &id, const std::function<void (const Sink::ApplicationDomain::ApplicationDomainType &)> &callback) |
112 | { | 112 | { |
113 | Q_ASSERT(mDatastore); | 113 | Q_ASSERT(mDatastore); |
114 | mDatastore->readPrevious(key, callback); | 114 | mDatastore->readPrevious(id, callback); |
115 | } | 115 | } |
116 | 116 | ||
117 | virtual void skip() { mSource->skip(); } | 117 | virtual void skip() { mSource->skip(); } |
diff --git a/common/storage/entitystore.cpp b/common/storage/entitystore.cpp index be51c2c..672eea1 100644 --- a/common/storage/entitystore.cpp +++ b/common/storage/entitystore.cpp | |||
@@ -461,11 +461,11 @@ QVector<QByteArray> EntityStore::indexLookup(const QByteArray &type, const Query | |||
461 | return d->typeIndex(type).query(query, appliedFilters, appliedSorting, d->getTransaction(), d->resourceContext.instanceId()); | 461 | return d->typeIndex(type).query(query, appliedFilters, appliedSorting, d->getTransaction(), d->resourceContext.instanceId()); |
462 | } | 462 | } |
463 | 463 | ||
464 | QVector<QByteArray> EntityStore::indexLookup(const QByteArray &type, const QByteArray &property, const QVariant &value) | 464 | QVector<Identifier> EntityStore::indexLookup(const QByteArray &type, const QByteArray &property, const QVariant &value) |
465 | { | 465 | { |
466 | if (!d->exists()) { | 466 | if (!d->exists()) { |
467 | SinkTraceCtx(d->logCtx) << "Database is not existing: " << type; | 467 | SinkTraceCtx(d->logCtx) << "Database is not existing: " << type; |
468 | return QVector<QByteArray>(); | 468 | return {}; |
469 | } | 469 | } |
470 | return d->typeIndex(type).lookup(property, value, d->getTransaction()); | 470 | return d->typeIndex(type).lookup(property, value, d->getTransaction()); |
471 | } | 471 | } |
@@ -476,9 +476,9 @@ void EntityStore::indexLookup(const QByteArray &type, const QByteArray &property | |||
476 | SinkTraceCtx(d->logCtx) << "Database is not existing: " << type; | 476 | SinkTraceCtx(d->logCtx) << "Database is not existing: " << type; |
477 | return; | 477 | return; |
478 | } | 478 | } |
479 | auto list = d->typeIndex(type).lookup(property, value, d->getTransaction()); | 479 | auto list = indexLookup(type, property, value); |
480 | for (const auto &uid : list) { | 480 | for (const auto &id : list) { |
481 | callback(uid); | 481 | callback(id.toDisplayByteArray()); |
482 | } | 482 | } |
483 | /* Index index(type + ".index." + property, d->transaction); */ | 483 | /* Index index(type + ".index." + property, d->transaction); */ |
484 | /* index.lookup(value, [&](const QByteArray &sinkId) { */ | 484 | /* index.lookup(value, [&](const QByteArray &sinkId) { */ |
@@ -530,16 +530,7 @@ void EntityStore::readLatest(const QByteArray &type, const Identifier &uid, cons | |||
530 | 530 | ||
531 | void EntityStore::readLatest(const QByteArray &type, const QByteArray &uid, const std::function<void(const ApplicationDomainType &, Sink::Operation)> callback) | 531 | void EntityStore::readLatest(const QByteArray &type, const QByteArray &uid, const std::function<void(const ApplicationDomainType &, Sink::Operation)> callback) |
532 | { | 532 | { |
533 | // TODO: we shouldn't pass whole keys to this function | 533 | readLatest(type, Identifier::fromDisplayByteArray(uid), callback); |
534 | // check the testSingle test from querytest | ||
535 | const auto id = [&uid]() { | ||
536 | if(uid.size() == Identifier::DISPLAY_REPR_SIZE) { | ||
537 | return Identifier::fromDisplayByteArray(uid); | ||
538 | } else { | ||
539 | return Key::fromDisplayByteArray(uid).identifier(); | ||
540 | } | ||
541 | }(); | ||
542 | readLatest(type, id, callback); | ||
543 | } | 534 | } |
544 | 535 | ||
545 | ApplicationDomain::ApplicationDomainType EntityStore::readLatest(const QByteArray &type, const QByteArray &uid) | 536 | ApplicationDomain::ApplicationDomainType EntityStore::readLatest(const QByteArray &type, const QByteArray &uid) |
@@ -588,7 +579,7 @@ void EntityStore::readAll(const QByteArray &type, const std::function<void(const | |||
588 | }); | 579 | }); |
589 | } | 580 | } |
590 | 581 | ||
591 | void EntityStore::readRevisions(qint64 baseRevision, const QByteArray &expectedType, const std::function<void(const QByteArray &key)> &callback) | 582 | void EntityStore::readRevisions(qint64 baseRevision, const QByteArray &expectedType, const std::function<void(const Key &key)> &callback) |
592 | { | 583 | { |
593 | qint64 revisionCounter = baseRevision; | 584 | qint64 revisionCounter = baseRevision; |
594 | const qint64 topRevision = DataStore::maxRevision(d->getTransaction()); | 585 | const qint64 topRevision = DataStore::maxRevision(d->getTransaction()); |
@@ -607,15 +598,15 @@ void EntityStore::readRevisions(qint64 baseRevision, const QByteArray &expectedT | |||
607 | const auto key = Key(Identifier::fromDisplayByteArray(uid), revisionCounter); | 598 | const auto key = Key(Identifier::fromDisplayByteArray(uid), revisionCounter); |
608 | 599 | ||
609 | revisionCounter++; | 600 | revisionCounter++; |
610 | callback(key.toDisplayByteArray()); | 601 | callback(key); |
611 | } | 602 | } |
612 | } | 603 | } |
613 | 604 | ||
614 | void EntityStore::readPrevious(const QByteArray &type, const QByteArray &uid, qint64 revision, const std::function<void(const QByteArray &uid, const EntityBuffer &entity)> callback) | 605 | void EntityStore::readPrevious(const QByteArray &type, const Identifier &id, qint64 revision, const std::function<void(const QByteArray &uid, const EntityBuffer &entity)> callback) |
615 | { | 606 | { |
616 | auto db = DataStore::mainDatabase(d->getTransaction(), type); | 607 | auto db = DataStore::mainDatabase(d->getTransaction(), type); |
617 | qint64 latestRevision = 0; | 608 | qint64 latestRevision = 0; |
618 | const auto internalUid = Identifier::fromDisplayByteArray(uid).toInternalByteArray(); | 609 | const auto internalUid = id.toInternalByteArray(); |
619 | db.scan(internalUid, | 610 | db.scan(internalUid, |
620 | [&latestRevision, revision](const QByteArray &key, const QByteArray &) -> bool { | 611 | [&latestRevision, revision](const QByteArray &key, const QByteArray &) -> bool { |
621 | const auto foundRevision = Key::fromInternalByteArray(key).revision().toQint64(); | 612 | const auto foundRevision = Key::fromInternalByteArray(key).revision().toQint64(); |
@@ -625,21 +616,21 @@ void EntityStore::readPrevious(const QByteArray &type, const QByteArray &uid, qi | |||
625 | return true; | 616 | return true; |
626 | }, | 617 | }, |
627 | [&](const DataStore::Error &error) { SinkWarningCtx(d->logCtx) << "Failed to read current value from storage: " << error.message; }, true); | 618 | [&](const DataStore::Error &error) { SinkWarningCtx(d->logCtx) << "Failed to read current value from storage: " << error.message; }, true); |
628 | const auto key = Key(Identifier::fromDisplayByteArray(uid), latestRevision); | 619 | const auto key = Key(id, latestRevision); |
629 | readEntity(type, key.toDisplayByteArray(), callback); | 620 | readEntity(type, key.toDisplayByteArray(), callback); |
630 | } | 621 | } |
631 | 622 | ||
632 | void EntityStore::readPrevious(const QByteArray &type, const QByteArray &uid, qint64 revision, const std::function<void(const ApplicationDomainType &)> callback) | 623 | void EntityStore::readPrevious(const QByteArray &type, const Identifier &id, qint64 revision, const std::function<void(const ApplicationDomainType &)> callback) |
633 | { | 624 | { |
634 | readPrevious(type, uid, revision, [&](const QByteArray &uid, const EntityBuffer &buffer) { | 625 | readPrevious(type, id, revision, [&](const QByteArray &uid, const EntityBuffer &buffer) { |
635 | callback(d->createApplicationDomainType(type, uid, DataStore::maxRevision(d->getTransaction()), buffer)); | 626 | callback(d->createApplicationDomainType(type, uid, DataStore::maxRevision(d->getTransaction()), buffer)); |
636 | }); | 627 | }); |
637 | } | 628 | } |
638 | 629 | ||
639 | ApplicationDomain::ApplicationDomainType EntityStore::readPrevious(const QByteArray &type, const QByteArray &uid, qint64 revision) | 630 | ApplicationDomain::ApplicationDomainType EntityStore::readPrevious(const QByteArray &type, const Identifier &id, qint64 revision) |
640 | { | 631 | { |
641 | ApplicationDomainType dt; | 632 | ApplicationDomainType dt; |
642 | readPrevious(type, uid, revision, [&](const ApplicationDomainType &entity) { | 633 | readPrevious(type, id, revision, [&](const ApplicationDomainType &entity) { |
643 | dt = *ApplicationDomainType::getInMemoryRepresentation<ApplicationDomainType>(entity, entity.availableProperties()); | 634 | dt = *ApplicationDomainType::getInMemoryRepresentation<ApplicationDomainType>(entity, entity.availableProperties()); |
644 | }); | 635 | }); |
645 | return dt; | 636 | return dt; |
diff --git a/common/storage/entitystore.h b/common/storage/entitystore.h index c23a659..f3aa07d 100644 --- a/common/storage/entitystore.h +++ b/common/storage/entitystore.h | |||
@@ -59,7 +59,7 @@ public: | |||
59 | 59 | ||
60 | QVector<QByteArray> fullScan(const QByteArray &type); | 60 | QVector<QByteArray> fullScan(const QByteArray &type); |
61 | QVector<QByteArray> indexLookup(const QByteArray &type, const QueryBase &query, QSet<QByteArrayList> &appliedFilters, QByteArray &appliedSorting); | 61 | QVector<QByteArray> indexLookup(const QByteArray &type, const QueryBase &query, QSet<QByteArrayList> &appliedFilters, QByteArray &appliedSorting); |
62 | QVector<QByteArray> indexLookup(const QByteArray &type, const QByteArray &property, const QVariant &value); | 62 | QVector<Sink::Storage::Identifier> indexLookup(const QByteArray &type, const QByteArray &property, const QVariant &value); |
63 | void indexLookup(const QByteArray &type, const QByteArray &property, const QVariant &value, const std::function<void(const QByteArray &uid)> &callback); | 63 | void indexLookup(const QByteArray &type, const QByteArray &property, const QVariant &value, const std::function<void(const QByteArray &uid)> &callback); |
64 | template<typename EntityType, typename PropertyType> | 64 | template<typename EntityType, typename PropertyType> |
65 | void indexLookup(const QVariant &value, const std::function<void(const QByteArray &uid)> &callback) { | 65 | void indexLookup(const QVariant &value, const std::function<void(const QByteArray &uid)> &callback) { |
@@ -97,10 +97,10 @@ public: | |||
97 | } | 97 | } |
98 | 98 | ||
99 | 99 | ||
100 | void readPrevious(const QByteArray &type, const QByteArray &uid, qint64 revision, const std::function<void(const QByteArray &uid, const EntityBuffer &entity)> callback); | 100 | void readPrevious(const QByteArray &type, const Sink::Storage::Identifier &uid, qint64 revision, const std::function<void(const QByteArray &uid, const EntityBuffer &entity)> callback); |
101 | void readPrevious(const QByteArray &type, const QByteArray &uid, qint64 revision, const std::function<void(const ApplicationDomainType &entity)> callback); | 101 | void readPrevious(const QByteArray &type, const Sink::Storage::Identifier &id, qint64 revision, const std::function<void(const ApplicationDomainType &entity)> callback); |
102 | ///Returns a copy | 102 | ///Returns a copy |
103 | ApplicationDomainType readPrevious(const QByteArray &type, const QByteArray &uid, qint64 revision); | 103 | ApplicationDomainType readPrevious(const QByteArray &type, const Sink::Storage::Identifier &id, qint64 revision); |
104 | 104 | ||
105 | template<typename T> | 105 | template<typename T> |
106 | T readPrevious(const QByteArray &uid, qint64 revision) { | 106 | T readPrevious(const QByteArray &uid, qint64 revision) { |
@@ -118,7 +118,7 @@ public: | |||
118 | }); | 118 | }); |
119 | } | 119 | } |
120 | 120 | ||
121 | void readRevisions(qint64 baseRevision, const QByteArray &type, const std::function<void(const QByteArray &key)> &callback); | 121 | void readRevisions(qint64 baseRevision, const QByteArray &type, const std::function<void(const Key &key)> &callback); |
122 | 122 | ||
123 | ///Db contains entity (but may already be marked as removed | 123 | ///Db contains entity (but may already be marked as removed |
124 | bool contains(const QByteArray &type, const QByteArray &uid); | 124 | bool contains(const QByteArray &type, const QByteArray &uid); |
diff --git a/common/storage/key.h b/common/storage/key.h index 76dbd13..40f4aca 100644 --- a/common/storage/key.h +++ b/common/storage/key.h | |||
@@ -76,6 +76,9 @@ public: | |||
76 | static const constexpr size_t INTERNAL_REPR_SIZE = Identifier::INTERNAL_REPR_SIZE + Revision::INTERNAL_REPR_SIZE; | 76 | static const constexpr size_t INTERNAL_REPR_SIZE = Identifier::INTERNAL_REPR_SIZE + Revision::INTERNAL_REPR_SIZE; |
77 | static const constexpr size_t DISPLAY_REPR_SIZE = Identifier::DISPLAY_REPR_SIZE + Revision::DISPLAY_REPR_SIZE; | 77 | static const constexpr size_t DISPLAY_REPR_SIZE = Identifier::DISPLAY_REPR_SIZE + Revision::DISPLAY_REPR_SIZE; |
78 | 78 | ||
79 | // Just to be able to store keys into Qt containers | ||
80 | [[deprecated("Don't use the default constructor")]] | ||
81 | Key() : id(), rev(0) {} | ||
79 | Key(const Identifier &id, const Revision &rev) : id(id), rev(rev) {} | 82 | Key(const Identifier &id, const Revision &rev) : id(id), rev(rev) {} |
80 | 83 | ||
81 | QByteArray toInternalByteArray() const; | 84 | QByteArray toInternalByteArray() const; |
diff --git a/common/typeindex.cpp b/common/typeindex.cpp index 887a146..1dd54e8 100644 --- a/common/typeindex.cpp +++ b/common/typeindex.cpp | |||
@@ -427,17 +427,17 @@ QVector<QByteArray> TypeIndex::query(const Sink::QueryBase &query, QSet<QByteArr | |||
427 | return {}; | 427 | return {}; |
428 | } | 428 | } |
429 | 429 | ||
430 | QVector<QByteArray> TypeIndex::lookup(const QByteArray &property, const QVariant &value, | 430 | QVector<Identifier> TypeIndex::lookup(const QByteArray &property, const QVariant &value, |
431 | Sink::Storage::DataStore::Transaction &transaction) | 431 | Sink::Storage::DataStore::Transaction &transaction) |
432 | { | 432 | { |
433 | SinkTraceCtx(mLogCtx) << "Index lookup on property: " << property << mSecondaryProperties.keys() << mProperties; | 433 | SinkTraceCtx(mLogCtx) << "Index lookup on property: " << property << mSecondaryProperties.keys() << mProperties; |
434 | if (mProperties.contains(property)) { | 434 | if (mProperties.contains(property)) { |
435 | QVector<QByteArray> keys; | 435 | QVector<Identifier> keys; |
436 | Index index(indexName(property), transaction); | 436 | Index index(indexName(property), transaction); |
437 | const auto lookupKey = getByteArray(value); | 437 | const auto lookupKey = getByteArray(value); |
438 | index.lookup(lookupKey, | 438 | index.lookup(lookupKey, |
439 | [&](const QByteArray &value) { | 439 | [&](const QByteArray &value) { |
440 | keys << Identifier::fromInternalByteArray(value).toDisplayByteArray(); | 440 | keys << Identifier::fromInternalByteArray(value); |
441 | }, | 441 | }, |
442 | [property](const Index::Error &error) { | 442 | [property](const Index::Error &error) { |
443 | SinkWarning() << "Error in index: " << error.message << property; | 443 | SinkWarning() << "Error in index: " << error.message << property; |
@@ -447,7 +447,7 @@ QVector<QByteArray> TypeIndex::lookup(const QByteArray &property, const QVariant | |||
447 | } else if (mSecondaryProperties.contains(property)) { | 447 | } else if (mSecondaryProperties.contains(property)) { |
448 | // Lookups on secondary indexes first lookup the key, and then lookup the results again to | 448 | // Lookups on secondary indexes first lookup the key, and then lookup the results again to |
449 | // resolve to entity id's | 449 | // resolve to entity id's |
450 | QVector<QByteArray> keys; | 450 | QVector<Identifier> keys; |
451 | auto resultProperty = mSecondaryProperties.value(property); | 451 | auto resultProperty = mSecondaryProperties.value(property); |
452 | 452 | ||
453 | QVector<QByteArray> secondaryKeys; | 453 | QVector<QByteArray> secondaryKeys; |
@@ -466,7 +466,7 @@ QVector<QByteArray> TypeIndex::lookup(const QByteArray &property, const QVariant | |||
466 | } else { | 466 | } else { |
467 | SinkWarning() << "Tried to lookup " << property << " but couldn't find value"; | 467 | SinkWarning() << "Tried to lookup " << property << " but couldn't find value"; |
468 | } | 468 | } |
469 | return QVector<QByteArray>(); | 469 | return {}; |
470 | } | 470 | } |
471 | 471 | ||
472 | template <> | 472 | template <> |
diff --git a/common/typeindex.h b/common/typeindex.h index a701e9c..f2cabaf 100644 --- a/common/typeindex.h +++ b/common/typeindex.h | |||
@@ -95,7 +95,7 @@ public: | |||
95 | void remove(const Sink::Storage::Identifier &identifier, const Sink::ApplicationDomain::ApplicationDomainType &entity, Sink::Storage::DataStore::Transaction &transaction, const QByteArray &resourceInstanceId); | 95 | void remove(const Sink::Storage::Identifier &identifier, const Sink::ApplicationDomain::ApplicationDomainType &entity, Sink::Storage::DataStore::Transaction &transaction, const QByteArray &resourceInstanceId); |
96 | 96 | ||
97 | QVector<QByteArray> query(const Sink::QueryBase &query, QSet<QByteArrayList> &appliedFilters, QByteArray &appliedSorting, Sink::Storage::DataStore::Transaction &transaction, const QByteArray &resourceInstanceId); | 97 | QVector<QByteArray> query(const Sink::QueryBase &query, QSet<QByteArrayList> &appliedFilters, QByteArray &appliedSorting, Sink::Storage::DataStore::Transaction &transaction, const QByteArray &resourceInstanceId); |
98 | QVector<QByteArray> lookup(const QByteArray &property, const QVariant &value, Sink::Storage::DataStore::Transaction &transaction); | 98 | QVector<Sink::Storage::Identifier> lookup(const QByteArray &property, const QVariant &value, Sink::Storage::DataStore::Transaction &transaction); |
99 | 99 | ||
100 | template <typename Left, typename Right> | 100 | template <typename Left, typename Right> |
101 | QVector<QByteArray> secondaryLookup(const QVariant &value) | 101 | QVector<QByteArray> secondaryLookup(const QVariant &value) |