diff options
Diffstat (limited to 'common/storage/entitystore.h')
-rw-r--r-- | common/storage/entitystore.h | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/common/storage/entitystore.h b/common/storage/entitystore.h new file mode 100644 index 0000000..de29e87 --- /dev/null +++ b/common/storage/entitystore.h | |||
@@ -0,0 +1,109 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2016 Christian Mollekopf <mollekopf@kolabsys.com> | ||
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 "sink_export.h" | ||
23 | |||
24 | #include <memory> | ||
25 | #include "domaintypeadaptorfactoryinterface.h" | ||
26 | #include "query.h" | ||
27 | #include "storage.h" | ||
28 | #include "resourcecontext.h" | ||
29 | |||
30 | namespace Sink { | ||
31 | class EntityBuffer; | ||
32 | namespace Storage { | ||
33 | |||
34 | class SINK_EXPORT EntityStore | ||
35 | { | ||
36 | public: | ||
37 | typedef QSharedPointer<EntityStore> Ptr; | ||
38 | EntityStore(const ResourceContext &resourceContext); | ||
39 | |||
40 | void add(const ApplicationDomain::ApplicationDomainType &); | ||
41 | void modify(const ApplicationDomain::ApplicationDomainType &); | ||
42 | void remove(const ApplicationDomain::ApplicationDomainType &); | ||
43 | |||
44 | void startTransaction(Sink::Storage::DataStore::AccessMode); | ||
45 | void commitTransaction(); | ||
46 | void abortTransaction(); | ||
47 | |||
48 | QVector<QByteArray> fullScan(const QByteArray &type); | ||
49 | QVector<QByteArray> indexLookup(const QByteArray &type, const Query &query, QSet<QByteArray> &appliedFilters, QByteArray &appliedSorting); | ||
50 | QVector<QByteArray> indexLookup(const QByteArray &type, const QByteArray &property, const QVariant &value); | ||
51 | void indexLookup(const QByteArray &type, const QByteArray &property, const QVariant &value, const std::function<void(const QByteArray &uid)> &callback); | ||
52 | template<typename EntityType, typename PropertyType> | ||
53 | void indexLookup(const QVariant &value, const std::function<void(const QByteArray &uid)> &callback) { | ||
54 | return indexLookup(ApplicationDomain::getTypeName<EntityType>(), PropertyType::name, value, callback); | ||
55 | } | ||
56 | |||
57 | void readLatest(const QByteArray &type, const QByteArray &uid, const std::function<void(const QByteArray &uid, const EntityBuffer &entity)> callback); | ||
58 | void readLatest(const QByteArray &type, const QByteArray &uid, const std::function<void(const ApplicationDomain::ApplicationDomainType &entity)> callback); | ||
59 | |||
60 | ApplicationDomain::ApplicationDomainType readLatest(const QByteArray &type, const QByteArray &uid); | ||
61 | |||
62 | template<typename T> | ||
63 | T readLatest(const QByteArray &uid) { | ||
64 | return T(readLatest(ApplicationDomain::getTypeName<T>(), uid)); | ||
65 | } | ||
66 | |||
67 | void readEntity(const QByteArray &type, const QByteArray &uid, const std::function<void(const QByteArray &uid, const EntityBuffer &entity)> callback); | ||
68 | void readEntity(const QByteArray &type, const QByteArray &uid, const std::function<void(const ApplicationDomain::ApplicationDomainType &entity)> callback); | ||
69 | ApplicationDomain::ApplicationDomainType readEntity(const QByteArray &type, const QByteArray &key); | ||
70 | |||
71 | template<typename T> | ||
72 | T readEntity(const QByteArray &key) { | ||
73 | return T(readEntity(ApplicationDomain::getTypeName<T>(), key)); | ||
74 | } | ||
75 | |||
76 | |||
77 | void readPrevious(const QByteArray &type, const QByteArray &uid, qint64 revision, const std::function<void(const QByteArray &uid, const EntityBuffer &entity)> callback); | ||
78 | void readPrevious(const QByteArray &type, const QByteArray &uid, qint64 revision, const std::function<void(const ApplicationDomain::ApplicationDomainType &entity)> callback); | ||
79 | ApplicationDomain::ApplicationDomainType readPrevious(const QByteArray &type, const QByteArray &uid, qint64 revision); | ||
80 | |||
81 | template<typename T> | ||
82 | T readPrevious(const QByteArray &uid, qint64 revision) { | ||
83 | return T(readPrevious(ApplicationDomain::getTypeName<T>(), uid, revision)); | ||
84 | } | ||
85 | |||
86 | void readAllUids(const QByteArray &type, const std::function<void(const QByteArray &uid)> callback); | ||
87 | |||
88 | void readAll(const QByteArray &type, const std::function<void(const ApplicationDomain::ApplicationDomainType &entity)> &callback); | ||
89 | |||
90 | template<typename T> | ||
91 | void readAll(const std::function<void(const T &entity)> &callback) { | ||
92 | return readAll(ApplicationDomain::getTypeName<T>(), [&](const ApplicationDomain::ApplicationDomainType &entity) { | ||
93 | callback(T(entity)); | ||
94 | }); | ||
95 | } | ||
96 | |||
97 | void readRevisions(qint64 baseRevision, const QByteArray &type, const std::function<void(const QByteArray &key)> &callback); | ||
98 | |||
99 | bool contains(const QByteArray &type, const QByteArray &uid); | ||
100 | |||
101 | qint64 maxRevision(); | ||
102 | |||
103 | private: | ||
104 | class Private; | ||
105 | const QSharedPointer<Private> d; | ||
106 | }; | ||
107 | |||
108 | } | ||
109 | } | ||