diff options
author | Minijackson <minijackson@riseup.net> | 2018-06-26 14:10:30 +0200 |
---|---|---|
committer | Minijackson <minijackson@riseup.net> | 2018-07-04 15:37:14 +0200 |
commit | c90ba4a98292a39eb0b3df12fd7e2dec0300e58d (patch) | |
tree | 0c0c252087e6d8ccf31ba521ea76a7153032f20d | |
parent | 922e0979e2c27ff8dbc765ae151d17c7815b98a0 (diff) | |
download | sink-c90ba4a98292a39eb0b3df12fd7e2dec0300e58d.tar.gz sink-c90ba4a98292a39eb0b3df12fd7e2dec0300e58d.zip |
Move Key API into own files + some fixes
-rw-r--r-- | common/CMakeLists.txt | 1 | ||||
-rw-r--r-- | common/changereplay.cpp | 1 | ||||
-rw-r--r-- | common/storage.h | 148 | ||||
-rw-r--r-- | common/storage/entitystore.cpp | 5 | ||||
-rw-r--r-- | common/storage/entitystore.h | 1 | ||||
-rw-r--r-- | common/storage/key.cpp | 156 | ||||
-rw-r--r-- | common/storage/key.h | 100 | ||||
-rw-r--r-- | common/storage_common.cpp | 18 | ||||
-rw-r--r-- | sinksh/syntax_modules/sink_inspect.cpp | 2 | ||||
-rw-r--r-- | tests/pipelinetest.cpp | 9 | ||||
-rw-r--r-- | tests/querytest.cpp | 38 | ||||
-rw-r--r-- | tests/storagetest.cpp | 1 |
12 files changed, 271 insertions, 209 deletions
diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 970990f..7c4630b 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt | |||
@@ -73,6 +73,7 @@ add_library(${PROJECT_NAME} SHARED | |||
73 | specialpurposepreprocessor.cpp | 73 | specialpurposepreprocessor.cpp |
74 | datastorequery.cpp | 74 | datastorequery.cpp |
75 | storage/entitystore.cpp | 75 | storage/entitystore.cpp |
76 | storage/key.cpp | ||
76 | indexer.cpp | 77 | indexer.cpp |
77 | mail/threadindexer.cpp | 78 | mail/threadindexer.cpp |
78 | mail/fulltextindexer.cpp | 79 | mail/fulltextindexer.cpp |
diff --git a/common/changereplay.cpp b/common/changereplay.cpp index e81f52c..e94ed80 100644 --- a/common/changereplay.cpp +++ b/common/changereplay.cpp | |||
@@ -23,6 +23,7 @@ | |||
23 | #include "log.h" | 23 | #include "log.h" |
24 | #include "definitions.h" | 24 | #include "definitions.h" |
25 | #include "bufferutils.h" | 25 | #include "bufferutils.h" |
26 | #include "storage/key.h" | ||
26 | 27 | ||
27 | #include <QTimer> | 28 | #include <QTimer> |
28 | 29 | ||
diff --git a/common/storage.h b/common/storage.h index 3cc5adf..25d0fa6 100644 --- a/common/storage.h +++ b/common/storage.h | |||
@@ -40,151 +40,6 @@ struct SINK_EXPORT DbLayout { | |||
40 | Databases tables; | 40 | Databases tables; |
41 | }; | 41 | }; |
42 | 42 | ||
43 | class Identifier | ||
44 | { | ||
45 | public: | ||
46 | // RFC 4122 Section 4.1.2 says 128 bits -> 16 bytes | ||
47 | static const constexpr size_t INTERNAL_REPR_SIZE = 16; | ||
48 | static const constexpr size_t DISPLAY_REPR_SIZE = 38; | ||
49 | |||
50 | Identifier() : uid(QUuid::createUuid()) {}; | ||
51 | |||
52 | QByteArray toInternalByteArray() const | ||
53 | { | ||
54 | return uid.toRfc4122(); | ||
55 | } | ||
56 | |||
57 | static Identifier fromInternalByteArray(const QByteArray &bytes) | ||
58 | { | ||
59 | Q_ASSERT(bytes.size() == INTERNAL_REPR_SIZE); | ||
60 | return Identifier(QUuid::fromRfc4122(bytes)); | ||
61 | } | ||
62 | |||
63 | QString toDisplayString() const | ||
64 | { | ||
65 | return uid.toString(); | ||
66 | } | ||
67 | |||
68 | QByteArray toDisplayByteArray() const | ||
69 | { | ||
70 | return uid.toByteArray(); | ||
71 | } | ||
72 | |||
73 | static Identifier fromDisplayByteArray(const QByteArray &bytes) | ||
74 | { | ||
75 | Q_ASSERT(bytes.size() == DISPLAY_REPR_SIZE); | ||
76 | return Identifier(QUuid::fromString(QString::fromUtf8(bytes))); | ||
77 | } | ||
78 | |||
79 | private: | ||
80 | explicit Identifier(const QUuid &uid) : uid(uid) {} | ||
81 | QUuid uid; | ||
82 | }; | ||
83 | |||
84 | class Revision | ||
85 | { | ||
86 | public: | ||
87 | // qint64 has a 19 digit decimal representation | ||
88 | static const constexpr size_t INTERNAL_REPR_SIZE = 19; | ||
89 | static const constexpr size_t DISPLAY_REPR_SIZE = 19; | ||
90 | |||
91 | Revision(qint64 rev) : rev(rev) {} | ||
92 | |||
93 | QByteArray toInternalByteArray() const | ||
94 | { | ||
95 | return padNumber(rev); | ||
96 | } | ||
97 | |||
98 | static Revision fromInternalByteArray(const QByteArray &bytes) | ||
99 | { | ||
100 | Q_ASSERT(bytes.size() == INTERNAL_REPR_SIZE); | ||
101 | return Revision(bytes.toLongLong()); | ||
102 | } | ||
103 | |||
104 | QString toDisplayString() const | ||
105 | { | ||
106 | return QString::fromUtf8(toInternalByteArray()); | ||
107 | } | ||
108 | |||
109 | QByteArray toDisplayByteArray() const | ||
110 | { | ||
111 | return toInternalByteArray(); | ||
112 | } | ||
113 | |||
114 | static Revision fromDisplayByteArray(const QByteArray &bytes) | ||
115 | { | ||
116 | Q_ASSERT(bytes.size() == DISPLAY_REPR_SIZE); | ||
117 | return fromInternalByteArray(bytes); | ||
118 | } | ||
119 | |||
120 | qint64 toQint64() const | ||
121 | { | ||
122 | return rev; | ||
123 | } | ||
124 | |||
125 | private: | ||
126 | qint64 rev; | ||
127 | }; | ||
128 | |||
129 | class Key | ||
130 | { | ||
131 | public: | ||
132 | static const constexpr size_t INTERNAL_REPR_SIZE = Identifier::INTERNAL_REPR_SIZE + Revision::INTERNAL_REPR_SIZE; | ||
133 | static const constexpr size_t DISPLAY_REPR_SIZE = Identifier::DISPLAY_REPR_SIZE + Revision::DISPLAY_REPR_SIZE; | ||
134 | |||
135 | Key(const Identifier &id, const Revision &rev) : id(id), rev(rev) {} | ||
136 | |||
137 | QByteArray toInternalByteArray() const | ||
138 | { | ||
139 | return id.toInternalByteArray() + rev.toInternalByteArray(); | ||
140 | } | ||
141 | |||
142 | static Key fromInternalByteArray(const QByteArray &bytes) | ||
143 | { | ||
144 | Q_ASSERT(bytes.size() == INTERNAL_REPR_SIZE); | ||
145 | auto idBytes = bytes.mid(0, Identifier::INTERNAL_REPR_SIZE); | ||
146 | auto revBytes = bytes.mid(Identifier::INTERNAL_REPR_SIZE); | ||
147 | return Key(Identifier::fromInternalByteArray(idBytes), Revision::fromInternalByteArray(revBytes)); | ||
148 | } | ||
149 | |||
150 | QString toDisplayString() const | ||
151 | { | ||
152 | return id.toDisplayString() + rev.toDisplayString(); | ||
153 | } | ||
154 | |||
155 | QByteArray toDisplayByteArray() const | ||
156 | { | ||
157 | return id.toDisplayByteArray() + rev.toDisplayByteArray(); | ||
158 | } | ||
159 | |||
160 | static Key fromDisplayByteArray(const QByteArray &bytes) | ||
161 | { | ||
162 | Q_ASSERT(bytes.size() == DISPLAY_REPR_SIZE); | ||
163 | auto idBytes = bytes.mid(0, Identifier::DISPLAY_REPR_SIZE); | ||
164 | auto revBytes = bytes.mid(Identifier::DISPLAY_REPR_SIZE); | ||
165 | return Key(Identifier::fromDisplayByteArray(idBytes), Revision::fromDisplayByteArray(revBytes)); | ||
166 | } | ||
167 | |||
168 | const Identifier &identifier() const | ||
169 | { | ||
170 | return id; | ||
171 | } | ||
172 | |||
173 | const Revision &revision() const | ||
174 | { | ||
175 | return rev; | ||
176 | } | ||
177 | |||
178 | void setRevision(const Revision &newRev) | ||
179 | { | ||
180 | rev = newRev; | ||
181 | } | ||
182 | |||
183 | private: | ||
184 | Identifier id; | ||
185 | Revision rev; | ||
186 | }; | ||
187 | |||
188 | class SINK_EXPORT DataStore | 43 | class SINK_EXPORT DataStore |
189 | { | 44 | { |
190 | public: | 45 | public: |
@@ -407,6 +262,3 @@ private: | |||
407 | } // namespace Sink | 262 | } // namespace Sink |
408 | 263 | ||
409 | SINK_EXPORT QDebug& operator<<(QDebug &dbg, const Sink::Storage::DataStore::Error &error); | 264 | SINK_EXPORT QDebug& operator<<(QDebug &dbg, const Sink::Storage::DataStore::Error &error); |
410 | SINK_EXPORT QDebug& operator<<(QDebug &dbg, const Sink::Storage::Identifier &); | ||
411 | SINK_EXPORT QDebug& operator<<(QDebug &dbg, const Sink::Storage::Revision &); | ||
412 | SINK_EXPORT QDebug& operator<<(QDebug &dbg, const Sink::Storage::Key &); | ||
diff --git a/common/storage/entitystore.cpp b/common/storage/entitystore.cpp index f74d3df..efafe8a 100644 --- a/common/storage/entitystore.cpp +++ b/common/storage/entitystore.cpp | |||
@@ -678,9 +678,10 @@ void EntityStore::readRevisions(const QByteArray &type, const QByteArray &uid, q | |||
678 | DataStore::mainDatabase(d->transaction, type) | 678 | DataStore::mainDatabase(d->transaction, type) |
679 | .scan(uid, | 679 | .scan(uid, |
680 | [&](const QByteArray &key, const QByteArray &value) -> bool { | 680 | [&](const QByteArray &key, const QByteArray &value) -> bool { |
681 | const auto revision = DataStore::revisionFromKey(key); | 681 | const auto parsedKey = Key::fromDisplayByteArray(key); |
682 | const auto revision = parsedKey.revision().toQint64(); | ||
682 | if (revision >= startingRevision) { | 683 | if (revision >= startingRevision) { |
683 | callback(DataStore::uidFromKey(key), revision, Sink::EntityBuffer(value.data(), value.size())); | 684 | callback(parsedKey.identifier().toDisplayByteArray(), revision, Sink::EntityBuffer(value.data(), value.size())); |
684 | } | 685 | } |
685 | return true; | 686 | return true; |
686 | }, | 687 | }, |
diff --git a/common/storage/entitystore.h b/common/storage/entitystore.h index 69de76c..1dcd285 100644 --- a/common/storage/entitystore.h +++ b/common/storage/entitystore.h | |||
@@ -25,6 +25,7 @@ | |||
25 | #include "domaintypeadaptorfactoryinterface.h" | 25 | #include "domaintypeadaptorfactoryinterface.h" |
26 | #include "query.h" | 26 | #include "query.h" |
27 | #include "storage.h" | 27 | #include "storage.h" |
28 | #include "key.h" | ||
28 | #include "resourcecontext.h" | 29 | #include "resourcecontext.h" |
29 | #include "metadata_generated.h" | 30 | #include "metadata_generated.h" |
30 | 31 | ||
diff --git a/common/storage/key.cpp b/common/storage/key.cpp new file mode 100644 index 0000000..5d26722 --- /dev/null +++ b/common/storage/key.cpp | |||
@@ -0,0 +1,156 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2014 Christian Mollekopf <chrigi_1@fastmail.fm> | ||
3 | * Copyright (C) 2018 Rémi Nicole <minijackson@riseup.net> | ||
4 | * | ||
5 | * This library is free software; you can redistribute it and/or | ||
6 | * modify it under the terms of the GNU Lesser General Public | ||
7 | * License as published by the Free Software Foundation; either | ||
8 | * version 2.1 of the License, or (at your option) version 3, or any | ||
9 | * later version accepted by the membership of KDE e.V. (or its | ||
10 | * successor approved by the membership of KDE e.V.), which shall | ||
11 | * act as a proxy defined in Section 6 of version 3 of the license. | ||
12 | * | ||
13 | * This library is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
16 | * Lesser General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU Lesser General Public | ||
19 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
20 | */ | ||
21 | |||
22 | #include "key.h" | ||
23 | #include "utils.h" | ||
24 | |||
25 | using Sink::Storage::Identifier; | ||
26 | using Sink::Storage::Key; | ||
27 | using Sink::Storage::Revision; | ||
28 | |||
29 | QDebug &operator<<(QDebug &dbg, const Identifier &id) | ||
30 | { | ||
31 | dbg << id.toDisplayString(); | ||
32 | return dbg; | ||
33 | } | ||
34 | |||
35 | QDebug &operator<<(QDebug &dbg, const Revision &rev) | ||
36 | { | ||
37 | dbg << rev.toDisplayString(); | ||
38 | return dbg; | ||
39 | } | ||
40 | |||
41 | QDebug &operator<<(QDebug &dbg, const Key &key) | ||
42 | { | ||
43 | dbg << key.toDisplayString(); | ||
44 | return dbg; | ||
45 | } | ||
46 | |||
47 | // Identifier | ||
48 | |||
49 | QByteArray Identifier::toInternalByteArray() const | ||
50 | { | ||
51 | return uid.toRfc4122(); | ||
52 | } | ||
53 | |||
54 | Identifier Identifier::fromInternalByteArray(const QByteArray &bytes) | ||
55 | { | ||
56 | Q_ASSERT(bytes.size() == INTERNAL_REPR_SIZE); | ||
57 | return Identifier(QUuid::fromRfc4122(bytes)); | ||
58 | } | ||
59 | |||
60 | QString Identifier::toDisplayString() const | ||
61 | { | ||
62 | return uid.toString(); | ||
63 | } | ||
64 | |||
65 | QByteArray Identifier::toDisplayByteArray() const | ||
66 | { | ||
67 | return uid.toByteArray(); | ||
68 | } | ||
69 | |||
70 | Identifier Identifier::fromDisplayByteArray(const QByteArray &bytes) | ||
71 | { | ||
72 | Q_ASSERT(bytes.size() == DISPLAY_REPR_SIZE); | ||
73 | return Identifier(QUuid::fromString(QString::fromUtf8(bytes))); | ||
74 | } | ||
75 | |||
76 | // Revision | ||
77 | |||
78 | QByteArray Revision::toInternalByteArray() const | ||
79 | { | ||
80 | return padNumber(rev); | ||
81 | } | ||
82 | |||
83 | Revision Revision::fromInternalByteArray(const QByteArray &bytes) | ||
84 | { | ||
85 | Q_ASSERT(bytes.size() == INTERNAL_REPR_SIZE); | ||
86 | return Revision(bytes.toLongLong()); | ||
87 | } | ||
88 | |||
89 | QString Revision::toDisplayString() const | ||
90 | { | ||
91 | return QString::fromUtf8(toInternalByteArray()); | ||
92 | } | ||
93 | |||
94 | QByteArray Revision::toDisplayByteArray() const | ||
95 | { | ||
96 | return toInternalByteArray(); | ||
97 | } | ||
98 | |||
99 | Revision Revision::fromDisplayByteArray(const QByteArray &bytes) | ||
100 | { | ||
101 | Q_ASSERT(bytes.size() == DISPLAY_REPR_SIZE); | ||
102 | return fromInternalByteArray(bytes); | ||
103 | } | ||
104 | |||
105 | qint64 Revision::toQint64() const | ||
106 | { | ||
107 | return rev; | ||
108 | } | ||
109 | |||
110 | // Key | ||
111 | |||
112 | QByteArray Key::toInternalByteArray() const | ||
113 | { | ||
114 | return id.toInternalByteArray() + rev.toInternalByteArray(); | ||
115 | } | ||
116 | |||
117 | Key Key::fromInternalByteArray(const QByteArray &bytes) | ||
118 | { | ||
119 | Q_ASSERT(bytes.size() == INTERNAL_REPR_SIZE); | ||
120 | auto idBytes = bytes.mid(0, Identifier::INTERNAL_REPR_SIZE); | ||
121 | auto revBytes = bytes.mid(Identifier::INTERNAL_REPR_SIZE); | ||
122 | return Key(Identifier::fromInternalByteArray(idBytes), Revision::fromInternalByteArray(revBytes)); | ||
123 | } | ||
124 | |||
125 | QString Key::toDisplayString() const | ||
126 | { | ||
127 | return id.toDisplayString() + rev.toDisplayString(); | ||
128 | } | ||
129 | |||
130 | QByteArray Key::toDisplayByteArray() const | ||
131 | { | ||
132 | return id.toDisplayByteArray() + rev.toDisplayByteArray(); | ||
133 | } | ||
134 | |||
135 | Key Key::fromDisplayByteArray(const QByteArray &bytes) | ||
136 | { | ||
137 | Q_ASSERT(bytes.size() == DISPLAY_REPR_SIZE); | ||
138 | auto idBytes = bytes.mid(0, Identifier::DISPLAY_REPR_SIZE); | ||
139 | auto revBytes = bytes.mid(Identifier::DISPLAY_REPR_SIZE); | ||
140 | return Key(Identifier::fromDisplayByteArray(idBytes), Revision::fromDisplayByteArray(revBytes)); | ||
141 | } | ||
142 | |||
143 | const Identifier &Key::identifier() const | ||
144 | { | ||
145 | return id; | ||
146 | } | ||
147 | |||
148 | const Revision &Key::revision() const | ||
149 | { | ||
150 | return rev; | ||
151 | } | ||
152 | |||
153 | void Key::setRevision(const Revision &newRev) | ||
154 | { | ||
155 | rev = newRev; | ||
156 | } | ||
diff --git a/common/storage/key.h b/common/storage/key.h new file mode 100644 index 0000000..76dbd13 --- /dev/null +++ b/common/storage/key.h | |||
@@ -0,0 +1,100 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2014 Christian Mollekopf <chrigi_1@fastmail.fm> | ||
3 | * Copyright (C) 2018 Rémi Nicole <minijackson@riseup.net> | ||
4 | * | ||
5 | * This library is free software; you can redistribute it and/or | ||
6 | * modify it under the terms of the GNU Lesser General Public | ||
7 | * License as published by the Free Software Foundation; either | ||
8 | * version 2.1 of the License, or (at your option) version 3, or any | ||
9 | * later version accepted by the membership of KDE e.V. (or its | ||
10 | * successor approved by the membership of KDE e.V.), which shall | ||
11 | * act as a proxy defined in Section 6 of version 3 of the license. | ||
12 | * | ||
13 | * This library is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
16 | * Lesser General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU Lesser General Public | ||
19 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
20 | */ | ||
21 | |||
22 | #pragma once | ||
23 | |||
24 | #include "sink_export.h" | ||
25 | |||
26 | #include <QByteArray> | ||
27 | #include <QDebug> | ||
28 | #include <QUuid> | ||
29 | |||
30 | namespace Sink { | ||
31 | namespace Storage { | ||
32 | |||
33 | class Identifier | ||
34 | { | ||
35 | public: | ||
36 | // RFC 4122 Section 4.1.2 says 128 bits -> 16 bytes | ||
37 | static const constexpr size_t INTERNAL_REPR_SIZE = 16; | ||
38 | static const constexpr size_t DISPLAY_REPR_SIZE = 38; | ||
39 | |||
40 | Identifier() : uid(QUuid::createUuid()){}; | ||
41 | |||
42 | QByteArray toInternalByteArray() const; | ||
43 | static Identifier fromInternalByteArray(const QByteArray &bytes); | ||
44 | QString toDisplayString() const; | ||
45 | QByteArray toDisplayByteArray() const; | ||
46 | static Identifier fromDisplayByteArray(const QByteArray &bytes); | ||
47 | |||
48 | private: | ||
49 | explicit Identifier(const QUuid &uid) : uid(uid) {} | ||
50 | QUuid uid; | ||
51 | }; | ||
52 | |||
53 | class Revision | ||
54 | { | ||
55 | public: | ||
56 | // qint64 has a 19 digit decimal representation | ||
57 | static const constexpr size_t INTERNAL_REPR_SIZE = 19; | ||
58 | static const constexpr size_t DISPLAY_REPR_SIZE = 19; | ||
59 | |||
60 | Revision(qint64 rev) : rev(rev) {} | ||
61 | |||
62 | QByteArray toInternalByteArray() const; | ||
63 | static Revision fromInternalByteArray(const QByteArray &bytes); | ||
64 | QString toDisplayString() const; | ||
65 | QByteArray toDisplayByteArray() const; | ||
66 | static Revision fromDisplayByteArray(const QByteArray &bytes); | ||
67 | qint64 toQint64() const; | ||
68 | |||
69 | private: | ||
70 | qint64 rev; | ||
71 | }; | ||
72 | |||
73 | class Key | ||
74 | { | ||
75 | public: | ||
76 | static const constexpr size_t INTERNAL_REPR_SIZE = Identifier::INTERNAL_REPR_SIZE + Revision::INTERNAL_REPR_SIZE; | ||
77 | static const constexpr size_t DISPLAY_REPR_SIZE = Identifier::DISPLAY_REPR_SIZE + Revision::DISPLAY_REPR_SIZE; | ||
78 | |||
79 | Key(const Identifier &id, const Revision &rev) : id(id), rev(rev) {} | ||
80 | |||
81 | QByteArray toInternalByteArray() const; | ||
82 | static Key fromInternalByteArray(const QByteArray &bytes); | ||
83 | QString toDisplayString() const; | ||
84 | QByteArray toDisplayByteArray() const; | ||
85 | static Key fromDisplayByteArray(const QByteArray &bytes); | ||
86 | const Identifier &identifier() const; | ||
87 | const Revision &revision() const; | ||
88 | void setRevision(const Revision &newRev); | ||
89 | |||
90 | private: | ||
91 | Identifier id; | ||
92 | Revision rev; | ||
93 | }; | ||
94 | |||
95 | } // namespace Storage | ||
96 | } // namespace Sink | ||
97 | |||
98 | SINK_EXPORT QDebug& operator<<(QDebug &dbg, const Sink::Storage::Identifier &); | ||
99 | SINK_EXPORT QDebug& operator<<(QDebug &dbg, const Sink::Storage::Revision &); | ||
100 | SINK_EXPORT QDebug& operator<<(QDebug &dbg, const Sink::Storage::Key &); | ||
diff --git a/common/storage_common.cpp b/common/storage_common.cpp index b36ffcb..c922d9d 100644 --- a/common/storage_common.cpp +++ b/common/storage_common.cpp | |||
@@ -32,24 +32,6 @@ QDebug& operator<<(QDebug &dbg, const Sink::Storage::DataStore::Error &error) | |||
32 | return dbg; | 32 | return dbg; |
33 | } | 33 | } |
34 | 34 | ||
35 | QDebug& operator<<(QDebug &dbg, const Sink::Storage::Identifier &id) | ||
36 | { | ||
37 | dbg << id.toDisplayString(); | ||
38 | return dbg; | ||
39 | } | ||
40 | |||
41 | QDebug& operator<<(QDebug &dbg, const Sink::Storage::Revision &rev) | ||
42 | { | ||
43 | dbg << rev.toDisplayString(); | ||
44 | return dbg; | ||
45 | } | ||
46 | |||
47 | QDebug& operator<<(QDebug &dbg, const Sink::Storage::Key &key) | ||
48 | { | ||
49 | dbg << key.toDisplayString(); | ||
50 | return dbg; | ||
51 | } | ||
52 | |||
53 | namespace Sink { | 35 | namespace Sink { |
54 | namespace Storage { | 36 | namespace Storage { |
55 | 37 | ||
diff --git a/sinksh/syntax_modules/sink_inspect.cpp b/sinksh/syntax_modules/sink_inspect.cpp index b496fe6..019ef31 100644 --- a/sinksh/syntax_modules/sink_inspect.cpp +++ b/sinksh/syntax_modules/sink_inspect.cpp | |||
@@ -34,6 +34,8 @@ | |||
34 | #include "common/metadata_generated.h" | 34 | #include "common/metadata_generated.h" |
35 | #include "common/bufferutils.h" | 35 | #include "common/bufferutils.h" |
36 | 36 | ||
37 | #include "storage/key.h" | ||
38 | |||
37 | #include "sinksh_utils.h" | 39 | #include "sinksh_utils.h" |
38 | #include "state.h" | 40 | #include "state.h" |
39 | #include "syntaxtree.h" | 41 | #include "syntaxtree.h" |
diff --git a/tests/pipelinetest.cpp b/tests/pipelinetest.cpp index 7431deb..5165d35 100644 --- a/tests/pipelinetest.cpp +++ b/tests/pipelinetest.cpp | |||
@@ -20,6 +20,7 @@ | |||
20 | #include "domainadaptor.h" | 20 | #include "domainadaptor.h" |
21 | #include "definitions.h" | 21 | #include "definitions.h" |
22 | #include "adaptorfactoryregistry.h" | 22 | #include "adaptorfactoryregistry.h" |
23 | #include "storage/key.h" | ||
23 | 24 | ||
24 | static void removeFromDisk(const QString &name) | 25 | static void removeFromDisk(const QString &name) |
25 | { | 26 | { |
@@ -430,8 +431,8 @@ private slots: | |||
430 | // Get uid of written entity | 431 | // Get uid of written entity |
431 | auto keys = getKeys(instanceIdentifier(), "event.main"); | 432 | auto keys = getKeys(instanceIdentifier(), "event.main"); |
432 | QCOMPARE(keys.size(), 1); | 433 | QCOMPARE(keys.size(), 1); |
433 | const auto key = keys.first(); | 434 | auto key = Sink::Storage::Key::fromInternalByteArray(keys.first()); |
434 | const auto uid = Sink::Storage::DataStore::uidFromKey(key); | 435 | const auto uid = key.identifier().toDisplayByteArray(); |
435 | 436 | ||
436 | //Simulate local modification | 437 | //Simulate local modification |
437 | { | 438 | { |
@@ -453,8 +454,10 @@ private slots: | |||
453 | pipeline.commit(); | 454 | pipeline.commit(); |
454 | } | 455 | } |
455 | 456 | ||
457 | key.setRevision(3); | ||
458 | |||
456 | // Ensure we've got the new revision with the modification | 459 | // Ensure we've got the new revision with the modification |
457 | auto buffer = getEntity(instanceIdentifier(), "event.main", Sink::Storage::DataStore::assembleKey(uid, 3)); | 460 | auto buffer = getEntity(instanceIdentifier(), "event.main", key.toInternalByteArray()); |
458 | QVERIFY(!buffer.isEmpty()); | 461 | QVERIFY(!buffer.isEmpty()); |
459 | Sink::EntityBuffer entityBuffer(buffer.data(), buffer.size()); | 462 | Sink::EntityBuffer entityBuffer(buffer.data(), buffer.size()); |
460 | auto adaptor = adaptorFactory->createAdaptor(entityBuffer.entity()); | 463 | auto adaptor = adaptorFactory->createAdaptor(entityBuffer.entity()); |
diff --git a/tests/querytest.cpp b/tests/querytest.cpp index 41ce40c..7685086 100644 --- a/tests/querytest.cpp +++ b/tests/querytest.cpp | |||
@@ -1823,44 +1823,6 @@ private slots: | |||
1823 | 1823 | ||
1824 | } | 1824 | } |
1825 | 1825 | ||
1826 | void testOverlapLive() | ||
1827 | { | ||
1828 | eventsWithDates(); | ||
1829 | |||
1830 | { | ||
1831 | Sink::Query query; | ||
1832 | query.resourceFilter("sink.dummy.instance1"); | ||
1833 | query.setFlags(Query::LiveQuery); | ||
1834 | query.filter<Event::StartTime, Event::EndTime>(QueryBase::Comparator( | ||
1835 | QVariantList{ QDateTime::fromString("2018-05-22T12:00:00Z", Qt::ISODate), | ||
1836 | QDateTime::fromString("2018-05-30T13:00:00Z", Qt::ISODate) }, | ||
1837 | QueryBase::Comparator::Overlap)); | ||
1838 | auto model = Sink::Store::loadModel<Event>(query); | ||
1839 | QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); | ||
1840 | QCOMPARE(model->rowCount(), 5); | ||
1841 | |||
1842 | Event event = Event::createEntity<Event>("sink.dummy.instance1"); | ||
1843 | event.setExtractedStartTime(QDateTime::fromString("2018-05-23T12:00:00Z", Qt::ISODate)); | ||
1844 | event.setExtractedEndTime(QDateTime::fromString("2018-05-23T13:00:00Z", Qt::ISODate)); | ||
1845 | VERIFYEXEC(Sink::Store::create<Event>(event)); | ||
1846 | |||
1847 | Event event2 = Event::createEntity<Event>("sink.dummy.instance1"); | ||
1848 | event2.setExtractedStartTime(QDateTime::fromString("2018-05-33T12:00:00Z", Qt::ISODate)); | ||
1849 | event2.setExtractedEndTime(QDateTime::fromString("2018-05-33T13:00:00Z", Qt::ISODate)); | ||
1850 | VERIFYEXEC(Sink::Store::create<Event>(event2)); | ||
1851 | |||
1852 | QTest::qWait(500); | ||
1853 | QCOMPARE(model->rowCount(), 6); | ||
1854 | |||
1855 | VERIFYEXEC(Sink::Store::remove<Event>(event)); | ||
1856 | VERIFYEXEC(Sink::Store::remove<Event>(event2)); | ||
1857 | |||
1858 | QTest::qWait(500); | ||
1859 | QCOMPARE(model->rowCount(), 5); | ||
1860 | } | ||
1861 | |||
1862 | } | ||
1863 | |||
1864 | }; | 1826 | }; |
1865 | 1827 | ||
1866 | QTEST_MAIN(QueryTest) | 1828 | QTEST_MAIN(QueryTest) |
diff --git a/tests/storagetest.cpp b/tests/storagetest.cpp index 40492f0..d3f180a 100644 --- a/tests/storagetest.cpp +++ b/tests/storagetest.cpp | |||
@@ -7,6 +7,7 @@ | |||
7 | #include <QtConcurrent/QtConcurrentRun> | 7 | #include <QtConcurrent/QtConcurrentRun> |
8 | 8 | ||
9 | #include "common/storage.h" | 9 | #include "common/storage.h" |
10 | #include "storage/key.h" | ||
10 | 11 | ||
11 | /** | 12 | /** |
12 | * Test of the storage implementation to ensure it can do the low level operations as expected. | 13 | * Test of the storage implementation to ensure it can do the low level operations as expected. |