From d0ab46b20b74acef104038cbc5c1b769be863cd3 Mon Sep 17 00:00:00 2001 From: Minijackson Date: Fri, 13 Jul 2018 10:56:47 +0200 Subject: Add versions of readLatest with Identifier as argument in EntityStore --- common/storage/entitystore.cpp | 43 ++++++++++++++++++++++++++++-------------- common/storage/entitystore.h | 3 +++ 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/common/storage/entitystore.cpp b/common/storage/entitystore.cpp index a1f6108..be51c2c 100644 --- a/common/storage/entitystore.cpp +++ b/common/storage/entitystore.cpp @@ -489,29 +489,25 @@ void EntityStore::indexLookup(const QByteArray &type, const QByteArray &property /* }); */ } -void EntityStore::readLatest(const QByteArray &type, const QByteArray &key, const std::function callback) +void EntityStore::readLatest(const QByteArray &type, const Identifier &id, const std::function callback) { Q_ASSERT(d); - Q_ASSERT(!key.isEmpty()); - // TODO: we shouldn't pass whole keys to this function - // check the testSingle test from querytest - const auto internalKey = [&key]() { - if(key.size() == Identifier::DISPLAY_REPR_SIZE) { - return Identifier::fromDisplayByteArray(key).toInternalByteArray(); - } else { - return Key::fromDisplayByteArray(key).toInternalByteArray(); - } - }(); + const auto internalKey = id.toInternalByteArray(); auto db = DataStore::mainDatabase(d->getTransaction(), type); db.findLatest(internalKey, [=](const QByteArray &key, const QByteArray &value) { const auto uid = Sink::Storage::Key::fromInternalByteArray(key).identifier().toDisplayByteArray(); callback(uid, Sink::EntityBuffer(value.data(), value.size())); }, - [&](const DataStore::Error &error) { SinkWarningCtx(d->logCtx) << "Error during readLatest query: " << error.message << key; }); + [&](const DataStore::Error &error) { SinkWarningCtx(d->logCtx) << "Error during readLatest query: " << error.message << id; }); } -void EntityStore::readLatest(const QByteArray &type, const QByteArray &uid, const std::function callback) +void EntityStore::readLatest(const QByteArray &type, const QByteArray &key, const std::function callback) +{ + +} + +void EntityStore::readLatest(const QByteArray &type, const Identifier &uid, const std::function callback) { readLatest(type, uid, [&](const QByteArray &uid, const EntityBuffer &buffer) { //TODO cache max revision for the duration of the transaction. @@ -519,7 +515,12 @@ void EntityStore::readLatest(const QByteArray &type, const QByteArray &uid, cons }); } -void EntityStore::readLatest(const QByteArray &type, const QByteArray &uid, const std::function callback) +void EntityStore::readLatest(const QByteArray &type, const QByteArray &uid, const std::function callback) +{ + readLatest(type, Identifier::fromDisplayByteArray(uid), callback); +} + +void EntityStore::readLatest(const QByteArray &type, const Identifier &uid, const std::function callback) { readLatest(type, uid, [&](const QByteArray &uid, const EntityBuffer &buffer) { //TODO cache max revision for the duration of the transaction. @@ -527,6 +528,20 @@ void EntityStore::readLatest(const QByteArray &type, const QByteArray &uid, cons }); } +void EntityStore::readLatest(const QByteArray &type, const QByteArray &uid, const std::function callback) +{ + // TODO: we shouldn't pass whole keys to this function + // check the testSingle test from querytest + const auto id = [&uid]() { + if(uid.size() == Identifier::DISPLAY_REPR_SIZE) { + return Identifier::fromDisplayByteArray(uid); + } else { + return Key::fromDisplayByteArray(uid).identifier(); + } + }(); + readLatest(type, id, callback); +} + ApplicationDomain::ApplicationDomainType EntityStore::readLatest(const QByteArray &type, const QByteArray &uid) { ApplicationDomainType dt; diff --git a/common/storage/entitystore.h b/common/storage/entitystore.h index 1dcd285..c23a659 100644 --- a/common/storage/entitystore.h +++ b/common/storage/entitystore.h @@ -67,10 +67,13 @@ public: } ///Returns the uid and buffer. Note that the memory only remains valid until the next operation or transaction end. + void readLatest(const QByteArray &type, const Identifier &uid, const std::function callback); void readLatest(const QByteArray &type, const QByteArray &uid, const std::function callback); ///Returns an entity. Note that the memory only remains valid until the next operation or transaction end. + void readLatest(const QByteArray &type, const Identifier &uid, const std::function callback); void readLatest(const QByteArray &type, const QByteArray &uid, const std::function callback); ///Returns an entity and operation. Note that the memory only remains valid until the next operation or transaction end. + void readLatest(const QByteArray &type, const Identifier &uid, const std::function callback); void readLatest(const QByteArray &type, const QByteArray &uid, const std::function callback); ///Returns a copy -- cgit v1.2.3