summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/synchronizerstore.cpp29
-rw-r--r--common/synchronizerstore.h4
2 files changed, 33 insertions, 0 deletions
diff --git a/common/synchronizerstore.cpp b/common/synchronizerstore.cpp
index fcb3ed0..a9da2fe 100644
--- a/common/synchronizerstore.cpp
+++ b/common/synchronizerstore.cpp
@@ -54,6 +54,10 @@ void SynchronizerStore::updateRemoteId(const QByteArray &bufferType, const QByte
54 54
55QByteArray SynchronizerStore::resolveRemoteId(const QByteArray &bufferType, const QByteArray &remoteId) 55QByteArray SynchronizerStore::resolveRemoteId(const QByteArray &bufferType, const QByteArray &remoteId)
56{ 56{
57 if (remoteId.isEmpty()) {
58 SinkWarning() << "Cannot resolve empty remote id for type: " << bufferType;
59 return QByteArray();
60 }
57 // Lookup local id for remote id, or insert a new pair otherwise 61 // Lookup local id for remote id, or insert a new pair otherwise
58 Index index("rid.mapping." + bufferType, mTransaction); 62 Index index("rid.mapping." + bufferType, mTransaction);
59 QByteArray sinkId = index.lookup(remoteId); 63 QByteArray sinkId = index.lookup(remoteId);
@@ -96,8 +100,33 @@ QByteArray SynchronizerStore::readValue(const QByteArray &key)
96 return value; 100 return value;
97} 101}
98 102
103QByteArray SynchronizerStore::readValue(const QByteArray &prefix, const QByteArray &key)
104{
105 return readValue(prefix + key);
106}
107
99void SynchronizerStore::writeValue(const QByteArray &key, const QByteArray &value) 108void SynchronizerStore::writeValue(const QByteArray &key, const QByteArray &value)
100{ 109{
101 mTransaction.openDatabase("values").write(key, value); 110 mTransaction.openDatabase("values").write(key, value);
102} 111}
103 112
113void SynchronizerStore::writeValue(const QByteArray &prefix, const QByteArray &key, const QByteArray &value)
114{
115 writeValue(prefix + key, value);
116}
117
118void SynchronizerStore::removeValue(const QByteArray &prefix, const QByteArray &key)
119{
120 mTransaction.openDatabase("values").remove(prefix + key, [&](const Sink::Storage::DataStore::Error &error) {
121 SinkWarning() << "Failed to remove the value: " << prefix + key << error;
122 });
123}
124
125void SynchronizerStore::removePrefix(const QByteArray &prefix)
126{
127 //FIXME remove all values matching prefix
128 // mTransaction.openDatabase("values").remove(prefix, [](const Sink::Storage::DataStore::Error &) {
129 // //Ignore errors because we may not find the value
130 // });
131}
132
diff --git a/common/synchronizerstore.h b/common/synchronizerstore.h
index be33562..8aef68e 100644
--- a/common/synchronizerstore.h
+++ b/common/synchronizerstore.h
@@ -56,8 +56,12 @@ public:
56 QByteArray resolveLocalId(const QByteArray &bufferType, const QByteArray &localId); 56 QByteArray resolveLocalId(const QByteArray &bufferType, const QByteArray &localId);
57 QByteArrayList resolveLocalIds(const QByteArray &bufferType, const QByteArrayList &localId); 57 QByteArrayList resolveLocalIds(const QByteArray &bufferType, const QByteArrayList &localId);
58 58
59 void removePrefix(const QByteArray &prefix);
60 void removeValue(const QByteArray &prefix, const QByteArray &key);
59 QByteArray readValue(const QByteArray &key); 61 QByteArray readValue(const QByteArray &key);
62 QByteArray readValue(const QByteArray &prefix, const QByteArray &key);
60 void writeValue(const QByteArray &key, const QByteArray &value); 63 void writeValue(const QByteArray &key, const QByteArray &value);
64 void writeValue(const QByteArray &prefix, const QByteArray &key, const QByteArray &value);
61 65
62private: 66private:
63 Sink::Storage::DataStore::Transaction &mTransaction; 67 Sink::Storage::DataStore::Transaction &mTransaction;