diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/query.h | 28 | ||||
-rw-r--r-- | common/queryrunner.cpp | 4 | ||||
-rw-r--r-- | common/resourcefacade.cpp | 4 | ||||
-rw-r--r-- | common/synchronizer.cpp | 4 | ||||
-rw-r--r-- | common/typeindex.cpp | 8 |
5 files changed, 34 insertions, 14 deletions
diff --git a/common/query.h b/common/query.h index 3021fe2..0c6260b 100644 --- a/common/query.h +++ b/common/query.h | |||
@@ -235,22 +235,40 @@ public: | |||
235 | template <typename T> | 235 | template <typename T> |
236 | Query &filter(const QVariant &value) | 236 | Query &filter(const QVariant &value) |
237 | { | 237 | { |
238 | propertyFilter.insert(T::name, value); | 238 | return filter(T::name, value); |
239 | return *this; | ||
240 | } | 239 | } |
241 | 240 | ||
242 | template <typename T> | 241 | template <typename T> |
243 | Query &filter(const Comparator &comparator) | 242 | Query &filter(const Comparator &comparator) |
244 | { | 243 | { |
245 | propertyFilter.insert(T::name, comparator); | 244 | return filter(T::name, comparator); |
245 | } | ||
246 | |||
247 | Query &filter(const QByteArray &property, const Comparator &comparator) | ||
248 | { | ||
249 | propertyFilter.insert(property, comparator); | ||
246 | return *this; | 250 | return *this; |
247 | } | 251 | } |
248 | 252 | ||
253 | Comparator getFilter(const QByteArray &property) const | ||
254 | { | ||
255 | return propertyFilter.value(property); | ||
256 | } | ||
257 | |||
258 | bool hasFilter(const QByteArray &property) const | ||
259 | { | ||
260 | return propertyFilter.contains(property); | ||
261 | } | ||
262 | |||
263 | QHash<QByteArray, Comparator> getBaseFilters() const | ||
264 | { | ||
265 | return propertyFilter; | ||
266 | } | ||
267 | |||
249 | template <typename T> | 268 | template <typename T> |
250 | Query &filter(const ApplicationDomain::Entity &value) | 269 | Query &filter(const ApplicationDomain::Entity &value) |
251 | { | 270 | { |
252 | propertyFilter.insert(T::name, QVariant::fromValue(value.identifier())); | 271 | return filter(T::name, QVariant::fromValue(value.identifier())); |
253 | return *this; | ||
254 | } | 272 | } |
255 | 273 | ||
256 | Query &filter(const ApplicationDomain::SinkResource &resource) | 274 | Query &filter(const ApplicationDomain::SinkResource &resource) |
diff --git a/common/queryrunner.cpp b/common/queryrunner.cpp index 11459f1..d3f8f66 100644 --- a/common/queryrunner.cpp +++ b/common/queryrunner.cpp | |||
@@ -248,10 +248,10 @@ QPair<qint64, qint64> QueryWorker<DomainType>::executeInitialQuery( | |||
248 | if (!query.parentProperty.isEmpty()) { | 248 | if (!query.parentProperty.isEmpty()) { |
249 | if (parent) { | 249 | if (parent) { |
250 | SinkTrace() << "Running initial query for parent:" << parent->identifier(); | 250 | SinkTrace() << "Running initial query for parent:" << parent->identifier(); |
251 | modifiedQuery.propertyFilter.insert(query.parentProperty, Query::Comparator(parent->identifier())); | 251 | modifiedQuery.filter(query.parentProperty, Query::Comparator(parent->identifier())); |
252 | } else { | 252 | } else { |
253 | SinkTrace() << "Running initial query for toplevel"; | 253 | SinkTrace() << "Running initial query for toplevel"; |
254 | modifiedQuery.propertyFilter.insert(query.parentProperty, Query::Comparator(QVariant())); | 254 | modifiedQuery.filter(query.parentProperty, Query::Comparator(QVariant())); |
255 | } | 255 | } |
256 | } | 256 | } |
257 | 257 | ||
diff --git a/common/resourcefacade.cpp b/common/resourcefacade.cpp index 1c56fe5..391b1d1 100644 --- a/common/resourcefacade.cpp +++ b/common/resourcefacade.cpp | |||
@@ -68,7 +68,7 @@ LocalStorageQueryRunner<DomainType>::LocalStorageQueryRunner(const Query &query, | |||
68 | for (const auto &res : entries.keys()) { | 68 | for (const auto &res : entries.keys()) { |
69 | const auto type = entries.value(res); | 69 | const auto type = entries.value(res); |
70 | 70 | ||
71 | if (query.propertyFilter.contains("type") && query.propertyFilter.value("type").value.toByteArray() != type) { | 71 | if (query.hasFilter("type") && query.getFilter("type").value.toByteArray() != type) { |
72 | SinkTrace() << "Skipping due to type."; | 72 | SinkTrace() << "Skipping due to type."; |
73 | continue; | 73 | continue; |
74 | } | 74 | } |
@@ -76,7 +76,7 @@ LocalStorageQueryRunner<DomainType>::LocalStorageQueryRunner(const Query &query, | |||
76 | continue; | 76 | continue; |
77 | } | 77 | } |
78 | const auto configurationValues = mConfigStore.get(res); | 78 | const auto configurationValues = mConfigStore.get(res); |
79 | if (!matchesFilter(query.propertyFilter, configurationValues)){ | 79 | if (!matchesFilter(query.getBaseFilters(), configurationValues)){ |
80 | SinkTrace() << "Skipping due to filter."; | 80 | SinkTrace() << "Skipping due to filter."; |
81 | continue; | 81 | continue; |
82 | } | 82 | } |
diff --git a/common/synchronizer.cpp b/common/synchronizer.cpp index 8de45a9..53db82f 100644 --- a/common/synchronizer.cpp +++ b/common/synchronizer.cpp | |||
@@ -197,7 +197,9 @@ void Synchronizer::createOrModify(const QByteArray &bufferType, const QByteArray | |||
197 | if (!found) { | 197 | if (!found) { |
198 | if (!mergeCriteria.isEmpty()) { | 198 | if (!mergeCriteria.isEmpty()) { |
199 | Sink::Query query; | 199 | Sink::Query query; |
200 | query.propertyFilter = mergeCriteria; | 200 | for (auto it = mergeCriteria.constBegin(); it != mergeCriteria.constEnd(); it++) { |
201 | query.filter(it.key(), it.value()); | ||
202 | } | ||
201 | bool merge = false; | 203 | bool merge = false; |
202 | Sink::EntityReader<DomainType> reader(mResourceType, mResourceInstanceIdentifier, transaction()); | 204 | Sink::EntityReader<DomainType> reader(mResourceType, mResourceInstanceIdentifier, transaction()); |
203 | reader.query(query, | 205 | reader.query(query, |
diff --git a/common/typeindex.cpp b/common/typeindex.cpp index f537493..272237c 100644 --- a/common/typeindex.cpp +++ b/common/typeindex.cpp | |||
@@ -142,9 +142,9 @@ QVector<QByteArray> TypeIndex::query(const Sink::Query &query, QSet<QByteArray> | |||
142 | { | 142 | { |
143 | QVector<QByteArray> keys; | 143 | QVector<QByteArray> keys; |
144 | for (auto it = mSortedProperties.constBegin(); it != mSortedProperties.constEnd(); it++) { | 144 | for (auto it = mSortedProperties.constBegin(); it != mSortedProperties.constEnd(); it++) { |
145 | if (query.propertyFilter.contains(it.key()) && query.sortProperty == it.value()) { | 145 | if (query.hasFilter(it.key()) && query.sortProperty == it.value()) { |
146 | Index index(indexName(it.key(), it.value()), transaction); | 146 | Index index(indexName(it.key(), it.value()), transaction); |
147 | const auto lookupKey = getByteArray(query.propertyFilter.value(it.key()).value); | 147 | const auto lookupKey = getByteArray(query.getFilter(it.key()).value); |
148 | SinkTrace() << "looking for " << lookupKey; | 148 | SinkTrace() << "looking for " << lookupKey; |
149 | index.lookup(lookupKey, [&](const QByteArray &value) { keys << value; }, | 149 | index.lookup(lookupKey, [&](const QByteArray &value) { keys << value; }, |
150 | [it](const Index::Error &error) { SinkWarning() << "Error in index: " << error.message << it.key() << it.value(); }, true); | 150 | [it](const Index::Error &error) { SinkWarning() << "Error in index: " << error.message << it.key() << it.value(); }, true); |
@@ -155,9 +155,9 @@ QVector<QByteArray> TypeIndex::query(const Sink::Query &query, QSet<QByteArray> | |||
155 | } | 155 | } |
156 | } | 156 | } |
157 | for (const auto &property : mProperties) { | 157 | for (const auto &property : mProperties) { |
158 | if (query.propertyFilter.contains(property)) { | 158 | if (query.hasFilter(property)) { |
159 | Index index(indexName(property), transaction); | 159 | Index index(indexName(property), transaction); |
160 | const auto lookupKey = getByteArray(query.propertyFilter.value(property).value); | 160 | const auto lookupKey = getByteArray(query.getFilter(property).value); |
161 | index.lookup( | 161 | index.lookup( |
162 | lookupKey, [&](const QByteArray &value) { keys << value; }, [property](const Index::Error &error) { SinkWarning() << "Error in index: " << error.message << property; }); | 162 | lookupKey, [&](const QByteArray &value) { keys << value; }, [property](const Index::Error &error) { SinkWarning() << "Error in index: " << error.message << property; }); |
163 | appliedFilters << property; | 163 | appliedFilters << property; |