From c16b34c3612049d41edf18cb533dbfc3b9b427a2 Mon Sep 17 00:00:00 2001 From: Minijackson Date: Mon, 23 Jul 2018 10:37:56 +0200 Subject: Convert selection in Reduce filter in datastorequery --- common/datastorequery.cpp | 28 ++++++++++++++-------------- common/storage/key.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ common/storage/key.h | 13 +++++++++++++ 3 files changed, 68 insertions(+), 14 deletions(-) diff --git a/common/datastorequery.cpp b/common/datastorequery.cpp index 51b6230..0ba62eb 100644 --- a/common/datastorequery.cpp +++ b/common/datastorequery.cpp @@ -229,7 +229,7 @@ public: QSet mReducedValues; QSet mIncrementallyReducedValues; - QHash mSelectedValues; + QHash mSelectedValues; QByteArray mReductionProperty; QByteArray mSelectionProperty; QueryBase::Reduce::Selector::Comparator mSelectionComparator; @@ -270,7 +270,7 @@ public: } struct ReductionResult { - QByteArray selection; + Identifier selection; QVector aggregateIds; QMap aggregateValues; }; @@ -279,7 +279,7 @@ public: { QMap aggregateValues; QVariant selectionResultValue; - QByteArray selectionResult; + Identifier selectionResult; const auto results = indexLookup(mReductionProperty, reductionValue); for (auto &aggregator : mAggregators) { aggregator.reset(); @@ -303,7 +303,7 @@ public: auto selectionValue = entity.getProperty(mSelectionProperty); if (!selectionResultValue.isValid() || compare(selectionValue, selectionResultValue, mSelectionComparator)) { selectionResultValue = selectionValue; - selectionResult = entity.identifier(); + selectionResult = Identifier::fromDisplayByteArray(entity.identifier()); } }); } @@ -349,11 +349,11 @@ public: auto reductionResult = reduceOnValue(reductionValue); //This can happen if we get a removal message from a filtered entity and all entites of the reduction are filtered. - if (reductionResult.selection.isEmpty()) { + if (reductionResult.selection.isNull()) { return; } mSelectedValues.insert(reductionValueBa, reductionResult.selection); - readEntity(Identifier::fromDisplayByteArray(reductionResult.selection), [&](const Sink::ApplicationDomain::ApplicationDomainType &entity, Sink::Operation operation) { + readEntity(reductionResult.selection, [&](const Sink::ApplicationDomain::ApplicationDomainType &entity, Sink::Operation operation) { callback({entity, operation, reductionResult.aggregateValues, reductionResult.aggregateIds}); foundValue = true; }); @@ -370,28 +370,28 @@ public: auto oldSelectionResult = mSelectedValues.take(reductionValueBa); SinkTraceCtx(mDatastore->mLogCtx) << "Old selection result: " << oldSelectionResult << " New selection result: " << selectionResult.selection; //If mSelectedValues did not containthe value, oldSelectionResult will be empty.(Happens if entites have been filtered) - if (oldSelectionResult.isEmpty()) { + if (oldSelectionResult.isNull()) { return; } if (oldSelectionResult == selectionResult.selection) { mSelectedValues.insert(reductionValueBa, selectionResult.selection); - Q_ASSERT(!selectionResult.selection.isEmpty()); - readEntity(Identifier::fromDisplayByteArray(selectionResult.selection), [&](const Sink::ApplicationDomain::ApplicationDomainType &entity, Sink::Operation) { + Q_ASSERT(!selectionResult.selection.isNull()); + readEntity(selectionResult.selection, [&](const Sink::ApplicationDomain::ApplicationDomainType &entity, Sink::Operation) { callback({entity, Sink::Operation_Modification, selectionResult.aggregateValues, selectionResult.aggregateIds}); }); } else { //remove old result - Q_ASSERT(!oldSelectionResult.isEmpty()); - readEntity(Identifier::fromDisplayByteArray(oldSelectionResult), [&](const Sink::ApplicationDomain::ApplicationDomainType &entity, Sink::Operation) { + Q_ASSERT(!oldSelectionResult.isNull()); + readEntity(oldSelectionResult, [&](const Sink::ApplicationDomain::ApplicationDomainType &entity, Sink::Operation) { callback({entity, Sink::Operation_Removal}); }); //If the last item has been removed, then there's nothing to add - if (!selectionResult.selection.isEmpty()) { + if (!selectionResult.selection.isNull()) { //add new result mSelectedValues.insert(reductionValueBa, selectionResult.selection); - Q_ASSERT(!selectionResult.selection.isEmpty()); - readEntity(Identifier::fromDisplayByteArray(selectionResult.selection), [&](const Sink::ApplicationDomain::ApplicationDomainType &entity, Sink::Operation) { + Q_ASSERT(!selectionResult.selection.isNull()); + readEntity(selectionResult.selection, [&](const Sink::ApplicationDomain::ApplicationDomainType &entity, Sink::Operation) { callback({entity, Sink::Operation_Creation, selectionResult.aggregateValues, selectionResult.aggregateIds}); }); } diff --git a/common/storage/key.cpp b/common/storage/key.cpp index 4dacca2..cfeb016 100644 --- a/common/storage/key.cpp +++ b/common/storage/key.cpp @@ -79,6 +79,21 @@ Identifier Identifier::fromDisplayByteArray(const QByteArray &bytes) return Identifier(QUuid(bytes)); } +bool Identifier::isNull() const +{ + return uid.isNull(); +} + +bool Identifier::operator==(const Identifier &other) const +{ + return uid == other.uid; +} + +bool Identifier::operator!=(const Identifier &other) const +{ + return !(*this == other); +} + // Revision QByteArray Revision::toInternalByteArray() const @@ -113,6 +128,16 @@ qint64 Revision::toQint64() const return rev; } +bool Revision::operator==(const Revision &other) const +{ + return rev == other.rev; +} + +bool Revision::operator!=(const Revision &other) const +{ + return !(*this == other); +} + // Key QByteArray Key::toInternalByteArray() const @@ -160,3 +185,19 @@ void Key::setRevision(const Revision &newRev) { rev = newRev; } + +bool Key::isNull() const +{ + return id.isNull(); +} + +bool Key::operator==(const Key &other) const +{ + return (id == other.id) && (rev == other.rev); +} + +bool Key::operator!=(const Key &other) const +{ + return !(*this == other); +} + diff --git a/common/storage/key.h b/common/storage/key.h index 151c333..a5b92bb 100644 --- a/common/storage/key.h +++ b/common/storage/key.h @@ -46,6 +46,11 @@ public: QByteArray toDisplayByteArray() const; static Identifier fromDisplayByteArray(const QByteArray &bytes); + bool isNull() const; + + bool operator==(const Identifier &other) const; + bool operator!=(const Identifier &other) const; + private: explicit Identifier(const QUuid &uid) : uid(uid) {} QUuid uid; @@ -67,6 +72,9 @@ public: static Revision fromDisplayByteArray(const QByteArray &bytes); qint64 toQint64() const; + bool operator==(const Revision &other) const; + bool operator!=(const Revision &other) const; + private: qint64 rev; }; @@ -89,6 +97,11 @@ public: const Revision &revision() const; void setRevision(const Revision &newRev); + bool isNull() const; + + bool operator==(const Key &other) const; + bool operator!=(const Key &other) const; + private: Identifier id; Revision rev; -- cgit v1.2.3