summaryrefslogtreecommitdiffstats
path: root/common/storage/entitystore.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'common/storage/entitystore.cpp')
-rw-r--r--common/storage/entitystore.cpp18
1 files changed, 15 insertions, 3 deletions
diff --git a/common/storage/entitystore.cpp b/common/storage/entitystore.cpp
index 6021344..d5a7c5f 100644
--- a/common/storage/entitystore.cpp
+++ b/common/storage/entitystore.cpp
@@ -158,13 +158,23 @@ EntityStore::EntityStore(const ResourceContext &context, const Log::Context &ctx
158 158
159} 159}
160 160
161void EntityStore::createIfMissing() 161void EntityStore::initialize()
162{ 162{
163 if (!d->exists()) { 163 //This function is only called in the resource code where we want to be able to write to the databse.
164
165 //Check for the existience of the db without creating it or the envrionment.
166 //This is required to be able to set the database version only in the case where we create a new database.
167 if (!Storage::DataStore::exists(Sink::storageLocation(), d->resourceContext.instanceId())) {
168 //The first time we open the environment we always want it to be read/write. Otherwise subsequent tries to open a write transaction will fail.
164 startTransaction(Sink::Storage::DataStore::ReadWrite); 169 startTransaction(Sink::Storage::DataStore::ReadWrite);
170 //Create the database with the correct version if it wasn't existing before
171 SinkLogCtx(d->logCtx) << "Creating resource database.";
165 Storage::DataStore::setDatabaseVersion(d->transaction, Sink::latestDatabaseVersion()); 172 Storage::DataStore::setDatabaseVersion(d->transaction, Sink::latestDatabaseVersion());
166 commitTransaction(); 173 } else {
174 //The first time we open the environment we always want it to be read/write. Otherwise subsequent tries to open a write transaction will fail.
175 startTransaction(Sink::Storage::DataStore::ReadWrite);
167 } 176 }
177 commitTransaction();
168} 178}
169 179
170void EntityStore::startTransaction(Sink::Storage::DataStore::AccessMode accessMode) 180void EntityStore::startTransaction(Sink::Storage::DataStore::AccessMode accessMode)
@@ -383,9 +393,11 @@ void EntityStore::cleanupEntityRevisionsUntil(qint64 revision)
383 393
384bool EntityStore::cleanupRevisions(qint64 revision) 394bool EntityStore::cleanupRevisions(qint64 revision)
385{ 395{
396 Q_ASSERT(d->exists());
386 bool implicitTransaction = false; 397 bool implicitTransaction = false;
387 if (!d->transaction) { 398 if (!d->transaction) {
388 startTransaction(Sink::Storage::DataStore::ReadWrite); 399 startTransaction(Sink::Storage::DataStore::ReadWrite);
400 Q_ASSERT(d->transaction);
389 implicitTransaction = true; 401 implicitTransaction = true;
390 } 402 }
391 const auto lastCleanRevision = DataStore::cleanedUpRevision(d->transaction); 403 const auto lastCleanRevision = DataStore::cleanedUpRevision(d->transaction);