diff options
Diffstat (limited to 'common/storage/entitystore.cpp')
-rw-r--r-- | common/storage/entitystore.cpp | 25 |
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) | |||
381 | QVector<QByteArray> EntityStore::fullScan(const QByteArray &type) | 386 | QVector<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 | ||
403 | QVector<QByteArray> EntityStore::indexLookup(const QByteArray &type, const QueryBase &query, QSet<QByteArray> &appliedFilters, QByteArray &appliedSorting) | 412 | QVector<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 | ||
408 | QVector<QByteArray> EntityStore::indexLookup(const QByteArray &type, const QByteArray &property, const QVariant &value) | 421 | QVector<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 | ||
413 | void EntityStore::indexLookup(const QByteArray &type, const QByteArray &property, const QVariant &value, const std::function<void(const QByteArray &uid)> &callback) | 430 | void 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 | ||
577 | qint64 EntityStore::maxRevision() | 598 | qint64 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 | ||