diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-10-06 10:21:15 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-10-06 10:36:36 +0200 |
commit | f1e496f7c12ebc787ed47a4c048015f2098e65d9 (patch) | |
tree | ab903283757f4a19b4957992316a1eed4276091f | |
parent | c9a99b4f544adb3ae7eef8f07e0b52b714d919b1 (diff) | |
download | sink-f1e496f7c12ebc787ed47a4c048015f2098e65d9.tar.gz sink-f1e496f7c12ebc787ed47a4c048015f2098e65d9.zip |
Moved standard quries to a separate header.
-rw-r--r-- | common/CMakeLists.txt | 1 | ||||
-rw-r--r-- | common/query.h | 46 | ||||
-rw-r--r-- | common/standardqueries.h | 69 | ||||
-rw-r--r-- | tests/mailthreadtest.cpp | 5 |
4 files changed, 74 insertions, 47 deletions
diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 0fc8d81..84fe474 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt | |||
@@ -123,6 +123,7 @@ install(FILES | |||
123 | resourcecontrol.h | 123 | resourcecontrol.h |
124 | domain/applicationdomaintype.h | 124 | domain/applicationdomaintype.h |
125 | query.h | 125 | query.h |
126 | standardqueries.h | ||
126 | inspection.h | 127 | inspection.h |
127 | notification.h | 128 | notification.h |
128 | bufferadaptor.h | 129 | bufferadaptor.h |
diff --git a/common/query.h b/common/query.h index 85307aa..00ae086 100644 --- a/common/query.h +++ b/common/query.h | |||
@@ -59,7 +59,6 @@ public: | |||
59 | Comparators comparator; | 59 | Comparators comparator; |
60 | }; | 60 | }; |
61 | 61 | ||
62 | |||
63 | template <typename T> | 62 | template <typename T> |
64 | Query &request() | 63 | Query &request() |
65 | { | 64 | { |
@@ -289,7 +288,7 @@ public: | |||
289 | * a result set is generated containing all entries with the same value. | 288 | * a result set is generated containing all entries with the same value. |
290 | * | 289 | * |
291 | * Example: | 290 | * Example: |
292 | * For an input result set of one mail; return all emails with the same threadId. | 291 | * For an input set of one mail; return all emails with the same threadId. |
293 | */ | 292 | */ |
294 | class Bloom : public FilterStage { | 293 | class Bloom : public FilterStage { |
295 | public: | 294 | public: |
@@ -308,49 +307,6 @@ public: | |||
308 | mFilterStages << bloom; | 307 | mFilterStages << bloom; |
309 | } | 308 | } |
310 | 309 | ||
311 | //Query fixtures | ||
312 | |||
313 | /** | ||
314 | * Returns the complete thread, containing all mails from all folders. | ||
315 | */ | ||
316 | static Query completeThread(const ApplicationDomain::Mail &mail) | ||
317 | { | ||
318 | Sink::Query query; | ||
319 | if (!mail.resourceInstanceIdentifier().isEmpty()) { | ||
320 | query.resourceFilter(mail.resourceInstanceIdentifier()); | ||
321 | } | ||
322 | query.filter(mail.identifier()); | ||
323 | query.sort<ApplicationDomain::Mail::Date>(); | ||
324 | query.bloom<ApplicationDomain::Mail::ThreadId>(); | ||
325 | return query; | ||
326 | } | ||
327 | |||
328 | /** | ||
329 | * Returns thread leaders only, sorted by date. | ||
330 | */ | ||
331 | static Query threadLeaders(const ApplicationDomain::Folder &folder) | ||
332 | { | ||
333 | Sink::Query query; | ||
334 | if (!folder.resourceInstanceIdentifier().isEmpty()) { | ||
335 | query.resourceFilter(folder.resourceInstanceIdentifier()); | ||
336 | } | ||
337 | query.filter<ApplicationDomain::Mail::Folder>(folder); | ||
338 | query.sort<ApplicationDomain::Mail::Date>(); | ||
339 | query.reduce<ApplicationDomain::Mail::ThreadId>(Query::Reduce::Selector::max<ApplicationDomain::Mail::Date>()); | ||
340 | return query; | ||
341 | } | ||
342 | |||
343 | /** | ||
344 | * Outgoing mails. | ||
345 | */ | ||
346 | static Query outboxMails() | ||
347 | { | ||
348 | Sink::Query query; | ||
349 | query.resourceContainsFilter<ApplicationDomain::SinkResource::Capabilities>(ApplicationDomain::ResourceCapabilities::Mail::transport); | ||
350 | query.sort<ApplicationDomain::Mail::Date>(); | ||
351 | return query; | ||
352 | } | ||
353 | |||
354 | private: | 310 | private: |
355 | Filter mResourceFilter; | 311 | Filter mResourceFilter; |
356 | Filter mBaseFilterStage; | 312 | Filter mBaseFilterStage; |
diff --git a/common/standardqueries.h b/common/standardqueries.h new file mode 100644 index 0000000..06ce396 --- /dev/null +++ b/common/standardqueries.h | |||
@@ -0,0 +1,69 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2016 Christian Mollekopf <chrigi_1@fastmail.fm> | ||
3 | * | ||
4 | * This library is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU Lesser General Public | ||
6 | * License as published by the Free Software Foundation; either | ||
7 | * version 2.1 of the License, or (at your option) version 3, or any | ||
8 | * later version accepted by the membership of KDE e.V. (or its | ||
9 | * successor approved by the membership of KDE e.V.), which shall | ||
10 | * act as a proxy defined in Section 6 of version 3 of the license. | ||
11 | * | ||
12 | * This library is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | * Lesser General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU Lesser General Public | ||
18 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
19 | */ | ||
20 | #pragma once | ||
21 | |||
22 | #include "query.h" | ||
23 | |||
24 | namespace Sink { | ||
25 | namespace StandardQueries { | ||
26 | |||
27 | /** | ||
28 | * Returns the complete thread, containing all mails from all folders. | ||
29 | */ | ||
30 | static Query completeThread(const ApplicationDomain::Mail &mail) | ||
31 | { | ||
32 | Sink::Query query; | ||
33 | if (!mail.resourceInstanceIdentifier().isEmpty()) { | ||
34 | query.resourceFilter(mail.resourceInstanceIdentifier()); | ||
35 | } | ||
36 | query.filter(mail.identifier()); | ||
37 | query.sort<ApplicationDomain::Mail::Date>(); | ||
38 | query.bloom<ApplicationDomain::Mail::ThreadId>(); | ||
39 | return query; | ||
40 | } | ||
41 | |||
42 | /** | ||
43 | * Returns thread leaders only, sorted by date. | ||
44 | */ | ||
45 | static Query threadLeaders(const ApplicationDomain::Folder &folder) | ||
46 | { | ||
47 | Sink::Query query; | ||
48 | if (!folder.resourceInstanceIdentifier().isEmpty()) { | ||
49 | query.resourceFilter(folder.resourceInstanceIdentifier()); | ||
50 | } | ||
51 | query.filter<ApplicationDomain::Mail::Folder>(folder); | ||
52 | query.sort<ApplicationDomain::Mail::Date>(); | ||
53 | query.reduce<ApplicationDomain::Mail::ThreadId>(Query::Reduce::Selector::max<ApplicationDomain::Mail::Date>()); | ||
54 | return query; | ||
55 | } | ||
56 | |||
57 | /** | ||
58 | * Outgoing mails. | ||
59 | */ | ||
60 | static Query outboxMails() | ||
61 | { | ||
62 | Sink::Query query; | ||
63 | query.resourceContainsFilter<ApplicationDomain::SinkResource::Capabilities>(ApplicationDomain::ResourceCapabilities::Mail::transport); | ||
64 | query.sort<ApplicationDomain::Mail::Date>(); | ||
65 | return query; | ||
66 | } | ||
67 | |||
68 | } | ||
69 | } | ||
diff --git a/tests/mailthreadtest.cpp b/tests/mailthreadtest.cpp index b6b0da2..9e5e911 100644 --- a/tests/mailthreadtest.cpp +++ b/tests/mailthreadtest.cpp | |||
@@ -27,6 +27,7 @@ | |||
27 | #include "resourcecontrol.h" | 27 | #include "resourcecontrol.h" |
28 | #include "log.h" | 28 | #include "log.h" |
29 | #include "test.h" | 29 | #include "test.h" |
30 | #include "standardqueries.h" | ||
30 | 31 | ||
31 | using namespace Sink; | 32 | using namespace Sink; |
32 | using namespace Sink::ApplicationDomain; | 33 | using namespace Sink::ApplicationDomain; |
@@ -124,7 +125,7 @@ void MailThreadTest::testIndexInMixedOrder() | |||
124 | } | 125 | } |
125 | VERIFYEXEC(ResourceControl::flushMessageQueue(QByteArrayList() << mResourceInstanceIdentifier)); | 126 | VERIFYEXEC(ResourceControl::flushMessageQueue(QByteArrayList() << mResourceInstanceIdentifier)); |
126 | 127 | ||
127 | auto query = Sink::Query::threadLeaders(folder); | 128 | auto query = Sink::StandardQueries::threadLeaders(folder); |
128 | query.resourceFilter(mResourceInstanceIdentifier); | 129 | query.resourceFilter(mResourceInstanceIdentifier); |
129 | query.request<Mail::Subject>().request<Mail::MimeMessage>().request<Mail::Folder>().request<Mail::Date>(); | 130 | query.request<Mail::Subject>().request<Mail::MimeMessage>().request<Mail::Folder>().request<Mail::Date>(); |
130 | 131 | ||
@@ -165,7 +166,7 @@ void MailThreadTest::testIndexInMixedOrder() | |||
165 | 166 | ||
166 | //Ensure the thread is complete | 167 | //Ensure the thread is complete |
167 | { | 168 | { |
168 | auto query = Sink::Query::completeThread(threadLeader); | 169 | auto query = Sink::StandardQueries::completeThread(threadLeader); |
169 | query.request<Mail::Subject>().request<Mail::MimeMessage>().request<Mail::Folder>().request<Mail::Date>(); | 170 | query.request<Mail::Subject>().request<Mail::MimeMessage>().request<Mail::Folder>().request<Mail::Date>(); |
170 | 171 | ||
171 | auto mails = Store::read<Mail>(query); | 172 | auto mails = Store::read<Mail>(query); |