summaryrefslogtreecommitdiffstats
path: root/common/storage/entitystore.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-04-11 15:16:26 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-04-11 15:16:26 +0200
commitf6c3c144e60611d2da7ba7aa5b115affe92a57a4 (patch)
tree4e4b01382d7c2893d4d1d14489506e3b0066fce9 /common/storage/entitystore.cpp
parentadb11fd81404b9ab3b01975ed93babe12a22dee4 (diff)
downloadsink-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/entitystore.cpp')
-rw-r--r--common/storage/entitystore.cpp34
1 files changed, 22 insertions, 12 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
212bool EntityStore::modify(const QByteArray &type, const ApplicationDomain::ApplicationDomainType &diff, const QByteArrayList &deletions, bool replayToSource, const PreprocessModification &preprocess) 212ApplicationDomain::ApplicationDomainType EntityStore::applyDiff(const QByteArray &type, const ApplicationDomain::ApplicationDomainType &current, 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
236bool 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
248bool EntityStore::modify(const QByteArray &type, const ApplicationDomain::ApplicationDomainType &current, 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