diff options
Diffstat (limited to 'common/entityreader.h')
-rw-r--r-- | common/entityreader.h | 95 |
1 files changed, 0 insertions, 95 deletions
diff --git a/common/entityreader.h b/common/entityreader.h deleted file mode 100644 index a641106..0000000 --- a/common/entityreader.h +++ /dev/null | |||
@@ -1,95 +0,0 @@ | |||
1 | |||
2 | /* | ||
3 | * Copyright (C) 2016 Christian Mollekopf <mollekopf@kolabsys.com> | ||
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 | #pragma once | ||
22 | |||
23 | #include "sink_export.h" | ||
24 | #include <domainadaptor.h> | ||
25 | |||
26 | #include "storage.h" | ||
27 | #include "resultprovider.h" | ||
28 | #include "adaptorfactoryregistry.h" | ||
29 | |||
30 | namespace Sink { | ||
31 | |||
32 | namespace EntityReaderUtils { | ||
33 | SINK_EXPORT QSharedPointer<Sink::ApplicationDomain::BufferAdaptor> getLatest(const Sink::Storage::DataStore::NamedDatabase &db, const QByteArray &uid, DomainTypeAdaptorFactoryInterface &adaptorFactory, qint64 &retrievedRevision); | ||
34 | SINK_EXPORT QSharedPointer<Sink::ApplicationDomain::BufferAdaptor> get(const Sink::Storage::DataStore::NamedDatabase &db, const QByteArray &key, DomainTypeAdaptorFactoryInterface &adaptorFactory, qint64 &retrievedRevision); | ||
35 | SINK_EXPORT QSharedPointer<Sink::ApplicationDomain::BufferAdaptor> getPrevious(const Sink::Storage::DataStore::NamedDatabase &db, const QByteArray &uid, qint64 revision, DomainTypeAdaptorFactoryInterface &adaptorFactory, qint64 &retrievedRevision); | ||
36 | }; | ||
37 | |||
38 | /** | ||
39 | * A synchronous interface to read entities from the storage. | ||
40 | * | ||
41 | * All callbacks will be called before the end of the function. | ||
42 | * The caller must ensure passed in references remain valid for the lifetime of the object. | ||
43 | * | ||
44 | * This class is meant to be instantiated temporarily during reads on the stack. | ||
45 | * | ||
46 | * Note that all objects returned in callbacks are only valid during the execution of the callback and may start pointing into invalid memory if shallow-copied. | ||
47 | */ | ||
48 | template<typename DomainType> | ||
49 | class SINK_EXPORT EntityReader | ||
50 | { | ||
51 | typedef std::function<bool(const typename DomainType::Ptr &domainObject, Sink::Operation operation, const QMap<QByteArray, QVariant> &aggregateValues)> ResultCallback; | ||
52 | |||
53 | public: | ||
54 | EntityReader(Storage::EntityStore &store); | ||
55 | |||
56 | /** | ||
57 | * Reads the latest revision of an entity identified by @param uid | ||
58 | */ | ||
59 | DomainType read(const QByteArray &uid) const; | ||
60 | |||
61 | /** | ||
62 | * Reads the revision of the entity identified by @param key (uid + revision) | ||
63 | */ | ||
64 | DomainType readFromKey(const QByteArray &key) const; | ||
65 | |||
66 | /** | ||
67 | * Reads the (revision - 1) of an entity identified by @param uid | ||
68 | */ | ||
69 | DomainType readPrevious(const QByteArray &uid, qint64 revision) const; | ||
70 | |||
71 | /** | ||
72 | * Reads all entities that match @param query. | ||
73 | */ | ||
74 | void query(const Sink::Query &query, const std::function<bool(const DomainType &)> &callback); | ||
75 | |||
76 | /** | ||
77 | * Returns all entities that match @param query. | ||
78 | * | ||
79 | * @param offset and @param batchsize can be used to return paginated results. | ||
80 | */ | ||
81 | QPair<qint64, qint64> executeInitialQuery(const Sink::Query &query, int offset, int batchsize, const ResultCallback &callback); | ||
82 | |||
83 | /** | ||
84 | * Returns all changed entities that match @param query starting from @param lastRevision | ||
85 | */ | ||
86 | QPair<qint64, qint64> executeIncrementalQuery(const Sink::Query &query, qint64 lastRevision, const ResultCallback &callback); | ||
87 | |||
88 | private: | ||
89 | qint64 replaySet(ResultSet &resultSet, int offset, int batchSize, const ResultCallback &callback); | ||
90 | |||
91 | private: | ||
92 | Sink::Storage::EntityStore &mEntityStore; | ||
93 | }; | ||
94 | |||
95 | } | ||