/* * Copyright (C) 2016 Christian Mollekopf * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #pragma once #include "query.h" #include "storage.h" #include "resultset.h" #include "typeindex.h" #include "query.h" #include "entitybuffer.h" class DataStoreQuery { public: typedef QSharedPointer Ptr; DataStoreQuery(const Sink::Query &query, const QByteArray &type, Sink::Storage::Transaction &transaction, TypeIndex &typeIndex, std::function getProperty); ResultSet execute(); ResultSet update(qint64 baseRevision); protected: typedef std::function FilterFunction; typedef std::function BufferCallback; virtual QVariant getProperty(const Sink::Entity &entity, const QByteArray &property); virtual void readEntity(const QByteArray &key, const BufferCallback &resultCallback); virtual ResultSet loadInitialResultSet(QSet &remainingFilters, QByteArray &remainingSorting); virtual ResultSet loadIncrementalResultSet(qint64 baseRevision, QSet &remainingFilters); virtual ResultSet filterAndSortSet(ResultSet &resultSet, const FilterFunction &filter, const QByteArray &sortProperty); virtual ResultSet postSortFilter(ResultSet &resultSet); virtual FilterFunction getFilter(const QSet &remainingFilters); ResultSet createFilteredSet(ResultSet &resultSet, const std::function &); Sink::Query mQuery; Sink::Storage::Transaction &mTransaction; const QByteArray mType; TypeIndex &mTypeIndex; Sink::Storage::NamedDatabase mDb; std::function mGetProperty; bool mInitialQuery; };