MySQL 9.0.0
Source Code Documentation
foreign_key.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_INCLUDED
25#define DD__FOREIGN_KEY_INCLUDED
26
27#include "sql/dd/collection.h" // dd::Collection
28#include "sql/dd/sdi_fwd.h" // dd::Sdi_wcontext
29#include "sql/dd/types/entity_object.h" // dd::Entity_object
31
32namespace dd {
33
34///////////////////////////////////////////////////////////////////////////
35
36class Foreign_key_element;
37class Foreign_key_impl;
38class Index;
39class Table;
40
41namespace tables {
42class Foreign_keys;
43}
44
45///////////////////////////////////////////////////////////////////////////
46
47class Foreign_key : virtual public Entity_object {
48 public:
52
53 public:
54 enum enum_rule {
60 };
61
66 };
67
68 public:
69 ~Foreign_key() override = default;
70
71 /////////////////////////////////////////////////////////////////////////
72 // parent table.
73 /////////////////////////////////////////////////////////////////////////
74
75 virtual const Table &table() const = 0;
76
77 virtual Table &table() = 0;
78
79 /////////////////////////////////////////////////////////////////////////
80 // unique_constraint
81 /////////////////////////////////////////////////////////////////////////
82
83 // Note that setting "" as unique constraint name is interpreted as NULL
84 // when storing this to the DD tables. And correspondingly, if NULL is
85 // stored, and the dd::Foreign_key is fetched from the tables, then
86 // unique_constraint_name() will return "".
87
88 virtual const String_type &unique_constraint_name() const = 0;
90
91 /////////////////////////////////////////////////////////////////////////
92 // match_option.
93 /////////////////////////////////////////////////////////////////////////
94
95 virtual enum_match_option match_option() const = 0;
97
98 /////////////////////////////////////////////////////////////////////////
99 // update_rule.
100 /////////////////////////////////////////////////////////////////////////
101
102 virtual enum_rule update_rule() const = 0;
104
105 /////////////////////////////////////////////////////////////////////////
106 // delete_rule.
107 /////////////////////////////////////////////////////////////////////////
108
109 virtual enum_rule delete_rule() const = 0;
111
112 /////////////////////////////////////////////////////////////////////////
113 // the catalog name of the referenced table.
114 /////////////////////////////////////////////////////////////////////////
115
116 virtual const String_type &referenced_table_catalog_name() const = 0;
118
119 /////////////////////////////////////////////////////////////////////////
120 // the schema name of the referenced table.
121 /////////////////////////////////////////////////////////////////////////
122
123 virtual const String_type &referenced_table_schema_name() const = 0;
125
126 /////////////////////////////////////////////////////////////////////////
127 // the name of the referenced table.
128 /////////////////////////////////////////////////////////////////////////
129
130 virtual const String_type &referenced_table_name() const = 0;
132
133 /////////////////////////////////////////////////////////////////////////
134 // Foreign key element collection.
135 /////////////////////////////////////////////////////////////////////////
136
138
139 virtual const Foreign_key_elements &elements() const = 0;
140
142
143 /**
144 Converts *this into json.
145
146 Converts all member variables that are to be included in the sdi
147 into json by transforming them appropriately and passing them to
148 the rapidjson writer provided.
149
150 @param wctx opaque context for data needed by serialization
151 @param w rapidjson writer which will perform conversion to json
152
153 */
154
155 virtual void serialize(Sdi_wcontext *wctx, Sdi_writer *w) const = 0;
156
157 /**
158 Re-establishes the state of *this by reading sdi information from
159 the rapidjson DOM subobject provided.
160
161 Cross-references encountered within this object are tracked in
162 sdictx, so that they can be updated when the entire object graph
163 has been established.
164
165 @param rctx stores book-keeping information for the
166 deserialization process
167 @param val subobject of rapidjson DOM containing json
168 representation of this object
169 @retval false success
170 @retval true failure
171 */
172
173 virtual bool deserialize(Sdi_rcontext *rctx, const RJ_Value &val) = 0;
174};
175
176///////////////////////////////////////////////////////////////////////////
177
178// Class to hold de-normalized information about FKs to be added
179// to dd::Table objects representing FK parents.
180
182 public:
186 m_fk_name(),
187 m_update_rule(Foreign_key::enum_rule::RULE_NO_ACTION),
188 m_delete_rule(Foreign_key::enum_rule::RULE_NO_ACTION) {}
189
191
194 }
195
197
200 }
201
202 const String_type &fk_name() const { return m_fk_name; }
203
205
207
210 }
211
213
216 }
217
218 private:
224};
225
226///////////////////////////////////////////////////////////////////////////
227
228} // namespace dd
229
230#endif // DD__FOREIGN_KEY_INCLUDED
Definition: collection.h:44
Base class for dictionary objects which has single column integer primary key.
Definition: entity_object.h:48
virtual const String_type & name() const =0
Definition: foreign_key_element.h:45
Definition: foreign_key_impl.h:57
Definition: foreign_key.h:181
Foreign_key_parent()
Definition: foreign_key.h:183
const String_type & fk_name() const
Definition: foreign_key.h:202
Foreign_key::enum_rule delete_rule() const
Definition: foreign_key.h:212
const String_type & child_schema_name() const
Definition: foreign_key.h:190
Foreign_key::enum_rule m_delete_rule
Definition: foreign_key.h:223
void set_child_schema_name(const String_type &child_schema_name)
Definition: foreign_key.h:192
const String_type & child_table_name() const
Definition: foreign_key.h:196
void set_update_rule(Foreign_key::enum_rule update_rule)
Definition: foreign_key.h:208
Foreign_key::enum_rule m_update_rule
Definition: foreign_key.h:222
void set_child_table_name(const String_type &child_table_name)
Definition: foreign_key.h:198
String_type m_fk_name
Definition: foreign_key.h:221
Foreign_key::enum_rule update_rule() const
Definition: foreign_key.h:206
void set_fk_name(const String_type &fk_name)
Definition: foreign_key.h:204
void set_delete_rule(Foreign_key::enum_rule delete_rule)
Definition: foreign_key.h:214
String_type m_child_schema_name
Definition: foreign_key.h:219
String_type m_child_table_name
Definition: foreign_key.h:220
Definition: foreign_key.h:47
virtual void set_unique_constraint_name(const String_type &name)=0
~Foreign_key() override=default
virtual const String_type & referenced_table_schema_name() const =0
virtual void set_delete_rule(enum_rule delete_rule)=0
Collection< Foreign_key_element * > Foreign_key_elements
Definition: foreign_key.h:49
virtual void set_referenced_table_name(const String_type &name)=0
virtual const String_type & unique_constraint_name() const =0
virtual Foreign_key_element * add_element()=0
virtual void set_referenced_table_catalog_name(const String_type &name)=0
tables::Foreign_keys DD_table
Definition: foreign_key.h:51
enum_match_option
Definition: foreign_key.h:62
@ OPTION_PARTIAL
Definition: foreign_key.h:64
@ OPTION_NONE
Definition: foreign_key.h:63
@ OPTION_FULL
Definition: foreign_key.h:65
virtual void serialize(Sdi_wcontext *wctx, Sdi_writer *w) const =0
Converts *this into json.
virtual enum_match_option match_option() const =0
virtual Foreign_key_elements * elements()=0
virtual Table & table()=0
virtual void set_match_option(enum_match_option match_option)=0
virtual const Table & table() const =0
virtual void set_update_rule(enum_rule update_rule)=0
virtual void set_referenced_table_schema_name(const String_type &name)=0
virtual const Foreign_key_elements & elements() const =0
enum_rule
Definition: foreign_key.h:54
@ RULE_NO_ACTION
Definition: foreign_key.h:55
@ RULE_SET_DEFAULT
Definition: foreign_key.h:59
@ RULE_SET_NULL
Definition: foreign_key.h:58
@ RULE_RESTRICT
Definition: foreign_key.h:56
@ RULE_CASCADE
Definition: foreign_key.h:57
Foreign_key_impl Impl
Definition: foreign_key.h:50
virtual bool deserialize(Sdi_rcontext *rctx, const RJ_Value &val)=0
Re-establishes the state of *this by reading sdi information from the rapidjson DOM subobject provide...
virtual enum_rule update_rule() const =0
virtual enum_rule delete_rule() const =0
virtual const String_type & referenced_table_catalog_name() const =0
virtual const String_type & referenced_table_name() const =0
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.h:47
Definition: foreign_keys.h:40
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
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
This header provides Rapidjson Type Aliases.