diff --git a/include/caosdb/entity.h b/include/caosdb/entity.h index edd2018ba7a274fabe5e6eca0db09375dec78430..6d4b45181d198a12d0bac9eed9f77d774e8ebaa0 100644 --- a/include/caosdb/entity.h +++ b/include/caosdb/entity.h @@ -2,6 +2,7 @@ * This file is a part of the CaosDB Project. * * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> + * Copyright (C) 2021 Florian Spreckelsen <f.spreckelsen@indiscale.com> * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify @@ -450,6 +451,10 @@ public: auto AppendParent(const Parent &parent) -> void; auto Switch(ProtoEntity *entity) -> void; + /** + * Copy all of this entity's features to the target ProtoEntity. + */ + auto CopyTo(ProtoEntity *target) -> void; private: static auto CreateProtoEntity() -> ProtoEntity *; diff --git a/src/caosdb/entity.cpp b/src/caosdb/entity.cpp index 22f0effe8a8c345775eaf80b2dfaba37199c6675..999ba3753b068909dc7dd54518ca5ff8bd8033bf 100644 --- a/src/caosdb/entity.cpp +++ b/src/caosdb/entity.cpp @@ -1,6 +1,8 @@ /* * This file is a part of the CaosDB Project. + * * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> + * Copyright (C) 2021 Florian Spreckelsen <f.spreckelsen@indiscale.com> * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> * * This program is free software: you can redistribute it and/or modify @@ -175,12 +177,17 @@ auto Entity::SetVersionId(const std::string &id) -> void { this->wrapped->mutable_version()->set_id(id); } +// TODO(tf) Re-implement s.th. properties and parents are kept. auto Entity::Switch(ProtoEntity *entity) -> void { this->wrapped->Swap(entity); this->wrapped->Clear(); this->wrapped = entity; } +auto Entity::CopyTo(ProtoEntity *target) -> void { + target->CopyFrom(*(this->wrapped)); +} + auto Entity::SetRole(const std::string &role) -> void { this->wrapped->set_role(role); } diff --git a/src/caosdb/transaction.cpp b/src/caosdb/transaction.cpp index 380362a5e3f182d57baeb6e7410f71383e843411..7dd4a71558de93b703ac959909692065ea8e0725 100644 --- a/src/caosdb/transaction.cpp +++ b/src/caosdb/transaction.cpp @@ -148,8 +148,8 @@ auto Transaction::InsertEntity(Entity *entity) -> void { auto *sub_request = this->request->add_requests(); auto *proto_entity = sub_request->mutable_insert_request(); - // swap and switch - entity->Switch(proto_entity); + // copy the original entity for the transaction + entity->CopyTo(proto_entity); } auto Transaction::Execute() -> TransactionStatus {