summaryrefslogtreecommitdiffstats
path: root/common/storage/entitystore.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-12-16 10:10:22 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-12-16 10:10:22 +0100
commit6b7458332c1937de4393ae5104d3b6dcaffd886d (patch)
tree7501711228e9b5cb63dcda4e1c532226c9e17258 /common/storage/entitystore.cpp
parent9279222977dc3705a1e14f6bd7dbdbf0c2166c06 (diff)
downloadsink-6b7458332c1937de4393ae5104d3b6dcaffd886d.tar.gz
sink-6b7458332c1937de4393ae5104d3b6dcaffd886d.zip
Avoid unnecessary warnings if the db is not existing.
It is expected that a query returns nothing if the db is not existing yet.
Diffstat (limited to 'common/storage/entitystore.cpp')
-rw-r--r--common/storage/entitystore.cpp25
1 files changed, 25 insertions, 0 deletions
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:
49 DataStore::Transaction transaction; 49 DataStore::Transaction transaction;
50 QHash<QByteArray, QSharedPointer<TypeIndex> > indexByType; 50 QHash<QByteArray, QSharedPointer<TypeIndex> > indexByType;
51 51
52 bool exists()
53 {
54 return Sink::Storage::DataStore(Sink::storageLocation(), resourceContext.instanceId(), DataStore::ReadOnly).exists();
55 }
56
52 DataStore::Transaction &getTransaction() 57 DataStore::Transaction &getTransaction()
53 { 58 {
54 if (transaction) { 59 if (transaction) {
@@ -381,6 +386,10 @@ bool EntityStore::cleanupRevisions(qint64 revision)
381QVector<QByteArray> EntityStore::fullScan(const QByteArray &type) 386QVector<QByteArray> EntityStore::fullScan(const QByteArray &type)
382{ 387{
383 SinkTrace() << "Looking for : " << type; 388 SinkTrace() << "Looking for : " << type;
389 if (!d->exists()) {
390 SinkTrace() << "Database is not existing: " << type;
391 return QVector<QByteArray>();
392 }
384 //The scan can return duplicate results if we have multiple revisions, so we use a set to deduplicate. 393 //The scan can return duplicate results if we have multiple revisions, so we use a set to deduplicate.
385 QSet<QByteArray> keys; 394 QSet<QByteArray> keys;
386 DataStore::mainDatabase(d->getTransaction(), type) 395 DataStore::mainDatabase(d->getTransaction(), type)
@@ -402,16 +411,28 @@ QVector<QByteArray> EntityStore::fullScan(const QByteArray &type)
402 411
403QVector<QByteArray> EntityStore::indexLookup(const QByteArray &type, const QueryBase &query, QSet<QByteArray> &appliedFilters, QByteArray &appliedSorting) 412QVector<QByteArray> EntityStore::indexLookup(const QByteArray &type, const QueryBase &query, QSet<QByteArray> &appliedFilters, QByteArray &appliedSorting)
404{ 413{
414 if (!d->exists()) {
415 SinkTrace() << "Database is not existing: " << type;
416 return QVector<QByteArray>();
417 }
405 return d->typeIndex(type).query(query, appliedFilters, appliedSorting, d->getTransaction()); 418 return d->typeIndex(type).query(query, appliedFilters, appliedSorting, d->getTransaction());
406} 419}
407 420
408QVector<QByteArray> EntityStore::indexLookup(const QByteArray &type, const QByteArray &property, const QVariant &value) 421QVector<QByteArray> EntityStore::indexLookup(const QByteArray &type, const QByteArray &property, const QVariant &value)
409{ 422{
423 if (!d->exists()) {
424 SinkTrace() << "Database is not existing: " << type;
425 return QVector<QByteArray>();
426 }
410 return d->typeIndex(type).lookup(property, value, d->getTransaction()); 427 return d->typeIndex(type).lookup(property, value, d->getTransaction());
411} 428}
412 429
413void EntityStore::indexLookup(const QByteArray &type, const QByteArray &property, const QVariant &value, const std::function<void(const QByteArray &uid)> &callback) 430void EntityStore::indexLookup(const QByteArray &type, const QByteArray &property, const QVariant &value, const std::function<void(const QByteArray &uid)> &callback)
414{ 431{
432 if (!d->exists()) {
433 SinkTrace() << "Database is not existing: " << type;
434 return;
435 }
415 auto list = d->typeIndex(type).lookup(property, value, d->getTransaction()); 436 auto list = d->typeIndex(type).lookup(property, value, d->getTransaction());
416 for (const auto &uid : list) { 437 for (const auto &uid : list) {
417 callback(uid); 438 callback(uid);
@@ -576,6 +597,10 @@ bool EntityStore::contains(const QByteArray &type, const QByteArray &uid)
576 597
577qint64 EntityStore::maxRevision() 598qint64 EntityStore::maxRevision()
578{ 599{
600 if (!d->exists()) {
601 SinkTrace() << "Database is not existing.";
602 return 0;
603 }
579 return DataStore::maxRevision(d->getTransaction()); 604 return DataStore::maxRevision(d->getTransaction());
580} 605}
581 606