summaryrefslogtreecommitdiffstats
path: root/common/entitystore.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-05-28 02:09:58 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-05-28 02:09:58 +0200
commitb441386c4e138d19bbd79d578e0a2ff1b3f54a93 (patch)
tree1110b6ec00ce29a8bcd7f6db0717f4a483f50587 /common/entitystore.cpp
parentafb29c153daff23e491a350784ce6af5db5e28af (diff)
downloadsink-b441386c4e138d19bbd79d578e0a2ff1b3f54a93.tar.gz
sink-b441386c4e138d19bbd79d578e0a2ff1b3f54a93.zip
Moved the classes to individual files
Diffstat (limited to 'common/entitystore.cpp')
-rw-r--r--common/entitystore.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/common/entitystore.cpp b/common/entitystore.cpp
new file mode 100644
index 0000000..2c15abf
--- /dev/null
+++ b/common/entitystore.cpp
@@ -0,0 +1,48 @@
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#include "entitystore.h"
21
22using namespace Sink;
23
24EntityStore::EntityStore(const QByteArray &resourceType, const QByteArray &resourceInstanceIdentifier, Sink::Storage::Transaction &transaction)
25 : mResourceType(resourceType), mResourceInstanceIdentifier(resourceInstanceIdentifier),
26 mTransaction(transaction)
27{
28
29}
30
31QSharedPointer<Sink::ApplicationDomain::BufferAdaptor> EntityStore::getLatest(const Sink::Storage::NamedDatabase &db, const QByteArray &uid, DomainTypeAdaptorFactoryInterface &adaptorFactory)
32{
33 QSharedPointer<Sink::ApplicationDomain::BufferAdaptor> current;
34 db.findLatest(uid,
35 [&current, &adaptorFactory](const QByteArray &key, const QByteArray &data) -> bool {
36 Sink::EntityBuffer buffer(const_cast<const char *>(data.data()), data.size());
37 if (!buffer.isValid()) {
38 Warning() << "Read invalid buffer from disk";
39 } else {
40 Trace() << "Found value " << key;
41 current = adaptorFactory.createAdaptor(buffer.entity());
42 }
43 return false;
44 },
45 [](const Sink::Storage::Error &error) { Warning() << "Failed to read current value from storage: " << error.message; });
46 return current;
47}
48