Skip to content
Snippets Groups Projects
Verified Commit d9bb5c39 authored by Timm Fitschen's avatar Timm Fitschen
Browse files

WIP: cleanup

parent 7daa44c5
No related branches found
No related tags found
No related merge requests found
Pipeline #10055 failed
......@@ -21,43 +21,126 @@
/**
* @brief Anything entity-related.
* @file caosdb/entity.h
* @author Timm Fitchen
* @date 2021-07-07
*/
#ifndef CAOSDB_ENTITY_H
#define CAOSDB_ENTITY_H
#include <memory> // for shared_ptr
#include <string> // for string
#include <memory> // for shared_ptr
#include <string> // for string
#include <google/protobuf/repeated_field.h>
#include "caosdb/entity/v1alpha1/main.pb.h" // for Entity
namespace caosdb::entity {
using ProtoEntity = caosdb::entity::v1alpha1::Entity;
/**
* Entity ID.
* Parent of an Entity.
*/
class EntityID {
class Parent {
public:
explicit inline Parent(caosdb::entity::v1alpha1::Parent *wrapped)
: wrapped(wrapped){};
[[nodiscard]] auto GetId() const -> const std::string &;
[[nodiscard]] auto GetName() const -> const std::string &;
[[nodiscard]] auto GetDescription() const -> const std::string &;
private:
std::shared_ptr<std::string> id;
caosdb::entity::v1alpha1::Parent *wrapped;
};
/**
* Container for parents of entities.
*/
class Parents {
public:
explicit EntityID(const std::string &id);
explicit EntityID(const std::shared_ptr<std::string> &id);
inline Parents(){};
explicit inline Parents(
::google::protobuf::RepeatedField<caosdb::entity::v1alpha1::Parent>
*wrapped)
: wrapped(wrapped){};
[[nodiscard]] auto At(int index) const -> const Parent &;
private:
::google::protobuf::RepeatedField<caosdb::entity::v1alpha1::Parent> *wrapped;
friend class Entity;
};
/**
* @brief Wrapper for the Protobuf entity.
* Property of an Entity.
*
* This is a property which belongs to another entity. Don't confuse it with an
* Entity with the "Property" role.
*
* @brief Property of an Entity.
*/
class Entity {
class Property {
public:
explicit inline Property(caosdb::entity::v1alpha1::Property *wrapped)
: wrapped(wrapped){};
[[nodiscard]] auto GetId() const -> const std::string &;
[[nodiscard]] auto GetName() const -> const std::string &;
[[nodiscard]] auto GetDescription() const -> const std::string &;
[[nodiscard]] auto GetImportance() const -> const std::string &;
[[nodiscard]] auto GetValue() const -> const std::string &;
[[nodiscard]] auto GetUnit() const -> const std::string &;
[[nodiscard]] auto GetDatatype() const -> const std::string &;
private:
caosdb::entity::v1alpha1::Property *wrapped;
};
/**
* Container for Properties of Entities
*/
class Properties {
public:
inline Properties(){};
explicit inline Properties(
::google::protobuf::RepeatedField<caosdb::entity::v1alpha1::Property>
*wrapped)
: wrapped(wrapped){};
[[nodiscard]] auto At(int index) const -> const Property &;
private:
EntityID id;
std::shared_ptr<ProtoEntity> delegate;
::google::protobuf::RepeatedField<caosdb::entity::v1alpha1::Property>
*wrapped;
friend class Entity;
};
/**
* @brief Wrapper for the Protobuf entity.
*/
class Entity {
public:
explicit Entity(ProtoEntity *delegate);
[[nodiscard]] auto GetId() const -> EntityID;
auto SetId(EntityID id) -> void;
[[nodiscard]] auto GetName() const -> std::string;
[[nodiscard]] auto GetDescription() const -> std::string;
explicit inline Entity(caosdb::entity::v1alpha1::Entity *wrapped)
: wrapped(wrapped),
properties(
(::google::protobuf::RepeatedField<caosdb::entity::v1alpha1::Property>
*)wrapped->mutable_properties()),
parents(
(::google::protobuf::RepeatedField<caosdb::entity::v1alpha1::Parent> *)
wrapped->mutable_parents()){};
[[nodiscard]] auto GetId() const -> const std::string &;
[[nodiscard]] auto GetVersion() const -> const std::string &;
[[nodiscard]] auto GetRole() const -> const std::string &;
[[nodiscard]] auto GetName() const -> const std::string &;
[[nodiscard]] inline auto GetDescription() const -> const std::string & {
return wrapped->description();
}
[[nodiscard]] auto GetDatatype() const -> const std::string &;
[[nodiscard]] auto GetUnit() const -> const std::string &;
[[nodiscard]] auto GetParents() const -> const Parents &;
[[nodiscard]] auto GetProperties() const -> const Properties &;
private:
std::unique_ptr<caosdb::entity::v1alpha1::Entity> wrapped;
Properties properties;
Parents parents;
};
} // namespace caosdb::entity
......
......@@ -33,23 +33,20 @@
namespace caosdb::transaction {
using caosdb::entity::Entity;
using caosdb::entity::EntityID;
using ProtoEntity = caosdb::entity::v1alpha1::Entity;
using caosdb::entity::v1alpha1::EntityTransactionService;
using caosdb::entity::v1alpha1::RetrieveRequest;
class ResultSet {
// public:
//[[nodiscard]] auto GetEntityById(EntityID id) const -> Entity;
};
class ResultSet {};
class UniqueResult : public ResultSet {
private:
Entity entity;
std::unique_ptr<Entity> entity;
public:
UniqueResult(Entity entity);
[[nodiscard]] auto GetEntity() const -> Entity;
explicit inline UniqueResult(ProtoEntity *protoEntity)
: entity(new Entity(protoEntity)){};
[[nodiscard]] auto GetEntity() const -> const Entity &;
};
enum TransactionState { INIT = 10, EXECUTING = 20, SUCCESS = 30, ERROR = 40 };
......@@ -66,7 +63,7 @@ private:
public:
Transaction(std::shared_ptr<EntityTransactionService::Stub> service_stub);
auto Retrieve(const EntityID &id) -> void;
auto RetrieveById(const std::string &id) -> void;
auto Execute() -> void;
[[nodiscard]] auto GetResultSet() const -> std::shared_ptr<ResultSet>;
auto WaitForIt() const -> void;
......
Subproject commit dd9abe3499367c4eded4774ade1acbc90ef048b3
Subproject commit 12f072263c05208464b80c0124bde0396b100d86
......@@ -22,24 +22,4 @@
#include "caosdb/entity.h"
#include <utility>
namespace caosdb::entity {
EntityID::EntityID(const std::string &id) {
this->id = std::make_shared<std::string>(id);
}
EntityID::EntityID(const std::shared_ptr<std::string> &id) {
this->id = std::make_shared<std::string>(*id);
}
Entity::Entity(ProtoEntity *delegate)
: id(EntityID(delegate->eid())), delegate(delegate) {}
[[nodiscard]] auto Entity::GetDescription() const -> std::string {
return this->delegate->description();
}
[[nodiscard]] auto Entity::GetId() const -> EntityID { return this->id; }
auto Entity::SetId(EntityID id) -> void { this->id = std::move(id); }
} // namespace caosdb::entity
namespace caosdb::entity {} // namespace caosdb::entity
......@@ -39,10 +39,9 @@ using ProtoEntity = caosdb::entity::v1alpha1::Entity;
using caosdb::exceptions::AuthenticationError;
using caosdb::exceptions::ConnectionError;
UniqueResult::UniqueResult(Entity entity) : entity(std::move(entity)) {}
[[nodiscard]] auto UniqueResult::GetEntity() const -> Entity {
return this->entity;
[[nodiscard]] auto UniqueResult::GetEntity() const -> const Entity & {
const Entity *result = this->entity.get();
return *result;
}
Transaction::Transaction(
......@@ -50,9 +49,9 @@ Transaction::Transaction(
this->service_stub = std::move(service_stub);
}
auto Transaction::Retrieve(const EntityID & /*id*/) -> void {
// TODO(tf)
auto Transaction::RetrieveById(const std::string &id) -> void {
RetrieveRequest request;
request.mutable_by_id()->set_id(id);
this->request = request;
}
......@@ -78,7 +77,7 @@ auto Transaction::Execute() -> void {
}
}
auto entity = Entity(response.release_entity());
auto *entity = response.release_entity();
auto result_set = std::make_shared<UniqueResult>(entity);
this->result_set = result_set;
}
......
......@@ -69,7 +69,7 @@ auto main() -> int {
// retrieve an entity
auto transaction(connection.CreateTransaction());
transaction->Retrieve(caosdb::entity::EntityID("someid"));
transaction->RetrieveById("20");
transaction->Execute();
auto result_set(std::static_pointer_cast<caosdb::transaction::UniqueResult>(
transaction->GetResultSet()));
......
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