Compare commits
No commits in common. "a4b35b913e91cad6e2f8d159e1d790be3e5cacd2" and "839a214cef7ebb286212a6cdbc26a3e44a23e6cf" have entirely different histories.
a4b35b913e
...
839a214cef
|
|
@ -18,6 +18,8 @@ namespace matador::object {
|
||||||
* Processes the given node and ensures
|
* Processes the given node and ensures
|
||||||
* that all foreign nodes needed by the given node
|
* that all foreign nodes needed by the given node
|
||||||
* relations are attached in schema.
|
* relations are attached in schema.
|
||||||
|
*
|
||||||
|
* @tparam Type Type of node to complete
|
||||||
*/
|
*/
|
||||||
class foreign_node_completer final {
|
class foreign_node_completer final {
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
#ifndef OBJECT_PROXY_HPP
|
#ifndef OBJECT_PROXY_HPP
|
||||||
#define OBJECT_PROXY_HPP
|
#define OBJECT_PROXY_HPP
|
||||||
|
|
||||||
#include "matador/object/primary_key_resolver.hpp"
|
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace matador::object {
|
namespace matador::object {
|
||||||
|
|
@ -26,12 +24,12 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
template < typename Type >
|
template < typename Type >
|
||||||
class static_object_resolver final : public object_resolver<Type> {
|
class simple_object_resolver final : public object_resolver<Type> {
|
||||||
public:
|
public:
|
||||||
static_object_resolver() = default;
|
simple_object_resolver() = default;
|
||||||
explicit static_object_resolver(Type* obj)
|
explicit simple_object_resolver(Type* obj)
|
||||||
: obj_(obj) {}
|
: obj_(obj) {}
|
||||||
explicit static_object_resolver(std::unique_ptr<Type> obj)
|
explicit simple_object_resolver(std::unique_ptr<Type> obj)
|
||||||
: obj_(std::move(obj)) {}
|
: obj_(std::move(obj)) {}
|
||||||
|
|
||||||
Type* resolve(const object_proxy<Type> &/*proxy*/) const override {
|
Type* resolve(const object_proxy<Type> &/*proxy*/) const override {
|
||||||
|
|
@ -48,8 +46,9 @@ class object_proxy final : public basic_object_proxy {
|
||||||
public:
|
public:
|
||||||
object_proxy() = default;
|
object_proxy() = default;
|
||||||
explicit object_proxy(Type* obj)
|
explicit object_proxy(Type* obj)
|
||||||
: resolver_(std::make_unique<static_object_resolver<Type>>(obj))
|
: resolver_(std::make_unique<simple_object_resolver<Type>>(obj)) {}
|
||||||
, pk_(primary_key_resolver::resolve_object(*obj).pk) {}
|
explicit object_proxy(std::unique_ptr<Type> obj)
|
||||||
|
: resolver_(std::move(obj)) {}
|
||||||
|
|
||||||
[[nodiscard]] void *get() const override { return static_cast<void*>(pointer()); }
|
[[nodiscard]] void *get() const override { return static_cast<void*>(pointer()); }
|
||||||
|
|
||||||
|
|
@ -63,31 +62,22 @@ public:
|
||||||
const Type& ref() const { return *pointer(); }
|
const Type& ref() const { return *pointer(); }
|
||||||
|
|
||||||
void reset(Type* obj) {
|
void reset(Type* obj) {
|
||||||
pk_ = primary_key_resolver::resolve_object(*obj).pk;
|
resolver_ = std::make_unique<simple_object_resolver<Type>>(obj);
|
||||||
resolver_ = std::make_unique<static_object_resolver<Type>>(obj);
|
|
||||||
}
|
}
|
||||||
void reset(std::unique_ptr<Type> obj) {
|
void reset(std::unique_ptr<Type> obj) {
|
||||||
pk_ = primary_key_resolver::resolve_object(*obj).pk;
|
resolver_ = std::make_unique<simple_object_resolver<Type>>(std::move(obj));
|
||||||
resolver_ = std::make_unique<static_object_resolver<Type>>(std::move(obj));
|
|
||||||
}
|
}
|
||||||
void reset(std::unique_ptr<object_resolver<Type>> &&resolver) {
|
void reset(std::unique_ptr<object_resolver<Type>> &&resolver) {
|
||||||
resolver_ = std::move(resolver);
|
resolver_ = std::move(resolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] bool empty() const { return resolver_ == nullptr; }
|
|
||||||
[[nodiscard]] bool valid() const { return !empty(); }
|
|
||||||
[[nodiscard]] bool has_primary_key() const { return !pk_.is_null(); }
|
|
||||||
[[nodiscard]] const utils::identifier& primary_key() const { return pk_; }
|
|
||||||
void primary_key(const utils::identifier &pk) { pk_ = pk; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Type* resolve() const {
|
Type* resolve() const {
|
||||||
return resolver_->resolve(*this);
|
return resolver_->resolve(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<object_resolver<Type>> resolver_{std::make_unique<static_object_resolver<Type>>()};
|
std::unique_ptr<object_resolver<Type>> resolver_{std::make_unique<simple_object_resolver<Type>>()};
|
||||||
utils::identifier pk_{};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
#include "matador/utils/identifier.hpp"
|
#include "matador/utils/identifier.hpp"
|
||||||
|
|
||||||
#include "matador/object/object_proxy.hpp"
|
#include "matador/object/object_proxy.hpp"
|
||||||
|
#include "matador/object/primary_key_resolver.hpp"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
|
@ -14,7 +15,8 @@ public:
|
||||||
object_ptr()
|
object_ptr()
|
||||||
: ptr_(std::make_shared<object_proxy<Type>>()) {}
|
: ptr_(std::make_shared<object_proxy<Type>>()) {}
|
||||||
explicit object_ptr(Type *obj)
|
explicit object_ptr(Type *obj)
|
||||||
: ptr_(std::make_shared<object_proxy<Type>>(obj)) {}
|
: ptr_(std::make_shared<object_proxy<Type>>(obj))
|
||||||
|
, pk_(primary_key_resolver::resolve_object(*obj).pk) {}
|
||||||
object_ptr(const object_ptr &other) : ptr_(other.ptr_) {}
|
object_ptr(const object_ptr &other) : ptr_(other.ptr_) {}
|
||||||
object_ptr(object_ptr &&other) noexcept : ptr_(std::move(other.ptr_)) {}
|
object_ptr(object_ptr &&other) noexcept : ptr_(std::move(other.ptr_)) {}
|
||||||
object_ptr &operator=(const object_ptr &other) = default;
|
object_ptr &operator=(const object_ptr &other) = default;
|
||||||
|
|
@ -28,6 +30,7 @@ public:
|
||||||
[[nodiscard]] bool empty() const { return ptr_->pointer() == nullptr; }
|
[[nodiscard]] bool empty() const { return ptr_->pointer() == nullptr; }
|
||||||
void reset(Type *obj) {
|
void reset(Type *obj) {
|
||||||
ptr_->reset(obj);
|
ptr_->reset(obj);
|
||||||
|
pk_ = primary_key_resolver::resolve_object(*obj).pk;
|
||||||
}
|
}
|
||||||
|
|
||||||
Type* get() const { return static_cast<Type*>(ptr_->pointer()); }
|
Type* get() const { return static_cast<Type*>(ptr_->pointer()); }
|
||||||
|
|
@ -35,11 +38,11 @@ public:
|
||||||
operator bool() { return valid(); }
|
operator bool() { return valid(); }
|
||||||
bool valid() { return ptr_ != nullptr; }
|
bool valid() { return ptr_ != nullptr; }
|
||||||
|
|
||||||
[[nodiscard]] bool has_primary_key() const { return ptr_->has_primary_key(); }
|
[[nodiscard]] const utils::identifier& primary_key() const { return pk_; }
|
||||||
[[nodiscard]] const utils::identifier& primary_key() const { return ptr_->primary_key(); }
|
void primary_key(const utils::identifier &pk) { pk_ = pk; }
|
||||||
void primary_key(const utils::identifier &pk) { ptr_->primary_key(pk); }
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<object_proxy<Type>> ptr_{};
|
std::shared_ptr<object_proxy<Type>> ptr_{};
|
||||||
|
utils::identifier pk_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename>
|
template<typename>
|
||||||
|
|
|
||||||
|
|
@ -3,16 +3,13 @@
|
||||||
|
|
||||||
#include "matador/utils/access.hpp"
|
#include "matador/utils/access.hpp"
|
||||||
#include "matador/utils/field_attributes.hpp"
|
#include "matador/utils/field_attributes.hpp"
|
||||||
|
#include "matador/utils/foreign_attributes.hpp"
|
||||||
#include "matador/utils/identifier.hpp"
|
#include "matador/utils/identifier.hpp"
|
||||||
#include "matador/utils/primary_key_attribute.hpp"
|
#include "matador/utils/primary_key_attribute.hpp"
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace matador::utils {
|
|
||||||
class foreign_attributes;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace matador::object {
|
namespace matador::object {
|
||||||
|
|
||||||
struct primary_key_info {
|
struct primary_key_info {
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ public:
|
||||||
[[nodiscard]] std::string type_name() const;
|
[[nodiscard]] std::string type_name() const;
|
||||||
[[nodiscard]] const schema_node& node() const;
|
[[nodiscard]] const schema_node& node() const;
|
||||||
|
|
||||||
[[nodiscard]] std::shared_ptr<schema_node> node_ptr() const;
|
std::shared_ptr<schema_node> node_ptr() const;
|
||||||
|
|
||||||
[[nodiscard]] bool is_has_one() const;
|
[[nodiscard]] bool is_has_one() const;
|
||||||
[[nodiscard]] bool is_has_many() const;
|
[[nodiscard]] bool is_has_many() const;
|
||||||
|
|
|
||||||
|
|
@ -29,48 +29,6 @@ struct session_context {
|
||||||
size_t cache_size{500};
|
size_t cache_size{500};
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Type>
|
|
||||||
class lazy_object_resolver final : public object::object_resolver<Type> {
|
|
||||||
public:
|
|
||||||
Type* resolve(const object::object_proxy<Type>& proxy) const override {
|
|
||||||
return proxy.resolve();
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
class prototype_builder final {
|
|
||||||
public:
|
|
||||||
explicit prototype_builder(const std::unordered_map<std::string, sql::statement> &statements_per_column)
|
|
||||||
: statements_per_column_(statements_per_column) {}
|
|
||||||
|
|
||||||
template < class V >
|
|
||||||
static void on_primary_key(const char * /*id*/, V &/*pk*/, const utils::primary_key_attribute& /*attr*/ = utils::default_pk_attributes) {}
|
|
||||||
static void on_revision(const char * /*id*/, unsigned long long &/*rev*/) {}
|
|
||||||
template<typename Type>
|
|
||||||
static void on_attribute(const char * /*id*/, Type &/*obj*/, const utils::field_attributes &/*attr*/ = utils::null_attributes) {}
|
|
||||||
template<class Pointer>
|
|
||||||
void on_belongs_to(const char *id, Pointer &obj, const utils::foreign_attributes &attr) {
|
|
||||||
|
|
||||||
}
|
|
||||||
template<class Pointer>
|
|
||||||
void on_has_one(const char *id, Pointer &obj, const utils::foreign_attributes &attr) {
|
|
||||||
|
|
||||||
}
|
|
||||||
template<class ContainerType>
|
|
||||||
void on_has_many(const char * /*id*/, ContainerType &, const char *join_column, const utils::foreign_attributes &attr) {
|
|
||||||
}
|
|
||||||
template<class ContainerType>
|
|
||||||
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>
|
|
||||||
void on_has_many_to_many(const char *id, ContainerType &/*cont*/, const utils::foreign_attributes &attr) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
const std::unordered_map<std::string, sql::statement> &statements_per_column_;
|
|
||||||
};
|
|
||||||
class session final : public sql::executor {
|
class session final : public sql::executor {
|
||||||
public:
|
public:
|
||||||
explicit session(session_context &&ctx);
|
explicit session(session_context &&ctx);
|
||||||
|
|
|
||||||
|
|
@ -62,10 +62,10 @@ size_t identifier::null_pk::hash() const
|
||||||
}
|
}
|
||||||
|
|
||||||
identifier::identifier()
|
identifier::identifier()
|
||||||
: id_(std::make_shared<null_pk>()) {}
|
: id_(std::make_shared<null_pk>()) {}
|
||||||
|
|
||||||
identifier::identifier(const identifier &x)
|
identifier::identifier(const identifier &x)
|
||||||
: id_(x.id_->copy()) {}
|
: id_(x.id_->copy()) {}
|
||||||
|
|
||||||
identifier &identifier::operator=(const identifier &x) {
|
identifier &identifier::operator=(const identifier &x) {
|
||||||
if (this == &x) {
|
if (this == &x) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue