renamed schema to repository
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
#include "matador/object/attribute_definition_generator.hpp"
|
||||
#include "matador/object/schema.hpp"
|
||||
#include "matador/object/repository.hpp"
|
||||
|
||||
namespace matador::object {
|
||||
|
||||
attribute_definition_generator::attribute_definition_generator(std::vector<object::attribute_definition> &columns, const schema &repo)
|
||||
attribute_definition_generator::attribute_definition_generator(std::vector<object::attribute_definition> &columns, const repository &repo)
|
||||
: columns_(columns)
|
||||
, repo_(repo)
|
||||
{}
|
||||
@@ -18,7 +18,7 @@ utils::result<std::shared_ptr<attribute_definition>, utils::error> attribute_def
|
||||
}
|
||||
|
||||
void attribute_definition_generator::insert_missing_reference_column(const std::type_index& ti, std::shared_ptr<attribute_definition> ref_column) const {
|
||||
const_cast<schema&>(repo_).missing_references_.insert({ti, ref_column});
|
||||
const_cast<repository&>(repo_).missing_references_.insert({ti, ref_column});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
#include "matador/object/basic_object_info.hpp"
|
||||
|
||||
#include "matador/object/schema_node.hpp"
|
||||
#include "matador/object/repository_node.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace matador::object {
|
||||
basic_object_info::basic_object_info(std::shared_ptr<schema_node> node,
|
||||
basic_object_info::basic_object_info(std::shared_ptr<repository_node> node,
|
||||
utils::identifier &&pk,
|
||||
const std::shared_ptr<attribute_definition> &pk_column,
|
||||
object_definition &&definition)
|
||||
@@ -15,7 +15,7 @@ basic_object_info::basic_object_info(std::shared_ptr<schema_node> node,
|
||||
, pk_column_(pk_column) {
|
||||
}
|
||||
|
||||
basic_object_info::basic_object_info(std::shared_ptr<schema_node> node,
|
||||
basic_object_info::basic_object_info(std::shared_ptr<repository_node> node,
|
||||
utils::identifier &&pk,
|
||||
const std::shared_ptr<attribute_definition> &pk_column)
|
||||
: node_(std::move(node))
|
||||
@@ -23,7 +23,7 @@ basic_object_info::basic_object_info(std::shared_ptr<schema_node> node,
|
||||
, pk_column_(pk_column) {
|
||||
}
|
||||
|
||||
basic_object_info::basic_object_info(std::shared_ptr<schema_node> node,
|
||||
basic_object_info::basic_object_info(std::shared_ptr<repository_node> node,
|
||||
object_definition &&definition)
|
||||
: node_(std::move(node))
|
||||
, definition_(std::move(definition)) {}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#include "matador/object/foreign_node_completer.hpp"
|
||||
|
||||
#include "matador/object/schema.hpp"
|
||||
#include "matador/object/repository.hpp"
|
||||
|
||||
#include "matador/logger/logger.hpp"
|
||||
|
||||
namespace matador::object {
|
||||
foreign_node_completer::foreign_node_completer(internal::shadow_schema &shadow)
|
||||
: schema_(shadow)
|
||||
foreign_node_completer::foreign_node_completer(internal::shadow_repository &shadow)
|
||||
: repo_(shadow)
|
||||
, log_(logger::create_logger("node_completer")) {}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
#include "matador/object/internal/shadow_repository.hpp"
|
||||
|
||||
#include "matador/object/repository.hpp"
|
||||
#include "matador/object/repository_node.hpp"
|
||||
|
||||
namespace matador::object::internal {
|
||||
shadow_repository::shadow_repository( object::repository& s )
|
||||
: schema_(s) {}
|
||||
|
||||
repository& shadow_repository::repo() const {
|
||||
return schema_;
|
||||
}
|
||||
|
||||
bool shadow_repository::contains( const std::type_index& ti ) const {
|
||||
return schema_.contains(ti);
|
||||
}
|
||||
|
||||
utils::result<shadow_repository::node_ptr, utils::error> shadow_repository::find_node( const std::type_index& type_index ) const {
|
||||
return schema_.find_node(type_index);
|
||||
}
|
||||
|
||||
utils::result<shadow_repository::node_ptr, utils::error> shadow_repository::find_node( const std::string& name ) const {
|
||||
return schema_.find_node(name);
|
||||
}
|
||||
|
||||
utils::result<shadow_repository::node_ptr, utils::error> shadow_repository::attach_node( const std::shared_ptr<repository_node>& node ) const {
|
||||
return schema_.attach_node(node, "");
|
||||
}
|
||||
|
||||
utils::result<void, utils::error> shadow_repository::detach_node( const std::shared_ptr<repository_node>& node ) const {
|
||||
return schema_.detach(node);
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
#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::find_node( const std::string& name ) const {
|
||||
return schema_.find_node(name);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
#include "matador/object/relation_endpoint.hpp"
|
||||
|
||||
#include "matador/object/schema_node.hpp"
|
||||
#include "matador/object/repository_node.hpp"
|
||||
|
||||
namespace matador::object {
|
||||
relation_endpoint::relation_endpoint(std::string field_name, const relation_type type, const std::shared_ptr<schema_node> &node)
|
||||
relation_endpoint::relation_endpoint(std::string field_name, const relation_type type, const std::shared_ptr<repository_node> &node)
|
||||
: field_name_(std::move(field_name))
|
||||
, type_(type)
|
||||
, node_(node) {
|
||||
@@ -21,11 +21,11 @@ std::string relation_endpoint::type_name() const {
|
||||
return relation_type_enum.to_string(type_);
|
||||
}
|
||||
|
||||
const schema_node &relation_endpoint::node() const {
|
||||
const repository_node &relation_endpoint::node() const {
|
||||
return *node_;
|
||||
}
|
||||
|
||||
std::shared_ptr<schema_node> relation_endpoint::node_ptr() const {
|
||||
std::shared_ptr<repository_node> relation_endpoint::node_ptr() const {
|
||||
return node_;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,202 +1,202 @@
|
||||
#include <utility>
|
||||
|
||||
#include "matador/object/schema.hpp"
|
||||
|
||||
namespace matador::object {
|
||||
utils::error make_error(const error_code ec, const std::string &msg) {
|
||||
return utils::error(ec, msg);
|
||||
}
|
||||
|
||||
schema::schema(std::string name)
|
||||
: name_(std::move(name))
|
||||
, root_(schema_node::make_null_node(*this))
|
||||
, log_(logger::create_logger("schema")) {
|
||||
root_->first_child_ = std::shared_ptr<schema_node>(new schema_node(*this));
|
||||
root_->last_child_ = std::shared_ptr<schema_node>(new schema_node(*this));
|
||||
root_->first_child_->next_sibling_ = root_->last_child_;
|
||||
root_->last_child_->previous_sibling_ = root_->first_child_;
|
||||
}
|
||||
|
||||
utils::result<void, utils::error> schema::detach(const node_ptr &node) {
|
||||
log_.debug("detach node '%s' (type: %s)", node->name().c_str(), node->type_index().name());
|
||||
|
||||
remove_node(node);
|
||||
|
||||
return utils::ok<void>();
|
||||
}
|
||||
|
||||
schema::const_iterator schema::begin() const {
|
||||
return const_iterator(root_->first_child_->next_sibling_);
|
||||
}
|
||||
|
||||
schema::const_iterator schema::end() const {
|
||||
return const_iterator(root_->last_child_);
|
||||
}
|
||||
|
||||
bool schema::empty() const {
|
||||
return root_->first_child_ == root_->last_child_->previous_sibling_;
|
||||
}
|
||||
|
||||
size_t schema::size() const {
|
||||
return static_cast<size_t>(std::distance(begin(), end()));
|
||||
}
|
||||
|
||||
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_column(const std::type_index &type_index) const {
|
||||
const auto result = find_node(type_index);
|
||||
if (result) {
|
||||
return utils::ok((*result)->info().reference_column());
|
||||
}
|
||||
|
||||
return utils::failure(result.err());
|
||||
}
|
||||
|
||||
void schema::dump(std::ostream &os) const {
|
||||
for (const auto &node : *this) {
|
||||
dump(os, node);
|
||||
}
|
||||
os << "\n";
|
||||
}
|
||||
|
||||
void schema::dump( std::ostream& os, const node_ptr& node ) {
|
||||
os << "node [" << node->name() << "] (" << node->type_index().name() << ")\n";
|
||||
for (auto it = node->info().endpoint_begin(); it != node->info().endpoint_end(); ++it) {
|
||||
os << " " << node->name() << "::" << it->second->field_name() << " (" << it->second->type_name() << ")";
|
||||
if (it->second->foreign_endpoint()) {
|
||||
os << " <---> " << it->second->node().name() << "::" << it->second->foreign_endpoint()->field_name() << " (" << it->second->foreign_endpoint()->type_name() << ")\n";
|
||||
} else {
|
||||
os << " -> " << it->second->node().name() << " (type: " << it->second->node().type_index().name() << ")\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
utils::result<schema::node_ptr, utils::error> schema::attach_node(const std::shared_ptr<schema_node> &node,
|
||||
const std::string &parent) {
|
||||
if (has_node(node)) {
|
||||
return utils::failure(make_error(error_code::NodeAlreadyExists, "Node '" + node->name() + "' already exists."));
|
||||
}
|
||||
|
||||
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_;
|
||||
if (!parent.empty()) {
|
||||
auto result = find_node(parent);
|
||||
if (!result.is_ok() && result.err().ec() != error_code::NodeNotFound) {
|
||||
return result;
|
||||
}
|
||||
parent_node = *result;
|
||||
}
|
||||
|
||||
insert_node(parent_node, node);
|
||||
|
||||
// Todo: check return value
|
||||
nodes_by_name_.insert({node->name(), node});
|
||||
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
|
||||
const auto i = nodes_by_name_.find(name);
|
||||
if (i == nodes_by_name_.end()) {
|
||||
return utils::failure(make_error(error_code::NodeNotFound, "Couldn't find node by name '" + name + "'"));
|
||||
}
|
||||
return utils::ok(i->second);
|
||||
}
|
||||
|
||||
utils::result<schema::node_ptr, utils::error> schema::find_node(const std::type_index &type_index) const {
|
||||
const auto i = nodes_by_type_.find(type_index);
|
||||
if (i == nodes_by_type_.end()) {
|
||||
return utils::failure(make_error(error_code::NodeNotFound,
|
||||
"Couldn't find node by type '" + std::string(type_index.name()) + "'"));
|
||||
}
|
||||
return utils::ok(i->second);
|
||||
}
|
||||
|
||||
void schema::insert_node(const node_ptr &parent, const node_ptr &child) {
|
||||
child->parent_ = parent;
|
||||
child->previous_sibling_ = parent->last_child_->previous_sibling_;
|
||||
child->next_sibling_ = parent->last_child_;
|
||||
/*
|
||||
* +-----------------------------<- (first) parent (last) -> ----------------------------+
|
||||
* | |
|
||||
* first (next) -> <- (prev) child_1 (next) -> <- (prev) new_child (next) -> <- (prev) last
|
||||
* ^^^^^^^ inserted ^^^^^^
|
||||
*/
|
||||
parent->last_child_->previous_sibling_->next_sibling_ = child;
|
||||
parent->last_child_->previous_sibling_ = child;
|
||||
// set depth
|
||||
// child->depth = depth + 1;
|
||||
}
|
||||
|
||||
void schema::remove_node(const node_ptr &node) {
|
||||
auto next = node->next();
|
||||
|
||||
std::stack<node_ptr> nodes_to_remove;
|
||||
nodes_to_remove.push(node);
|
||||
|
||||
while (!nodes_to_remove.empty()) {
|
||||
const auto current = nodes_to_remove.top();
|
||||
|
||||
if (current->has_children()) {
|
||||
// Push all children to the stack (from right to left to maintain order)
|
||||
auto child = current->last_child_->previous_sibling_;
|
||||
while (child != current->first_child_) {
|
||||
nodes_to_remove.push(child);
|
||||
child = child->previous_sibling_;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// No children left, safe to remove this node
|
||||
nodes_to_remove.pop();
|
||||
current->unlink();
|
||||
nodes_by_name_.erase(current->name());
|
||||
nodes_by_type_.erase(current->type_index());
|
||||
}
|
||||
}
|
||||
|
||||
bool schema::has_node(const std::string &name) const {
|
||||
return nodes_by_name_.count(name) > 0;
|
||||
}
|
||||
|
||||
bool schema::has_node(const std::type_index &index) const {
|
||||
return nodes_by_type_.count(index) > 0;
|
||||
}
|
||||
|
||||
bool schema::has_node(const node_ptr& node) const {
|
||||
return nodes_by_name_.count(node->name()) > 0 || nodes_by_type_.count(node->type_index()) > 0;
|
||||
}
|
||||
} // namespace matador::object
|
||||
#include <utility>
|
||||
|
||||
#include "matador/object/repository.hpp"
|
||||
|
||||
namespace matador::object {
|
||||
utils::error make_error(const error_code ec, const std::string &msg) {
|
||||
return utils::error(ec, msg);
|
||||
}
|
||||
|
||||
repository::repository(std::string name)
|
||||
: name_(std::move(name))
|
||||
, root_(repository_node::make_null_node(*this))
|
||||
, log_(logger::create_logger("schema")) {
|
||||
root_->first_child_ = std::shared_ptr<repository_node>(new repository_node(*this));
|
||||
root_->last_child_ = std::shared_ptr<repository_node>(new repository_node(*this));
|
||||
root_->first_child_->next_sibling_ = root_->last_child_;
|
||||
root_->last_child_->previous_sibling_ = root_->first_child_;
|
||||
}
|
||||
|
||||
utils::result<void, utils::error> repository::detach(const node_ptr &node) {
|
||||
log_.debug("detach node '%s' (type: %s)", node->name().c_str(), node->type_index().name());
|
||||
|
||||
remove_node(node);
|
||||
|
||||
return utils::ok<void>();
|
||||
}
|
||||
|
||||
repository::const_iterator repository::begin() const {
|
||||
return const_iterator(root_->first_child_->next_sibling_);
|
||||
}
|
||||
|
||||
repository::const_iterator repository::end() const {
|
||||
return const_iterator(root_->last_child_);
|
||||
}
|
||||
|
||||
bool repository::empty() const {
|
||||
return root_->first_child_ == root_->last_child_->previous_sibling_;
|
||||
}
|
||||
|
||||
size_t repository::size() const {
|
||||
return static_cast<size_t>(std::distance(begin(), end()));
|
||||
}
|
||||
|
||||
std::string repository::name() const {
|
||||
return name_;
|
||||
}
|
||||
|
||||
bool repository::contains( const std::string& name ) const {
|
||||
return nodes_by_name_.count(name) > 0;
|
||||
}
|
||||
|
||||
bool repository::contains( const std::type_index& index ) const {
|
||||
return nodes_by_type_.count(index) > 0;
|
||||
}
|
||||
|
||||
utils::result<std::shared_ptr<attribute_definition>, utils::error> repository::reference_column(const std::type_index &type_index) const {
|
||||
const auto result = find_node(type_index);
|
||||
if (result) {
|
||||
return utils::ok((*result)->info().reference_column());
|
||||
}
|
||||
|
||||
return utils::failure(result.err());
|
||||
}
|
||||
|
||||
void repository::dump(std::ostream &os) const {
|
||||
for (const auto &node : *this) {
|
||||
dump(os, node);
|
||||
}
|
||||
os << "\n";
|
||||
}
|
||||
|
||||
void repository::dump( std::ostream& os, const node_ptr& node ) {
|
||||
os << "node [" << node->name() << "] (" << node->type_index().name() << ")\n";
|
||||
for (auto it = node->info().endpoint_begin(); it != node->info().endpoint_end(); ++it) {
|
||||
os << " " << node->name() << "::" << it->second->field_name() << " (" << it->second->type_name() << ")";
|
||||
if (it->second->foreign_endpoint()) {
|
||||
os << " <---> " << it->second->node().name() << "::" << it->second->foreign_endpoint()->field_name() << " (" << it->second->foreign_endpoint()->type_name() << ")\n";
|
||||
} else {
|
||||
os << " -> " << it->second->node().name() << " (type: " << it->second->node().type_index().name() << ")\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
utils::result<repository::node_ptr, utils::error> repository::attach_node(const std::shared_ptr<repository_node> &node,
|
||||
const std::string &parent) {
|
||||
if (has_node(node)) {
|
||||
return utils::failure(make_error(error_code::NodeAlreadyExists, "Node '" + node->name() + "' already exists."));
|
||||
}
|
||||
|
||||
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_;
|
||||
if (!parent.empty()) {
|
||||
auto result = find_node(parent);
|
||||
if (!result.is_ok() && result.err().ec() != error_code::NodeNotFound) {
|
||||
return result;
|
||||
}
|
||||
parent_node = *result;
|
||||
}
|
||||
|
||||
insert_node(parent_node, node);
|
||||
|
||||
// Todo: check return value
|
||||
nodes_by_name_.insert({node->name(), node});
|
||||
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<repository::node_ptr, utils::error> repository::find_node(const std::string &name) const {
|
||||
// first search in the prototype map
|
||||
const auto i = nodes_by_name_.find(name);
|
||||
if (i == nodes_by_name_.end()) {
|
||||
return utils::failure(make_error(error_code::NodeNotFound, "Couldn't find node by name '" + name + "'"));
|
||||
}
|
||||
return utils::ok(i->second);
|
||||
}
|
||||
|
||||
utils::result<repository::node_ptr, utils::error> repository::find_node(const std::type_index &type_index) const {
|
||||
const auto i = nodes_by_type_.find(type_index);
|
||||
if (i == nodes_by_type_.end()) {
|
||||
return utils::failure(make_error(error_code::NodeNotFound,
|
||||
"Couldn't find node by type '" + std::string(type_index.name()) + "'"));
|
||||
}
|
||||
return utils::ok(i->second);
|
||||
}
|
||||
|
||||
void repository::insert_node(const node_ptr &parent, const node_ptr &child) {
|
||||
child->parent_ = parent;
|
||||
child->previous_sibling_ = parent->last_child_->previous_sibling_;
|
||||
child->next_sibling_ = parent->last_child_;
|
||||
/*
|
||||
* +-----------------------------<- (first) parent (last) -> ----------------------------+
|
||||
* | |
|
||||
* first (next) -> <- (prev) child_1 (next) -> <- (prev) new_child (next) -> <- (prev) last
|
||||
* ^^^^^^^ inserted ^^^^^^
|
||||
*/
|
||||
parent->last_child_->previous_sibling_->next_sibling_ = child;
|
||||
parent->last_child_->previous_sibling_ = child;
|
||||
// set depth
|
||||
// child->depth = depth + 1;
|
||||
}
|
||||
|
||||
void repository::remove_node(const node_ptr &node) {
|
||||
auto next = node->next();
|
||||
|
||||
std::stack<node_ptr> nodes_to_remove;
|
||||
nodes_to_remove.push(node);
|
||||
|
||||
while (!nodes_to_remove.empty()) {
|
||||
const auto current = nodes_to_remove.top();
|
||||
|
||||
if (current->has_children()) {
|
||||
// Push all children to the stack (from right to left to maintain order)
|
||||
auto child = current->last_child_->previous_sibling_;
|
||||
while (child != current->first_child_) {
|
||||
nodes_to_remove.push(child);
|
||||
child = child->previous_sibling_;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// No children left, safe to remove this node
|
||||
nodes_to_remove.pop();
|
||||
current->unlink();
|
||||
nodes_by_name_.erase(current->name());
|
||||
nodes_by_type_.erase(current->type_index());
|
||||
}
|
||||
}
|
||||
|
||||
bool repository::has_node(const std::string &name) const {
|
||||
return nodes_by_name_.count(name) > 0;
|
||||
}
|
||||
|
||||
bool repository::has_node(const std::type_index &index) const {
|
||||
return nodes_by_type_.count(index) > 0;
|
||||
}
|
||||
|
||||
bool repository::has_node(const node_ptr& node) const {
|
||||
return nodes_by_name_.count(node->name()) > 0 || nodes_by_type_.count(node->type_index()) > 0;
|
||||
}
|
||||
} // namespace matador::object
|
||||
@@ -1,62 +1,62 @@
|
||||
#include <utility>
|
||||
|
||||
#include "matador/object/schema.hpp"
|
||||
#include "matador/object/schema_node.hpp"
|
||||
#include "matador/object/repository.hpp"
|
||||
#include "matador/object/repository_node.hpp"
|
||||
|
||||
namespace matador::object {
|
||||
schema_node::schema_node(object::schema &tree)
|
||||
: schema_(tree)
|
||||
repository_node::repository_node(object::repository &tree)
|
||||
: repo_(tree)
|
||||
, type_index_(typeid(detail::null_type)){
|
||||
}
|
||||
|
||||
schema_node::schema_node(object::schema &tree, const std::type_index& ti)
|
||||
: schema_(tree)
|
||||
repository_node::repository_node(object::repository &tree, const std::type_index& ti)
|
||||
: repo_(tree)
|
||||
, type_index_(ti) {
|
||||
}
|
||||
|
||||
schema_node::schema_node(object::schema &tree, std::string name, const std::type_index& ti)
|
||||
: schema_(tree)
|
||||
repository_node::repository_node(object::repository &tree, std::string name, const std::type_index& ti)
|
||||
: repo_(tree)
|
||||
, type_index_(ti)
|
||||
, first_child_(std::shared_ptr<schema_node>(new schema_node(tree)))
|
||||
, last_child_(std::shared_ptr<schema_node>(new schema_node(tree)))
|
||||
, first_child_(std::shared_ptr<repository_node>(new repository_node(tree)))
|
||||
, last_child_(std::shared_ptr<repository_node>(new repository_node(tree)))
|
||||
, name_(std::move(name)) {
|
||||
first_child_->next_sibling_ = last_child_;
|
||||
last_child_->previous_sibling_ = first_child_;
|
||||
}
|
||||
|
||||
std::shared_ptr<schema_node> schema_node::make_null_node(object::schema &tree) {
|
||||
auto node = std::shared_ptr<schema_node>(new schema_node(tree));
|
||||
std::shared_ptr<repository_node> repository_node::make_null_node(object::repository &tree) {
|
||||
auto node = std::shared_ptr<repository_node>(new repository_node(tree));
|
||||
node->info_ = std::make_unique<null_info>(node, std::shared_ptr<attribute_definition>{});
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
std::string schema_node::name() const {
|
||||
std::string repository_node::name() const {
|
||||
return name_;
|
||||
}
|
||||
|
||||
std::type_index schema_node::type_index() const {
|
||||
std::type_index repository_node::type_index() const {
|
||||
return type_index_;
|
||||
}
|
||||
|
||||
const basic_object_info &schema_node::info() const {
|
||||
const basic_object_info &repository_node::info() const {
|
||||
return *info_;
|
||||
}
|
||||
|
||||
void schema_node::update_name(const std::string& name) {
|
||||
void repository_node::update_name(const std::string& name) {
|
||||
name_ = name;
|
||||
info_->reference_column()->table_name(name);
|
||||
}
|
||||
|
||||
const object::schema& schema_node::schema() const {
|
||||
return schema_;
|
||||
const object::repository& repository_node::schema() const {
|
||||
return repo_;
|
||||
}
|
||||
|
||||
bool schema_node::has_children() const {
|
||||
bool repository_node::has_children() const {
|
||||
return first_child_->next_sibling_ != last_child_;
|
||||
}
|
||||
|
||||
schema_node::node_ptr schema_node::next() const {
|
||||
repository_node::node_ptr repository_node::next() const {
|
||||
// if we have a child, child is the next iterator to return
|
||||
// (if we don't iterate over the siblings)
|
||||
if (first_child_ && first_child_->next_sibling_ != last_child_) {
|
||||
@@ -72,7 +72,7 @@ schema_node::node_ptr schema_node::next() const {
|
||||
return node->parent_ ? node->next_sibling_ : node->last_child_;
|
||||
}
|
||||
|
||||
schema_node::node_ptr schema_node::prev() const {
|
||||
repository_node::node_ptr repository_node::prev() const {
|
||||
// if the node has a previous sibling, we set it
|
||||
// as our next iterator. then we check if there
|
||||
// are last children. if so, we set the last-last
|
||||
@@ -89,20 +89,20 @@ schema_node::node_ptr schema_node::prev() const {
|
||||
return parent_->parent_ ? parent_ : parent_->first_child_->next_sibling_;
|
||||
}
|
||||
|
||||
void schema_node::unlink() {
|
||||
void repository_node::unlink() {
|
||||
previous_sibling_->next_sibling_ = next_sibling_;
|
||||
next_sibling_->previous_sibling_ = previous_sibling_;
|
||||
next_sibling_.reset();
|
||||
previous_sibling_.reset();
|
||||
}
|
||||
|
||||
utils::result<schema_node::node_ptr, utils::error> schema_node::make_and_attach_node(object::schema& tree, const std::string& name, const std::type_index& ti) {
|
||||
const auto node = std::shared_ptr<schema_node>(new schema_node(tree, name, ti));
|
||||
utils::result<repository_node::node_ptr, utils::error> repository_node::make_and_attach_node(object::repository& tree, const std::string& name, const std::type_index& ti) {
|
||||
const auto node = std::shared_ptr<repository_node>(new repository_node(tree, name, ti));
|
||||
|
||||
return tree.attach_node(node, "");
|
||||
}
|
||||
|
||||
std::shared_ptr<attribute_definition> schema_node::determine_reference_column(const std::type_index& ti, const std::string& name, const primary_key_info& pk_info, object::schema& tree) {
|
||||
std::shared_ptr<attribute_definition> repository_node::determine_reference_column(const std::type_index& ti, const std::string& name, const primary_key_info& pk_info, object::repository& tree) {
|
||||
const auto it = tree.missing_references_.find(ti);
|
||||
if (it == tree.missing_references_.end()) {
|
||||
return std::make_shared<attribute_definition>(pk_info.pk_column_name, name, pk_info.type, utils::constraints::FOREIGN_KEY);
|
||||
@@ -0,0 +1,78 @@
|
||||
#include <utility>
|
||||
|
||||
#include "matador/object/repository_node_iterator.hpp"
|
||||
|
||||
namespace matador::object {
|
||||
|
||||
const_repository_node_iterator::const_repository_node_iterator(const value_type& node)
|
||||
: node_(node)
|
||||
{}
|
||||
|
||||
bool const_repository_node_iterator::operator==(const const_repository_node_iterator &i) const
|
||||
{
|
||||
return (node_ == i.node_);
|
||||
}
|
||||
|
||||
bool const_repository_node_iterator::operator!=(const const_repository_node_iterator &i) const
|
||||
{
|
||||
return !operator==(i);
|
||||
}
|
||||
|
||||
const_repository_node_iterator& const_repository_node_iterator::operator++()
|
||||
{
|
||||
increment();
|
||||
return *this;
|
||||
}
|
||||
|
||||
const_repository_node_iterator const_repository_node_iterator::operator++( int ) {
|
||||
const value_type tmp = node_;
|
||||
increment();
|
||||
return const_repository_node_iterator(tmp);
|
||||
}
|
||||
|
||||
const_repository_node_iterator& const_repository_node_iterator::operator--()
|
||||
{
|
||||
decrement();
|
||||
return *this;
|
||||
}
|
||||
|
||||
const_repository_node_iterator const_repository_node_iterator::operator--(int)
|
||||
{
|
||||
const value_type tmp = node_;
|
||||
decrement();
|
||||
return const_repository_node_iterator(tmp);
|
||||
}
|
||||
|
||||
const_repository_node_iterator::pointer const_repository_node_iterator::operator->() const
|
||||
{
|
||||
return node_.get();
|
||||
}
|
||||
|
||||
const_repository_node_iterator::reference const_repository_node_iterator::operator*() const
|
||||
{
|
||||
return node_;
|
||||
}
|
||||
|
||||
const_repository_node_iterator::pointer const_repository_node_iterator::get() const
|
||||
{
|
||||
return node_.get();
|
||||
}
|
||||
|
||||
void const_repository_node_iterator::increment()
|
||||
{
|
||||
if (!node_) {
|
||||
return;
|
||||
}
|
||||
|
||||
node_ = node_->next();
|
||||
}
|
||||
void const_repository_node_iterator::decrement()
|
||||
{
|
||||
if (!node_) {
|
||||
return;
|
||||
}
|
||||
|
||||
node_ = node_->prev();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
#include <utility>
|
||||
|
||||
#include "matador/object/schema_node_iterator.hpp"
|
||||
|
||||
namespace matador::object {
|
||||
|
||||
const_schema_node_iterator::const_schema_node_iterator(const value_type& node)
|
||||
: node_(node)
|
||||
{}
|
||||
|
||||
bool const_schema_node_iterator::operator==(const const_schema_node_iterator &i) const
|
||||
{
|
||||
return (node_ == i.node_);
|
||||
}
|
||||
|
||||
bool const_schema_node_iterator::operator!=(const const_schema_node_iterator &i) const
|
||||
{
|
||||
return !operator==(i);
|
||||
}
|
||||
|
||||
const_schema_node_iterator& const_schema_node_iterator::operator++()
|
||||
{
|
||||
increment();
|
||||
return *this;
|
||||
}
|
||||
|
||||
const_schema_node_iterator const_schema_node_iterator::operator++( int ) {
|
||||
const value_type tmp = node_;
|
||||
increment();
|
||||
return const_schema_node_iterator(tmp);
|
||||
}
|
||||
|
||||
const_schema_node_iterator& const_schema_node_iterator::operator--()
|
||||
{
|
||||
decrement();
|
||||
return *this;
|
||||
}
|
||||
|
||||
const_schema_node_iterator const_schema_node_iterator::operator--(int)
|
||||
{
|
||||
const value_type tmp = node_;
|
||||
decrement();
|
||||
return const_schema_node_iterator(tmp);
|
||||
}
|
||||
|
||||
const_schema_node_iterator::pointer const_schema_node_iterator::operator->() const
|
||||
{
|
||||
return node_.get();
|
||||
}
|
||||
|
||||
const_schema_node_iterator::reference const_schema_node_iterator::operator*() const
|
||||
{
|
||||
return node_;
|
||||
}
|
||||
|
||||
const_schema_node_iterator::pointer const_schema_node_iterator::get() const
|
||||
{
|
||||
return node_.get();
|
||||
}
|
||||
|
||||
void const_schema_node_iterator::increment()
|
||||
{
|
||||
if (!node_) {
|
||||
return;
|
||||
}
|
||||
|
||||
node_ = node_->next();
|
||||
}
|
||||
void const_schema_node_iterator::decrement()
|
||||
{
|
||||
if (!node_) {
|
||||
return;
|
||||
}
|
||||
|
||||
node_ = node_->prev();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user