From d4253ee4d06f67c3e3f41d94d4636aef34d24d89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sascha=20K=C3=BChl?= Date: Tue, 8 Jul 2025 14:15:32 +0200 Subject: [PATCH] removed redundant code in relation completer --- include/matador/net/socket.hpp | 24 ++++++++--------- include/matador/object/schema.hpp | 45 +++++++------------------------ 2 files changed, 21 insertions(+), 48 deletions(-) diff --git a/include/matador/net/socket.hpp b/include/matador/net/socket.hpp index 8bbbdda..721b2e5 100644 --- a/include/matador/net/socket.hpp +++ b/include/matador/net/socket.hpp @@ -17,7 +17,7 @@ namespace matador { /** - * Base class for several kind of socket + * Base class for some kind of socket * classes (acceptor, stream) representing a * socket. The protocol is selected via the * template parameter (/sa tcp and udp classes) @@ -72,7 +72,7 @@ public: * Releases the socket fd and sets * the internal socket to zero (0). * - * After the socket is released the user + * After the socket is released, the user * is in charge to take of the socket * * @return The released socket fd @@ -81,8 +81,8 @@ public: /** * Connect to the given peer. If the connection - * could be established true is returned, - * otherwise false is returned and errno is set. + * could be established, true is returned, + * otherwise false is returned, and errno is set. * * @param p Peer to execute to * @return True on successful connection @@ -91,21 +91,21 @@ public: /** * Sets the socket either blocking (false) or - * non blocking (true). + * non-blocking (true). * * @param nb True sets the socket non blocking false blocking */ void non_blocking(bool nb); /** - * Returns true if the socket is non blocking + * Returns true if the socket is non-blocking * otherwise returns false - * @return True if socket is non blocking + * @return True if the socket is non-blocking */ bool non_blocking() const; /** - * Set or unset the cose on exec flag + * Set or unset the cose on the exec flag * for the socket * * @param nb Flag to set or unset cloexec option @@ -113,15 +113,15 @@ public: void cloexec(bool nb); /** - * Returns true if close on exec option is set + * Returns true if the close-on-exec option is set * * @return True on set cloexec option */ bool cloexec() const; /** - * Sets a socket option represented by name. If option - * was successfully set true is returned. Otherwise false + * Sets a socket option represented by name. If the option + * was successfully set, true is returned. Otherwise, false * and errno ist set. * * @param name Option name @@ -139,7 +139,7 @@ public: /** * Assigns the given socket fd to this - * socket. If the socket is already opened + * socket. If the socket is already opened, * an exception is thrown. * * @param sock The socket fd to assign diff --git a/include/matador/object/schema.hpp b/include/matador/object/schema.hpp index f43119b..e3b6116 100644 --- a/include/matador/object/schema.hpp +++ b/include/matador/object/schema.hpp @@ -385,42 +385,15 @@ void relation_completer::on_has_many_to_many(const char *id, template template void relation_completer::on_has_many_to_many(const char *id, - CollectionType &/*collection*/, - const utils::foreign_attributes &/*attr*/) { - auto result = schema_.find_node(id); - if (!result) { - const auto join_columns = join_columns_collector_.collect(); - using relation_value_type = many_to_many_relation; - auto creator = [&join_columns] { - return std::make_unique(join_columns.inverse_join_column, join_columns.join_column); - }; - - auto node = schema_node::make_relation_node(schema_, id, std::move(creator)); - - auto local_endpoint = std::make_shared(id, relation_type::HAS_MANY, node_); - auto join_endpoint = std::make_shared(join_columns.join_column, relation_type::BELONGS_TO, node); - auto inverse_join_endpoint = std::make_shared(join_columns.inverse_join_column, - relation_type::BELONGS_TO, node); - node_->info_->register_relation_endpoint(typeid(typename CollectionType::value_type::value_type), local_endpoint); - node->info_->register_relation_endpoint(node_->type_index(), inverse_join_endpoint); - link_relation_endpoints(local_endpoint, inverse_join_endpoint); - node->info_->register_relation_endpoint(typeid(typename CollectionType::value_type::value_type), join_endpoint); - result = schema_.attach_node(node, ""); - if (!result) { - // Todo: throw internal error - return; - } - } else { - const auto &foreign_node = result.value(); - const auto local_endpoint = std::make_shared(id, relation_type::HAS_MANY, node_); - node_->info_->register_relation_endpoint(typeid(typename CollectionType::value_type::value_type), local_endpoint); - const auto it = foreign_node->info_->find_relation_endpoint(node_->type_index()); - if (it == foreign_node->info().endpoint_end()) { - // Todo: Throw internal error - return; - } - link_relation_endpoints(local_endpoint, it->second); - } + CollectionType &collection, + const utils::foreign_attributes &attr) { + const auto join_columns = join_columns_collector_.collect(); + on_has_many_to_many( + id, + collection, + join_columns.inverse_join_column.c_str(), + join_columns.join_column.c_str(), + attr); } template