MySQL 8.3.0
Source Code Documentation
foreign_key_impl.h
Go to the documentation of this file.
1/* Copyright (c) 2014, 2023, 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 "my_sharedlib.h"
30#include "mysql/strings/m_ctype.h" // my_strcasecmp
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#include "sql/mysqld_cs.h"
39
40namespace dd {
41
42///////////////////////////////////////////////////////////////////////////
43
44class Index;
45class Object_table;
46class Open_dictionary_tables_ctx;
47class Raw_record;
48class Sdi_rcontext;
49class Sdi_wcontext;
50class Table;
51class Table_impl;
52class Weak_object;
53
54///////////////////////////////////////////////////////////////////////////
55
57 public:
59
61
62 Foreign_key_impl(const Foreign_key_impl &src, Table_impl *parent);
63
64 ~Foreign_key_impl() override = default;
65
66 public:
67 const Object_table &object_table() const override;
68
70
71 bool validate() const override;
72
73 bool store(Open_dictionary_tables_ctx *otx) override;
74
76
78
79 bool drop_children(Open_dictionary_tables_ctx *otx) const override;
80
81 bool restore_attributes(const Raw_record &r) override;
82
83 bool store_attributes(Raw_record *r) override;
84
85 void serialize(Sdi_wcontext *wctx, Sdi_writer *w) const override;
86
87 bool deserialize(Sdi_rcontext *rctx, const RJ_Value &val) override;
88
89 void debug_print(String_type &outb) const override;
90
91 public:
93
94 virtual uint ordinal_position() const { return -1; }
95
96 public:
97 /////////////////////////////////////////////////////////////////////////
98 // parent table.
99 /////////////////////////////////////////////////////////////////////////
100
101 const Table &table() const override;
102
103 Table &table() override;
104
105 /* non-virtual */ const Table_impl &table_impl() const { return *m_table; }
106
107 /* non-virtual */ Table_impl &table_impl() { return *m_table; }
108
109 /////////////////////////////////////////////////////////////////////////
110 // unique_constraint
111 /////////////////////////////////////////////////////////////////////////
112
113 const String_type &unique_constraint_name() const override {
115 }
116
119 }
120
121 /////////////////////////////////////////////////////////////////////////
122 // match_option.
123 /////////////////////////////////////////////////////////////////////////
124
125 enum_match_option match_option() const override { return m_match_option; }
126
129 }
130
131 /////////////////////////////////////////////////////////////////////////
132 // update_rule.
133 /////////////////////////////////////////////////////////////////////////
134
135 enum_rule update_rule() const override { return m_update_rule; }
136
139 }
140
141 /////////////////////////////////////////////////////////////////////////
142 // delete_rule.
143 /////////////////////////////////////////////////////////////////////////
144
145 enum_rule delete_rule() const override { return m_delete_rule; }
146
149 }
150
151 /////////////////////////////////////////////////////////////////////////
152 // the catalog name of the referenced table.
153 /////////////////////////////////////////////////////////////////////////
154
157 }
158
161 }
162
163 /////////////////////////////////////////////////////////////////////////
164 // the schema name of the referenced table.
165 /////////////////////////////////////////////////////////////////////////
166
169 }
170
173 }
174
175 /////////////////////////////////////////////////////////////////////////
176 // the name of the referenced table.
177 /////////////////////////////////////////////////////////////////////////
178
179 const String_type &referenced_table_name() const override {
181 }
182
185 }
186
187 /////////////////////////////////////////////////////////////////////////
188 // Foreign key element collection.
189 /////////////////////////////////////////////////////////////////////////
190
192
193 const Foreign_key_elements &elements() const override { return m_elements; }
194
195 Foreign_key_elements *elements() override { return &m_elements; }
196
197 // Fix "inherits ... via dominance" warnings
199 const Entity_object_impl *impl() const override {
201 }
202 Object_id id() const override { return Entity_object_impl::id(); }
203 bool is_persistent() const override {
205 }
206 const String_type &name() const override {
208 }
209 void set_name(const String_type &name) override {
211 }
212
213 public:
215 return new (std::nothrow) Foreign_key_impl(table);
216 }
217
219 Table_impl *table) {
220 return new (std::nothrow) Foreign_key_impl(other, table);
221 }
222
223 private:
227
229
233
235
236 // Collections.
237
239
240 public:
242 return new Foreign_key_impl(*this, parent);
243 }
244};
245
246///////////////////////////////////////////////////////////////////////////
247
248/** Class used to sort Foreign key's by name for the same table. */
251 const dd::Foreign_key *fk2) const {
252 return (my_strcasecmp(system_charset_info, fk1->name().c_str(),
253 fk2->name().c_str()) < 0);
254 }
255};
256
257///////////////////////////////////////////////////////////////////////////
258} // namespace dd
259
260#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:56
Foreign_key_element * add_element() override
Definition: foreign_key_impl.cc:293
static Foreign_key_impl * clone(const Foreign_key_impl &other, Table_impl *table)
Definition: foreign_key_impl.h:218
Foreign_key_elements m_elements
Definition: foreign_key_impl.h:238
void set_unique_constraint_name(const String_type &name) override
Definition: foreign_key_impl.h:117
Entity_object_impl * impl() override
Definition: foreign_key_impl.h:198
void set_match_option(enum_match_option match_option) override
Definition: foreign_key_impl.h:127
void set_name(const String_type &name) override
Definition: foreign_key_impl.h:209
Table_impl * m_table
Definition: foreign_key_impl.h:234
String_type m_referenced_table_name
Definition: foreign_key_impl.h:232
Foreign_key_elements * elements() override
Definition: foreign_key_impl.h:195
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:248
void set_update_rule(enum_rule update_rule) override
Definition: foreign_key_impl.h:137
enum_rule m_update_rule
Definition: foreign_key_impl.h:225
bool validate() const override
Definition: foreign_key_impl.cc:122
Foreign_key_impl * clone(Table_impl *parent) const
Definition: foreign_key_impl.h:241
const String_type & referenced_table_name() const override
Definition: foreign_key_impl.h:179
bool store_children(Open_dictionary_tables_ctx *otx) override
Definition: foreign_key_impl.cc:160
String_type m_referenced_table_schema_name
Definition: foreign_key_impl.h:231
static Foreign_key_impl * restore_item(Table_impl *table)
Definition: foreign_key_impl.h:214
bool restore_attributes(const Raw_record &r) override
Definition: foreign_key_impl.cc:174
const String_type & unique_constraint_name() const override
Definition: foreign_key_impl.h:113
void set_ordinal_position(uint)
Definition: foreign_key_impl.h:92
bool is_persistent() const override
Is dictionary object persistent in dictionary tables ?
Definition: foreign_key_impl.h:203
String_type m_referenced_table_catalog_name
Definition: foreign_key_impl.h:230
void set_delete_rule(enum_rule delete_rule) override
Definition: foreign_key_impl.h:147
void set_referenced_table_schema_name(const String_type &name) override
Definition: foreign_key_impl.h:171
static void register_tables(Open_dictionary_tables_ctx *otx)
Definition: foreign_key_impl.cc:326
void set_referenced_table_name(const String_type &name) override
Definition: foreign_key_impl.h:183
void debug_print(String_type &outb) const override
Definition: foreign_key_impl.cc:267
void set_referenced_table_catalog_name(const String_type &name) override
Definition: foreign_key_impl.h:159
enum_rule m_delete_rule
Definition: foreign_key_impl.h:226
enum_rule delete_rule() const override
Definition: foreign_key_impl.h:145
enum_match_option m_match_option
Definition: foreign_key_impl.h:224
bool store_attributes(Raw_record *r) override
Definition: foreign_key_impl.cc:201
const String_type & referenced_table_catalog_name() const override
Definition: foreign_key_impl.h:155
enum_match_option match_option() const override
Definition: foreign_key_impl.h:125
bool restore_children(Open_dictionary_tables_ctx *otx) override
Definition: foreign_key_impl.cc:152
const Table & table() const override
Definition: foreign_key_impl.cc:84
const String_type & referenced_table_schema_name() const override
Definition: foreign_key_impl.h:167
~Foreign_key_impl() override=default
const Foreign_key_elements & elements() const override
Definition: foreign_key_impl.h:193
virtual uint ordinal_position() const
Definition: foreign_key_impl.h:94
void serialize(Sdi_wcontext *wctx, Sdi_writer *w) const override
Converts *this into json.
Definition: foreign_key_impl.cc:224
const Object_table & object_table() const override
Definition: foreign_key_impl.cc:320
String_type m_unique_constraint_name
Definition: foreign_key_impl.h:228
const String_type & name() const override
Definition: foreign_key_impl.h:206
bool drop_children(Open_dictionary_tables_ctx *otx) const override
Definition: foreign_key_impl.cc:166
Object_id id() const override
The unique dictionary object id.
Definition: foreign_key_impl.h:202
enum_rule update_rule() const override
Definition: foreign_key_impl.h:135
Foreign_key_impl()
Definition: foreign_key_impl.cc:68
const Table_impl & table_impl() const
Definition: foreign_key_impl.h:105
bool store(Open_dictionary_tables_ctx *otx) override
Store the DD object into DD table.
Definition: foreign_key_impl.cc:107
Table_impl & table_impl()
Definition: foreign_key_impl.h:107
const Entity_object_impl * impl() const override
Definition: foreign_key_impl.h:199
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.
int my_strcasecmp(const CHARSET_INFO *cs, const char *s1, const char *s2)
Definition: m_ctype.h:652
MYSQL_PLUGIN_IMPORT CHARSET_INFO * system_charset_info
Definition: mysqld.cc:1556
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:249
bool operator()(const dd::Foreign_key *fk1, const dd::Foreign_key *fk2) const
Definition: foreign_key_impl.h:250