attaching schema nodes progress

This commit is contained in:
Sascha Kühl
2025-07-11 16:08:49 +02:00
parent 6982eebfd6
commit 27e2c51175
18 changed files with 697 additions and 446 deletions
+7
View File
@@ -17,12 +17,15 @@ add_library(matador-core STATIC
../../include/matador/object/attribute_definition.hpp
../../include/matador/object/basic_object_info.hpp
../../include/matador/object/error_code.hpp
../../include/matador/object/foreign_node_completer.hpp
../../include/matador/object/internal/shadow_schema.hpp
../../include/matador/object/many_to_many_relation.hpp
../../include/matador/object/object_definition.hpp
../../include/matador/object/object_info.hpp
../../include/matador/object/object_proxy.hpp
../../include/matador/object/object_ptr.hpp
../../include/matador/object/primary_key_resolver.hpp
../../include/matador/object/relation_completer.hpp
../../include/matador/object/relation_endpoint.hpp
../../include/matador/object/schema.hpp
../../include/matador/object/schema_node.hpp
@@ -53,6 +56,7 @@ add_library(matador-core STATIC
../../include/matador/utils/macro_map.hpp
../../include/matador/utils/os.hpp
../../include/matador/utils/placeholder.hpp
../../include/matador/utils/primary_key_attribute.hpp
../../include/matador/utils/result.hpp
../../include/matador/utils/singleton.hpp
../../include/matador/utils/string.hpp
@@ -72,6 +76,8 @@ add_library(matador-core STATIC
object/attribute_definition.cpp
object/basic_object_info.cpp
object/error_code.cpp
object/foreign_node_completer.cpp
object/internal/shadow_schema.cpp
object/object_definition.cpp
object/primary_key_resolver.cpp
object/relation_endpoint.cpp
@@ -88,6 +94,7 @@ add_library(matador-core STATIC
utils/leader_follower_thread_pool.cpp
utils/library.cpp
utils/os.cpp
utils/primary_key_attribute.cpp
utils/string.cpp
utils/thread_pool.cpp
utils/types.cpp
+2 -4
View File
@@ -86,8 +86,7 @@ void log_domain::add_sink(sink_ptr sink)
sinks.push_back(std::move(sink));
}
void log_domain::log(log_level lvl, const std::string &source, const char *message)
{
void log_domain::log(log_level lvl, const std::string &source, const char *message) const {
if (lvl < log_level_range_.max_level || lvl > log_level_range_.min_level) {
return;
}
@@ -114,8 +113,7 @@ void log_domain::clear()
sinks.clear();
}
void log_domain::get_time_stamp(char* const timestamp_buffer)
{
void log_domain::get_time_stamp(char* const timestamp_buffer) const {
std::lock_guard l(mutex_);
details::gettimestamp(timestamp_buffer, 80);
}
@@ -0,0 +1,11 @@
#include "matador/object/foreign_node_completer.hpp"
#include "matador/object/schema.hpp"
#include "matador/logger/logger.hpp"
namespace matador::object {
foreign_node_completer::foreign_node_completer(internal::shadow_schema &shadow)
: schema_(shadow)
, log_(logger::create_logger("node_completer")) {}
}
@@ -0,0 +1,29 @@
#include "matador/object/internal/shadow_schema.hpp"
#include "matador/object/schema.hpp"
#include "matador/object/schema_node.hpp"
namespace matador::object::internal {
shadow_schema::shadow_schema( object::schema& s )
: schema_(s) {}
schema& shadow_schema::schema() const {
return schema_;
}
bool shadow_schema::schema_contains( const std::type_index& ti ) const {
return schema_.contains(ti);
}
utils::result<shadow_schema::node_ptr, utils::error> shadow_schema::find_node( const std::type_index& type_index ) const {
return schema_.find_node(type_index);
}
utils::result<shadow_schema::node_ptr, utils::error> shadow_schema::attach_node( const std::shared_ptr<schema_node>& node ) const {
return schema_.attach_node(node, "");
}
utils::result<void, utils::error> shadow_schema::detach_node( const std::shared_ptr<schema_node>& node ) const {
return schema_.detach(node);
}
}
+27 -38
View File
@@ -25,25 +25,6 @@ utils::result<void, utils::error> schema::detach(const node_ptr &node) {
return utils::ok<void>();
}
// utils::result<void, utils::error> schema::detach(const std::string& name) {
// const auto nit = nodes_by_name_.find(name);
// if (nit == nodes_by_name_.end()) {
// return utils::failure(make_error(error_code::NodeNotFound, "Node '" + name + "' not found."));
// }
//
// const auto ti = nit->second->type_index();
// nodes_by_name_.erase(nit);
//
// const auto it = nodes_by_type_.find(ti);
// if (it == nodes_by_type_.end()) {
// return utils::failure(make_error(error_code::NodeNotFound, "Node '" + name + "' not found."));
// }
//
// nodes_by_type_.erase(it);
//
// return utils::ok<void>();
// }
schema::const_iterator schema::begin() const {
return const_iterator(root_->first_child_->next_sibling_);
}
@@ -64,6 +45,14 @@ std::string schema::name() const {
return name_;
}
bool schema::contains( const std::string& name ) const {
return nodes_by_name_.count(name) > 0;
}
bool schema::contains( const std::type_index& index ) const {
return nodes_by_type_.count(index) > 0;
}
utils::result<std::shared_ptr<attribute_definition>, utils::error> schema::reference(const std::type_index &type_index) const {
const auto result = find_node(type_index);
if (result) {
@@ -93,7 +82,7 @@ utils::result<schema::node_ptr, utils::error> schema::attach_node(const std::sha
return utils::failure(make_error(error_code::NodeAlreadyExists, "Node '" + node->name() + "' already exists."));
}
log_.info("attach node '%s' (type: %s)", node->name().c_str(), node->type_index().name());
log_.info("attach: insert node '%s' (type: %s)", node->name().c_str(), node->type_index().name());
// set node to root node
auto parent_node = root_;
@@ -114,24 +103,24 @@ utils::result<schema::node_ptr, utils::error> schema::attach_node(const std::sha
return utils::ok(node);
}
utils::result<schema::node_ptr, utils::error> schema::attach_node(const std::shared_ptr<schema_node> &node,
const std::type_index &type_index) {
if (has_node(node)) {
return utils::failure(make_error(error_code::NodeAlreadyExists, "Node '" + node->name() + "' already exists."));
}
auto result = find_node(type_index);
if (!result.is_ok() && result.err().ec() != error_code::NodeNotFound) {
return result;
}
insert_node(*result, node);
// Todo: check return value
nodes_by_name_.insert({node->name(), node})/*.first*/;
nodes_by_type_.insert({node->type_index(), node});
return utils::ok(node);
}
// utils::result<schema::node_ptr, utils::error> schema::attach_node(const std::shared_ptr<schema_node> &node,
// const std::type_index &type_index) {
// if (has_node(node)) {
// return utils::failure(make_error(error_code::NodeAlreadyExists, "Node '" + node->name() + "' already exists."));
// }
// auto result = find_node(type_index);
// if (!result.is_ok() && result.err().ec() != error_code::NodeNotFound) {
// return result;
// }
//
// insert_node(*result, node);
//
// // Todo: check return value
// nodes_by_name_.insert({node->name(), node})/*.first*/;
// nodes_by_type_.insert({node->type_index(), node});
//
// return utils::ok(node);
// }
utils::result<schema::node_ptr, utils::error> schema::find_node(const std::string &name) const {
// first search in the prototype map
@@ -0,0 +1,15 @@
#include "matador/utils/primary_key_attribute.hpp"
namespace matador::utils {
primary_key_attribute::primary_key_attribute(const size_t size)
: size_(size) {}
primary_key_attribute& primary_key_attribute::operator=(const size_t size) {
size_ = size;
return *this;
}
size_t primary_key_attribute::size() const {
return size_;
}
}