Skip to content
Snippets Groups Projects
Commit 249dce56 authored by florian's avatar florian
Browse files

ENH: Add a CopoyTo method to Entity

parent dfdce337
No related branches found
No related tags found
1 merge request!4ENH: Allow insertion and deletion of single entities
Pipeline #11190 passed
Pipeline: caosdb-cppinttest

#11191

    This commit is part of merge request !4. Comments created here will be created in the context of that merge request.
    ......@@ -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 *;
    ......
    /*
    * 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);
    }
    ......
    ......@@ -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 {
    ......
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment