diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-08-10 01:19:14 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-08-10 01:19:14 +0200 |
commit | cf0d0fd0c6afaeb9cdee276ee0305126b66604b3 (patch) | |
tree | 6e5f2dee55d866b8839c52039514444a508df140 /common/entitystorage.cpp | |
parent | 51c4e476cdde1eedb73dd1e0f0aa89e3d76292fc (diff) | |
download | sink-cf0d0fd0c6afaeb9cdee276ee0305126b66604b3.tar.gz sink-cf0d0fd0c6afaeb9cdee276ee0305126b66604b3.zip |
Ported entitystorage to new store API
Diffstat (limited to 'common/entitystorage.cpp')
-rw-r--r-- | common/entitystorage.cpp | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/common/entitystorage.cpp b/common/entitystorage.cpp index f84e9f5..420c3b0 100644 --- a/common/entitystorage.cpp +++ b/common/entitystorage.cpp | |||
@@ -19,16 +19,16 @@ | |||
19 | 19 | ||
20 | #include "entitystorage.h" | 20 | #include "entitystorage.h" |
21 | 21 | ||
22 | static void scan(const QSharedPointer<Akonadi2::Storage> &storage, const QByteArray &key, std::function<bool(const QByteArray &key, const Akonadi2::Entity &entity)> callback) | 22 | static void scan(const Akonadi2::Storage::Transaction &transaction, const QByteArray &key, std::function<bool(const QByteArray &key, const Akonadi2::Entity &entity)> callback) |
23 | { | 23 | { |
24 | storage->scan(key, [=](void *keyValue, int keySize, void *dataValue, int dataSize) -> bool { | 24 | transaction.scan(key, [=](const QByteArray &key, const QByteArray &value) -> bool { |
25 | //Skip internals | 25 | //Skip internals |
26 | if (Akonadi2::Storage::isInternalKey(keyValue, keySize)) { | 26 | if (Akonadi2::Storage::isInternalKey(key)) { |
27 | return true; | 27 | return true; |
28 | } | 28 | } |
29 | 29 | ||
30 | //Extract buffers | 30 | //Extract buffers |
31 | Akonadi2::EntityBuffer buffer(dataValue, dataSize); | 31 | Akonadi2::EntityBuffer buffer(value.data(), value.size()); |
32 | 32 | ||
33 | //FIXME implement buffer.isValid() | 33 | //FIXME implement buffer.isValid() |
34 | // const auto resourceBuffer = Akonadi2::EntityBuffer::readBuffer<DummyEvent>(buffer.entity().resource()); | 34 | // const auto resourceBuffer = Akonadi2::EntityBuffer::readBuffer<DummyEvent>(buffer.entity().resource()); |
@@ -39,16 +39,16 @@ static void scan(const QSharedPointer<Akonadi2::Storage> &storage, const QByteAr | |||
39 | // qWarning() << "invalid buffer " << QByteArray::fromRawData(static_cast<char*>(keyValue), keySize); | 39 | // qWarning() << "invalid buffer " << QByteArray::fromRawData(static_cast<char*>(keyValue), keySize); |
40 | // return true; | 40 | // return true; |
41 | // } | 41 | // } |
42 | return callback(QByteArray::fromRawData(static_cast<char*>(keyValue), keySize), buffer.entity()); | 42 | return callback(key, buffer.entity()); |
43 | }, | 43 | }, |
44 | [](const Akonadi2::Storage::Error &error) { | 44 | [](const Akonadi2::Storage::Error &error) { |
45 | qWarning() << "Error during query: " << error.message; | 45 | qWarning() << "Error during query: " << error.message; |
46 | }); | 46 | }); |
47 | } | 47 | } |
48 | 48 | ||
49 | void EntityStorageBase::readValue(const QSharedPointer<Akonadi2::Storage> &storage, const QByteArray &key, const std::function<void(const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &)> &resultCallback) | 49 | void EntityStorageBase::readValue(const Akonadi2::Storage::Transaction &transaction, const QByteArray &key, const std::function<void(const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &)> &resultCallback) |
50 | { | 50 | { |
51 | scan(storage, key, [=](const QByteArray &key, const Akonadi2::Entity &entity) { | 51 | scan(transaction, key, [=](const QByteArray &key, const Akonadi2::Entity &entity) { |
52 | const auto metadataBuffer = Akonadi2::EntityBuffer::readBuffer<Akonadi2::Metadata>(entity.metadata()); | 52 | const auto metadataBuffer = Akonadi2::EntityBuffer::readBuffer<Akonadi2::Metadata>(entity.metadata()); |
53 | qint64 revision = metadataBuffer ? metadataBuffer->revision() : -1; | 53 | qint64 revision = metadataBuffer ? metadataBuffer->revision() : -1; |
54 | //This only works for a 1:1 mapping of resource to domain types. | 54 | //This only works for a 1:1 mapping of resource to domain types. |
@@ -61,11 +61,11 @@ void EntityStorageBase::readValue(const QSharedPointer<Akonadi2::Storage> &stora | |||
61 | }); | 61 | }); |
62 | } | 62 | } |
63 | 63 | ||
64 | static ResultSet fullScan(const QSharedPointer<Akonadi2::Storage> &storage) | 64 | static ResultSet fullScan(const Akonadi2::Storage::Transaction &transaction) |
65 | { | 65 | { |
66 | //TODO use a result set with an iterator, to read values on demand | 66 | //TODO use a result set with an iterator, to read values on demand |
67 | QVector<QByteArray> keys; | 67 | QVector<QByteArray> keys; |
68 | scan(storage, QByteArray(), [=, &keys](const QByteArray &key, const Akonadi2::Entity &) { | 68 | scan(transaction, QByteArray(), [=, &keys](const QByteArray &key, const Akonadi2::Entity &) { |
69 | keys << key; | 69 | keys << key; |
70 | return true; | 70 | return true; |
71 | }); | 71 | }); |
@@ -73,14 +73,14 @@ static ResultSet fullScan(const QSharedPointer<Akonadi2::Storage> &storage) | |||
73 | return ResultSet(keys); | 73 | return ResultSet(keys); |
74 | } | 74 | } |
75 | 75 | ||
76 | ResultSet EntityStorageBase::filteredSet(const ResultSet &resultSet, const std::function<bool(const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &domainObject)> &filter, const QSharedPointer<Akonadi2::Storage> &storage, qint64 baseRevision, qint64 topRevision) | 76 | ResultSet EntityStorageBase::filteredSet(const ResultSet &resultSet, const std::function<bool(const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &domainObject)> &filter, const Akonadi2::Storage::Transaction &transaction, qint64 baseRevision, qint64 topRevision) |
77 | { | 77 | { |
78 | auto resultSetPtr = QSharedPointer<ResultSet>::create(resultSet); | 78 | auto resultSetPtr = QSharedPointer<ResultSet>::create(resultSet); |
79 | 79 | ||
80 | //Read through the source values and return whatever matches the filter | 80 | //Read through the source values and return whatever matches the filter |
81 | std::function<bool(std::function<void(const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &)>)> generator = [this, resultSetPtr, storage, filter](std::function<void(const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &)> callback) -> bool { | 81 | std::function<bool(std::function<void(const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &)>)> generator = [this, resultSetPtr, &transaction, filter](std::function<void(const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &)> callback) -> bool { |
82 | while (resultSetPtr->next()) { | 82 | while (resultSetPtr->next()) { |
83 | readValue(storage, resultSetPtr->id(), [this, filter, callback](const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &domainObject) { | 83 | readValue(transaction, resultSetPtr->id(), [this, filter, callback](const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &domainObject) { |
84 | if (filter(domainObject)) { | 84 | if (filter(domainObject)) { |
85 | callback(domainObject); | 85 | callback(domainObject); |
86 | } | 86 | } |
@@ -91,7 +91,7 @@ ResultSet EntityStorageBase::filteredSet(const ResultSet &resultSet, const std:: | |||
91 | return ResultSet(generator); | 91 | return ResultSet(generator); |
92 | } | 92 | } |
93 | 93 | ||
94 | ResultSet EntityStorageBase::getResultSet(const Akonadi2::Query &query, const QSharedPointer<Akonadi2::Storage> &storage, qint64 baseRevision, qint64 topRevision) | 94 | ResultSet EntityStorageBase::getResultSet(const Akonadi2::Query &query, const Akonadi2::Storage::Transaction &transaction, qint64 baseRevision, qint64 topRevision) |
95 | { | 95 | { |
96 | QSet<QByteArray> appliedFilters; | 96 | QSet<QByteArray> appliedFilters; |
97 | ResultSet resultSet = queryIndexes(query, mResourceInstanceIdentifier, appliedFilters); | 97 | ResultSet resultSet = queryIndexes(query, mResourceInstanceIdentifier, appliedFilters); |
@@ -99,7 +99,7 @@ ResultSet EntityStorageBase::getResultSet(const Akonadi2::Query &query, const QS | |||
99 | 99 | ||
100 | //We do a full scan if there were no indexes available to create the initial set. | 100 | //We do a full scan if there were no indexes available to create the initial set. |
101 | if (appliedFilters.isEmpty()) { | 101 | if (appliedFilters.isEmpty()) { |
102 | resultSet = fullScan(storage); | 102 | resultSet = fullScan(transaction); |
103 | } | 103 | } |
104 | 104 | ||
105 | auto filter = [remainingFilters, query, baseRevision, topRevision](const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &domainObject) -> bool { | 105 | auto filter = [remainingFilters, query, baseRevision, topRevision](const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &domainObject) -> bool { |
@@ -118,5 +118,5 @@ ResultSet EntityStorageBase::getResultSet(const Akonadi2::Query &query, const QS | |||
118 | return true; | 118 | return true; |
119 | }; | 119 | }; |
120 | 120 | ||
121 | return filteredSet(resultSet, filter, storage, baseRevision, topRevision); | 121 | return filteredSet(resultSet, filter, transaction, baseRevision, topRevision); |
122 | } | 122 | } |