summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/storage.h1
-rw-r--r--common/storage/entitystore.cpp5
-rw-r--r--common/storage_common.cpp12
3 files changed, 15 insertions, 3 deletions
diff --git a/common/storage.h b/common/storage.h
index 22d8046..ac6509d 100644
--- a/common/storage.h
+++ b/common/storage.h
@@ -258,6 +258,7 @@ public:
258 static void recordUid(DataStore::Transaction &transaction, const QByteArray &uid, const QByteArray &type); 258 static void recordUid(DataStore::Transaction &transaction, const QByteArray &uid, const QByteArray &type);
259 static void removeUid(DataStore::Transaction &transaction, const QByteArray &uid, const QByteArray &type); 259 static void removeUid(DataStore::Transaction &transaction, const QByteArray &uid, const QByteArray &type);
260 static void getUids(const QByteArray &type, const Transaction &, const std::function<void(const QByteArray &uid)> &); 260 static void getUids(const QByteArray &type, const Transaction &, const std::function<void(const QByteArray &uid)> &);
261 static bool hasUid(const QByteArray &type, const Transaction &, const QByteArray &uid);
261 262
262 bool exists() const; 263 bool exists() const;
263 static bool exists(const QString &storageRoot, const QString &name); 264 static bool exists(const QString &storageRoot, const QString &name);
diff --git a/common/storage/entitystore.cpp b/common/storage/entitystore.cpp
index a92de40..454e25a 100644
--- a/common/storage/entitystore.cpp
+++ b/common/storage/entitystore.cpp
@@ -630,11 +630,10 @@ void EntityStore::readAllUids(const QByteArray &type, const std::function<void(c
630 DataStore::getUids(type, d->getTransaction(), callback); 630 DataStore::getUids(type, d->getTransaction(), callback);
631} 631}
632 632
633bool EntityStore::contains(const QByteArray &type, const QByteArray &uid) 633bool EntityStore::contains(const QByteArray & /* type */, const QByteArray &uid)
634{ 634{
635 Q_ASSERT(!uid.isEmpty()); 635 Q_ASSERT(!uid.isEmpty());
636 const auto internalUid = Identifier::fromDisplayByteArray(uid).toInternalByteArray(); 636 return !DataStore::getRevisionsFromUid(d->getTransaction(), uid).isEmpty();
637 return DataStore::mainDatabase(d->getTransaction(), type).contains(internalUid);
638} 637}
639 638
640bool EntityStore::exists(const QByteArray &type, const QByteArray &uid) 639bool EntityStore::exists(const QByteArray &type, const QByteArray &uid)
diff --git a/common/storage_common.cpp b/common/storage_common.cpp
index 09b7707..7c794c3 100644
--- a/common/storage_common.cpp
+++ b/common/storage_common.cpp
@@ -233,6 +233,18 @@ void DataStore::getUids(const QByteArray &type, const Transaction &transaction,
233 }); 233 });
234} 234}
235 235
236bool DataStore::hasUid(const QByteArray &type, const Transaction &transaction, const QByteArray &uid)
237{
238 bool hasTheUid = false;
239 transaction.openDatabase(type + "uids").scan(uid, [&](const QByteArray &key, const QByteArray &) {
240 Q_ASSERT(uid == key);
241 hasTheUid = true;
242 return false;
243 });
244
245 return hasTheUid;
246}
247
236bool DataStore::isInternalKey(const char *key) 248bool DataStore::isInternalKey(const char *key)
237{ 249{
238 return key && strncmp(key, s_internalPrefix, s_internalPrefixSize) == 0; 250 return key && strncmp(key, s_internalPrefix, s_internalPrefixSize) == 0;