removed redundant code in relation completer

This commit is contained in:
Sascha Kühl 2025-07-08 14:15:32 +02:00
parent 3374aba5ab
commit d4253ee4d0
2 changed files with 21 additions and 48 deletions

View File

@ -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

View File

@ -385,42 +385,15 @@ void relation_completer<Type>::on_has_many_to_many(const char *id,
template<typename Type>
template<class CollectionType>
void relation_completer<Type>::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<typename CollectionType::value_type::value_type>();
using relation_value_type = many_to_many_relation<typename CollectionType::value_type::value_type, Type>;
auto creator = [&join_columns] {
return std::make_unique<relation_value_type>(join_columns.inverse_join_column, join_columns.join_column);
};
auto node = schema_node::make_relation_node<relation_value_type>(schema_, id, std::move(creator));
auto local_endpoint = std::make_shared<relation_endpoint>(id, relation_type::HAS_MANY, node_);
auto join_endpoint = std::make_shared<relation_endpoint>(join_columns.join_column, relation_type::BELONGS_TO, node);
auto inverse_join_endpoint = std::make_shared<relation_endpoint>(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<relation_endpoint>(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<typename CollectionType::value_type::value_type>();
on_has_many_to_many(
id,
collection,
join_columns.inverse_join_column.c_str(),
join_columns.join_column.c_str(),
attr);
}
template<typename Type>