From 8057af27dcaf9bb6f42f4566e7b43eff78c72bbe Mon Sep 17 00:00:00 2001
From: Timm Fitschen <t.fitschen@indiscale.com>
Date: Fri, 17 Sep 2021 17:26:43 +0200
Subject: [PATCH] WIP: mixed write transactions

---
 CMakeLists.txt                   |  2 +-
 conanfile.py                     |  2 +-
 include/caosdb/protobuf_helper.h |  2 +-
 include/caosdb/transaction.h     |  8 ++++----
 include/caosdb/value.h           |  9 ++++++---
 src/caosdb/transaction.cpp       | 10 ++--------
 test/test_ccaosdb.cpp            |  3 +--
 7 files changed, 16 insertions(+), 20 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9783055..1cdccf8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -20,7 +20,7 @@
 
 cmake_minimum_required(VERSION 3.13)
 
-set(libcaosdb_VERSION 0.0.17)
+set(libcaosdb_VERSION 0.0.19)
 set(libcaosdb_COMPATIBLE_SERVER_VERSION_MAJOR 0)
 set(libcaosdb_COMPATIBLE_SERVER_VERSION_MINOR 5)
 set(libcaosdb_COMPATIBLE_SERVER_VERSION_PATCH 0)
diff --git a/conanfile.py b/conanfile.py
index 7a712bb..d29a0a6 100644
--- a/conanfile.py
+++ b/conanfile.py
@@ -3,7 +3,7 @@ from conans import ConanFile, CMake, tools
 
 class CaosdbConan(ConanFile):
     name = "caosdb"
-    version = "0.0.17"
+    version = "0.0.19"
     license = "AGPL-3.0-or-later"
     author = "Timm C. Fitschen <t.fitschen@indiscale.com>"
     url = "https://gitlab.indiscale.com/caosdb/src/caosdb-cpplib.git"
diff --git a/include/caosdb/protobuf_helper.h b/include/caosdb/protobuf_helper.h
index 9a73c0d..8574845 100644
--- a/include/caosdb/protobuf_helper.h
+++ b/include/caosdb/protobuf_helper.h
@@ -52,7 +52,7 @@ public:
   /**
    * Return a json representation of this object.
    */
-  inline auto ToString() const noexcept -> const std::string {
+  [[nodiscard]] inline auto ToString() const noexcept -> const std::string {
     CAOSDB_DEBUG_MESSAGE_STRING(*wrapped, out)
     return out;
   }
diff --git a/include/caosdb/transaction.h b/include/caosdb/transaction.h
index 0699e14..153ee46 100644
--- a/include/caosdb/transaction.h
+++ b/include/caosdb/transaction.h
@@ -93,7 +93,7 @@
   }                                                                                                \
   switch (this->transaction_type) {                                                                \
   case NONE:                                                                                       \
-    this->transaction_type = TransactionType::DELETE;                                              \
+    this->transaction_type = TransactionType::MIXED_WRITE;                                         \
   case DELETE:                                                                                     \
   case MIXED_WRITE:                                                                                \
   case MIXED_READ_AND_WRITE:                                                                       \
@@ -115,7 +115,7 @@
   }                                                                                                \
   switch (this->transaction_type) {                                                                \
   case NONE:                                                                                       \
-    this->transaction_type = TransactionType::INSERT;                                              \
+    this->transaction_type = TransactionType::MIXED_WRITE;                                         \
   case INSERT:                                                                                     \
   case MIXED_WRITE:                                                                                \
   case MIXED_READ_AND_WRITE:                                                                       \
@@ -137,8 +137,8 @@
   }                                                                                                \
   switch (this->transaction_type) {                                                                \
   case NONE:                                                                                       \
-    this->transaction_type = TransactionType::INSERT;                                              \
-  case INSERT:                                                                                     \
+    this->transaction_type = TransactionType::MIXED_WRITE;                                         \
+  case UPDATE:                                                                                     \
   case MIXED_WRITE:                                                                                \
   case MIXED_READ_AND_WRITE:                                                                       \
     break;                                                                                         \
diff --git a/include/caosdb/value.h b/include/caosdb/value.h
index b7da990..fd70c4f 100644
--- a/include/caosdb/value.h
+++ b/include/caosdb/value.h
@@ -247,9 +247,8 @@ public:
     static const std::vector<ScalarValue> empty_collection;
     return empty_collection;
   }
-  inline auto ToString() const noexcept -> const std::string {
-    CAOSDB_DEBUG_MESSAGE_STRING(*wrapped, out)
-    return out;
+  [[nodiscard]] inline auto ToString() const noexcept -> const std::string {
+    return ProtoMessageWrapper::ToString();
   }
 
   friend class Value;
@@ -416,6 +415,10 @@ public:
     return *this;
   }
 
+  [[nodiscard]] inline auto ToString() const noexcept -> const std::string {
+    return ProtoMessageWrapper::ToString();
+  }
+
   friend class Entity;
   friend class Property;
 
diff --git a/src/caosdb/transaction.cpp b/src/caosdb/transaction.cpp
index 551d905..678d6fb 100644
--- a/src/caosdb/transaction.cpp
+++ b/src/caosdb/transaction.cpp
@@ -158,7 +158,7 @@ auto Transaction::InsertEntity(Entity *entity) noexcept -> StatusCode {
     entity->SetFileTransmissionId(file_transmission_id);
     upload_files.push_back(entity->GetFileDescriptor());
   }
-  this->status = TransactionStatus::READY();
+  this->status = TransactionStatus::GO_ON();
   return this->status.GetCode();
 }
 
@@ -175,7 +175,7 @@ auto Transaction::UpdateEntity(Entity *entity) noexcept -> StatusCode {
     entity->SetFileTransmissionId(file_transmission_id);
     upload_files.push_back(entity->GetFileDescriptor());
   }
-  this->status = TransactionStatus::READY();
+  this->status = TransactionStatus::GO_ON();
   return this->status.GetCode();
 }
 
@@ -194,12 +194,6 @@ auto Transaction::ExecuteAsynchronously() noexcept -> StatusCode { // NOLINT
     return StatusCode::TRANSACTION_STATUS_ERROR;
   }
   switch (this->transaction_type) {
-  case MIXED_WRITE:
-    CAOSDB_LOG_ERROR_AND_RETURN_STATUS(
-      logger_name, StatusCode::UNSUPPORTED_FEATURE,
-      "MIXED_WRITE UNSUPPORTED: The current implementation does not support "
-      "mixed write transactions (containing insertions, deletions, and updates "
-      "in one transaction).")
   case MIXED_READ_AND_WRITE:
     CAOSDB_LOG_ERROR_AND_RETURN_STATUS(
       logger_name, StatusCode::UNSUPPORTED_FEATURE,
diff --git a/test/test_ccaosdb.cpp b/test/test_ccaosdb.cpp
index 361b091..d5b894b 100644
--- a/test/test_ccaosdb.cpp
+++ b/test/test_ccaosdb.cpp
@@ -984,8 +984,7 @@ TEST_F(test_ccaosdb, test_insert_update_delete) {
   caosdb_entity_entity_set_file_path(&entity, "some_name");
 
   auto return_code = caosdb_transaction_transaction_insert_entity(&insert_transaction, &entity);
-  // For now, nothing further can be done here, so it should be READY
-  EXPECT_EQ(return_code, caosdb::StatusCode::READY);
+  EXPECT_EQ(return_code, caosdb::StatusCode::GO_ON);
 
   caosdb_transaction_transaction update_transaction;
   caosdb_connection_connection_create_transaction(&connection, &update_transaction);
-- 
GitLab