diff options
Diffstat (limited to 'common/entitystore.cpp')
-rw-r--r-- | common/entitystore.cpp | 52 |
1 files changed, 0 insertions, 52 deletions
diff --git a/common/entitystore.cpp b/common/entitystore.cpp index 5296d53..5fb213d 100644 --- a/common/entitystore.cpp +++ b/common/entitystore.cpp | |||
@@ -28,55 +28,3 @@ EntityStore::EntityStore(const QByteArray &resourceType, const QByteArray &resou | |||
28 | 28 | ||
29 | } | 29 | } |
30 | 30 | ||
31 | QSharedPointer<Sink::ApplicationDomain::BufferAdaptor> EntityStore::getLatest(const Sink::Storage::NamedDatabase &db, const QByteArray &uid, DomainTypeAdaptorFactoryInterface &adaptorFactory, qint64 &retrievedRevision) | ||
32 | { | ||
33 | QSharedPointer<Sink::ApplicationDomain::BufferAdaptor> current; | ||
34 | db.findLatest(uid, | ||
35 | [¤t, &adaptorFactory, &retrievedRevision](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 | retrievedRevision = Sink::Storage::revisionFromKey(key); | ||
43 | } | ||
44 | return false; | ||
45 | }, | ||
46 | [](const Sink::Storage::Error &error) { Warning() << "Failed to read current value from storage: " << error.message; }); | ||
47 | return current; | ||
48 | } | ||
49 | |||
50 | QSharedPointer<Sink::ApplicationDomain::BufferAdaptor> EntityStore::get(const Sink::Storage::NamedDatabase &db, const QByteArray &key, DomainTypeAdaptorFactoryInterface &adaptorFactory, qint64 &retrievedRevision) | ||
51 | { | ||
52 | QSharedPointer<Sink::ApplicationDomain::BufferAdaptor> current; | ||
53 | db.scan(key, | ||
54 | [¤t, &adaptorFactory, &retrievedRevision](const QByteArray &key, const QByteArray &data) -> bool { | ||
55 | Sink::EntityBuffer buffer(const_cast<const char *>(data.data()), data.size()); | ||
56 | if (!buffer.isValid()) { | ||
57 | Warning() << "Read invalid buffer from disk"; | ||
58 | } else { | ||
59 | current = adaptorFactory.createAdaptor(buffer.entity()); | ||
60 | retrievedRevision = Sink::Storage::revisionFromKey(key); | ||
61 | } | ||
62 | return false; | ||
63 | }, | ||
64 | [](const Sink::Storage::Error &error) { Warning() << "Failed to read current value from storage: " << error.message; }); | ||
65 | return current; | ||
66 | } | ||
67 | |||
68 | QSharedPointer<Sink::ApplicationDomain::BufferAdaptor> EntityStore::getPrevious(const Sink::Storage::NamedDatabase &db, const QByteArray &uid, qint64 revision, DomainTypeAdaptorFactoryInterface &adaptorFactory, qint64 &retrievedRevision) | ||
69 | { | ||
70 | QSharedPointer<Sink::ApplicationDomain::BufferAdaptor> current; | ||
71 | qint64 latestRevision = 0; | ||
72 | db.scan(uid, | ||
73 | [¤t, &latestRevision, revision](const QByteArray &key, const QByteArray &) -> bool { | ||
74 | auto foundRevision = Sink::Storage::revisionFromKey(key); | ||
75 | if (foundRevision < revision && foundRevision > latestRevision) { | ||
76 | latestRevision = foundRevision; | ||
77 | } | ||
78 | return true; | ||
79 | }, | ||
80 | [](const Sink::Storage::Error &error) { Warning() << "Failed to read current value from storage: " << error.message; }, true); | ||
81 | return get(db, Sink::Storage::assembleKey(uid, latestRevision), adaptorFactory, retrievedRevision); | ||
82 | } | ||