|
|
|
@@ -12,24 +12,32 @@
|
|
|
|
|
#include "matador/logger/log_manager.hpp"
|
|
|
|
|
|
|
|
|
|
#include <stack>
|
|
|
|
|
|
|
|
|
|
#include "repository.hpp"
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
namespace matador::object {
|
|
|
|
|
template<typename NodeType, template<typename> typename... Observers>
|
|
|
|
|
class completer {
|
|
|
|
|
public:
|
|
|
|
|
template<typename Type>
|
|
|
|
|
void foo(Observers<NodeType>&&... observers) {
|
|
|
|
|
(std::unique_ptr<Observers<Type>>(new Observers(std::forward<Observers>(observers))), ...);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Processes the given node and ensures
|
|
|
|
|
* that all foreign nodes needed by the given node
|
|
|
|
|
* relations are attached in schema.
|
|
|
|
|
*/
|
|
|
|
|
template<typename NodeType>
|
|
|
|
|
template<typename NodeType, template<typename> typename ...Observers>
|
|
|
|
|
class foreign_node_completer final {
|
|
|
|
|
private:
|
|
|
|
|
using node_ptr = std::shared_ptr<repository_node>;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
static void complete(const std::shared_ptr<repository_node> &node) {
|
|
|
|
|
static void complete(const std::shared_ptr<repository_node> &node, Observers<NodeType>... observers) {
|
|
|
|
|
internal::shadow_repository shadow(node->repo_);
|
|
|
|
|
foreign_node_completer completer(shadow);
|
|
|
|
|
foreign_node_completer completer(shadow, observers...);
|
|
|
|
|
|
|
|
|
|
completer.complete_node(node);
|
|
|
|
|
}
|
|
|
|
@@ -60,18 +68,20 @@ public:
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class CollectionType>
|
|
|
|
|
void on_has_many_to_many(const char *id,
|
|
|
|
|
CollectionType &collection,
|
|
|
|
|
const char *join_column,
|
|
|
|
|
const char *inverse_join_column,
|
|
|
|
|
const utils::foreign_attributes &attr);
|
|
|
|
|
static void on_has_many_to_many(const char * /*id*/,
|
|
|
|
|
CollectionType &/*collection*/,
|
|
|
|
|
const char * /*join_column*/,
|
|
|
|
|
const char * /*inverse_join_column*/,
|
|
|
|
|
const utils::foreign_attributes &/*attr*/) {}
|
|
|
|
|
template<class CollectionType>
|
|
|
|
|
void on_has_many_to_many(const char *id, CollectionType &collection, const utils::foreign_attributes &attr);
|
|
|
|
|
static void on_has_many_to_many(const char * /*id*/, CollectionType &/*collection*/, const utils::foreign_attributes &/*attr*/) {}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
explicit foreign_node_completer(internal::shadow_repository &shadow)
|
|
|
|
|
explicit foreign_node_completer(internal::shadow_repository &shadow, Observers<NodeType>... observers)
|
|
|
|
|
: repo_(shadow)
|
|
|
|
|
, log_(logger::create_logger("node_completer")) {}
|
|
|
|
|
, log_(logger::create_logger("node_completer")) {
|
|
|
|
|
// observers_.emplace_back(observers...);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void complete_node(const std::shared_ptr<repository_node> &node) {
|
|
|
|
|
nodes_.push(node);
|
|
|
|
@@ -160,7 +170,7 @@ private:
|
|
|
|
|
const endpoint_ptr &other_endpoint);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
template<typename Type>
|
|
|
|
|
template<typename Type, template<typename> typename ...OtherObservers>
|
|
|
|
|
friend class foreign_node_completer;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
@@ -168,69 +178,41 @@ private:
|
|
|
|
|
internal::shadow_repository &repo_;
|
|
|
|
|
logger::logger log_;
|
|
|
|
|
join_columns_collector join_columns_collector_{};
|
|
|
|
|
// const std::vector<Observers<NodeType>...> observers_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename NodeType>
|
|
|
|
|
template<typename NodeType, template<typename> typename ...Observers>
|
|
|
|
|
template<class ForeignPointerType>
|
|
|
|
|
void foreign_node_completer<NodeType>::on_belongs_to(const char * /*id*/, ForeignPointerType &, const utils::foreign_attributes &) {
|
|
|
|
|
void foreign_node_completer<NodeType, Observers...>::on_belongs_to(const char * /*id*/, ForeignPointerType &, const utils::foreign_attributes &) {
|
|
|
|
|
attach_node<typename ForeignPointerType::value_type>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename NodeType>
|
|
|
|
|
template<typename NodeType, template<typename> typename ...Observers>
|
|
|
|
|
template<class ForeignPointerType>
|
|
|
|
|
void foreign_node_completer<NodeType>::on_has_one(const char *, ForeignPointerType &, const utils::foreign_attributes &) {
|
|
|
|
|
void foreign_node_completer<NodeType, Observers...>::on_has_one(const char *, ForeignPointerType &, const utils::foreign_attributes &) {
|
|
|
|
|
attach_node<typename ForeignPointerType::value_type>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename NodeType>
|
|
|
|
|
template<typename NodeType, template<typename> typename ...Observers>
|
|
|
|
|
template<class CollectionType>
|
|
|
|
|
void foreign_node_completer<NodeType>::on_has_many(const char * /*id*/,
|
|
|
|
|
void foreign_node_completer<NodeType, Observers...>::on_has_many(const char * /*id*/,
|
|
|
|
|
CollectionType &, const char * /*join_column*/,
|
|
|
|
|
const utils::foreign_attributes & /*attr*/,
|
|
|
|
|
std::enable_if_t<is_object_ptr<typename CollectionType::value_type>::value> *) {
|
|
|
|
|
attach_node<typename CollectionType::value_type::value_type>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename NodeType>
|
|
|
|
|
template<class CollectionType>
|
|
|
|
|
void foreign_node_completer<NodeType>::on_has_many_to_many(const char * /*id*/,
|
|
|
|
|
CollectionType & /*collection*/,
|
|
|
|
|
const char * /*join_column*/,
|
|
|
|
|
const char * /*inverse_join_column*/,
|
|
|
|
|
const utils::foreign_attributes & /*attr*/) {
|
|
|
|
|
// if (!repo_.expecting_relation_node(id)) {
|
|
|
|
|
// repo_.expect_relation_node(id, typeid(typename CollectionType::value_type::value_type));
|
|
|
|
|
// } else {
|
|
|
|
|
// attach_relation_node<typename CollectionType::value_type::value_type>(id, join_column, inverse_join_column);
|
|
|
|
|
// repo_.remove_expected_relation_node(id);
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename NodeType>
|
|
|
|
|
template<class CollectionType>
|
|
|
|
|
void foreign_node_completer<NodeType>::on_has_many_to_many(const char * /*id*/,
|
|
|
|
|
CollectionType & /*collection*/,
|
|
|
|
|
const utils::foreign_attributes & /*attr*/) {
|
|
|
|
|
// if (!repo_.expecting_relation_node(id)) {
|
|
|
|
|
// repo_.expect_relation_node(id, typeid(typename CollectionType::value_type::value_type));
|
|
|
|
|
// } else {
|
|
|
|
|
// const auto join_columns = join_columns_collector_.collect<typename CollectionType::value_type::value_type>();
|
|
|
|
|
// attach_relation_node<typename CollectionType::value_type::value_type>(id, join_columns.join_column, join_columns.inverse_join_column);
|
|
|
|
|
// repo_.remove_expected_relation_node(id);
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename NodeType>
|
|
|
|
|
void foreign_node_completer<NodeType>::register_relation_endpoints(const endpoint_ptr &endpoint,
|
|
|
|
|
template<typename NodeType, template<typename> typename ...Observers>
|
|
|
|
|
void foreign_node_completer<NodeType, Observers...>::register_relation_endpoints(const endpoint_ptr &endpoint,
|
|
|
|
|
const endpoint_ptr &other_endpoint) {
|
|
|
|
|
endpoint->node_->info_->register_relation_endpoint(other_endpoint->node_->type_index(), endpoint);
|
|
|
|
|
other_endpoint->node_->info_->register_relation_endpoint(endpoint->node_->type_index(), other_endpoint);
|
|
|
|
|
link_relation_endpoints(endpoint, other_endpoint);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename NodeType>
|
|
|
|
|
void foreign_node_completer<NodeType>::link_relation_endpoints(const endpoint_ptr &endpoint, const endpoint_ptr &other_endpoint) {
|
|
|
|
|
template<typename NodeType, template<typename> typename ...Observers>
|
|
|
|
|
void foreign_node_completer<NodeType, Observers...>::link_relation_endpoints(const endpoint_ptr &endpoint, const endpoint_ptr &other_endpoint) {
|
|
|
|
|
endpoint->link_foreign_endpoint(other_endpoint);
|
|
|
|
|
other_endpoint->link_foreign_endpoint(endpoint);
|
|
|
|
|
}
|
|
|
|
|