From f4381b746da350f44168674da69bd6ad6876de19 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 2 Feb 2016 14:00:37 +0100 Subject: Writeback of unread flag changes --- common/genericresource.cpp | 27 +++++++++++++++------------ common/genericresource.h | 1 + 2 files changed, 16 insertions(+), 12 deletions(-) (limited to 'common') diff --git a/common/genericresource.cpp b/common/genericresource.cpp index a9eab36..29cd8b1 100644 --- a/common/genericresource.cpp +++ b/common/genericresource.cpp @@ -312,12 +312,14 @@ GenericResource::GenericResource(const QByteArray &resourceInstanceIdentifier, c QVariant expectedValue; s >> expectedValue; inspect(inspectionType, inspectionId, domainType, entityId, property, expectedValue).then([=]() { + Log() << "Inspection was successful: " << inspectionType << inspectionId << entityId; Sink::Notification n; n.type = Sink::Commands::NotificationType_Inspection; n.id = inspectionId; n.code = Sink::Commands::NotificationCode_Success; emit notify(n); }, [=](int code, const QString &message) { + Log() << "Inspection failed: "<< inspectionType << inspectionId << entityId << message; Sink::Notification n; n.type = Sink::Commands::NotificationType_Inspection; n.message = message; @@ -555,38 +557,39 @@ void GenericResource::deleteEntity(const QByteArray &sinkId, qint64 revision, co void GenericResource::recordRemoteId(const QByteArray &bufferType, const QByteArray &localId, const QByteArray &remoteId, Sink::Storage::Transaction &transaction) { - Index index("rid.mapping." + bufferType, transaction); - Index localIndex("localid.mapping." + bufferType, transaction); - index.add(remoteId, localId); - localIndex.add(localId, remoteId); + Index("rid.mapping." + bufferType, transaction).add(remoteId, localId);; + Index("localid.mapping." + bufferType, transaction).add(localId, remoteId); } void GenericResource::removeRemoteId(const QByteArray &bufferType, const QByteArray &localId, const QByteArray &remoteId, Sink::Storage::Transaction &transaction) { - Index index("rid.mapping." + bufferType, transaction); - Index localIndex("localid.mapping." + bufferType, transaction); - index.remove(remoteId, localId); - localIndex.remove(localId, remoteId); + Index("rid.mapping." + bufferType, transaction).remove(remoteId, localId); + Index("localid.mapping." + bufferType, transaction).remove(localId, remoteId); +} + +void GenericResource::updateRemoteId(const QByteArray &bufferType, const QByteArray &localId, const QByteArray &remoteId, Sink::Storage::Transaction &transaction) +{ + const auto oldRemoteId = Index("localid.mapping." + bufferType, transaction).lookup(localId); + removeRemoteId(bufferType, localId, oldRemoteId, transaction); + recordRemoteId(bufferType, localId, remoteId, transaction); } QByteArray GenericResource::resolveRemoteId(const QByteArray &bufferType, const QByteArray &remoteId, Sink::Storage::Transaction &transaction) { //Lookup local id for remote id, or insert a new pair otherwise Index index("rid.mapping." + bufferType, transaction); - Index localIndex("localid.mapping." + bufferType, transaction); QByteArray sinkId = index.lookup(remoteId); if (sinkId.isEmpty()) { sinkId = QUuid::createUuid().toString().toUtf8(); index.add(remoteId, sinkId); - localIndex.add(sinkId, remoteId); + Index("localid.mapping." + bufferType, transaction).add(sinkId, remoteId); } return sinkId; } QByteArray GenericResource::resolveLocalId(const QByteArray &bufferType, const QByteArray &localId, Sink::Storage::Transaction &transaction) { - Index index("localid.mapping." + bufferType, transaction); - QByteArray remoteId = index.lookup(localId); + QByteArray remoteId = Index("localid.mapping." + bufferType, transaction).lookup(localId); if (remoteId.isEmpty()) { Warning() << "Couldn't find the remote id for " << localId; return QByteArray(); diff --git a/common/genericresource.h b/common/genericresource.h index 8779077..1bbb0f5 100644 --- a/common/genericresource.h +++ b/common/genericresource.h @@ -74,6 +74,7 @@ protected: */ void recordRemoteId(const QByteArray &bufferType, const QByteArray &localId, const QByteArray &remoteId, Sink::Storage::Transaction &transaction); void removeRemoteId(const QByteArray &bufferType, const QByteArray &localId, const QByteArray &remoteId, Sink::Storage::Transaction &transaction); + void updateRemoteId(const QByteArray &bufferType, const QByteArray &localId, const QByteArray &remoteId, Sink::Storage::Transaction &transaction); /** * Tries to find a local id for the remote id, and creates a new local id otherwise. -- cgit v1.2.3