diff options
Diffstat (limited to 'common/storage/entitystore.cpp')
-rw-r--r-- | common/storage/entitystore.cpp | 59 |
1 files changed, 0 insertions, 59 deletions
diff --git a/common/storage/entitystore.cpp b/common/storage/entitystore.cpp index 5514e31..4ad3eaf 100644 --- a/common/storage/entitystore.cpp +++ b/common/storage/entitystore.cpp | |||
@@ -96,14 +96,6 @@ class EntityStore::Private { | |||
96 | public: | 96 | public: |
97 | Private(const ResourceContext &context, const Sink::Log::Context &ctx) : resourceContext(context), logCtx(ctx.subContext("entitystore")) | 97 | Private(const ResourceContext &context, const Sink::Log::Context &ctx) : resourceContext(context), logCtx(ctx.subContext("entitystore")) |
98 | { | 98 | { |
99 | static bool initialized = false; | ||
100 | if (!initialized) { | ||
101 | if (QDir{}.mkpath(entityBlobStorageDir())) { | ||
102 | initialized = true; | ||
103 | } else { | ||
104 | SinkWarningCtx(logCtx) << "Failed to create the directory: " << entityBlobStorageDir(); | ||
105 | } | ||
106 | } | ||
107 | } | 99 | } |
108 | 100 | ||
109 | ResourceContext resourceContext; | 101 | ResourceContext resourceContext; |
@@ -158,17 +150,6 @@ public: | |||
158 | auto adaptor = resourceContext.adaptorFactory(type).createAdaptor(buffer.entity(), &typeIndex(type)); | 150 | auto adaptor = resourceContext.adaptorFactory(type).createAdaptor(buffer.entity(), &typeIndex(type)); |
159 | return ApplicationDomain::ApplicationDomainType{resourceContext.instanceId(), uid, revision, adaptor}; | 151 | return ApplicationDomain::ApplicationDomainType{resourceContext.instanceId(), uid, revision, adaptor}; |
160 | } | 152 | } |
161 | |||
162 | QString entityBlobStorageDir() | ||
163 | { | ||
164 | return Sink::resourceStorageLocation(resourceContext.instanceId()) + "/blob"; | ||
165 | } | ||
166 | |||
167 | QString entityBlobStoragePath(const QByteArray &id) | ||
168 | { | ||
169 | return entityBlobStorageDir() +"/"+ id; | ||
170 | } | ||
171 | |||
172 | }; | 153 | }; |
173 | 154 | ||
174 | EntityStore::EntityStore(const ResourceContext &context, const Log::Context &ctx) | 155 | EntityStore::EntityStore(const ResourceContext &context, const Log::Context &ctx) |
@@ -205,35 +186,6 @@ bool EntityStore::hasTransaction() const | |||
205 | return d->transaction; | 186 | return d->transaction; |
206 | } | 187 | } |
207 | 188 | ||
208 | void EntityStore::copyBlobs(ApplicationDomain::ApplicationDomainType &entity, qint64 newRevision) | ||
209 | { | ||
210 | const auto directory = d->entityBlobStoragePath(entity.identifier()); | ||
211 | |||
212 | for (const auto &property : entity.changedProperties()) { | ||
213 | const auto value = entity.getProperty(property); | ||
214 | if (value.canConvert<ApplicationDomain::BLOB>()) { | ||
215 | const auto blob = value.value<ApplicationDomain::BLOB>(); | ||
216 | //Any blob that is not part of the storage yet has to be moved there. | ||
217 | if (blob.isExternal) { | ||
218 | auto oldPath = blob.value; | ||
219 | auto filePath = directory + QString("_%1%2.blob").arg(QString::number(newRevision)).arg(QString::fromLatin1(property)); | ||
220 | //In case we hit the same revision again due to a rollback. | ||
221 | QFile::remove(filePath); | ||
222 | QFile origFile(oldPath); | ||
223 | if (!origFile.open(QIODevice::ReadWrite)) { | ||
224 | SinkWarningCtx(d->logCtx) << "Failed to open the original file with write rights: " << origFile.errorString(); | ||
225 | } | ||
226 | if (!origFile.rename(filePath)) { | ||
227 | SinkWarningCtx(d->logCtx) << "Failed to move the file from: " << oldPath << " to " << filePath << ". " << origFile.errorString(); | ||
228 | } | ||
229 | origFile.close(); | ||
230 | SinkTraceCtx(d->logCtx) << "Moved blob property: " << property << " from " << oldPath << "to" << filePath; | ||
231 | entity.setProperty(property, QVariant::fromValue(ApplicationDomain::BLOB{filePath})); | ||
232 | } | ||
233 | } | ||
234 | } | ||
235 | } | ||
236 | |||
237 | bool EntityStore::add(const QByteArray &type, ApplicationDomain::ApplicationDomainType entity, bool replayToSource) | 189 | bool EntityStore::add(const QByteArray &type, ApplicationDomain::ApplicationDomainType entity, bool replayToSource) |
238 | { | 190 | { |
239 | if (entity.identifier().isEmpty()) { | 191 | if (entity.identifier().isEmpty()) { |
@@ -248,8 +200,6 @@ bool EntityStore::add(const QByteArray &type, ApplicationDomain::ApplicationDoma | |||
248 | //The maxRevision may have changed meanwhile if the entity created sub-entities | 200 | //The maxRevision may have changed meanwhile if the entity created sub-entities |
249 | const qint64 newRevision = maxRevision() + 1; | 201 | const qint64 newRevision = maxRevision() + 1; |
250 | 202 | ||
251 | copyBlobs(entity, newRevision); | ||
252 | |||
253 | // Add metadata buffer | 203 | // Add metadata buffer |
254 | flatbuffers::FlatBufferBuilder metadataFbb; | 204 | flatbuffers::FlatBufferBuilder metadataFbb; |
255 | auto metadataBuilder = MetadataBuilder(metadataFbb); | 205 | auto metadataBuilder = MetadataBuilder(metadataFbb); |
@@ -317,8 +267,6 @@ bool EntityStore::modify(const QByteArray &type, const ApplicationDomain::Applic | |||
317 | 267 | ||
318 | const qint64 newRevision = DataStore::maxRevision(d->transaction) + 1; | 268 | const qint64 newRevision = DataStore::maxRevision(d->transaction) + 1; |
319 | 269 | ||
320 | copyBlobs(newEntity, newRevision); | ||
321 | |||
322 | // Add metadata buffer | 270 | // Add metadata buffer |
323 | flatbuffers::FlatBufferBuilder metadataFbb; | 271 | flatbuffers::FlatBufferBuilder metadataFbb; |
324 | { | 272 | { |
@@ -408,13 +356,6 @@ void EntityStore::cleanupEntityRevisionsUntil(qint64 revision) | |||
408 | DataStore::removeRevision(d->transaction, rev); | 356 | DataStore::removeRevision(d->transaction, rev); |
409 | DataStore::mainDatabase(d->transaction, bufferType).remove(key); | 357 | DataStore::mainDatabase(d->transaction, bufferType).remove(key); |
410 | } | 358 | } |
411 | if (isRemoval) { | ||
412 | QDir dir{d->entityBlobStorageDir()}; | ||
413 | const auto infoList = dir.entryInfoList(QStringList{} << QString{uid + "*"}); | ||
414 | for (const auto &fileInfo : infoList) { | ||
415 | QFile::remove(fileInfo.filePath()); | ||
416 | } | ||
417 | } | ||
418 | //Don't cleanup more than specified | 359 | //Don't cleanup more than specified |
419 | if (rev >= revision) { | 360 | if (rev >= revision) { |
420 | return false; | 361 | return false; |