QxDao_Trigger.inl 5.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /****************************************************************************
  2. **
  3. ** https://www.qxorm.com/
  4. ** Copyright (C) 2013 Lionel Marty (contact@qxorm.com)
  5. **
  6. ** This file is part of the QxOrm library
  7. **
  8. ** This software is provided 'as-is', without any express or implied
  9. ** warranty. In no event will the authors be held liable for any
  10. ** damages arising from the use of this software
  11. **
  12. ** Commercial Usage
  13. ** Licensees holding valid commercial QxOrm licenses may use this file in
  14. ** accordance with the commercial license agreement provided with the
  15. ** Software or, alternatively, in accordance with the terms contained in
  16. ** a written agreement between you and Lionel Marty
  17. **
  18. ** GNU General Public License Usage
  19. ** Alternatively, this file may be used under the terms of the GNU
  20. ** General Public License version 3.0 as published by the Free Software
  21. ** Foundation and appearing in the file 'license.gpl3.txt' included in the
  22. ** packaging of this file. Please review the following information to
  23. ** ensure the GNU General Public License version 3.0 requirements will be
  24. ** met : http://www.gnu.org/copyleft/gpl.html
  25. **
  26. ** If you are unsure which license is appropriate for your use, or
  27. ** if you have questions regarding the use of this file, please contact :
  28. ** contact@qxorm.com
  29. **
  30. ****************************************************************************/
  31. namespace qx {
  32. namespace dao {
  33. namespace detail {
  34. template <class T>
  35. struct QxDao_Trigger
  36. {
  37. private:
  38. typedef typename qx::trait::get_base_class<T>::type type_base;
  39. enum { is_valid_base_class = (! std::is_same<type_base, qx::trait::no_base_class_defined>::value) };
  40. public:
  41. static inline void onBeforeInsert(T * t, qx::dao::detail::IxDao_Helper * dao) { TriggerHelper<is_valid_base_class, 0>::onBeforeInsert(t, dao); }
  42. static inline void onBeforeUpdate(T * t, qx::dao::detail::IxDao_Helper * dao) { TriggerHelper<is_valid_base_class, 0>::onBeforeUpdate(t, dao); }
  43. static inline void onBeforeDelete(T * t, qx::dao::detail::IxDao_Helper * dao) { TriggerHelper<is_valid_base_class, 0>::onBeforeDelete(t, dao); }
  44. static inline void onBeforeFetch(T * t, qx::dao::detail::IxDao_Helper * dao) { TriggerHelper<is_valid_base_class, 0>::onBeforeFetch(t, dao); }
  45. static inline void onAfterInsert(T * t, qx::dao::detail::IxDao_Helper * dao) { TriggerHelper<is_valid_base_class, 0>::onAfterInsert(t, dao); }
  46. static inline void onAfterUpdate(T * t, qx::dao::detail::IxDao_Helper * dao) { TriggerHelper<is_valid_base_class, 0>::onAfterUpdate(t, dao); }
  47. static inline void onAfterDelete(T * t, qx::dao::detail::IxDao_Helper * dao) { TriggerHelper<is_valid_base_class, 0>::onAfterDelete(t, dao); }
  48. static inline void onAfterFetch(T * t, qx::dao::detail::IxDao_Helper * dao) { TriggerHelper<is_valid_base_class, 0>::onAfterFetch(t, dao); }
  49. private:
  50. template <bool isValidBaseClass /* = false */, int dummy>
  51. struct TriggerHelper
  52. {
  53. static inline void onBeforeInsert(T * t, qx::dao::detail::IxDao_Helper * dao) { Q_UNUSED(t); Q_UNUSED(dao); }
  54. static inline void onBeforeUpdate(T * t, qx::dao::detail::IxDao_Helper * dao) { Q_UNUSED(t); Q_UNUSED(dao); }
  55. static inline void onBeforeDelete(T * t, qx::dao::detail::IxDao_Helper * dao) { Q_UNUSED(t); Q_UNUSED(dao); }
  56. static inline void onBeforeFetch(T * t, qx::dao::detail::IxDao_Helper * dao) { Q_UNUSED(t); Q_UNUSED(dao); }
  57. static inline void onAfterInsert(T * t, qx::dao::detail::IxDao_Helper * dao) { Q_UNUSED(t); Q_UNUSED(dao); }
  58. static inline void onAfterUpdate(T * t, qx::dao::detail::IxDao_Helper * dao) { Q_UNUSED(t); Q_UNUSED(dao); }
  59. static inline void onAfterDelete(T * t, qx::dao::detail::IxDao_Helper * dao) { Q_UNUSED(t); Q_UNUSED(dao); }
  60. static inline void onAfterFetch(T * t, qx::dao::detail::IxDao_Helper * dao) { Q_UNUSED(t); Q_UNUSED(dao); }
  61. };
  62. template <int dummy>
  63. struct TriggerHelper<true, dummy>
  64. {
  65. static inline void onBeforeInsert(T * t, qx::dao::detail::IxDao_Helper * dao) { qx::dao::detail::QxDao_Trigger<type_base>::onBeforeInsert(static_cast<type_base *>(t), dao); }
  66. static inline void onBeforeUpdate(T * t, qx::dao::detail::IxDao_Helper * dao) { qx::dao::detail::QxDao_Trigger<type_base>::onBeforeUpdate(static_cast<type_base *>(t), dao); }
  67. static inline void onBeforeDelete(T * t, qx::dao::detail::IxDao_Helper * dao) { qx::dao::detail::QxDao_Trigger<type_base>::onBeforeDelete(static_cast<type_base *>(t), dao); }
  68. static inline void onBeforeFetch(T * t, qx::dao::detail::IxDao_Helper * dao) { qx::dao::detail::QxDao_Trigger<type_base>::onBeforeFetch(static_cast<type_base *>(t), dao); }
  69. static inline void onAfterInsert(T * t, qx::dao::detail::IxDao_Helper * dao) { qx::dao::detail::QxDao_Trigger<type_base>::onAfterInsert(static_cast<type_base *>(t), dao); }
  70. static inline void onAfterUpdate(T * t, qx::dao::detail::IxDao_Helper * dao) { qx::dao::detail::QxDao_Trigger<type_base>::onAfterUpdate(static_cast<type_base *>(t), dao); }
  71. static inline void onAfterDelete(T * t, qx::dao::detail::IxDao_Helper * dao) { qx::dao::detail::QxDao_Trigger<type_base>::onAfterDelete(static_cast<type_base *>(t), dao); }
  72. static inline void onAfterFetch(T * t, qx::dao::detail::IxDao_Helper * dao) { qx::dao::detail::QxDao_Trigger<type_base>::onAfterFetch(static_cast<type_base *>(t), dao); }
  73. };
  74. };
  75. } // namespace detail
  76. } // namespace dao
  77. } // namespace qx