removed attribute_generator and constraints_generator
This commit is contained in:
@@ -15,7 +15,6 @@ enum class null_option_type : uint8_t {
|
||||
};
|
||||
|
||||
class object;
|
||||
class attribute_generator;
|
||||
|
||||
class attribute {
|
||||
public:
|
||||
@@ -65,7 +64,6 @@ public:
|
||||
|
||||
private:
|
||||
friend class object;
|
||||
friend class attribute_generator;
|
||||
friend class object_generator;
|
||||
|
||||
std::string name_;
|
||||
|
||||
@@ -1,157 +0,0 @@
|
||||
#ifndef QUERY_COLUMN_DEFINITION_GENERATOR_HPP
|
||||
#define QUERY_COLUMN_DEFINITION_GENERATOR_HPP
|
||||
|
||||
#include "matador/object/attribute.hpp"
|
||||
|
||||
#include "matador/utils/access.hpp"
|
||||
#include "matador/utils/data_type_traits.hpp"
|
||||
#include "matador/utils/error.hpp"
|
||||
#include "matador/utils/field_attributes.hpp"
|
||||
#include "matador/utils/identifier.hpp"
|
||||
#include "matador/utils/primary_key_attribute.hpp"
|
||||
#include "matador/utils/result.hpp"
|
||||
|
||||
#include <memory>
|
||||
#include <typeindex>
|
||||
#include <vector>
|
||||
|
||||
namespace matador::object {
|
||||
|
||||
class repository;
|
||||
|
||||
class fk_attribute_generator
|
||||
{
|
||||
public:
|
||||
fk_attribute_generator() = default;
|
||||
|
||||
template<class Type>
|
||||
attribute generate(const char *id, Type &x) {
|
||||
access::process(*this, x);
|
||||
return attribute{id, type_, {utils::constraints::ForeignKey }, null_option_type::NotNull};
|
||||
}
|
||||
|
||||
template<typename ValueType>
|
||||
void on_primary_key(const char *, ValueType &/*pk*/, const utils::primary_key_attribute& attr = utils::default_pk_attributes) {
|
||||
type_ = utils::data_type_traits<ValueType>::type(attr.size());
|
||||
}
|
||||
static void on_revision(const char * /*id*/, uint64_t &/*rev*/) {}
|
||||
template < class Type >
|
||||
static void on_attribute(const char * /*id*/, Type &/*x*/, const utils::field_attributes &/*attr*/ = utils::null_attributes) {}
|
||||
static void on_attribute(const char * /*id*/, char * /*x*/, const utils::field_attributes &/*attr*/ = utils::null_attributes) {}
|
||||
template<class Pointer>
|
||||
static void on_belongs_to(const char * /*id*/, Pointer &/*x*/, const utils::foreign_attributes &/*attr*/) {}
|
||||
template<class Pointer>
|
||||
static void on_has_one(const char * /*id*/, Pointer &/*x*/, const utils::foreign_attributes &/*attr*/) {}
|
||||
template<class ContainerType>
|
||||
static void on_has_many(const char * /*id*/, ContainerType &, const char *, const utils::foreign_attributes &/*attr*/) {}
|
||||
template<class ContainerType>
|
||||
static void on_has_many_to_many(const char * /*id*/, ContainerType & /*cont*/, const char * /*join_column*/, const char * /*inverse_join_column*/, const utils::foreign_attributes &/*attr*/) {}
|
||||
template<class ContainerType>
|
||||
static void on_has_many_to_many(const char * /*id*/, ContainerType & /*cont*/, const utils::foreign_attributes &/*attr*/) {}
|
||||
|
||||
private:
|
||||
utils::basic_type type_{};
|
||||
};
|
||||
|
||||
class attribute_generator final {
|
||||
private:
|
||||
attribute_generator(std::vector<attribute> &columns, const repository &repo, const std::shared_ptr<object>& obj);
|
||||
|
||||
public:
|
||||
~attribute_generator() = default;
|
||||
|
||||
template < class Type >
|
||||
static std::vector<attribute> generate(const repository &repo, const std::shared_ptr<object> &obj) {
|
||||
Type t;
|
||||
return generate(t, repo, obj);
|
||||
}
|
||||
|
||||
template < class Type >
|
||||
static std::vector<attribute> generate(const Type& t, const repository &repo, const std::shared_ptr<object> &obj) {
|
||||
std::vector<attribute> columns;
|
||||
attribute_generator gen(columns, repo, obj);
|
||||
access::process(gen, t);
|
||||
return columns;
|
||||
}
|
||||
|
||||
template < class Type >
|
||||
void on_primary_key(const char *, Type &x, const utils::primary_key_attribute& attr = utils::default_pk_attributes);
|
||||
void on_revision(const char *id, uint64_t &rev);
|
||||
|
||||
template<typename Type>
|
||||
void on_attribute(const char *id, Type &x, const utils::field_attributes &attr = utils::null_attributes);
|
||||
|
||||
template<typename Type>
|
||||
void on_attribute(const char *id, std::optional<Type> &x, const utils::field_attributes &attr = utils::null_attributes);
|
||||
|
||||
template<class Pointer>
|
||||
void on_belongs_to(const char *id, Pointer &x, const utils::foreign_attributes &/*attr*/) {
|
||||
on_foreign_key(id, x);
|
||||
}
|
||||
template<class Pointer>
|
||||
static void on_has_one(const char * /*id*/, Pointer &/*x*/, const utils::foreign_attributes &/*attr*/) {}
|
||||
|
||||
template <class Pointer>
|
||||
void on_foreign_key(const char *id, Pointer &x) {
|
||||
attribute* ref_column;
|
||||
std::type_index ti = typeid(typename Pointer::value_type);
|
||||
if (auto result = determine_foreign_ref(std::type_index(ti))) {
|
||||
ref_column = *result;
|
||||
} else {
|
||||
ref_column = nullptr;
|
||||
insert_missing_reference_column(ti, ref_column);
|
||||
}
|
||||
if (x.empty()) {
|
||||
typename Pointer::value_type temp_val;
|
||||
columns_.push_back(fk_column_generator_.generate(id, temp_val));
|
||||
} else {
|
||||
columns_.push_back(fk_column_generator_.generate(id, *x));
|
||||
}
|
||||
}
|
||||
template<class ContainerType>
|
||||
static void on_has_many(const char * /*id*/, ContainerType &, const char *, const utils::foreign_attributes &/*attr*/) {}
|
||||
template<class ContainerType>
|
||||
static void on_has_many_to_many(const char * /*id*/, ContainerType & /*cont*/, const char * /*join_column*/, const char * /*inverse_join_column*/, const utils::foreign_attributes &/*attr*/) {}
|
||||
template<class ContainerType>
|
||||
static void on_has_many_to_many(const char * /*id*/, ContainerType & /*cont*/, const utils::foreign_attributes &/*attr*/) {}
|
||||
|
||||
private:
|
||||
[[nodiscard]] utils::result<attribute*, utils::error> determine_foreign_ref(const std::type_index &ti) const;
|
||||
void insert_missing_reference_column(const std::type_index &ti, attribute* ref_column) const;
|
||||
|
||||
template<typename ValueType>
|
||||
attribute &emplace_attribute(const char *id, const utils::field_attributes& attr, null_option_type null_option) {
|
||||
auto &ref = columns_.emplace_back(id, utils::data_type_traits<ValueType>::type(attr.size()), attr, null_option);
|
||||
ref.owner_ = obj_;
|
||||
return ref;
|
||||
}
|
||||
|
||||
void prepare_primary_key(attribute &ref, utils::identifier &&pk) const;
|
||||
|
||||
private:
|
||||
size_t index_ = 0;
|
||||
std::vector<attribute> &columns_;
|
||||
const repository &repo_;
|
||||
const std::shared_ptr<object> obj_;
|
||||
|
||||
fk_attribute_generator fk_column_generator_;
|
||||
};
|
||||
|
||||
template<typename ValueType>
|
||||
void attribute_generator::on_primary_key(const char *id, ValueType &x, const utils::primary_key_attribute& attr) {
|
||||
auto &ref = emplace_attribute<ValueType>(id, { attr.size(), utils::constraints::PrimaryKey }, null_option_type::NotNull);
|
||||
prepare_primary_key(ref, utils::identifier(x));
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
void attribute_generator::on_attribute(const char *id, Type &/*x*/, const utils::field_attributes &attr) {
|
||||
std::ignore = emplace_attribute<Type>(id, attr, null_option_type::NotNull);
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
void attribute_generator::on_attribute(const char *id, std::optional<Type> & /*x*/, const utils::field_attributes &attr) {
|
||||
std::ignore = emplace_attribute<Type>(id, attr, null_option_type::Nullable);
|
||||
}
|
||||
|
||||
}
|
||||
#endif //QUERY_COLUMN_DEFINITION_GENERATOR_HPP
|
||||
@@ -1,78 +0,0 @@
|
||||
#ifndef MATADOR_CONSTRAINTS_GENERATOR_HPP
|
||||
#define MATADOR_CONSTRAINTS_GENERATOR_HPP
|
||||
|
||||
#include "matador/object/restriction.hpp"
|
||||
|
||||
#include "matador/utils/access.hpp"
|
||||
#include "matador/utils/field_attributes.hpp"
|
||||
#include "matador/utils/primary_key_attribute.hpp"
|
||||
|
||||
#include <list>
|
||||
#include <typeindex>
|
||||
|
||||
namespace matador::object {
|
||||
class object;
|
||||
class basic_object_info;
|
||||
class repository;
|
||||
|
||||
class constraints_generator final {
|
||||
private:
|
||||
constraints_generator(std::list<class restriction> &constraints, const repository &repo, const std::shared_ptr<object> &obj);
|
||||
|
||||
public:
|
||||
constraints_generator() = delete;
|
||||
|
||||
template < typename Type >
|
||||
static std::list<class restriction> generate(const repository &repo, const std::shared_ptr<object> &obj) {
|
||||
Type t;
|
||||
return generate(t, repo, obj);
|
||||
}
|
||||
|
||||
template < typename Type >
|
||||
static std::list<class restriction> generate(const Type& t, const repository &repo, const std::shared_ptr<object> &obj) {
|
||||
std::list<class restriction> constraints;
|
||||
constraints_generator gen(constraints, repo, obj);
|
||||
access::process(gen, t);
|
||||
return constraints;
|
||||
}
|
||||
|
||||
template < class Type >
|
||||
void on_primary_key(const char *id, Type &/*x*/, const utils::primary_key_attribute& /*attr*/ = utils::default_pk_attributes) {
|
||||
create_pk_constraint(id);
|
||||
}
|
||||
static void on_revision(const char * /*id*/, uint64_t &/*rev*/) {}
|
||||
template<typename Type>
|
||||
void on_attribute(const char *id, Type &/*x*/, const utils::field_attributes &attr = utils::null_attributes) {
|
||||
if (utils::is_constraint_set(attr.options() ,utils::constraints::Unique)) {
|
||||
create_unique_constraint(id);
|
||||
}
|
||||
}
|
||||
|
||||
template<class Pointer>
|
||||
void on_belongs_to(const char *id, Pointer &/*x*/, const utils::foreign_attributes &/*attr*/) {
|
||||
create_fk_constraint( typeid(typename Pointer::value_type), id);
|
||||
}
|
||||
template<class Pointer>
|
||||
static void on_has_one(const char * /*id*/, Pointer &/*x*/, const utils::foreign_attributes &/*attr*/) {}
|
||||
template<class ContainerType>
|
||||
static void on_has_many(const char * /*id*/, ContainerType &, const char *, const utils::foreign_attributes &/*attr*/) {}
|
||||
template<class ContainerType>
|
||||
static void on_has_many_to_many(const char * /*id*/, ContainerType & /*cont*/, const char * /*join_column*/, const char * /*inverse_join_column*/, const utils::foreign_attributes &/*attr*/) {}
|
||||
template<class ContainerType>
|
||||
static void on_has_many_to_many(const char * /*id*/, ContainerType & /*cont*/, const utils::foreign_attributes &/*attr*/) {}
|
||||
|
||||
private:
|
||||
void create_pk_constraint(const std::string& name) const;
|
||||
void create_fk_constraint(const std::type_index& ti, const std::string& name) const;
|
||||
void create_unique_constraint(const std::string& name) const;
|
||||
|
||||
[[nodiscard]] std::list<attribute>::iterator find_attribute_by_name(const std::string &name) const;
|
||||
|
||||
private:
|
||||
std::list<class restriction> &constraints_;
|
||||
const repository &repo_;
|
||||
std::shared_ptr<object> obj_;
|
||||
};
|
||||
}
|
||||
|
||||
#endif //MATADOR_CONSTRAINTS_GENERATOR_HPP
|
||||
@@ -38,7 +38,6 @@ public:
|
||||
friend std::ostream& operator<<(std::ostream& os, const object& obj);
|
||||
|
||||
private:
|
||||
friend class constraints_generator;
|
||||
friend class attribute_generator;
|
||||
friend class object_generator;
|
||||
|
||||
@@ -46,7 +45,7 @@ private:
|
||||
attribute* pk_attribute_{nullptr};
|
||||
utils::identifier pk_identifier_;
|
||||
std::list<attribute> attributes_;
|
||||
std::list<class restriction> constraints_;
|
||||
std::list<restriction> constraints_;
|
||||
};
|
||||
}
|
||||
#endif //MATADOR_OBJECT_HPP
|
||||
@@ -189,7 +189,6 @@ private:
|
||||
private:
|
||||
friend class internal::shadow_repository;
|
||||
friend class repository_node;
|
||||
friend class attribute_generator;
|
||||
template < typename NodeType >
|
||||
friend class foreign_node_completer;
|
||||
friend class object_generator;
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
#ifndef SCHEMA_NODE_HPP
|
||||
#define SCHEMA_NODE_HPP
|
||||
|
||||
#include "matador/object/attribute_generator.hpp"
|
||||
#include "matador/object/object_generator.hpp"
|
||||
#include "matador/object/object_info.hpp"
|
||||
|
||||
#include "matador/utils/error.hpp"
|
||||
#include "matador/utils/result.hpp"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace matador::object {
|
||||
|
||||
@@ -32,11 +32,10 @@ public:
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& os, const restriction& c);
|
||||
|
||||
std::string prefix() const;
|
||||
std::string type_string() const;
|
||||
|
||||
private:
|
||||
friend class constraint_builder;
|
||||
friend class constraints_generator;
|
||||
friend class object_generator;
|
||||
friend class object;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user