removed attribute_generator and constraints_generator
This commit is contained in:
@@ -1,29 +0,0 @@
|
||||
#include "matador/object/attribute_generator.hpp"
|
||||
#include "matador/object/repository.hpp"
|
||||
#include "matador/object/object.hpp"
|
||||
|
||||
namespace matador::object {
|
||||
|
||||
attribute_generator::attribute_generator(std::vector<attribute> &columns, const repository &repo, const std::shared_ptr<object> &obj)
|
||||
: columns_(columns)
|
||||
, repo_(repo)
|
||||
, obj_(obj)
|
||||
{}
|
||||
|
||||
void attribute_generator::on_revision(const char *id, uint64_t &rev) {
|
||||
on_attribute(id, rev);
|
||||
}
|
||||
|
||||
utils::result<attribute*, utils::error> attribute_generator::determine_foreign_ref(const std::type_index &ti) const {
|
||||
return repo_.primary_key_attribute(ti);
|
||||
}
|
||||
|
||||
void attribute_generator::insert_missing_reference_column(const std::type_index& ti, attribute* ref_column) const {
|
||||
const_cast<repository&>(repo_).missing_references_.insert({ti, ref_column});
|
||||
}
|
||||
|
||||
void attribute_generator::prepare_primary_key(attribute& ref, utils::identifier &&pk) const {
|
||||
obj_->pk_attribute_ = &ref;
|
||||
obj_->pk_identifier_ = std::move(pk);
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
#include "matador/object/constraints_generator.hpp"
|
||||
#include "matador/object/object.hpp"
|
||||
#include "matador/object/repository.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace matador::object {
|
||||
constraints_generator::constraints_generator(std::list<class restriction> &constraints, const repository& repo, const std::shared_ptr<object> &obj)
|
||||
: constraints_(constraints)
|
||||
, repo_(repo)
|
||||
, obj_(obj) {}
|
||||
|
||||
void constraints_generator::create_pk_constraint(const std::string& name) const {
|
||||
restriction pk_constraint("PK_" + obj_->name());
|
||||
pk_constraint.options_ |= utils::constraints::PrimaryKey;
|
||||
if (const auto pk_attr = find_attribute_by_name(name); pk_attr != std::end(obj_->attributes_)) {
|
||||
pk_constraint.attr_ = &*pk_attr;
|
||||
}
|
||||
pk_constraint.owner_ = obj_;
|
||||
constraints_.emplace_back(std::move(pk_constraint));
|
||||
}
|
||||
|
||||
void constraints_generator::create_fk_constraint(const std::type_index& ti, const std::string& name) const {
|
||||
const auto result = repo_.basic_info(ti);
|
||||
if (!result) {
|
||||
return;
|
||||
}
|
||||
restriction pk_constraint("FK_" + obj_->name() + "_" + name);
|
||||
pk_constraint.options_ |= utils::constraints::ForeignKey;
|
||||
if (const auto pk_attr = find_attribute_by_name(name); pk_attr != std::end(obj_->attributes_)) {
|
||||
pk_constraint.attr_ = &*pk_attr;
|
||||
}
|
||||
pk_constraint.owner_ = obj_;
|
||||
constraints_.emplace_back(std::move(pk_constraint));
|
||||
}
|
||||
|
||||
void constraints_generator::create_unique_constraint(const std::string& name) const {
|
||||
class restriction pk_constraint("UK_" + obj_->name() + "_" + name);
|
||||
pk_constraint.options_ |= utils::constraints::Unique;
|
||||
if (const auto pk_attr = find_attribute_by_name(name); pk_attr != std::end(obj_->attributes_)) {
|
||||
pk_constraint.attr_ = &*pk_attr;
|
||||
}
|
||||
pk_constraint.owner_ = obj_;
|
||||
}
|
||||
|
||||
std::list<attribute>::iterator constraints_generator::find_attribute_by_name(const std::string& name) const {
|
||||
return std::find_if(std::begin(obj_->attributes_), std::end(obj_->attributes_), [&name](const attribute& elem) {
|
||||
return elem.name() == name;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -66,7 +66,7 @@ void object_generator::prepare_primary_key(attribute& ref, utils::identifier &&p
|
||||
object_->pk_identifier_ = std::move(pk);
|
||||
}
|
||||
|
||||
std::shared_ptr<class object> object_generator::fk_object(const std::type_index& ti) const {
|
||||
std::shared_ptr<object> object_generator::fk_object(const std::type_index& ti) const {
|
||||
const auto result = repo_.basic_info(ti);
|
||||
if (result) {
|
||||
return result->get().object();
|
||||
|
||||
@@ -8,7 +8,7 @@ restriction::restriction(std::string name)
|
||||
: name_(std::move(name)) {}
|
||||
|
||||
std::string restriction::name() const {
|
||||
return prefix() + name_;
|
||||
return type_string() + name_;
|
||||
}
|
||||
|
||||
const class attribute* restriction::attribute() const {
|
||||
@@ -55,21 +55,21 @@ const std::string& restriction::ref_column_name() const {
|
||||
}
|
||||
|
||||
std::ostream & operator<<(std::ostream &os, const class restriction &c) {
|
||||
os << "constraint " << c.name() << " for column " << c.column_name();
|
||||
os << "constraint " << c.type_string() << " for column " << c.column_name();
|
||||
return os;
|
||||
}
|
||||
|
||||
std::string restriction::prefix() const {
|
||||
std::string restriction::type_string() const {
|
||||
if (utils::is_constraint_set(options_, utils::constraints::PrimaryKey)) {
|
||||
return "PK_";
|
||||
return "PrimaryKey";
|
||||
}
|
||||
if (utils::is_constraint_set(options_, utils::constraints::ForeignKey)) {
|
||||
return "FK_";
|
||||
return "ForeignKey";
|
||||
}
|
||||
if (utils::is_constraint_set(options_, utils::constraints::Unique)) {
|
||||
return "UK_";
|
||||
return "Unique";
|
||||
}
|
||||
return "";
|
||||
return "Unknown";
|
||||
}
|
||||
|
||||
// constraint_builder & constraint_builder::constraint(std::string name) {
|
||||
|
||||
Reference in New Issue
Block a user