diff options
Diffstat (limited to 'common/datastorequery.h')
-rw-r--r-- | common/datastorequery.h | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/common/datastorequery.h b/common/datastorequery.h new file mode 100644 index 0000000..cf9d9e2 --- /dev/null +++ b/common/datastorequery.h | |||
@@ -0,0 +1,59 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2016 Christian Mollekopf <chrigi_1@fastmail.fm> | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation; either version 2 of the License, or | ||
7 | * (at your option) any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the | ||
16 | * Free Software Foundation, Inc., | ||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | */ | ||
19 | #pragma once | ||
20 | |||
21 | #include "query.h" | ||
22 | #include "storage.h" | ||
23 | #include "resultset.h" | ||
24 | #include "typeindex.h" | ||
25 | #include "query.h" | ||
26 | #include "entitybuffer.h" | ||
27 | |||
28 | class DataStoreQuery { | ||
29 | public: | ||
30 | DataStoreQuery(const Sink::Query &query, const QByteArray &type, Sink::Storage::Transaction &transaction, TypeIndex &typeIndex, std::function<QVariant(const Sink::Entity &entity, const QByteArray &property)> getProperty); | ||
31 | ResultSet execute(); | ||
32 | ResultSet update(qint64 baseRevision); | ||
33 | |||
34 | private: | ||
35 | |||
36 | typedef std::function<bool(const QByteArray &uid, const Sink::EntityBuffer &entityBuffer)> FilterFunction; | ||
37 | typedef std::function<void(const QByteArray &uid, const Sink::EntityBuffer &entityBuffer)> BufferCallback; | ||
38 | |||
39 | QVariant getProperty(const Sink::Entity &entity, const QByteArray &property); | ||
40 | |||
41 | void readEntity(const QByteArray &key, const BufferCallback &resultCallback); | ||
42 | |||
43 | ResultSet loadInitialResultSet(QSet<QByteArray> &remainingFilters, QByteArray &remainingSorting); | ||
44 | ResultSet loadIncrementalResultSet(qint64 baseRevision, QSet<QByteArray> &remainingFilters); | ||
45 | |||
46 | ResultSet filterAndSortSet(ResultSet &resultSet, const FilterFunction &filter, bool initialQuery, const QByteArray &sortProperty); | ||
47 | FilterFunction getFilter(const QSet<QByteArray> &remainingFilters); | ||
48 | |||
49 | Sink::Query mQuery; | ||
50 | Sink::Storage::Transaction &mTransaction; | ||
51 | const QByteArray mType; | ||
52 | TypeIndex &mTypeIndex; | ||
53 | Sink::Storage::NamedDatabase mDb; | ||
54 | std::function<QVariant(const Sink::Entity &entity, const QByteArray &property)> mGetProperty; | ||
55 | }; | ||
56 | |||
57 | |||
58 | |||
59 | |||