MySQL 8.0.30
Source Code Documentation
foreign_key_impl.h
Go to the documentation of this file.
1/* Copyright (c) 2014, 2022, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is also distributed with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef DD__FOREIGN_KEY_IMPL_INCLUDED
24#define DD__FOREIGN_KEY_IMPL_INCLUDED
25
26#include <sys/types.h>
27#include <new>
28
29#include "m_ctype.h" // my_strcasecmp
30#include "my_sharedlib.h"
31#include "sql/dd/impl/types/entity_object_impl.h" // dd::Entity_object_impl
33#include "sql/dd/object_id.h"
34#include "sql/dd/sdi_fwd.h"
35#include "sql/dd/string_type.h"
36#include "sql/dd/types/foreign_key.h" // dd::Foreign_key
37#include "sql/dd/types/foreign_key_element.h" // IWYU pragma: keep
38
39namespace dd {
40
41///////////////////////////////////////////////////////////////////////////
42
43class Index;
44class Object_table;
45class Open_dictionary_tables_ctx;
46class Raw_record;
47class Sdi_rcontext;
48class Sdi_wcontext;
49class Table;
50class Table_impl;
51class Weak_object;
52
53///////////////////////////////////////////////////////////////////////////
54
56 public:
58
60
61 Foreign_key_impl(const Foreign_key_impl &src, Table_impl *parent);
62
63 ~Foreign_key_impl() override = default;
64
65 public:
66 const Object_table &object_table() const override;
67
69
70 bool validate() const override;
71
72 bool store(Open_dictionary_tables_ctx *otx) override;
73
75
77
78 bool drop_children(Open_dictionary_tables_ctx *otx) const override;
79
80 bool restore_attributes(const Raw_record &r) override;
81
82 bool store_attributes(Raw_record *r) override;
83
84 void serialize(Sdi_wcontext *wctx, Sdi_writer *w) const override;
85
86 bool deserialize(Sdi_rcontext *rctx, const RJ_Value &val) override;
87
88 void debug_print(String_type &outb) const override;
89
90 public:
92
93 virtual uint ordinal_position() const { return -1; }
94
95 public:
96 /////////////////////////////////////////////////////////////////////////
97 // parent table.
98 /////////////////////////////////////////////////////////////////////////
99
100 const Table &table() const override;
101
102 Table &table() override;
103
104 /* non-virtual */ const Table_impl &table_impl() const { return *m_table; }
105
106 /* non-virtual */ Table_impl &table_impl() { return *m_table; }
107
108 /////////////////////////////////////////////////////////////////////////
109 // unique_constraint
110 /////////////////////////////////////////////////////////////////////////
111
112 const String_type &unique_constraint_name() const override {
114 }
115
118 }
119
120 /////////////////////////////////////////////////////////////////////////
121 // match_option.
122 /////////////////////////////////////////////////////////////////////////
123
124 enum_match_option match_option() const override { return m_match_option; }
125
128 }
129
130 /////////////////////////////////////////////////////////////////////////
131 // update_rule.
132 /////////////////////////////////////////////////////////////////////////
133
134 enum_rule update_rule() const override { return m_update_rule; }
135
138 }
139
140 /////////////////////////////////////////////////////////////////////////
141 // delete_rule.
142 /////////////////////////////////////////////////////////////////////////
143
144 enum_rule delete_rule() const override { return m_delete_rule; }
145
148 }
149
150 /////////////////////////////////////////////////////////////////////////
151 // the catalog name of the referenced table.
152 /////////////////////////////////////////////////////////////////////////
153
156 }
157
160 }
161
162 /////////////////////////////////////////////////////////////////////////
163 // the schema name of the referenced table.
164 /////////////////////////////////////////////////////////////////////////
165
168 }
169
172 }
173
174 /////////////////////////////////////////////////////////////////////////
175 // the name of the referenced table.
176 /////////////////////////////////////////////////////////////////////////
177
178 const String_type &referenced_table_name() const override {
180 }
181
184 }
185
186 /////////////////////////////////////////////////////////////////////////
187 // Foreign key element collection.
188 /////////////////////////////////////////////////////////////////////////
189
191
192 const Foreign_key_elements &elements() const override { return m_elements; }
193
194 Foreign_key_elements *elements() override { return &m_elements; }
195
196 // Fix "inherits ... via dominance" warnings
198 const Entity_object_impl *impl() const override {
200 }
201 Object_id id() const override { return Entity_object_impl::id(); }
202 bool is_persistent() const override {
204 }
205 const String_type &name() const override {
207 }
208 void set_name(const String_type &name) override {
210 }
211
212 public:
214 return new (std::nothrow) Foreign_key_impl(table);
215 }
216
218 Table_impl *table) {
219 return new (std::nothrow) Foreign_key_impl(other, table);
220 }
221
222 private:
226
228
232
234
235 // Collections.
236
238
239 public:
241 return new Foreign_key_impl(*this, parent);
242 }
243};
244
245///////////////////////////////////////////////////////////////////////////
246
247/** Class used to sort Foreign key's by name for the same table. */
250 const dd::Foreign_key *fk2) const {
251 return (my_strcasecmp(system_charset_info, fk1->name().c_str(),
252 fk2->name().c_str()) < 0);
253 }
254};
255
256///////////////////////////////////////////////////////////////////////////
257} // namespace dd
258
259#endif // DD__FOREIGN_KEY_IMPL_INCLUDED
Definition: collection.h:43
Definition: entity_object_impl.h:43
void set_name(const String_type &name) override
Definition: entity_object_impl.h:61
Object_id id() const override
The unique dictionary object id.
Definition: entity_object_impl.h:48
const String_type & name() const override
Definition: entity_object_impl.h:59
Entity_object_impl * impl() override
Definition: entity_object_impl.h:67
bool is_persistent() const override
Is dictionary object persistent in dictionary tables ?
Definition: entity_object_impl.h:56
virtual const String_type & name() const =0
Definition: foreign_key_element.h:44
Definition: foreign_key_impl.h:55
Foreign_key_element * add_element() override
Definition: foreign_key_impl.cc:292
static Foreign_key_impl * clone(const Foreign_key_impl &other, Table_impl *table)
Definition: foreign_key_impl.h:217
Foreign_key_elements m_elements
Definition: foreign_key_impl.h:237
void set_unique_constraint_name(const String_type &name) override
Definition: foreign_key_impl.h:116
Entity_object_impl * impl() override
Definition: foreign_key_impl.h:197
void set_match_option(enum_match_option match_option) override
Definition: foreign_key_impl.h:126
void set_name(const String_type &name) override
Definition: foreign_key_impl.h:208
Table_impl * m_table
Definition: foreign_key_impl.h:233
String_type m_referenced_table_name
Definition: foreign_key_impl.h:231
Foreign_key_elements * elements() override
Definition: foreign_key_impl.h:194
bool deserialize(Sdi_rcontext *rctx, const RJ_Value &val) override
Re-establishes the state of *this by reading sdi information from the rapidjson DOM subobject provide...
Definition: foreign_key_impl.cc:247
void set_update_rule(enum_rule update_rule) override
Definition: foreign_key_impl.h:136
enum_rule m_update_rule
Definition: foreign_key_impl.h:224
bool validate() const override
Definition: foreign_key_impl.cc:121
Foreign_key_impl * clone(Table_impl *parent) const
Definition: foreign_key_impl.h:240
const String_type & referenced_table_name() const override
Definition: foreign_key_impl.h:178
bool store_children(Open_dictionary_tables_ctx *otx) override
Definition: foreign_key_impl.cc:159
String_type m_referenced_table_schema_name
Definition: foreign_key_impl.h:230
static Foreign_key_impl * restore_item(Table_impl *table)
Definition: foreign_key_impl.h:213
bool restore_attributes(const Raw_record &r) override
Definition: foreign_key_impl.cc:173
const String_type & unique_constraint_name() const override
Definition: foreign_key_impl.h:112
void set_ordinal_position(uint)
Definition: foreign_key_impl.h:91
bool is_persistent() const override
Is dictionary object persistent in dictionary tables ?
Definition: foreign_key_impl.h:202
String_type m_referenced_table_catalog_name
Definition: foreign_key_impl.h:229
void set_delete_rule(enum_rule delete_rule) override
Definition: foreign_key_impl.h:146
void set_referenced_table_schema_name(const String_type &name) override
Definition: foreign_key_impl.h:170
static void register_tables(Open_dictionary_tables_ctx *otx)
Definition: foreign_key_impl.cc:325
void set_referenced_table_name(const String_type &name) override
Definition: foreign_key_impl.h:182
void debug_print(String_type &outb) const override
Definition: foreign_key_impl.cc:266
void set_referenced_table_catalog_name(const String_type &name) override
Definition: foreign_key_impl.h:158
enum_rule m_delete_rule
Definition: foreign_key_impl.h:225
enum_rule delete_rule() const override
Definition: foreign_key_impl.h:144
enum_match_option m_match_option
Definition: foreign_key_impl.h:223
bool store_attributes(Raw_record *r) override
Definition: foreign_key_impl.cc:200
const String_type & referenced_table_catalog_name() const override
Definition: foreign_key_impl.h:154
enum_match_option match_option() const override
Definition: foreign_key_impl.h:124
bool restore_children(Open_dictionary_tables_ctx *otx) override
Definition: foreign_key_impl.cc:151
const Table & table() const override
Definition: foreign_key_impl.cc:83
const String_type & referenced_table_schema_name() const override
Definition: foreign_key_impl.h:166
~Foreign_key_impl() override=default
const Foreign_key_elements & elements() const override
Definition: foreign_key_impl.h:192
virtual uint ordinal_position() const
Definition: foreign_key_impl.h:93
void serialize(Sdi_wcontext *wctx, Sdi_writer *w) const override
Converts *this into json.
Definition: foreign_key_impl.cc:223
const Object_table & object_table() const override
Definition: foreign_key_impl.cc:319
String_type m_unique_constraint_name
Definition: foreign_key_impl.h:227
const String_type & name() const override
Definition: foreign_key_impl.h:205
bool drop_children(Open_dictionary_tables_ctx *otx) const override
Definition: foreign_key_impl.cc:165
Object_id id() const override
The unique dictionary object id.
Definition: foreign_key_impl.h:201
enum_rule update_rule() const override
Definition: foreign_key_impl.h:134
Foreign_key_impl()
Definition: foreign_key_impl.cc:67
const Table_impl & table_impl() const
Definition: foreign_key_impl.h:104
bool store(Open_dictionary_tables_ctx *otx) override
Store the DD object into DD table.
Definition: foreign_key_impl.cc:106
Table_impl & table_impl()
Definition: foreign_key_impl.h:106
const Entity_object_impl * impl() const override
Definition: foreign_key_impl.h:198
Definition: foreign_key.h:46
enum_match_option
Definition: foreign_key.h:61
enum_rule
Definition: foreign_key.h:53
This class represents all data dictionary table like mysql.tables, mysql.columns and more.
Definition: object_table.h:71
Auxiliary class for opening dictionary tables.
Definition: transaction_impl.h:75
Definition: raw_record.h:45
Opaque context which keeps reusable resoureces needed during deserialization.
Definition: sdi.cc:230
Opaque context which keeps reusable resources needed during serialization.
Definition: sdi.cc:128
Definition: table_impl.h:67
Definition: table.h:46
A better implementation of the UNIX ctype(3) library.
MYSQL_PLUGIN_IMPORT CHARSET_INFO * system_charset_info
Definition: mysqld.cc:1525
#define my_strcasecmp(s, a, b)
Definition: m_ctype.h:677
Functions related to handling of plugins and other dynamically loaded libraries.
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:42
RJ_Writer Sdi_writer
Alias for the rapidjson Writer type to use in serialization.
Definition: sdi_fwd.h:63
unsigned long long Object_id
Definition: object_id.h:30
rapidjson::GenericValue< RJ_Encoding, RJ_Allocator > RJ_Value
Definition: sdi_fwd.h:48
Char_string_template< String_type_allocator > String_type
Definition: string_type.h:50
const mysql_service_registry_t * r
Definition: pfs_example_plugin_employee.cc:85
This header provides Rapidjson Type Aliases.
Class used to sort Foreign key's by name for the same table.
Definition: foreign_key_impl.h:248
bool operator()(const dd::Foreign_key *fk1, const dd::Foreign_key *fk2) const
Definition: foreign_key_impl.h:249
unsigned int uint
Definition: uca-dump.cc:29