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