collection_resolver progress
This commit is contained in:
parent
b6cabbe3ed
commit
6205ae81c9
|
|
@ -0,0 +1,25 @@
|
|||
#ifndef MATADOR_ABSTRACT_COLLECTION_RESOLVER_HPP
|
||||
#define MATADOR_ABSTRACT_COLLECTION_RESOLVER_HPP
|
||||
|
||||
#include <string>
|
||||
#include <typeindex>
|
||||
|
||||
namespace matador::object {
|
||||
class abstract_collection_resolver {
|
||||
public:
|
||||
virtual ~abstract_collection_resolver() = default;
|
||||
|
||||
[[nodiscard]] const std::type_index& root_type() const;
|
||||
[[nodiscard]] const std::type_index& type() const;
|
||||
[[nodiscard]] const std::string& collection_name() const;
|
||||
|
||||
protected:
|
||||
explicit abstract_collection_resolver(const std::type_index& root_type, const std::type_index& type, std::string collection_name);
|
||||
|
||||
public:
|
||||
const std::type_index root_type_;
|
||||
const std::type_index type_;
|
||||
const std::string collection_name_;
|
||||
};
|
||||
}
|
||||
#endif // MATADOR_ABSTRACT_COLLECTION_RESOLVER_HPP
|
||||
|
|
@ -1,30 +1,21 @@
|
|||
#ifndef MATADOR_COLLECTION_RESOLVER_HPP
|
||||
#define MATADOR_COLLECTION_RESOLVER_HPP
|
||||
|
||||
#include "matador/object/abstract_type_resolver.hpp"
|
||||
#include "matador/object/object_ptr.hpp"
|
||||
#include "matador/object/abstract_collection_resolver.hpp"
|
||||
|
||||
#include <typeindex>
|
||||
#include <vector>
|
||||
|
||||
namespace matador::utils {
|
||||
class identifier;
|
||||
}
|
||||
|
||||
namespace matador::object {
|
||||
class abstract_collection_resolver {
|
||||
public:
|
||||
virtual ~abstract_collection_resolver() = default;
|
||||
|
||||
[[nodiscard]] const std::type_index& type() const { return type_; }
|
||||
|
||||
protected:
|
||||
explicit abstract_collection_resolver(const std::type_index& ti) : type_(ti) {}
|
||||
|
||||
public:
|
||||
const std::type_index type_;
|
||||
};
|
||||
|
||||
template<typename Type>
|
||||
class collection_resolver : public abstract_type_resolver {
|
||||
class collection_resolver : public abstract_collection_resolver {
|
||||
public:
|
||||
collection_resolver() : abstract_type_resolver(typeid(std::vector<Type>)) {}
|
||||
collection_resolver(const std::type_index& root_type, std::string collection_name)
|
||||
: abstract_collection_resolver(root_type, typeid(Type), std::move(collection_name)) {}
|
||||
|
||||
virtual std::vector<Type> resolve(const utils::identifier& id) = 0;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
#ifndef MATADOR_CONTAINER_RESOLVER_FACTORY_HPP
|
||||
#define MATADOR_CONTAINER_RESOLVER_FACTORY_HPP
|
||||
|
||||
#include "matador/object/abstract_type_resolver_factory.hpp"
|
||||
#include "matador/object/collection_resolver.hpp"
|
||||
|
||||
namespace matador::object {
|
||||
|
|
@ -13,11 +12,11 @@ public:
|
|||
virtual void register_collection_resolver(std::shared_ptr<abstract_collection_resolver> &&resolver) = 0;
|
||||
};
|
||||
|
||||
class collection_resolver_factory : public abstract_type_resolver_factory {
|
||||
class collection_resolver_factory : public abstract_collection_resolver_factory {
|
||||
public:
|
||||
template<class Type>
|
||||
std::shared_ptr<collection_resolver<Type>> resolver() {
|
||||
const auto res = acquire_object_resolver(typeid(std::vector<object_ptr<Type>>));
|
||||
std::shared_ptr<collection_resolver<Type>> resolver(const std::type_index &root_type, const std::string &collection_name) {
|
||||
const auto res = acquire_collection_resolver(typeid(Type), root_type, collection_name);
|
||||
if (!res) {
|
||||
return std::dynamic_pointer_cast<collection_resolver<Type>>(res);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +0,0 @@
|
|||
#ifndef MATADOR_CONTAINER_RESOLVER_HPP
|
||||
#define MATADOR_CONTAINER_RESOLVER_HPP
|
||||
|
||||
#include "matador/object/abstract_type_resolver.hpp"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace matador::utils {
|
||||
class identifier;
|
||||
}
|
||||
|
||||
namespace matador::object {
|
||||
template<typename Type>
|
||||
class container_resolver : public abstract_type_resolver {
|
||||
public:
|
||||
container_resolver() : abstract_type_resolver(typeid(Type)) {}
|
||||
|
||||
virtual std::shared_ptr<std::vector<Type>> resolve(const utils::identifier& id) = 0;
|
||||
};
|
||||
}
|
||||
|
||||
#endif //MATADOR_CONTAINER_RESOLVER_HPP
|
||||
|
|
@ -18,10 +18,5 @@ public:
|
|||
return std::dynamic_pointer_cast<object_resolver<Type>>(res);
|
||||
}
|
||||
};
|
||||
|
||||
class object_resolver_service : public object_resolver_factory, public collection_resolver_factory {
|
||||
public:
|
||||
};
|
||||
|
||||
}
|
||||
#endif //MATADOR_OBJECT_RESOLVER_FACTORY_HPP
|
||||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "matador/object/repository.hpp"
|
||||
|
||||
#include "matador/sql/internal/collection_resolver_producer.hpp"
|
||||
#include "matador/sql/producer_resolver_factory.hpp"
|
||||
|
||||
#include "matador/query/table.hpp"
|
||||
|
|
@ -55,10 +56,12 @@ public:
|
|||
protected:
|
||||
template<typename Type>
|
||||
friend class schema_observer;
|
||||
friend class producer_creator;
|
||||
|
||||
object::repository repo_;
|
||||
std::unordered_map<std::type_index, schema_node> schema_nodes_;
|
||||
std::unordered_map<std::type_index, std::unique_ptr<sql::object_resolver_producer>> resolver_producers_;
|
||||
std::unordered_map<sql::composite_key, std::unique_ptr<sql::collection_resolver_producer>, sql::composite_key_hash> collection_resolver_producers_;
|
||||
};
|
||||
}
|
||||
#endif //MATADOR_BASIC_SCHEMA_HPP
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
#ifndef MATADOR_QUERY_CONTAINER_RESOLVER_HPP
|
||||
#define MATADOR_QUERY_CONTAINER_RESOLVER_HPP
|
||||
|
||||
#include "matador/object/collection_resolver.hpp"
|
||||
|
||||
#include "matador/sql/internal/identifier_statement_binder.hpp"
|
||||
#include "matador/sql/statement.hpp"
|
||||
|
||||
#include "matador/query/table.hpp"
|
||||
#include "matador/query/select_query_builder.hpp"
|
||||
|
||||
namespace matador::sql {
|
||||
class executor;
|
||||
}
|
||||
|
||||
namespace matador::query {
|
||||
template<typename Type>
|
||||
class query_collection_resolver : public object::collection_resolver<Type> {
|
||||
public:
|
||||
explicit query_collection_resolver(const basic_schema &repo, sql::executor& exec, const table &tab, std::string pk_name, const std::type_index& root_type, std::string join_column)
|
||||
: object::collection_resolver<Type>(root_type, join_column)
|
||||
, executor_(exec)
|
||||
, schema_(repo)
|
||||
, table_(tab)
|
||||
, pk_name_(std::move(pk_name))
|
||||
, join_column_(std::move(join_column))
|
||||
{}
|
||||
|
||||
std::vector<Type> resolve(const utils::identifier &id) override;
|
||||
protected:
|
||||
sql::executor& executor_;
|
||||
const basic_schema &schema_;
|
||||
const table &table_;
|
||||
std::string pk_name_;
|
||||
std::string join_column_;
|
||||
std::type_index index{typeid(Type)};
|
||||
};
|
||||
|
||||
template<typename Type>
|
||||
std::vector<Type> query_collection_resolver<Type>::resolve(const utils::identifier &id) {
|
||||
const auto *pk_column = table_[pk_name_];
|
||||
const auto *join_column = table_[join_column_];
|
||||
|
||||
auto stmt = query::select({*pk_column})
|
||||
.from(table_)
|
||||
.where(*join_column == id)
|
||||
.prepare(executor_);
|
||||
|
||||
if (!stmt) {
|
||||
return {};
|
||||
}
|
||||
|
||||
sql::identifier_statement_binder binder(*stmt);
|
||||
binder.bind(id);
|
||||
|
||||
auto result = stmt->template fetch_one_raw<Type>();
|
||||
if (!result) {
|
||||
return {};
|
||||
}
|
||||
return {};
|
||||
}
|
||||
}
|
||||
#endif //MATADOR_QUERY_CONTAINER_RESOLVER_HPP
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
#ifndef MATADOR_QUERY_CONTAINER_RESOLVER_HPP
|
||||
#define MATADOR_QUERY_CONTAINER_RESOLVER_HPP
|
||||
|
||||
#include "matador/object/container_resolver.hpp"
|
||||
|
||||
#include "matador/sql/internal/identifier_statement_binder.hpp"
|
||||
#include "matador/sql/statement.hpp"
|
||||
|
||||
#include "matador/query/table.hpp"
|
||||
#include "matador/query/select_query_builder.hpp"
|
||||
|
||||
namespace matador::sql {
|
||||
class executor;
|
||||
}
|
||||
|
||||
namespace matador::query {
|
||||
template<typename Type>
|
||||
class query_container_resolver : public object::container_resolver<Type> {
|
||||
public:
|
||||
explicit query_container_resolver(const basic_schema &repo, sql::executor& exec, const table &tab, std::string pk_name)
|
||||
: executor_(exec)
|
||||
, schema_(repo)
|
||||
, table_(tab)
|
||||
, pk_name_(std::move(pk_name)) {}
|
||||
|
||||
std::shared_ptr<Type> resolve(const utils::identifier &id) override;
|
||||
protected:
|
||||
sql::executor& executor_;
|
||||
const basic_schema &schema_;
|
||||
const table &table_;
|
||||
std::string pk_name_;
|
||||
std::type_index index{typeid(Type)};
|
||||
};
|
||||
|
||||
utils::result<sql::statement, utils::error> prepare_collection_statement(sql::executor& exec, entity_query_data &&data);
|
||||
|
||||
template<typename Type>
|
||||
std::shared_ptr<Type> query_container_resolver<Type>::resolve(const utils::identifier &id) {
|
||||
|
||||
}
|
||||
}
|
||||
#endif //MATADOR_QUERY_CONTAINER_RESOLVER_HPP
|
||||
|
|
@ -5,7 +5,9 @@
|
|||
|
||||
#include "matador/sql/query_context.hpp"
|
||||
#include "matador/sql/internal/object_resolver_producer.hpp"
|
||||
#include "matador/sql/internal/collection_resolver_producer.hpp"
|
||||
|
||||
#include "matador/query/query_collection_resolver.hpp"
|
||||
#include "matador/query/query_object_resolver.hpp"
|
||||
#include "matador/query/basic_schema.hpp"
|
||||
|
||||
|
|
@ -38,17 +40,18 @@ private:
|
|||
};
|
||||
|
||||
template<typename Type>
|
||||
class query_collection_resolver_producer : public sql::object_resolver_producer {
|
||||
class query_collection_resolver_producer : public sql::collection_resolver_producer {
|
||||
public:
|
||||
query_collection_resolver_producer() = default;
|
||||
query_collection_resolver_producer(const basic_schema& repo, const table& tab, std::string pk_name)
|
||||
: object_resolver_producer(typeid(Type))
|
||||
query_collection_resolver_producer(const basic_schema& repo, const table& tab, std::string pk_name, const std::type_index& root_type, std::string join_column)
|
||||
: collection_resolver_producer(root_type, typeid(Type), std::move(join_column))
|
||||
, repo_(repo)
|
||||
, table_(tab)
|
||||
, pk_name_(std::move(pk_name)) {}
|
||||
, pk_name_(std::move(pk_name))
|
||||
{}
|
||||
|
||||
std::shared_ptr<object::abstract_type_resolver> produce(sql::executor &exec) override {
|
||||
return std::make_shared<query_object_resolver<Type>>(repo_, exec, table_, std::move(pk_name_));
|
||||
std::shared_ptr<object::abstract_collection_resolver> produce(sql::executor &exec) override {
|
||||
return std::make_shared<query_collection_resolver<Type>>(repo_, exec, table_, std::move(pk_name_), root_type(), collection_name());
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
@ -167,6 +170,11 @@ utils::result<void, utils::error> schema::drop_table(const sql::connection &conn
|
|||
|
||||
class producer_creator final {
|
||||
public:
|
||||
producer_creator(basic_schema& schema, const std::type_index& root_type)
|
||||
: schema_(schema)
|
||||
, root_type_(root_type)
|
||||
{}
|
||||
|
||||
template<typename ValueType>
|
||||
void on_primary_key(const char *id, ValueType &value, const utils::primary_key_attribute& attr = utils::default_pk_attributes) {
|
||||
|
||||
|
|
@ -184,8 +192,24 @@ public:
|
|||
void on_has_many_to_many(const char *, ContainerType &, const utils::foreign_attributes &attr) {}
|
||||
|
||||
template<class CollectionType>
|
||||
void on_has_many(const char * /*id*/, CollectionType &cont, const char * /*join_column*/, const utils::foreign_attributes &attr, std::enable_if_t<object::is_object_ptr<typename CollectionType::value_type>::value> * = nullptr) {
|
||||
void on_has_many(const char * /*id*/, CollectionType &cont, const char *join_column, const utils::foreign_attributes &attr, std::enable_if_t<object::is_object_ptr<typename CollectionType::value_type>::value> * = nullptr) {
|
||||
// SELECT id FROM books where author_id = ?;
|
||||
const auto it = schema_.find(typeid(typename CollectionType::value_type::value_type));
|
||||
if (it == schema_.end()) {
|
||||
throw query_builder_exception{query_build_error::UnknownType};
|
||||
}
|
||||
if (!it->second.node().info().has_primary_key()) {
|
||||
throw query_builder_exception{query_build_error::MissingPrimaryKey};
|
||||
}
|
||||
|
||||
auto producer = std::make_unique<query_collection_resolver_producer<typename CollectionType::value_type::value_type>>(
|
||||
schema_,
|
||||
it->second.table(),
|
||||
it->second.node().info().primary_key_attribute()->name(),
|
||||
root_type_,
|
||||
join_column);
|
||||
const sql::composite_key key{root_type_, typeid(typename CollectionType::value_type::value_type), join_column};
|
||||
schema_.collection_resolver_producers_[key] = std::move(producer);
|
||||
}
|
||||
|
||||
template<class CollectionType>
|
||||
|
|
@ -193,16 +217,26 @@ public:
|
|||
|
||||
}
|
||||
|
||||
private:
|
||||
basic_schema& schema_;
|
||||
const std::type_index root_type_;
|
||||
};
|
||||
|
||||
template <typename Type>
|
||||
void schema_observer<Type>::on_attach(const object::repository_node &node, const Type &/*prototype*/) const {
|
||||
const auto it = schema_.insert_table(typeid(Type), node);
|
||||
|
||||
if (it->second.node().info().has_primary_key()) {
|
||||
auto producer = std::make_unique<query_object_resolver_producer<Type>>(schema_, it->second.table(), it->second.node().info().primary_key_attribute()->name());
|
||||
schema_.resolver_producers_[typeid(Type)] = std::move(producer);
|
||||
if (!it->second.node().info().has_primary_key()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto producer = std::make_unique<query_object_resolver_producer<Type>>(schema_, it->second.table(), it->second.node().info().primary_key_attribute()->name());
|
||||
schema_.resolver_producers_[typeid(Type)] = std::move(producer);
|
||||
|
||||
producer_creator pc(schema_, typeid(Type));
|
||||
Type obj;
|
||||
access::process(pc, obj);
|
||||
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
#ifndef MATADOR_COLLECTION_RESOLVER_PRODUCER_HPP
|
||||
#define MATADOR_COLLECTION_RESOLVER_PRODUCER_HPP
|
||||
|
||||
#include "matador/object/abstract_collection_resolver.hpp"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace matador::sql {
|
||||
class executor;
|
||||
class collection_resolver_producer {
|
||||
public:
|
||||
virtual ~collection_resolver_producer() = default;
|
||||
virtual std::shared_ptr<object::abstract_collection_resolver> produce(executor &exec) = 0;
|
||||
|
||||
[[nodiscard]] const std::type_index& root_type() const;
|
||||
[[nodiscard]] const std::type_index& type() const;
|
||||
[[nodiscard]] const std::string& collection_name() const;
|
||||
|
||||
protected:
|
||||
explicit collection_resolver_producer(const std::type_index &root_type, const std::type_index &type, std::string collection_name);
|
||||
|
||||
private:
|
||||
std::type_index root_type_;
|
||||
std::type_index type_;
|
||||
std::string collection_name_;
|
||||
};
|
||||
}
|
||||
#endif // MATADOR_COLLECTION_RESOLVER_PRODUCER_HPP
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef MATADOR_RESOLVER_PRODUCER_HPP
|
||||
#define MATADOR_RESOLVER_PRODUCER_HPP
|
||||
|
||||
#include "matador/object/object_resolver.hpp"
|
||||
#include "matador/object/abstract_type_resolver.hpp"
|
||||
|
||||
#include <memory>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,23 +1,60 @@
|
|||
#ifndef MATADOR_RESOLVER_FACTORY_HPP
|
||||
#define MATADOR_RESOLVER_FACTORY_HPP
|
||||
|
||||
#include "matador/object/object_resolver_factory.hpp"
|
||||
|
||||
#include "matador/sql/internal/object_resolver_producer.hpp"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
#include "matador/object/abstract_collection_resolver.hpp"
|
||||
#include "matador/object/object_resolver_factory.hpp"
|
||||
#include "matador/sql/internal/object_resolver_producer.hpp"
|
||||
|
||||
namespace matador::sql {
|
||||
class executor;
|
||||
|
||||
class producer_resolver_factory : public object::object_resolver_factory {
|
||||
public:
|
||||
|
||||
std::shared_ptr<object::abstract_type_resolver> acquire_object_resolver(const std::type_index &type) override;
|
||||
void register_object_resolver(std::shared_ptr<object::abstract_type_resolver> &&resolver) override;
|
||||
|
||||
private:
|
||||
std::unordered_map<std::type_index, std::shared_ptr<object::abstract_type_resolver>> resolvers_;
|
||||
};
|
||||
|
||||
struct composite_key {
|
||||
std::type_index root_type;
|
||||
std::type_index type;
|
||||
std::string name;
|
||||
|
||||
bool operator==(const composite_key& other) const {
|
||||
return root_type == other.root_type &&
|
||||
type == other.type &&
|
||||
name == other.name;
|
||||
}
|
||||
};
|
||||
|
||||
struct composite_key_hash {
|
||||
std::size_t operator()(const composite_key& k) const noexcept {
|
||||
const std::size_t h1 = std::hash<std::type_index>{}(k.root_type);
|
||||
const std::size_t h2 = std::hash<std::type_index>{}(k.type);
|
||||
const std::size_t h3 = std::hash<std::string>{}(k.name);
|
||||
|
||||
// Klassische Hash-Kombination (Boost-Style)
|
||||
std::size_t seed = h1;
|
||||
seed ^= h2 + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
seed ^= h3 + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
|
||||
return seed;
|
||||
}
|
||||
};
|
||||
|
||||
class producer_collection_resolver_factory : public object::collection_resolver_factory {
|
||||
public:
|
||||
std::shared_ptr<object::abstract_collection_resolver> acquire_collection_resolver(const std::type_index& root_type,
|
||||
const std::type_index& element_type,
|
||||
const std::string& collection_name) override;
|
||||
void register_collection_resolver(std::shared_ptr<object::abstract_collection_resolver>&& resolver) override;
|
||||
|
||||
private:
|
||||
std::unordered_map<composite_key, std::shared_ptr<object::abstract_collection_resolver>, composite_key_hash> resolvers_;
|
||||
};
|
||||
}
|
||||
#endif //MATADOR_RESOLVER_FACTORY_HPP
|
||||
|
|
@ -13,9 +13,15 @@ add_library(matador-core STATIC
|
|||
../../include/matador/net/reactor.hpp
|
||||
../../include/matador/net/select_fd_sets.hpp
|
||||
../../include/matador/net/socket_interrupter.hpp
|
||||
../../include/matador/object/abstract_collection_resolver.hpp
|
||||
../../include/matador/object/abstract_type_resolver.hpp
|
||||
../../include/matador/object/abstract_type_resolver_factory.hpp
|
||||
../../include/matador/object/attribute.hpp
|
||||
../../include/matador/object/basic_object_info.hpp
|
||||
../../include/matador/object/basic_repository.hpp
|
||||
../../include/matador/object/collection_proxy.hpp
|
||||
../../include/matador/object/collection_resolver.hpp
|
||||
../../include/matador/object/collection_resolver_factory.hpp
|
||||
../../include/matador/object/error_code.hpp
|
||||
../../include/matador/object/foreign_node_completer.hpp
|
||||
../../include/matador/object/internal/observer_list_copy_creator.hpp
|
||||
|
|
@ -81,6 +87,7 @@ add_library(matador-core STATIC
|
|||
logger/log_manager.cpp
|
||||
logger/logger.cpp
|
||||
logger/rotating_file_sink.cpp
|
||||
object/abstract_collection_resolver.cpp
|
||||
object/attribute.cpp
|
||||
object/basic_object_info.cpp
|
||||
object/basic_repository.cpp
|
||||
|
|
@ -113,12 +120,6 @@ add_library(matador-core STATIC
|
|||
utils/uuid.cpp
|
||||
utils/value.cpp
|
||||
utils/version.cpp
|
||||
../../include/matador/object/collection_proxy.hpp
|
||||
../../include/matador/object/collection_resolver_factory.hpp
|
||||
../../include/matador/object/collection_resolver.hpp
|
||||
../../include/matador/object/abstract_type_resolver.hpp
|
||||
../../include/matador/object/abstract_type_resolver_factory.hpp
|
||||
../../include/matador/object/container_resolver.hpp
|
||||
)
|
||||
|
||||
target_link_libraries(matador-core ${CMAKE_DL_LIBS})
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
#include "matador/object/abstract_collection_resolver.hpp"
|
||||
|
||||
namespace matador::object {
|
||||
|
||||
const std::type_index& abstract_collection_resolver::root_type() const {
|
||||
return root_type_;
|
||||
}
|
||||
|
||||
const std::type_index& abstract_collection_resolver::type() const {
|
||||
return type_;
|
||||
}
|
||||
|
||||
const std::string& abstract_collection_resolver::collection_name() const {
|
||||
return collection_name_;
|
||||
}
|
||||
|
||||
abstract_collection_resolver::abstract_collection_resolver(const std::type_index& root_type, const std::type_index& type, std::string collection_name)
|
||||
: root_type_(root_type)
|
||||
, type_(type)
|
||||
, collection_name_(std::move(collection_name)) {}
|
||||
|
||||
|
||||
} // namespace matador::object
|
||||
|
|
@ -54,14 +54,15 @@ add_library(matador-orm STATIC
|
|||
../../include/matador/query/meta_table_macro.hpp
|
||||
../../include/matador/query/meta_table_macro.hpp
|
||||
../../include/matador/query/query.hpp
|
||||
../../include/matador/query/select_query_builder.hpp
|
||||
../../include/matador/query/query_builder.hpp
|
||||
../../include/matador/query/query_collection_resolver.hpp
|
||||
../../include/matador/query/query_data.hpp
|
||||
../../include/matador/query/query_intermediates.hpp
|
||||
../../include/matador/query/query_object_resolver.hpp
|
||||
../../include/matador/query/query_part.hpp
|
||||
../../include/matador/query/query_utils.hpp
|
||||
../../include/matador/query/schema.hpp
|
||||
../../include/matador/query/select_query_builder.hpp
|
||||
../../include/matador/query/table.hpp
|
||||
../../include/matador/query/table_column.hpp
|
||||
../../include/matador/query/table_constraint.hpp
|
||||
|
|
@ -81,12 +82,13 @@ add_library(matador-orm STATIC
|
|||
../../include/matador/sql/interface/query_result_reader.hpp
|
||||
../../include/matador/sql/interface/statement_impl.hpp
|
||||
../../include/matador/sql/interface/statement_proxy.hpp
|
||||
../../include/matador/sql/internal/collection_resolver_producer.hpp
|
||||
../../include/matador/sql/internal/identifier_reader.hpp
|
||||
../../include/matador/sql/internal/identifier_statement_binder.hpp
|
||||
../../include/matador/sql/internal/object_resolver_producer.hpp
|
||||
../../include/matador/sql/internal/object_result_binder.hpp
|
||||
../../include/matador/sql/internal/query_result_impl.hpp
|
||||
../../include/matador/sql/internal/query_result_pk_resolver.hpp
|
||||
../../include/matador/sql/internal/object_resolver_producer.hpp
|
||||
../../include/matador/sql/internal/statement_object_resolver.hpp
|
||||
../../include/matador/sql/producer_resolver_factory.hpp
|
||||
../../include/matador/sql/query_context.hpp
|
||||
|
|
@ -146,13 +148,14 @@ add_library(matador-orm STATIC
|
|||
query/internal/string_builder_utils.cpp
|
||||
query/key_value_generator.cpp
|
||||
query/query.cpp
|
||||
query/select_query_builder.cpp
|
||||
query/query_builder_exception.cpp
|
||||
query/query_builder.cpp
|
||||
query/query_builder_exception.cpp
|
||||
query/query_collection_resolver.cpp
|
||||
query/query_object_resolver.cpp
|
||||
query/query_part.cpp
|
||||
query/query_utils.cpp
|
||||
query/schema.cpp
|
||||
query/select_query_builder.cpp
|
||||
query/table.cpp
|
||||
query/table_column.cpp
|
||||
query/table_constraint.cpp
|
||||
|
|
@ -169,19 +172,18 @@ add_library(matador-orm STATIC
|
|||
sql/interface/query_result_reader.cpp
|
||||
sql/interface/statement_impl.cpp
|
||||
sql/interface/statement_proxy.cpp
|
||||
sql/internal/collection_resolver_producer.cpp
|
||||
sql/internal/identifier_reader.cpp
|
||||
sql/internal/identifier_statement_binder.cpp
|
||||
sql/internal/object_resolver_producer.cpp
|
||||
sql/internal/object_result_binder.cpp
|
||||
sql/internal/query_result_pk_resolver.cpp
|
||||
sql/internal/object_resolver_producer.cpp
|
||||
sql/object_parameter_binder.cpp
|
||||
sql/producer_resolver_factory.cpp
|
||||
sql/query_result.cpp
|
||||
sql/record.cpp
|
||||
sql/statement.cpp
|
||||
sql/statement_cache.cpp
|
||||
../../include/matador/query/query_container_resolver.hpp
|
||||
query/query_container_resolver.cpp
|
||||
)
|
||||
|
||||
target_include_directories(matador-orm
|
||||
|
|
|
|||
|
|
@ -87,6 +87,12 @@ void basic_schema::initialize_executor(sql::executor &exec) const {
|
|||
auto resolver = producer->produce(exec);
|
||||
exec.resolver_factory()->register_object_resolver(std::move(resolver));
|
||||
}
|
||||
|
||||
auto collection_factory = std::make_shared<sql::producer_collection_resolver_factory>();
|
||||
for (const auto &[key, producer] : collection_resolver_producers_) {
|
||||
auto resolver = producer->produce(exec);
|
||||
// exec.resolver_factory()->register_collection_resolver(std::move(resolver));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
#include "matador/query/query_collection_resolver.hpp"
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
#include "matador/query/query_container_resolver.hpp"
|
||||
|
||||
namespace matador::query {
|
||||
utils::result<sql::statement, utils::error> prepare_collection_statement(sql::executor& exec, entity_query_data &&data) {
|
||||
return query::query::select(data.columns)
|
||||
.from(*data.root_table)
|
||||
.join_left(data.joins)
|
||||
.where(std::move(data.where_clause))
|
||||
.order_by({data.root_table, data.pk_column_name})
|
||||
.asc()
|
||||
.prepare(exec);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
#include "matador/sql/internal/collection_resolver_producer.hpp"
|
||||
|
||||
namespace matador::sql {
|
||||
const std::type_index& collection_resolver_producer::root_type() const {
|
||||
return root_type_;
|
||||
}
|
||||
const std::type_index& collection_resolver_producer::type() const {
|
||||
return type_;
|
||||
}
|
||||
const std::string& collection_resolver_producer::collection_name() const {
|
||||
return collection_name_;
|
||||
}
|
||||
collection_resolver_producer::collection_resolver_producer(const std::type_index& root_type,
|
||||
const std::type_index& type,
|
||||
std::string collection_name)
|
||||
: root_type_(root_type), type_(type), collection_name_(std::move(collection_name)) {}
|
||||
} // namespace matador::sql
|
||||
|
|
@ -11,4 +11,18 @@ std::shared_ptr<object::abstract_type_resolver> producer_resolver_factory::acqui
|
|||
void producer_resolver_factory::register_object_resolver(std::shared_ptr<object::abstract_type_resolver> &&resolver) {
|
||||
resolvers_[resolver->type()] = std::move(resolver);
|
||||
}
|
||||
std::shared_ptr<object::abstract_collection_resolver>
|
||||
producer_collection_resolver_factory::acquire_collection_resolver(const std::type_index& root_type,
|
||||
const std::type_index& element_type,
|
||||
const std::string& collection_name) {
|
||||
const composite_key key{root_type, element_type, collection_name};
|
||||
if (const auto it = resolvers_.find(key); it != resolvers_.end()) {
|
||||
return it->second;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
void producer_collection_resolver_factory::register_collection_resolver(std::shared_ptr<object::abstract_collection_resolver>&& resolver) {
|
||||
const composite_key key{resolver->root_type(), resolver->type(), resolver->collection_name()};
|
||||
resolvers_[key] = std::move(resolver);
|
||||
}
|
||||
} // namespace matador::sql
|
||||
|
|
|
|||
Loading…
Reference in New Issue