diff options
Diffstat (limited to 'common/indexupdater.h')
-rw-r--r-- | common/indexupdater.h | 91 |
1 files changed, 0 insertions, 91 deletions
diff --git a/common/indexupdater.h b/common/indexupdater.h deleted file mode 100644 index 221a4ed..0000000 --- a/common/indexupdater.h +++ /dev/null | |||
@@ -1,91 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2015 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 <pipeline.h> | ||
22 | #include <index.h> | ||
23 | |||
24 | class IndexUpdater : public Sink::Preprocessor | ||
25 | { | ||
26 | public: | ||
27 | IndexUpdater(const QByteArray &index, const QByteArray &type, const QByteArray &property) : mIndexIdentifier(index), mBufferType(type), mProperty(property) | ||
28 | { | ||
29 | } | ||
30 | |||
31 | void newEntity(const QByteArray &uid, qint64 revision, Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::DataStore::Transaction &transaction) Q_DECL_OVERRIDE | ||
32 | { | ||
33 | add(newEntity.getProperty(mProperty), uid, transaction); | ||
34 | } | ||
35 | |||
36 | void modifiedEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, Sink::ApplicationDomain::BufferAdaptor &newEntity, | ||
37 | Sink::Storage::DataStore::Transaction &transaction) Q_DECL_OVERRIDE | ||
38 | { | ||
39 | remove(oldEntity.getProperty(mProperty), uid, transaction); | ||
40 | add(newEntity.getProperty(mProperty), uid, transaction); | ||
41 | } | ||
42 | |||
43 | void deletedEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, Sink::Storage::DataStore::Transaction &transaction) Q_DECL_OVERRIDE | ||
44 | { | ||
45 | remove(oldEntity.getProperty(mProperty), uid, transaction); | ||
46 | } | ||
47 | |||
48 | private: | ||
49 | void add(const QVariant &value, const QByteArray &uid, Sink::Storage::DataStore::Transaction &transaction) | ||
50 | { | ||
51 | if (value.isValid()) { | ||
52 | Index(mIndexIdentifier, transaction).add(value.toByteArray(), uid); | ||
53 | } | ||
54 | } | ||
55 | |||
56 | void remove(const QVariant &value, const QByteArray &uid, Sink::Storage::DataStore::Transaction &transaction) | ||
57 | { | ||
58 | if (value.isValid()) { | ||
59 | const auto data = value.toByteArray(); | ||
60 | if (!data.isEmpty()) { | ||
61 | Index(mIndexIdentifier, transaction).remove(data, uid); | ||
62 | } | ||
63 | } | ||
64 | } | ||
65 | |||
66 | QByteArray mIndexIdentifier; | ||
67 | QByteArray mBufferType; | ||
68 | QByteArray mProperty; | ||
69 | }; | ||
70 | |||
71 | template <typename DomainType> | ||
72 | class DefaultIndexUpdater : public Sink::Preprocessor | ||
73 | { | ||
74 | public: | ||
75 | void newEntity(const QByteArray &uid, qint64 revision, Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::DataStore::Transaction &transaction) Q_DECL_OVERRIDE | ||
76 | { | ||
77 | Sink::ApplicationDomain::TypeImplementation<DomainType>::index(uid, newEntity, transaction); | ||
78 | } | ||
79 | |||
80 | void modifiedEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, Sink::ApplicationDomain::BufferAdaptor &newEntity, | ||
81 | Sink::Storage::DataStore::Transaction &transaction) Q_DECL_OVERRIDE | ||
82 | { | ||
83 | Sink::ApplicationDomain::TypeImplementation<DomainType>::removeIndex(uid, oldEntity, transaction); | ||
84 | Sink::ApplicationDomain::TypeImplementation<DomainType>::index(uid, newEntity, transaction); | ||
85 | } | ||
86 | |||
87 | void deletedEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, Sink::Storage::DataStore::Transaction &transaction) Q_DECL_OVERRIDE | ||
88 | { | ||
89 | Sink::ApplicationDomain::TypeImplementation<DomainType>::removeIndex(uid, oldEntity, transaction); | ||
90 | } | ||
91 | }; | ||