diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-04-11 15:16:26 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-04-11 15:16:26 +0200 |
commit | f6c3c144e60611d2da7ba7aa5b115affe92a57a4 (patch) | |
tree | 4e4b01382d7c2893d4d1d14489506e3b0066fce9 /common/storage | |
parent | adb11fd81404b9ab3b01975ed93babe12a22dee4 (diff) | |
download | sink-f6c3c144e60611d2da7ba7aa5b115affe92a57a4.tar.gz sink-f6c3c144e60611d2da7ba7aa5b115affe92a57a4.zip |
Move the preprocssing back out of entitystore into the pipeline.
This is where this really belongs, only the indexing is part of storage.
This is necessary so preprocessors can move entities as well.
Diffstat (limited to 'common/storage')
-rw-r--r-- | common/storage/entitystore.cpp | 34 | ||||
-rw-r--r-- | common/storage/entitystore.h | 4 |
2 files changed, 25 insertions, 13 deletions
diff --git a/common/storage/entitystore.cpp b/common/storage/entitystore.cpp index 4afb407..3ef8784 100644 --- a/common/storage/entitystore.cpp +++ b/common/storage/entitystore.cpp | |||
@@ -209,22 +209,15 @@ bool EntityStore::add(const QByteArray &type, const ApplicationDomain::Applicati | |||
209 | return true; | 209 | return true; |
210 | } | 210 | } |
211 | 211 | ||
212 | bool EntityStore::modify(const QByteArray &type, const ApplicationDomain::ApplicationDomainType &diff, const QByteArrayList &deletions, bool replayToSource, const PreprocessModification &preprocess) | 212 | ApplicationDomain::ApplicationDomainType EntityStore::applyDiff(const QByteArray &type, const ApplicationDomain::ApplicationDomainType ¤t, const ApplicationDomain::ApplicationDomainType &diff, const QByteArrayList &deletions) const |
213 | { | 213 | { |
214 | auto changeset = diff.changedProperties(); | ||
215 | const auto current = readLatest(type, diff.identifier()); | ||
216 | if (current.identifier().isEmpty()) { | ||
217 | SinkWarningCtx(d->logCtx) << "Failed to read current version: " << diff.identifier(); | ||
218 | return false; | ||
219 | } | ||
220 | |||
221 | auto newEntity = *ApplicationDomain::ApplicationDomainType::getInMemoryRepresentation<ApplicationDomain::ApplicationDomainType>(current, current.availableProperties()); | 214 | auto newEntity = *ApplicationDomain::ApplicationDomainType::getInMemoryRepresentation<ApplicationDomain::ApplicationDomainType>(current, current.availableProperties()); |
222 | 215 | ||
223 | SinkTraceCtx(d->logCtx) << "Modified entity: " << newEntity; | 216 | SinkTraceCtx(d->logCtx) << "Modified entity: " << newEntity; |
224 | 217 | ||
225 | // Apply diff | 218 | // Apply diff |
226 | //SinkTrace() << "Applying changed properties: " << changeset; | 219 | //SinkTrace() << "Applying changed properties: " << changeset; |
227 | for (const auto &property : changeset) { | 220 | for (const auto &property : diff.changedProperties()) { |
228 | const auto value = diff.getProperty(property); | 221 | const auto value = diff.getProperty(property); |
229 | if (value.isValid()) { | 222 | if (value.isValid()) { |
230 | //SinkTrace() << "Setting property: " << property; | 223 | //SinkTrace() << "Setting property: " << property; |
@@ -237,8 +230,25 @@ bool EntityStore::modify(const QByteArray &type, const ApplicationDomain::Applic | |||
237 | //SinkTrace() << "Removing property: " << property; | 230 | //SinkTrace() << "Removing property: " << property; |
238 | newEntity.setProperty(property, QVariant()); | 231 | newEntity.setProperty(property, QVariant()); |
239 | } | 232 | } |
233 | return newEntity; | ||
234 | } | ||
235 | |||
236 | bool EntityStore::modify(const QByteArray &type, const ApplicationDomain::ApplicationDomainType &diff, const QByteArrayList &deletions, bool replayToSource) | ||
237 | { | ||
238 | const auto current = readLatest(type, diff.identifier()); | ||
239 | if (current.identifier().isEmpty()) { | ||
240 | SinkWarningCtx(d->logCtx) << "Failed to read current version: " << diff.identifier(); | ||
241 | return false; | ||
242 | } | ||
243 | |||
244 | auto newEntity = applyDiff(type, current, diff, deletions); | ||
245 | return modify(type, current, newEntity, replayToSource); | ||
246 | } | ||
247 | |||
248 | bool EntityStore::modify(const QByteArray &type, const ApplicationDomain::ApplicationDomainType ¤t, ApplicationDomain::ApplicationDomainType newEntity, bool replayToSource) | ||
249 | { | ||
250 | SinkTraceCtx(d->logCtx) << "Modified entity: " << newEntity; | ||
240 | 251 | ||
241 | preprocess(current, newEntity); | ||
242 | d->typeIndex(type).remove(current.identifier(), current, d->transaction); | 252 | d->typeIndex(type).remove(current.identifier(), current, d->transaction); |
243 | d->typeIndex(type).add(newEntity.identifier(), newEntity, d->transaction); | 253 | d->typeIndex(type).add(newEntity.identifier(), newEntity, d->transaction); |
244 | 254 | ||
@@ -250,7 +260,7 @@ bool EntityStore::modify(const QByteArray &type, const ApplicationDomain::Applic | |||
250 | flatbuffers::FlatBufferBuilder metadataFbb; | 260 | flatbuffers::FlatBufferBuilder metadataFbb; |
251 | { | 261 | { |
252 | //We add availableProperties to account for the properties that have been changed by the preprocessors | 262 | //We add availableProperties to account for the properties that have been changed by the preprocessors |
253 | auto modifiedProperties = BufferUtils::toVector(metadataFbb, changeset + newEntity.changedProperties()); | 263 | auto modifiedProperties = BufferUtils::toVector(metadataFbb, newEntity.changedProperties()); |
254 | auto metadataBuilder = MetadataBuilder(metadataFbb); | 264 | auto metadataBuilder = MetadataBuilder(metadataFbb); |
255 | metadataBuilder.add_revision(newRevision); | 265 | metadataBuilder.add_revision(newRevision); |
256 | metadataBuilder.add_operation(Operation_Modification); | 266 | metadataBuilder.add_operation(Operation_Modification); |
@@ -259,7 +269,7 @@ bool EntityStore::modify(const QByteArray &type, const ApplicationDomain::Applic | |||
259 | auto metadataBuffer = metadataBuilder.Finish(); | 269 | auto metadataBuffer = metadataBuilder.Finish(); |
260 | FinishMetadataBuffer(metadataFbb, metadataBuffer); | 270 | FinishMetadataBuffer(metadataFbb, metadataBuffer); |
261 | } | 271 | } |
262 | SinkTraceCtx(d->logCtx) << "Changed properties: " << changeset + newEntity.changedProperties(); | 272 | SinkTraceCtx(d->logCtx) << "Changed properties: " << newEntity.changedProperties(); |
263 | 273 | ||
264 | newEntity.setChangedProperties(newEntity.availableProperties().toSet()); | 274 | newEntity.setChangedProperties(newEntity.availableProperties().toSet()); |
265 | 275 | ||
diff --git a/common/storage/entitystore.h b/common/storage/entitystore.h index 46410cd..ddb4ef9 100644 --- a/common/storage/entitystore.h +++ b/common/storage/entitystore.h | |||
@@ -44,9 +44,11 @@ public: | |||
44 | 44 | ||
45 | //Only the pipeline may call the following functions outside of tests | 45 | //Only the pipeline may call the following functions outside of tests |
46 | bool add(const QByteArray &type, const ApplicationDomain::ApplicationDomainType &, bool replayToSource, const PreprocessCreation &); | 46 | bool add(const QByteArray &type, const ApplicationDomain::ApplicationDomainType &, bool replayToSource, const PreprocessCreation &); |
47 | bool modify(const QByteArray &type, const ApplicationDomain::ApplicationDomainType &, const QByteArrayList &deletions, bool replayToSource, const PreprocessModification &); | 47 | bool modify(const QByteArray &type, const ApplicationDomain::ApplicationDomainType &diff, const QByteArrayList &deletions, bool replayToSource); |
48 | bool modify(const QByteArray &type, const ApplicationDomain::ApplicationDomainType ¤t, ApplicationDomain::ApplicationDomainType newEntity, bool replayToSource); | ||
48 | bool remove(const QByteArray &type, const QByteArray &uid, bool replayToSource, const PreprocessRemoval &); | 49 | bool remove(const QByteArray &type, const QByteArray &uid, bool replayToSource, const PreprocessRemoval &); |
49 | bool cleanupRevisions(qint64 revision); | 50 | bool cleanupRevisions(qint64 revision); |
51 | ApplicationDomain::ApplicationDomainType applyDiff(const QByteArray &type, const ApplicationDomain::ApplicationDomainType ¤t, const ApplicationDomain::ApplicationDomainType &diff, const QByteArrayList &deletions) const; | ||
50 | 52 | ||
51 | void startTransaction(Sink::Storage::DataStore::AccessMode); | 53 | void startTransaction(Sink::Storage::DataStore::AccessMode); |
52 | void commitTransaction(); | 54 | void commitTransaction(); |