/* * Copyright (C) 2016 Christian Mollekopf * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #pragma once #include "sink_export.h" #include #include "domaintypeadaptorfactoryinterface.h" #include "query.h" #include "storage.h" #include "resourcecontext.h" #include "metadata_generated.h" namespace Sink { class EntityBuffer; namespace Storage { class SINK_EXPORT EntityStore { public: typedef QSharedPointer Ptr; EntityStore(const ResourceContext &resourceContext, const Sink::Log::Context &); //Only the pipeline may call the following functions outside of tests bool add(const QByteArray &type, ApplicationDomain::ApplicationDomainType newEntity, bool replayToSource); bool modify(const QByteArray &type, const ApplicationDomain::ApplicationDomainType &diff, const QByteArrayList &deletions, bool replayToSource); bool modify(const QByteArray &type, const ApplicationDomain::ApplicationDomainType ¤t, ApplicationDomain::ApplicationDomainType newEntity, bool replayToSource); bool remove(const QByteArray &type, const ApplicationDomain::ApplicationDomainType ¤t, bool replayToSource); bool cleanupRevisions(qint64 revision); ApplicationDomain::ApplicationDomainType applyDiff(const QByteArray &type, const ApplicationDomain::ApplicationDomainType ¤t, const ApplicationDomain::ApplicationDomainType &diff, const QByteArrayList &deletions) const; void startTransaction(Sink::Storage::DataStore::AccessMode); void commitTransaction(); void abortTransaction(); bool hasTransaction() const; QVector fullScan(const QByteArray &type); QVector indexLookup(const QByteArray &type, const QueryBase &query, QSet &appliedFilters, QByteArray &appliedSorting); QVector indexLookup(const QByteArray &type, const QByteArray &property, const QVariant &value); void indexLookup(const QByteArray &type, const QByteArray &property, const QVariant &value, const std::function &callback); template void indexLookup(const QVariant &value, const std::function &callback) { return indexLookup(ApplicationDomain::getTypeName(), PropertyType::name, value, callback); } void readLatest(const QByteArray &type, const QByteArray &uid, const std::function callback); void readLatest(const QByteArray &type, const QByteArray &uid, const std::function callback); void readLatest(const QByteArray &type, const QByteArray &uid, const std::function callback); ApplicationDomain::ApplicationDomainType readLatest(const QByteArray &type, const QByteArray &uid); template T readLatest(const QByteArray &uid) { return T(readLatest(ApplicationDomain::getTypeName(), uid)); } void readEntity(const QByteArray &type, const QByteArray &uid, const std::function callback); void readEntity(const QByteArray &type, const QByteArray &uid, const std::function callback); ApplicationDomain::ApplicationDomainType readEntity(const QByteArray &type, const QByteArray &key); template T readEntity(const QByteArray &key) { return T(readEntity(ApplicationDomain::getTypeName(), key)); } void readPrevious(const QByteArray &type, const QByteArray &uid, qint64 revision, const std::function callback); void readPrevious(const QByteArray &type, const QByteArray &uid, qint64 revision, const std::function callback); ApplicationDomain::ApplicationDomainType readPrevious(const QByteArray &type, const QByteArray &uid, qint64 revision); template T readPrevious(const QByteArray &uid, qint64 revision) { return T(readPrevious(ApplicationDomain::getTypeName(), uid, revision)); } void readAllUids(const QByteArray &type, const std::function callback); void readAll(const QByteArray &type, const std::function &callback); template void readAll(const std::function &callback) { return readAll(ApplicationDomain::getTypeName(), [&](const ApplicationDomain::ApplicationDomainType &entity) { callback(T(entity)); }); } void readRevisions(qint64 baseRevision, const QByteArray &type, const std::function &callback); ///Db contains entity (but may already be marked as removed bool contains(const QByteArray &type, const QByteArray &uid); ///Db contains entity and entity is not yet removed bool exists(const QByteArray &type, const QByteArray &uid); qint64 maxRevision(); Sink::Log::Context logContext() const; private: /* * Remove any old revisions of the same entity up until @param revision */ void cleanupEntityRevisionsUntil(qint64 revision); void copyBlobs(ApplicationDomain::ApplicationDomainType &entity, qint64 newRevision); class Private; const QSharedPointer d; }; } }