From 6b7458332c1937de4393ae5104d3b6dcaffd886d Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 16 Dec 2016 10:10:22 +0100 Subject: Avoid unnecessary warnings if the db is not existing. It is expected that a query returns nothing if the db is not existing yet. --- common/storage/entitystore.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'common') diff --git a/common/storage/entitystore.cpp b/common/storage/entitystore.cpp index d8b1121..3b0d3c9 100644 --- a/common/storage/entitystore.cpp +++ b/common/storage/entitystore.cpp @@ -49,6 +49,11 @@ public: DataStore::Transaction transaction; QHash > indexByType; + bool exists() + { + return Sink::Storage::DataStore(Sink::storageLocation(), resourceContext.instanceId(), DataStore::ReadOnly).exists(); + } + DataStore::Transaction &getTransaction() { if (transaction) { @@ -381,6 +386,10 @@ bool EntityStore::cleanupRevisions(qint64 revision) QVector EntityStore::fullScan(const QByteArray &type) { SinkTrace() << "Looking for : " << type; + if (!d->exists()) { + SinkTrace() << "Database is not existing: " << type; + return QVector(); + } //The scan can return duplicate results if we have multiple revisions, so we use a set to deduplicate. QSet keys; DataStore::mainDatabase(d->getTransaction(), type) @@ -402,16 +411,28 @@ QVector EntityStore::fullScan(const QByteArray &type) QVector EntityStore::indexLookup(const QByteArray &type, const QueryBase &query, QSet &appliedFilters, QByteArray &appliedSorting) { + if (!d->exists()) { + SinkTrace() << "Database is not existing: " << type; + return QVector(); + } return d->typeIndex(type).query(query, appliedFilters, appliedSorting, d->getTransaction()); } QVector EntityStore::indexLookup(const QByteArray &type, const QByteArray &property, const QVariant &value) { + if (!d->exists()) { + SinkTrace() << "Database is not existing: " << type; + return QVector(); + } return d->typeIndex(type).lookup(property, value, d->getTransaction()); } void EntityStore::indexLookup(const QByteArray &type, const QByteArray &property, const QVariant &value, const std::function &callback) { + if (!d->exists()) { + SinkTrace() << "Database is not existing: " << type; + return; + } auto list = d->typeIndex(type).lookup(property, value, d->getTransaction()); for (const auto &uid : list) { callback(uid); @@ -576,6 +597,10 @@ bool EntityStore::contains(const QByteArray &type, const QByteArray &uid) qint64 EntityStore::maxRevision() { + if (!d->exists()) { + SinkTrace() << "Database is not existing."; + return 0; + } return DataStore::maxRevision(d->getTransaction()); } -- cgit v1.2.3