summaryrefslogtreecommitdiffstats
path: root/common/storage
diff options
context:
space:
mode:
Diffstat (limited to 'common/storage')
-rw-r--r--common/storage/entitystore.cpp39
-rw-r--r--common/storage/entitystore.h10
-rw-r--r--common/storage/key.h3
3 files changed, 23 insertions, 29 deletions
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
464QVector<QByteArray> EntityStore::indexLookup(const QByteArray &type, const QByteArray &property, const QVariant &value) 464QVector<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
531void EntityStore::readLatest(const QByteArray &type, const QByteArray &uid, const std::function<void(const ApplicationDomainType &, Sink::Operation)> callback) 531void 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
545ApplicationDomain::ApplicationDomainType EntityStore::readLatest(const QByteArray &type, const QByteArray &uid) 536ApplicationDomain::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
591void EntityStore::readRevisions(qint64 baseRevision, const QByteArray &expectedType, const std::function<void(const QByteArray &key)> &callback) 582void 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
614void EntityStore::readPrevious(const QByteArray &type, const QByteArray &uid, qint64 revision, const std::function<void(const QByteArray &uid, const EntityBuffer &entity)> callback) 605void 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
632void EntityStore::readPrevious(const QByteArray &type, const QByteArray &uid, qint64 revision, const std::function<void(const ApplicationDomainType &)> callback) 623void 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
639ApplicationDomain::ApplicationDomainType EntityStore::readPrevious(const QByteArray &type, const QByteArray &uid, qint64 revision) 630ApplicationDomain::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;