QxOrm 1.4.9
C++ Object Relational Mapping library
Loading...
Searching...
No Matches
QxSqlRelation.h
Go to the documentation of this file.
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
32#ifndef _QX_SQL_RELATION_H_
33#define _QX_SQL_RELATION_H_
34
35#ifdef _MSC_VER
36#pragma once
37#endif
38
46#include <QxDao/QxDao.h>
47#include <QxDao/IxSqlRelation.h>
49
56
57#include <QxRegister/IxClass.h>
58
59namespace qx {
60
61template <class T>
62class QxClass;
63
68template <class DataType, class Owner>
70{
71
72protected:
73
79 typedef typename std::conditional<qx::trait::is_container<type_container>::value, typename type_generic_container::type_value_qx, type_container>::type type_tmp_3;
81 typedef Owner type_owner;
82
84 enum { is_data_pointer = (std::is_pointer<DataType>::value || qx::trait::is_smart_ptr<DataType>::value) };
86 enum { is_same_data_owner = std::is_same<type_data, type_owner>::value };
87
88public:
89
91 virtual ~QxSqlRelation() { static_assert(is_valid, "is_valid"); }
92
93 virtual void init()
94 {
95 if (! this->canInit()) { return; }
98 }
99
100protected:
101
102 DataType * getDataTypePtr(QxSqlRelationParams & params) const
103 { qAssert(params.owner() && this->getDataMember()); return static_cast<DataType *>(this->getDataMember()->getValueVoidPtr(params.owner())); }
104
106 { qAssert(params.owner()); return (* static_cast<type_owner *>(params.owner())); }
107
110
113
116
119
121 {
122 if (! params.builder().getDaoHelper()) { return true; }
124 return params.builder().getDaoHelper()->isValid();
125 }
126
128 {
129 if (! params.builder().getDaoHelper()) { return true; }
131 return params.builder().getDaoHelper()->isValid();
132 }
133
134private:
135
136 template <bool bIsPointer /* = false */, bool bIsContainer /* = false */, int dummy>
138 { static type_data & get(DataType * t) { return (* t); } };
139
140 template <int dummy>
141 struct getData_Helper<true, false, dummy>
142 { static type_data & get(DataType * t) { if (! (* t)) { qx::trait::construct_ptr<DataType>::get(* t); }; return (** t); } };
143
144 template <int dummy>
145 struct getData_Helper<false, true, dummy>
146 { static type_data & get(DataType * t) { qAssert(false); Q_UNUSED(t); type_data * pDummy(NULL); return (* pDummy); } };
147
148 template <int dummy>
149 struct getData_Helper<true, true, dummy>
150 { static type_data & get(DataType * t) { qAssert(false); Q_UNUSED(t); type_data * pDummy(NULL); return (* pDummy); } };
151
152 template <bool bIsPointer /* = false */, bool bIsContainer /* = false */, int dummy>
154 { static type_container & get(DataType * t) { qAssert(false); Q_UNUSED(t); type_container * pDummy(NULL); return (* pDummy); } };
155
156 template <int dummy>
157 struct getContainer_Helper<true, false, dummy>
158 { static type_container & get(DataType * t) { qAssert(false); Q_UNUSED(t); type_container * pDummy(NULL); return (* pDummy); } };
159
160 template <int dummy>
161 struct getContainer_Helper<false, true, dummy>
162 { static type_container & get(DataType * t) { return (* t); } };
163
164 template <int dummy>
165 struct getContainer_Helper<true, true, dummy>
166 { static type_container & get(DataType * t) { if (! (* t)) { qx::trait::construct_ptr<DataType>::get(* t); }; return (** t); } };
167
168 template <bool bIsContainer /* = false */, int dummy>
170 { static type_item get() { qAssert(false); type_item * pDummy(NULL); return (* pDummy); } };
171
172 template <int dummy>
173 struct createItem_Helper<true, dummy>
174 { static type_item get() { return type_generic_container::createItem(); } };
175
176 template <bool bIsPointer /* = false */, int dummy>
178 { static bool get(DataType * t) { Q_UNUSED(t); return false; } };
179
180 template <int dummy>
181 struct isNullData_Helper<true, dummy>
182 { static bool get(DataType * t) { return ((! (* t)) ? true : false); } };
183
184};
185
186} // namespace qx
187
193
194#endif // _QX_SQL_RELATION_H_
Common interface for all classes registered into QxOrm context.
Common interface to build SQL queries to communicate with database.
Common interface for all relationships defined between 2 classes (or between 2 tables in database)
Provide template functions to map C++ class registered into QxOrm context with table database (ORM - ...
#define qAssert(x)
Definition QxMacro.h:52
Manage a relationship many-to-many defined between 2 classes (or between 2 tables in database)
Manage a relationship many-to-one defined between 2 classes (or between 2 tables in database)
Manage a relationship one-to-many defined between 2 classes (or between 2 tables in database)
Manage a relationship one-to-one defined between 2 classes (or between 2 tables in database)
qx::IxDataMember : common interface for all class properties registered into QxOrm context
void * getValueVoidPtr(const void *pOwner) const
qx::dao::detail::IxDao_Helper * getDaoHelper() const
qx::IxSqlRelation : common interface for all relationships defined between 2 classes (or between 2 ta...
void setIsSameDataOwner(int i)
bool canInit() const
void setClass(IxClass *pClass, IxClass *pClassOwner)
IxDataMember * getDataMember() const
virtual void init()
qx::QxClass<T> : concrete class of type T registered into QxOrm context (this class is a singleton an...
Definition QxClass.h:79
qx::QxSqlRelation<DataType, Owner> : base class for all relationships defined between 2 classes (or b...
qx::trait::remove_smart_ptr< type_tmp_1 >::type type_tmp_2
bool callTriggerBeforeFetch(type_data &t, QxSqlRelationParams &params) const
QxSqlRelation(IxDataMember *p)
DataType * getDataTypePtr(QxSqlRelationParams &params) const
type_generic_container::type_item type_item
qx::trait::generic_container< type_container > type_generic_container
virtual ~QxSqlRelation()
virtual void init()
bool isNullData(QxSqlRelationParams &params) const
qx::trait::remove_attr< DataType >::type type_tmp_1
QxSqlRelation< DataType, Owner >::type_tmp_3 type_data
type_data & getData(QxSqlRelationParams &params) const
type_tmp_2 type_container
type_container & getContainer(QxSqlRelationParams &params) const
bool callTriggerAfterFetch(type_data &t, QxSqlRelationParams &params) const
std::conditional< qx::trait::is_container< type_container >::value, typenametype_generic_container::type_value_qx, type_container >::type type_tmp_3
type_owner & getOwner(QxSqlRelationParams &params) const
type_item createItem() const
qx::QxSqlRelationParams : define list of parameters to transfer to relationships to manage SQL querie...
IxSqlQueryBuilder & builder()
qx::trait::generic_container<T> : provide some tools to manage all containers without knowing its typ...
void on_before_fetch(T *t, qx::dao::detail::IxDao_Helper *dao)
Callback before fetching an object from database (here is an example using QxOrm Trigger)
Definition QxDao.h:775
void on_after_fetch(T *t, qx::dao::detail::IxDao_Helper *dao)
Callback after fetching an object from database (here is an example using QxOrm trigger)
Definition QxDao.h:807
qx::trait::is_container<T>::value : return true if T is a container from stl, boost,...
qx::trait::is_qx_registered<T>::value : return true if T is registered into QxOrm context to provide ...
qx::trait::is_valid_primary_key<T>(const T & t) : return true if t can be a valid primary key to be i...
Root namespace for all QxOrm library features.
qx::trait::remove_attr<T>::type : return a type without pointer, const, reference and/or volatile att...
qx::trait::remove_smart_ptr<T>::type : return a type without smart-pointer attribute from boost,...
static type_container & get(DataType *t)
static type_data & get(DataType *t)
static void get(T &t, bool bReset=false)
qx::trait::generic_container<T> : provide some tools to manage all containers without knowing its typ...
qx::trait::is_container<T>::value : return true if T is a container from stl, boost,...
qx::trait::is_qx_registered<T>::value : return true if T is registered into QxOrm context to provide ...
qx::trait::is_smart_ptr<T>::value : return true if T is a smart-pointer of boost, Qt or QxOrm librari...