diff options
Diffstat (limited to 'common/store.cpp')
-rw-r--r-- | common/store.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/common/store.cpp b/common/store.cpp index 29e826a..392f9ce 100644 --- a/common/store.cpp +++ b/common/store.cpp | |||
@@ -40,6 +40,25 @@ Q_DECLARE_METATYPE(QSharedPointer<Sink::ResultEmitter<Sink::ApplicationDomain::S | |||
40 | Q_DECLARE_METATYPE(QSharedPointer<Sink::ResourceAccessInterface>); | 40 | Q_DECLARE_METATYPE(QSharedPointer<Sink::ResourceAccessInterface>); |
41 | Q_DECLARE_METATYPE(std::shared_ptr<void>); | 41 | Q_DECLARE_METATYPE(std::shared_ptr<void>); |
42 | 42 | ||
43 | |||
44 | static bool sanityCheckQuery(const Sink::Query &query) | ||
45 | { | ||
46 | for (const auto &id : query.ids()) { | ||
47 | if (id.isEmpty()) { | ||
48 | SinkError() << "Empty id in query."; | ||
49 | return false; | ||
50 | } | ||
51 | } | ||
52 | for (const auto &id : query.getResourceFilter().ids) { | ||
53 | if (id.isEmpty()) { | ||
54 | SinkError() << "Empty resourceid in query."; | ||
55 | return false; | ||
56 | } | ||
57 | } | ||
58 | return true; | ||
59 | } | ||
60 | |||
61 | |||
43 | namespace Sink { | 62 | namespace Sink { |
44 | 63 | ||
45 | QString Store::storageLocation() | 64 | QString Store::storageLocation() |
@@ -138,6 +157,7 @@ static Log::Context getQueryContext(const Sink::Query &query, const QByteArray & | |||
138 | template <class DomainType> | 157 | template <class DomainType> |
139 | QSharedPointer<QAbstractItemModel> Store::loadModel(const Query &query) | 158 | QSharedPointer<QAbstractItemModel> Store::loadModel(const Query &query) |
140 | { | 159 | { |
160 | Q_ASSERT(sanityCheckQuery(query)); | ||
141 | auto ctx = getQueryContext(query, ApplicationDomain::getTypeName<DomainType>()); | 161 | auto ctx = getQueryContext(query, ApplicationDomain::getTypeName<DomainType>()); |
142 | auto model = QSharedPointer<ModelResult<DomainType, typename DomainType::Ptr>>::create(query, query.requestedProperties, ctx); | 162 | auto model = QSharedPointer<ModelResult<DomainType, typename DomainType::Ptr>>::create(query, query.requestedProperties, ctx); |
143 | 163 | ||
@@ -342,6 +362,7 @@ KAsync::Job<QList<typename DomainType::Ptr>> Store::fetchAll(const Sink::Query & | |||
342 | template <class DomainType> | 362 | template <class DomainType> |
343 | KAsync::Job<QList<typename DomainType::Ptr>> Store::fetch(const Sink::Query &query, int minimumAmount) | 363 | KAsync::Job<QList<typename DomainType::Ptr>> Store::fetch(const Sink::Query &query, int minimumAmount) |
344 | { | 364 | { |
365 | Q_ASSERT(sanityCheckQuery(query)); | ||
345 | auto model = loadModel<DomainType>(query); | 366 | auto model = loadModel<DomainType>(query); |
346 | auto list = QSharedPointer<QList<typename DomainType::Ptr>>::create(); | 367 | auto list = QSharedPointer<QList<typename DomainType::Ptr>>::create(); |
347 | auto context = QSharedPointer<QObject>::create(); | 368 | auto context = QSharedPointer<QObject>::create(); |
@@ -393,6 +414,7 @@ DomainType Store::readOne(const Sink::Query &query) | |||
393 | template <class DomainType> | 414 | template <class DomainType> |
394 | QList<DomainType> Store::read(const Sink::Query &query_) | 415 | QList<DomainType> Store::read(const Sink::Query &query_) |
395 | { | 416 | { |
417 | Q_ASSERT(sanityCheckQuery(query_)); | ||
396 | auto query = query_; | 418 | auto query = query_; |
397 | query.setFlags(Query::SynchronousQuery); | 419 | query.setFlags(Query::SynchronousQuery); |
398 | 420 | ||