summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/datastorequery.cpp28
-rw-r--r--common/storage/key.cpp41
-rw-r--r--common/storage/key.h13
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:
229 229
230 QSet<QByteArray> mReducedValues; 230 QSet<QByteArray> mReducedValues;
231 QSet<QByteArray> mIncrementallyReducedValues; 231 QSet<QByteArray> mIncrementallyReducedValues;
232 QHash<QByteArray, QByteArray> mSelectedValues; 232 QHash<QByteArray, Identifier> mSelectedValues;
233 QByteArray mReductionProperty; 233 QByteArray mReductionProperty;
234 QByteArray mSelectionProperty; 234 QByteArray mSelectionProperty;
235 QueryBase::Reduce::Selector::Comparator mSelectionComparator; 235 QueryBase::Reduce::Selector::Comparator mSelectionComparator;
@@ -270,7 +270,7 @@ public:
270 } 270 }
271 271
272 struct ReductionResult { 272 struct ReductionResult {
273 QByteArray selection; 273 Identifier selection;
274 QVector<QByteArray> aggregateIds; 274 QVector<QByteArray> aggregateIds;
275 QMap<QByteArray, QVariant> aggregateValues; 275 QMap<QByteArray, QVariant> aggregateValues;
276 }; 276 };
@@ -279,7 +279,7 @@ public:
279 { 279 {
280 QMap<QByteArray, QVariant> aggregateValues; 280 QMap<QByteArray, QVariant> aggregateValues;
281 QVariant selectionResultValue; 281 QVariant selectionResultValue;
282 QByteArray selectionResult; 282 Identifier selectionResult;
283 const auto results = indexLookup(mReductionProperty, reductionValue); 283 const auto results = indexLookup(mReductionProperty, reductionValue);
284 for (auto &aggregator : mAggregators) { 284 for (auto &aggregator : mAggregators) {
285 aggregator.reset(); 285 aggregator.reset();
@@ -303,7 +303,7 @@ public:
303 auto selectionValue = entity.getProperty(mSelectionProperty); 303 auto selectionValue = entity.getProperty(mSelectionProperty);
304 if (!selectionResultValue.isValid() || compare(selectionValue, selectionResultValue, mSelectionComparator)) { 304 if (!selectionResultValue.isValid() || compare(selectionValue, selectionResultValue, mSelectionComparator)) {
305 selectionResultValue = selectionValue; 305 selectionResultValue = selectionValue;
306 selectionResult = entity.identifier(); 306 selectionResult = Identifier::fromDisplayByteArray(entity.identifier());
307 } 307 }
308 }); 308 });
309 } 309 }
@@ -349,11 +349,11 @@ public:
349 auto reductionResult = reduceOnValue(reductionValue); 349 auto reductionResult = reduceOnValue(reductionValue);
350 350
351 //This can happen if we get a removal message from a filtered entity and all entites of the reduction are filtered. 351 //This can happen if we get a removal message from a filtered entity and all entites of the reduction are filtered.
352 if (reductionResult.selection.isEmpty()) { 352 if (reductionResult.selection.isNull()) {
353 return; 353 return;
354 } 354 }
355 mSelectedValues.insert(reductionValueBa, reductionResult.selection); 355 mSelectedValues.insert(reductionValueBa, reductionResult.selection);
356 readEntity(Identifier::fromDisplayByteArray(reductionResult.selection), [&](const Sink::ApplicationDomain::ApplicationDomainType &entity, Sink::Operation operation) { 356 readEntity(reductionResult.selection, [&](const Sink::ApplicationDomain::ApplicationDomainType &entity, Sink::Operation operation) {
357 callback({entity, operation, reductionResult.aggregateValues, reductionResult.aggregateIds}); 357 callback({entity, operation, reductionResult.aggregateValues, reductionResult.aggregateIds});
358 foundValue = true; 358 foundValue = true;
359 }); 359 });
@@ -370,28 +370,28 @@ public:
370 auto oldSelectionResult = mSelectedValues.take(reductionValueBa); 370 auto oldSelectionResult = mSelectedValues.take(reductionValueBa);
371 SinkTraceCtx(mDatastore->mLogCtx) << "Old selection result: " << oldSelectionResult << " New selection result: " << selectionResult.selection; 371 SinkTraceCtx(mDatastore->mLogCtx) << "Old selection result: " << oldSelectionResult << " New selection result: " << selectionResult.selection;
372 //If mSelectedValues did not containthe value, oldSelectionResult will be empty.(Happens if entites have been filtered) 372 //If mSelectedValues did not containthe value, oldSelectionResult will be empty.(Happens if entites have been filtered)
373 if (oldSelectionResult.isEmpty()) { 373 if (oldSelectionResult.isNull()) {
374 return; 374 return;
375 } 375 }
376 if (oldSelectionResult == selectionResult.selection) { 376 if (oldSelectionResult == selectionResult.selection) {
377 mSelectedValues.insert(reductionValueBa, selectionResult.selection); 377 mSelectedValues.insert(reductionValueBa, selectionResult.selection);
378 Q_ASSERT(!selectionResult.selection.isEmpty()); 378 Q_ASSERT(!selectionResult.selection.isNull());
379 readEntity(Identifier::fromDisplayByteArray(selectionResult.selection), [&](const Sink::ApplicationDomain::ApplicationDomainType &entity, Sink::Operation) { 379 readEntity(selectionResult.selection, [&](const Sink::ApplicationDomain::ApplicationDomainType &entity, Sink::Operation) {
380 callback({entity, Sink::Operation_Modification, selectionResult.aggregateValues, selectionResult.aggregateIds}); 380 callback({entity, Sink::Operation_Modification, selectionResult.aggregateValues, selectionResult.aggregateIds});
381 }); 381 });
382 } else { 382 } else {
383 //remove old result 383 //remove old result
384 Q_ASSERT(!oldSelectionResult.isEmpty()); 384 Q_ASSERT(!oldSelectionResult.isNull());
385 readEntity(Identifier::fromDisplayByteArray(oldSelectionResult), [&](const Sink::ApplicationDomain::ApplicationDomainType &entity, Sink::Operation) { 385 readEntity(oldSelectionResult, [&](const Sink::ApplicationDomain::ApplicationDomainType &entity, Sink::Operation) {
386 callback({entity, Sink::Operation_Removal}); 386 callback({entity, Sink::Operation_Removal});
387 }); 387 });
388 388
389 //If the last item has been removed, then there's nothing to add 389 //If the last item has been removed, then there's nothing to add
390 if (!selectionResult.selection.isEmpty()) { 390 if (!selectionResult.selection.isNull()) {
391 //add new result 391 //add new result
392 mSelectedValues.insert(reductionValueBa, selectionResult.selection); 392 mSelectedValues.insert(reductionValueBa, selectionResult.selection);
393 Q_ASSERT(!selectionResult.selection.isEmpty()); 393 Q_ASSERT(!selectionResult.selection.isNull());
394 readEntity(Identifier::fromDisplayByteArray(selectionResult.selection), [&](const Sink::ApplicationDomain::ApplicationDomainType &entity, Sink::Operation) { 394 readEntity(selectionResult.selection, [&](const Sink::ApplicationDomain::ApplicationDomainType &entity, Sink::Operation) {
395 callback({entity, Sink::Operation_Creation, selectionResult.aggregateValues, selectionResult.aggregateIds}); 395 callback({entity, Sink::Operation_Creation, selectionResult.aggregateValues, selectionResult.aggregateIds});
396 }); 396 });
397 } 397 }
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)
79 return Identifier(QUuid(bytes)); 79 return Identifier(QUuid(bytes));
80} 80}
81 81
82bool Identifier::isNull() const
83{
84 return uid.isNull();
85}
86
87bool Identifier::operator==(const Identifier &other) const
88{
89 return uid == other.uid;
90}
91
92bool Identifier::operator!=(const Identifier &other) const
93{
94 return !(*this == other);
95}
96
82// Revision 97// Revision
83 98
84QByteArray Revision::toInternalByteArray() const 99QByteArray Revision::toInternalByteArray() const
@@ -113,6 +128,16 @@ qint64 Revision::toQint64() const
113 return rev; 128 return rev;
114} 129}
115 130
131bool Revision::operator==(const Revision &other) const
132{
133 return rev == other.rev;
134}
135
136bool Revision::operator!=(const Revision &other) const
137{
138 return !(*this == other);
139}
140
116// Key 141// Key
117 142
118QByteArray Key::toInternalByteArray() const 143QByteArray Key::toInternalByteArray() const
@@ -160,3 +185,19 @@ void Key::setRevision(const Revision &newRev)
160{ 185{
161 rev = newRev; 186 rev = newRev;
162} 187}
188
189bool Key::isNull() const
190{
191 return id.isNull();
192}
193
194bool Key::operator==(const Key &other) const
195{
196 return (id == other.id) && (rev == other.rev);
197}
198
199bool Key::operator!=(const Key &other) const
200{
201 return !(*this == other);
202}
203
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:
46 QByteArray toDisplayByteArray() const; 46 QByteArray toDisplayByteArray() const;
47 static Identifier fromDisplayByteArray(const QByteArray &bytes); 47 static Identifier fromDisplayByteArray(const QByteArray &bytes);
48 48
49 bool isNull() const;
50
51 bool operator==(const Identifier &other) const;
52 bool operator!=(const Identifier &other) const;
53
49private: 54private:
50 explicit Identifier(const QUuid &uid) : uid(uid) {} 55 explicit Identifier(const QUuid &uid) : uid(uid) {}
51 QUuid uid; 56 QUuid uid;
@@ -67,6 +72,9 @@ public:
67 static Revision fromDisplayByteArray(const QByteArray &bytes); 72 static Revision fromDisplayByteArray(const QByteArray &bytes);
68 qint64 toQint64() const; 73 qint64 toQint64() const;
69 74
75 bool operator==(const Revision &other) const;
76 bool operator!=(const Revision &other) const;
77
70private: 78private:
71 qint64 rev; 79 qint64 rev;
72}; 80};
@@ -89,6 +97,11 @@ public:
89 const Revision &revision() const; 97 const Revision &revision() const;
90 void setRevision(const Revision &newRev); 98 void setRevision(const Revision &newRev);
91 99
100 bool isNull() const;
101
102 bool operator==(const Key &other) const;
103 bool operator!=(const Key &other) const;
104
92private: 105private:
93 Identifier id; 106 Identifier id;
94 Revision rev; 107 Revision rev;