No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

107 líneas
3.5 KiB

  1. #pragma once
  2. #include "../classes/schema/schema.h"
  3. namespace cpphibernate {
  4. namespace mariadb {
  5. struct driver_t;
  6. /**
  7. * @brief Actual implementation of the mariadb driver.
  8. *
  9. * This class is used/owner by the mariadb driver class (as a member).
  10. * The public interface of this class will not be part of the cpphibernate context.
  11. */
  12. struct driver_impl_t
  13. {
  14. driver_t& owner;
  15. schema_ptr_u schema;
  16. /**
  17. * @brief Constructor.
  18. * @param[in] p_owner Object the driver implementation is owned by.
  19. * @param[in] p_schema Cpphibernate schema to use with the driver.
  20. */
  21. template<typename T_schema>
  22. inline driver_impl_t(driver_t& p_owner, T_schema&& p_schema);
  23. /**
  24. * @brief Initialize the schema in the database.
  25. *
  26. * @param[in] recreate Recreate the whole schema (this will drop all existing data).
  27. */
  28. inline void init(bool recreate) const;
  29. /**
  30. * @brief Create a new dataset in the database.
  31. * This will update the primary key field of the passed dataset.
  32. *
  33. * @param[in] dataset Dataset to create in database.
  34. */
  35. template<typename T_dataset>
  36. inline void create(T_dataset& dataset) const;
  37. /*
  38. }
  39. protected:
  40. inline void init_impl(bool recreate) const
  41. {
  42. transaction_lock trans(*_connection);
  43. _schema.init(init_context(_schema, *_connection, recreate));
  44. trans.commit();
  45. }
  46. template<typename T_dataset>
  47. inline void create_impl(T_dataset& dataset) const
  48. {
  49. create_update_impl_t<T_dataset>::apply(
  50. create_update_context(dataset, _schema, *_connection, _filter, false));
  51. }
  52. template<typename T_dataset, typename T_modifiers>
  53. inline void read_impl(T_dataset& dataset, T_modifiers&& modifiers) const
  54. {
  55. using dataset_type = mp::decay_t<T_dataset>;
  56. using real_dataset_type = misc::real_dataset_t<dataset_type>;
  57. auto dataset_id = misc::get_type_id(hana::type_c<real_dataset_type>);
  58. auto& table = _schema.table(dataset_id);
  59. auto context = make_read_context(dataset, _schema, *_connection, _filter);
  60. context.where = build_where(_schema, modifiers).query(*_connection);
  61. context.limit = build_limit(modifiers).query(*_connection);
  62. context.order_by = build_order_by(_schema, modifiers).query(*_connection);
  63. transaction_lock trans(*_connection);
  64. table.read(context);
  65. trans.commit();
  66. }
  67. template<typename T_dataset>
  68. inline void update_impl(T_dataset& dataset) const
  69. {
  70. create_update_impl_t<T_dataset>::apply(
  71. create_update_context(dataset, _schema, *_connection, _filter, true));
  72. }
  73. template<typename T_dataset>
  74. inline void destroy_impl(T_dataset& dataset) const
  75. {
  76. using dataset_type = mp::decay_t<T_dataset>;
  77. using real_dataset_type = misc::real_dataset_t<dataset_type>;
  78. auto dataset_id = misc::get_type_id(hana::type_c<real_dataset_type>);
  79. auto& table = _schema.table(dataset_id);
  80. destroy_context context(dataset, _schema, *_connection);
  81. context.where = table.get_where_primary_key(context);
  82. destroy_impl_t<T_dataset>::apply(context);
  83. }
  84. */
  85. };
  86. } }