From 75e4085a0c0b05aa380be8efcac095c80f5cce57 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 21 Oct 2016 07:22:29 +0200 Subject: Cleanup --- common/storage/entitystore.cpp | 43 ++++++++++++++++++------------------------ 1 file changed, 18 insertions(+), 25 deletions(-) (limited to 'common') diff --git a/common/storage/entitystore.cpp b/common/storage/entitystore.cpp index dce2fc6..3c3840a 100644 --- a/common/storage/entitystore.cpp +++ b/common/storage/entitystore.cpp @@ -57,40 +57,33 @@ public: return transaction; } - /* template */ - /* TypeIndex &typeIndex(const QByteArray &type) */ - /* { */ - /* if (indexByType.contains(type)) { */ - /* return *indexByType.value(type); */ - /* } */ - /* auto index = QSharedPointer::create(type); */ - /* ApplicationDomain::TypeImplementation::configure(*index); */ - /* indexByType.insert(type, index); */ - /* return *index; */ - /* } */ - - TypeIndex &cachedIndex(const QByteArray &type) + template + void configure(const QByteArray &type, Args && ... args) { - if (indexByType.contains(type)) { - return *indexByType.value(type); - } - auto index = QSharedPointer::create(type); - //TODO expand for all types - /* TypeHelper::configureIndex(*index); */ - // Try this: (T would i.e. become - // TypeHelper::T::configureIndex(*index); if (type == ApplicationDomain::getTypeName()) { - ApplicationDomain::TypeImplementation::configure(*index); + ApplicationDomain::TypeImplementation::configure(std::forward(args...)); } else if (type == ApplicationDomain::getTypeName()) { - ApplicationDomain::TypeImplementation::configure(*index); + ApplicationDomain::TypeImplementation::configure(std::forward(args...)); } else if (type == ApplicationDomain::getTypeName()) { - ApplicationDomain::TypeImplementation::configure(*index); + ApplicationDomain::TypeImplementation::configure(std::forward(args...)); } else { Q_ASSERT(false); SinkError() << "Unkonwn type " << type; } + } + + TypeIndex &cachedIndex(const QByteArray &type) + { + if (indexByType.contains(type)) { + return *indexByType.value(type); + } + auto index = QSharedPointer::create(type); + configure(type, *index); indexByType.insert(type, index); return *index; + + } + TypeIndex &typeIndex(const QByteArray &type) { auto &index = cachedIndex(type); @@ -114,6 +107,7 @@ EntityStore::EntityStore(const ResourceContext &context) void EntityStore::startTransaction(Sink::Storage::DataStore::AccessMode accessMode) { + SinkTrace() << "Starting transaction"; Sink::Storage::DataStore store(Sink::storageLocation(), d->resourceContext.instanceId(), accessMode); d->transaction = store.createTransaction(accessMode); Q_ASSERT(d->transaction.validateNamedDatabases()); @@ -173,7 +167,6 @@ bool EntityStore::add(const QByteArray &type, const ApplicationDomain::Applicati bool EntityStore::modify(const QByteArray &type, const ApplicationDomain::ApplicationDomainType &diff, const QByteArrayList &deletions, bool replayToSource, const PreprocessModification &preprocess) { auto changeset = diff.changedProperties(); - //TODO handle errors const auto current = readLatest(type, diff.identifier()); if (current.identifier().isEmpty()) { SinkWarning() << "Failed to read current version: " << diff.identifier(); -- cgit v1.2.3