diff options
Diffstat (limited to 'common/entitystorage.h')
-rw-r--r-- | common/entitystorage.h | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/common/entitystorage.h b/common/entitystorage.h index 9d928b8..f1d7f84 100644 --- a/common/entitystorage.h +++ b/common/entitystorage.h | |||
@@ -31,6 +31,8 @@ | |||
31 | 31 | ||
32 | /** | 32 | /** |
33 | * Wraps storage, entity adaptor factory and indexes into one. | 33 | * Wraps storage, entity adaptor factory and indexes into one. |
34 | * | ||
35 | * TODO: customize with readEntity instead of adaptor factory | ||
34 | */ | 36 | */ |
35 | class EntityStorageBase | 37 | class EntityStorageBase |
36 | { | 38 | { |
@@ -46,14 +48,26 @@ protected: | |||
46 | virtual Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr copy(const Akonadi2::ApplicationDomain::ApplicationDomainType &) = 0; | 48 | virtual Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr copy(const Akonadi2::ApplicationDomain::ApplicationDomainType &) = 0; |
47 | virtual ResultSet queryIndexes(const Akonadi2::Query &query, const QByteArray &resourceInstanceIdentifier, QSet<QByteArray> &appliedFilters, Akonadi2::Storage::Transaction &transaction) = 0; | 49 | virtual ResultSet queryIndexes(const Akonadi2::Query &query, const QByteArray &resourceInstanceIdentifier, QSet<QByteArray> &appliedFilters, Akonadi2::Storage::Transaction &transaction) = 0; |
48 | 50 | ||
49 | void readValue(const Akonadi2::Storage::Transaction &transaction, const QByteArray &key, const std::function<void(const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &)> &resultCallback); | 51 | /** |
50 | ResultSet filteredSet(const ResultSet &resultSet, const std::function<bool(const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &domainObject)> &filter, const Akonadi2::Storage::Transaction &transaction, qint64 baseRevision, qint64 topRevision); | 52 | * Loads a single entity by uid from storage. |
53 | * | ||
54 | * TODO: Resources should be able to customize this for cases where an entity is not the same as a single buffer. | ||
55 | */ | ||
56 | void readEntity(const Akonadi2::Storage::Transaction &transaction, const QByteArray &key, const std::function<void(const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &, Akonadi2::Operation)> &resultCallback); | ||
51 | ResultSet getResultSet(const Akonadi2::Query &query, Akonadi2::Storage::Transaction &transaction, qint64 baseRevision, qint64 topRevision); | 57 | ResultSet getResultSet(const Akonadi2::Query &query, Akonadi2::Storage::Transaction &transaction, qint64 baseRevision, qint64 topRevision); |
52 | 58 | ||
53 | protected: | 59 | protected: |
54 | QByteArray mResourceInstanceIdentifier; | 60 | QByteArray mResourceInstanceIdentifier; |
55 | QByteArray mBufferType; | 61 | QByteArray mBufferType; |
56 | DomainTypeAdaptorFactoryInterface::Ptr mDomainTypeAdaptorFactory; | 62 | DomainTypeAdaptorFactoryInterface::Ptr mDomainTypeAdaptorFactory; |
63 | private: | ||
64 | /** | ||
65 | * Returns the initial result set that still needs to be filtered. | ||
66 | * | ||
67 | * To make this efficient indexes should be chosen that are as selective as possible. | ||
68 | */ | ||
69 | ResultSet loadInitialResultSet(const Akonadi2::Query &query, Akonadi2::Storage::Transaction &transaction, QSet<QByteArray> &remainingFilters); | ||
70 | ResultSet filteredSet(const ResultSet &resultSet, const std::function<bool(const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &domainObject)> &filter, const Akonadi2::Storage::Transaction &transaction, bool isInitialQuery); | ||
57 | }; | 71 | }; |
58 | 72 | ||
59 | template<typename DomainType> | 73 | template<typename DomainType> |
@@ -95,13 +109,25 @@ public: | |||
95 | auto transaction = storage.createTransaction(Akonadi2::Storage::ReadOnly); | 109 | auto transaction = storage.createTransaction(Akonadi2::Storage::ReadOnly); |
96 | 110 | ||
97 | Log() << "Querying" << revisionRange.first << revisionRange.second; | 111 | Log() << "Querying" << revisionRange.first << revisionRange.second; |
112 | //TODO fallback in case the old revision is no longer available to clear + redo complete initial scan | ||
113 | // | ||
98 | auto resultSet = getResultSet(query, transaction, revisionRange.first, revisionRange.second); | 114 | auto resultSet = getResultSet(query, transaction, revisionRange.first, revisionRange.second); |
99 | while(resultSet.next([this, resultProvider](const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &value) -> bool { | 115 | while(resultSet.next([this, resultProvider](const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &value, Akonadi2::Operation operation) -> bool { |
100 | auto cloned = copy(*value); | 116 | switch (operation) { |
101 | resultProvider->add(cloned.template staticCast<DomainType>()); | 117 | case Akonadi2::Operation_Creation: |
118 | Trace() << "Got creation"; | ||
119 | resultProvider->add(copy(*value).template staticCast<DomainType>()); | ||
120 | break; | ||
121 | case Akonadi2::Operation_Modification: | ||
122 | Trace() << "Got modification"; | ||
123 | resultProvider->add(copy(*value).template staticCast<DomainType>()); | ||
124 | break; | ||
125 | case Akonadi2::Operation_Removal: | ||
126 | Trace() << "Got removal"; | ||
127 | break; | ||
128 | } | ||
102 | return true; | 129 | return true; |
103 | })){}; | 130 | })){}; |
104 | //TODO replay removals and modifications | ||
105 | } | 131 | } |
106 | 132 | ||
107 | }; | 133 | }; |