diff options
Diffstat (limited to 'common/storage_common.cpp')
-rw-r--r-- | common/storage_common.cpp | 78 |
1 files changed, 42 insertions, 36 deletions
diff --git a/common/storage_common.cpp b/common/storage_common.cpp index 0b842d1..2873f5f 100644 --- a/common/storage_common.cpp +++ b/common/storage_common.cpp | |||
@@ -23,8 +23,7 @@ | |||
23 | 23 | ||
24 | #include "log.h" | 24 | #include "log.h" |
25 | 25 | ||
26 | namespace Sink | 26 | namespace Sink { |
27 | { | ||
28 | 27 | ||
29 | static const char *s_internalPrefix = "__internal"; | 28 | static const char *s_internalPrefix = "__internal"; |
30 | static const int s_internalPrefixSize = strlen(s_internalPrefix); | 29 | static const int s_internalPrefixSize = strlen(s_internalPrefix); |
@@ -60,14 +59,16 @@ void Storage::setMaxRevision(Sink::Storage::Transaction &transaction, qint64 rev | |||
60 | qint64 Storage::maxRevision(const Sink::Storage::Transaction &transaction) | 59 | qint64 Storage::maxRevision(const Sink::Storage::Transaction &transaction) |
61 | { | 60 | { |
62 | qint64 r = 0; | 61 | qint64 r = 0; |
63 | transaction.openDatabase().scan("__internal_maxRevision", [&](const QByteArray &, const QByteArray &revision) -> bool { | 62 | transaction.openDatabase().scan("__internal_maxRevision", |
64 | r = revision.toLongLong(); | 63 | [&](const QByteArray &, const QByteArray &revision) -> bool { |
65 | return false; | 64 | r = revision.toLongLong(); |
66 | }, [](const Error &error){ | 65 | return false; |
67 | if (error.code != Sink::Storage::NotFound) { | 66 | }, |
68 | Warning() << "Coultn'd find the maximum revision."; | 67 | [](const Error &error) { |
69 | } | 68 | if (error.code != Sink::Storage::NotFound) { |
70 | }); | 69 | Warning() << "Coultn'd find the maximum revision."; |
70 | } | ||
71 | }); | ||
71 | return r; | 72 | return r; |
72 | } | 73 | } |
73 | 74 | ||
@@ -79,44 +80,48 @@ void Storage::setCleanedUpRevision(Sink::Storage::Transaction &transaction, qint | |||
79 | qint64 Storage::cleanedUpRevision(const Sink::Storage::Transaction &transaction) | 80 | qint64 Storage::cleanedUpRevision(const Sink::Storage::Transaction &transaction) |
80 | { | 81 | { |
81 | qint64 r = 0; | 82 | qint64 r = 0; |
82 | transaction.openDatabase().scan("__internal_cleanedUpRevision", [&](const QByteArray &, const QByteArray &revision) -> bool { | 83 | transaction.openDatabase().scan("__internal_cleanedUpRevision", |
83 | r = revision.toLongLong(); | 84 | [&](const QByteArray &, const QByteArray &revision) -> bool { |
84 | return false; | 85 | r = revision.toLongLong(); |
85 | }, [](const Error &error){ | 86 | return false; |
86 | if (error.code != Sink::Storage::NotFound) { | 87 | }, |
87 | Warning() << "Coultn'd find the maximum revision."; | 88 | [](const Error &error) { |
88 | } | 89 | if (error.code != Sink::Storage::NotFound) { |
89 | }); | 90 | Warning() << "Coultn'd find the maximum revision."; |
91 | } | ||
92 | }); | ||
90 | return r; | 93 | return r; |
91 | } | 94 | } |
92 | 95 | ||
93 | QByteArray Storage::getUidFromRevision(const Sink::Storage::Transaction &transaction, qint64 revision) | 96 | QByteArray Storage::getUidFromRevision(const Sink::Storage::Transaction &transaction, qint64 revision) |
94 | { | 97 | { |
95 | QByteArray uid; | 98 | QByteArray uid; |
96 | transaction.openDatabase("revisions").scan(QByteArray::number(revision), [&](const QByteArray &, const QByteArray &value) -> bool { | 99 | transaction.openDatabase("revisions") |
97 | uid = value; | 100 | .scan(QByteArray::number(revision), |
98 | return false; | 101 | [&](const QByteArray &, const QByteArray &value) -> bool { |
99 | }, [revision](const Error &error){ | 102 | uid = value; |
100 | Warning() << "Coultn'd find uid for revision " << revision; | 103 | return false; |
101 | }); | 104 | }, |
105 | [revision](const Error &error) { Warning() << "Coultn'd find uid for revision " << revision; }); | ||
102 | return uid; | 106 | return uid; |
103 | } | 107 | } |
104 | 108 | ||
105 | QByteArray Storage::getTypeFromRevision(const Sink::Storage::Transaction &transaction, qint64 revision) | 109 | QByteArray Storage::getTypeFromRevision(const Sink::Storage::Transaction &transaction, qint64 revision) |
106 | { | 110 | { |
107 | QByteArray type; | 111 | QByteArray type; |
108 | transaction.openDatabase("revisionType").scan(QByteArray::number(revision), [&](const QByteArray &, const QByteArray &value) -> bool { | 112 | transaction.openDatabase("revisionType") |
109 | type = value; | 113 | .scan(QByteArray::number(revision), |
110 | return false; | 114 | [&](const QByteArray &, const QByteArray &value) -> bool { |
111 | }, [revision](const Error &error){ | 115 | type = value; |
112 | Warning() << "Coultn'd find type for revision " << revision; | 116 | return false; |
113 | }); | 117 | }, |
118 | [revision](const Error &error) { Warning() << "Coultn'd find type for revision " << revision; }); | ||
114 | return type; | 119 | return type; |
115 | } | 120 | } |
116 | 121 | ||
117 | void Storage::recordRevision(Sink::Storage::Transaction &transaction, qint64 revision, const QByteArray &uid, const QByteArray &type) | 122 | void Storage::recordRevision(Sink::Storage::Transaction &transaction, qint64 revision, const QByteArray &uid, const QByteArray &type) |
118 | { | 123 | { |
119 | //TODO use integerkeys | 124 | // TODO use integerkeys |
120 | transaction.openDatabase("revisions").write(QByteArray::number(revision), uid); | 125 | transaction.openDatabase("revisions").write(QByteArray::number(revision), uid); |
121 | transaction.openDatabase("revisionType").write(QByteArray::number(revision), type); | 126 | transaction.openDatabase("revisionType").write(QByteArray::number(revision), type); |
122 | } | 127 | } |
@@ -164,11 +169,12 @@ Storage::NamedDatabase Storage::mainDatabase(const Sink::Storage::Transaction &t | |||
164 | bool Storage::NamedDatabase::contains(const QByteArray &uid) | 169 | bool Storage::NamedDatabase::contains(const QByteArray &uid) |
165 | { | 170 | { |
166 | bool found = false; | 171 | bool found = false; |
167 | scan(uid, [&found](const QByteArray &, const QByteArray &) -> bool { | 172 | scan(uid, |
168 | found = true; | 173 | [&found](const QByteArray &, const QByteArray &) -> bool { |
169 | return false; | 174 | found = true; |
170 | }, [this](const Sink::Storage::Error &error) { | 175 | return false; |
171 | }, true); | 176 | }, |
177 | [this](const Sink::Storage::Error &error) {}, true); | ||
172 | return found; | 178 | return found; |
173 | } | 179 | } |
174 | 180 | ||