summaryrefslogtreecommitdiffstats
path: root/common/datastorequery.h
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-09-19 18:55:21 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-09-19 18:55:21 +0200
commit4a14a6fade947aa830d3f21598a4a6ba7316b933 (patch)
treec6b340bf1c6284e5501d371f65b58e3a69391a26 /common/datastorequery.h
parent1deac558af4b1c9f04352ede7f8e172f11a70a6b (diff)
downloadsink-4a14a6fade947aa830d3f21598a4a6ba7316b933.tar.gz
sink-4a14a6fade947aa830d3f21598a4a6ba7316b933.zip
Refactored the query part of the entity reader into DataStoreQuery.
DataStoreQuery now encapsulates the low-level query that operates directly on the storage. It no longer has access to the resource buffers, and is instantiated by the type implementation, so we can specialize the query alogorithm per type, but not per resource. This will allow us to implement the threading queries for the mailtype.
Diffstat (limited to 'common/datastorequery.h')
-rw-r--r--common/datastorequery.h59
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
28class DataStoreQuery {
29public:
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
34private:
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