MySQL 9.0.0
Source Code Documentation
foreign_key_impl.h
Go to the documentation of this file.
1/* Copyright (c) 2014, 2024, 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 designed to work 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 either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef DD__FOREIGN_KEY_IMPL_INCLUDED
25#define DD__FOREIGN_KEY_IMPL_INCLUDED
26
27#include <sys/types.h>
28#include <new>
29
30#include "my_sharedlib.h"
31#include "mysql/strings/m_ctype.h" // my_strcasecmp
32#include "sql/dd/impl/types/entity_object_impl.h" // dd::Entity_object_impl
34#include "sql/dd/object_id.h"
35#include "sql/dd/sdi_fwd.h"
36#include "sql/dd/string_type.h"
37#include "sql/dd/types/foreign_key.h" // dd::Foreign_key
38#include "sql/dd/types/foreign_key_element.h" // IWYU pragma: keep
39#include "sql/mysqld_cs.h"
40
41namespace dd {
42
43///////////////////////////////////////////////////////////////////////////
44
45class Index;
46class Object_table;
47class Open_dictionary_tables_ctx;
48class Raw_record;
49class Sdi_rcontext;
50class Sdi_wcontext;
51class Table;
52class Table_impl;
53class Weak_object;
54
55///////////////////////////////////////////////////////////////////////////
56
58 public:
60
62
63 Foreign_key_impl(const Foreign_key_impl &src, Table_impl *parent);
64
65 ~Foreign_key_impl() override = default;
66
67 public:
68 const Object_table &object_table() const override;
69
71
72 bool validate() const override;
73
74 bool store(Open_dictionary_tables_ctx *otx) override;
75
77
79
80 bool drop_children(Open_dictionary_tables_ctx *otx) const override;
81
82 bool restore_attributes(const Raw_record &r) override;
83
84 bool store_attributes(Raw_record *r) override;
85
86 void serialize(Sdi_wcontext *wctx, Sdi_writer *w) const override;
87
88 bool deserialize(Sdi_rcontext *rctx, const RJ_Value &val) override;
89
90 void debug_print(String_type &outb) const override;
91
92 public:
94
95 virtual uint ordinal_position() const { return -1; }
96
97 public:
98 /////////////////////////////////////////////////////////////////////////
99 // parent table.
100 /////////////////////////////////////////////////////////////////////////
101
102 const Table &table() const override;
103
104 Table &table() override;
105
106 /* non-virtual */ const Table_impl &table_impl() const { return *m_table; }
107
108 /* non-virtual */ Table_impl &table_impl() { return *m_table; }
109
110 /////////////////////////////////////////////////////////////////////////
111 // unique_constraint
112 /////////////////////////////////////////////////////////////////////////
113
114 const String_type &unique_constraint_name() const override {
116 }
117
120 }
121
122 /////////////////////////////////////////////////////////////////////////
123 // match_option.
124 /////////////////////////////////////////////////////////////////////////
125
126 enum_match_option match_option() const override { return m_match_option; }
127
130 }
131
132 /////////////////////////////////////////////////////////////////////////
133 // update_rule.
134 /////////////////////////////////////////////////////////////////////////
135
136 enum_rule update_rule() const override { return m_update_rule; }
137
140 }
141
142 /////////////////////////////////////////////////////////////////////////
143 // delete_rule.
144 /////////////////////////////////////////////////////////////////////////
145
146 enum_rule delete_rule() const override { return m_delete_rule; }
147
150 }
151
152 /////////////////////////////////////////////////////////////////////////
153 // the catalog name of the referenced table.
154 /////////////////////////////////////////////////////////////////////////
155
158 }
159
162 }
163
164 /////////////////////////////////////////////////////////////////////////
165 // the schema name of the referenced table.
166 /////////////////////////////////////////////////////////////////////////
167
170 }
171
174 }
175
176 /////////////////////////////////////////////////////////////////////////
177 // the name of the referenced table.
178 /////////////////////////////////////////////////////////////////////////
179
180 const String_type &referenced_table_name() const override {
182 }
183
186 }
187
188 /////////////////////////////////////////////////////////////////////////
189 // Foreign key element collection.
190 /////////////////////////////////////////////////////////////////////////
191
193
194 const Foreign_key_elements &elements() const override { return m_elements; }
195
196 Foreign_key_elements *elements() override { return &m_elements; }
197
198 // Fix "inherits ... via dominance" warnings
200 const Entity_object_impl *impl() const override {
202 }
203 Object_id id() const override { return Entity_object_impl::id(); }
204 bool is_persistent() const override {
206 }
207 const String_type &name() const override {
209 }
210 void set_name(const String_type &name) override {
212 }
213
214 public:
216 return new (std::nothrow) Foreign_key_impl(table);
217 }
218
220 Table_impl *table) {
221 return new (std::nothrow) Foreign_key_impl(other, table);
222 }
223
224 private:
228
230
234
236
237 // Collections.
238
240
241 public:
243 return new Foreign_key_impl(*this, parent);
244 }
245};
246
247///////////////////////////////////////////////////////////////////////////
248
249/** Class used to sort Foreign key's by name for the same table. */
252 const dd::Foreign_key *fk2) const {
253 return (my_strcasecmp(system_charset_info, fk1->name().c_str(),
254 fk2->name().c_str()) < 0);
255 }
256};
257
258///////////////////////////////////////////////////////////////////////////
259} // namespace dd
260
261#endif // DD__FOREIGN_KEY_IMPL_INCLUDED
Definition: collection.h:44
Definition: entity_object_impl.h:44
void set_name(const String_type &name) override
Definition: entity_object_impl.h:62
Object_id id() const override
The unique dictionary object id.
Definition: entity_object_impl.h:49
const String_type & name() const override
Definition: entity_object_impl.h:60
Entity_object_impl * impl() override
Definition: entity_object_impl.h:68
bool is_persistent() const override
Is dictionary object persistent in dictionary tables ?
Definition: entity_object_impl.h:57
virtual const String_type & name() const =0
Definition: foreign_key_element.h:45
Definition: foreign_key_impl.h:57
Foreign_key_element * add_element() override
Definition: foreign_key_impl.cc:294
static Foreign_key_impl * clone(const Foreign_key_impl &other, Table_impl *table)
Definition: foreign_key_impl.h:219
Foreign_key_elements m_elements
Definition: foreign_key_impl.h:239
void set_unique_constraint_name(const String_type &name) override
Definition: foreign_key_impl.h:118
Entity_object_impl * impl() override
Definition: foreign_key_impl.h:199
void set_match_option(enum_match_option match_option) override
Definition: foreign_key_impl.h:128
void set_name(const String_type &name) override
Definition: foreign_key_impl.h:210
Table_impl * m_table
Definition: foreign_key_impl.h:235
String_type m_referenced_table_name
Definition: foreign_key_impl.h:233
Foreign_key_elements * elements() override
Definition: foreign_key_impl.h:196
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:249
void set_update_rule(enum_rule update_rule) override
Definition: foreign_key_impl.h:138
enum_rule m_update_rule
Definition: foreign_key_impl.h:226
bool validate() const override
Definition: foreign_key_impl.cc:123
Foreign_key_impl * clone(Table_impl *parent) const
Definition: foreign_key_impl.h:242
const String_type & referenced_table_name() const override
Definition: foreign_key_impl.h:180
bool store_children(Open_dictionary_tables_ctx *otx) override
Definition: foreign_key_impl.cc:161
String_type m_referenced_table_schema_name
Definition: foreign_key_impl.h:232
static Foreign_key_impl * restore_item(Table_impl *table)
Definition: foreign_key_impl.h:215
bool restore_attributes(const Raw_record &r) override
Definition: foreign_key_impl.cc:175
const String_type & unique_constraint_name() const override
Definition: foreign_key_impl.h:114
void set_ordinal_position(uint)
Definition: foreign_key_impl.h:93
bool is_persistent() const override
Is dictionary object persistent in dictionary tables ?
Definition: foreign_key_impl.h:204
String_type m_referenced_table_catalog_name
Definition: foreign_key_impl.h:231
void set_delete_rule(enum_rule delete_rule) override
Definition: foreign_key_impl.h:148
void set_referenced_table_schema_name(const String_type &name) override
Definition: foreign_key_impl.h:172
static void register_tables(Open_dictionary_tables_ctx *otx)
Definition: foreign_key_impl.cc:327
void set_referenced_table_name(const String_type &name) override
Definition: foreign_key_impl.h:184
void debug_print(String_type &outb) const override
Definition: foreign_key_impl.cc:268
void set_referenced_table_catalog_name(const String_type &name) override
Definition: foreign_key_impl.h:160
enum_rule m_delete_rule
Definition: foreign_key_impl.h:227
enum_rule delete_rule() const override
Definition: foreign_key_impl.h:146
enum_match_option m_match_option
Definition: foreign_key_impl.h:225
bool store_attributes(Raw_record *r) override
Definition: foreign_key_impl.cc:202
const String_type & referenced_table_catalog_name() const override
Definition: foreign_key_impl.h:156
enum_match_option match_option() const override
Definition: foreign_key_impl.h:126
bool restore_children(Open_dictionary_tables_ctx *otx) override
Definition: foreign_key_impl.cc:153
const Table & table() const override
Definition: foreign_key_impl.cc:85
const String_type & referenced_table_schema_name() const override
Definition: foreign_key_impl.h:168
~Foreign_key_impl() override=default
const Foreign_key_elements & elements() const override
Definition: foreign_key_impl.h:194
virtual uint ordinal_position() const
Definition: foreign_key_impl.h:95
void serialize(Sdi_wcontext *wctx, Sdi_writer *w) const override
Converts *this into json.
Definition: foreign_key_impl.cc:225
const Object_table & object_table() const override
Definition: foreign_key_impl.cc:321
String_type m_unique_constraint_name
Definition: foreign_key_impl.h:229
const String_type & name() const override
Definition: foreign_key_impl.h:207
bool drop_children(Open_dictionary_tables_ctx *otx) const override
Definition: foreign_key_impl.cc:167
Object_id id() const override
The unique dictionary object id.
Definition: foreign_key_impl.h:203
enum_rule update_rule() const override
Definition: foreign_key_impl.h:136
Foreign_key_impl()
Definition: foreign_key_impl.cc:69
const Table_impl & table_impl() const
Definition: foreign_key_impl.h:106
bool store(Open_dictionary_tables_ctx *otx) override
Store the DD object into DD table.
Definition: foreign_key_impl.cc:108
Table_impl & table_impl()
Definition: foreign_key_impl.h:108
const Entity_object_impl * impl() const override
Definition: foreign_key_impl.h:200
Definition: foreign_key.h:47
enum_match_option
Definition: foreign_key.h:62
enum_rule
Definition: foreign_key.h:54
This class represents all data dictionary table like mysql.tables, mysql.columns and more.
Definition: object_table.h:72
Auxiliary class for opening dictionary tables.
Definition: transaction_impl.h:76
Definition: raw_record.h:46
Opaque context which keeps reusable resoureces needed during deserialization.
Definition: sdi.cc:231
Opaque context which keeps reusable resources needed during serialization.
Definition: sdi.cc:129
Definition: table_impl.h:68
Definition: table.h:47
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:651
MYSQL_PLUGIN_IMPORT CHARSET_INFO * system_charset_info
Definition: mysqld.cc:1544
Functions related to handling of plugins and other dynamically loaded libraries.
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:43
RJ_Writer Sdi_writer
Alias for the rapidjson Writer type to use in serialization.
Definition: sdi_fwd.h:64
unsigned long long Object_id
Definition: object_id.h:31
rapidjson::GenericValue< RJ_Encoding, RJ_Allocator > RJ_Value
Definition: sdi_fwd.h:49
Char_string_template< String_type_allocator > String_type
Definition: string_type.h:51
const mysql_service_registry_t * r
Definition: pfs_example_plugin_employee.cc:86
This header provides Rapidjson Type Aliases.
Class used to sort Foreign key's by name for the same table.
Definition: foreign_key_impl.h:250
bool operator()(const dd::Foreign_key *fk1, const dd::Foreign_key *fk2) const
Definition: foreign_key_impl.h:251