MySQL  8.0.19
Source Code Documentation
trigger_impl.h
Go to the documentation of this file.
1 /* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
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__TRIGGER_IMPL_INCLUDED
24 #define DD__TRIGGER_IMPL_INCLUDED
25 
26 #include "my_config.h"
27 
28 #include "my_inttypes.h"
29 #include "sql/dd/string_type.h"
30 
31 #ifdef HAVE_SYS_TIME_H
32 #include <sys/time.h>
33 #endif
34 #include <sys/types.h>
35 #include <new>
36 
38 #include "sql/dd/impl/types/entity_object_impl.h" // dd::Entity_object_impl
39 #include "sql/dd/impl/types/table_impl.h" // dd::Table_impl
41 #include "sql/dd/object_id.h"
42 #include "sql/dd/types/trigger.h" // dd::Trigger
43 
44 namespace dd {
45 
46 ///////////////////////////////////////////////////////////////////////////
47 
48 class Object_table;
49 class Open_dictionary_tables_ctx;
50 class Table;
51 class Weak_object;
52 
53 class Trigger_impl : virtual public Entity_object_impl, virtual public Trigger {
54  public:
55  Trigger_impl();
56 
58 
59  Trigger_impl(const Trigger_impl &src, Table_impl *parent);
60 
61  public:
62  virtual const Object_table &object_table() const override;
63 
64  virtual bool validate() const override;
65 
66  virtual bool restore_attributes(const Raw_record &r) override;
67 
68  virtual bool store_attributes(Raw_record *r) override;
69 
70  virtual void debug_print(String_type &outb) const override;
71 
74  }
75 
77 
78  public:
80 
81  /////////////////////////////////////////////////////////////////////////
82  // Table.
83  /////////////////////////////////////////////////////////////////////////
84 
85  virtual const Table &table() const;
86 
87  virtual Table &table();
88 
89  /* non-virtual */ void set_table(Table_impl *parent) { m_table = parent; }
90 
91  /* non-virtual */ const Table_impl &table_impl() const { return *m_table; }
92 
93  /* non-virtual */ Table_impl &table_impl() { return *m_table; }
94 
95  /////////////////////////////////////////////////////////////////////////
96  // schema.
97  /////////////////////////////////////////////////////////////////////////
98 
99  virtual Object_id schema_id() const override {
100  return (m_table != nullptr ? m_table->schema_id() : INVALID_OBJECT_ID);
101  }
102 
103  /////////////////////////////////////////////////////////////////////////
104  // event type
105  /////////////////////////////////////////////////////////////////////////
106 
107  virtual enum_event_type event_type() const override { return m_event_type; }
108 
109  virtual void set_event_type(enum_event_type event_type) override {
111  }
112 
113  /////////////////////////////////////////////////////////////////////////
114  // table.
115  /////////////////////////////////////////////////////////////////////////
116 
117  virtual Object_id table_id() const override { return m_table->id(); }
118 
119  /////////////////////////////////////////////////////////////////////////
120  // action timing
121  /////////////////////////////////////////////////////////////////////////
122 
123  virtual enum_action_timing action_timing() const override {
124  return m_action_timing;
125  }
126 
129  }
130 
131  /////////////////////////////////////////////////////////////////////////
132  // action_order.
133  /////////////////////////////////////////////////////////////////////////
134 
135  virtual uint action_order() const override { return m_action_order; }
136 
137  virtual void set_action_order(uint action_order) override {
139  }
140 
141  /////////////////////////////////////////////////////////////////////////
142  // action_statement/utf8.
143  /////////////////////////////////////////////////////////////////////////
144 
145  virtual const String_type &action_statement() const override {
146  return m_action_statement;
147  }
148 
149  virtual void set_action_statement(
150  const String_type &action_statement) override {
152  }
153 
154  virtual const String_type &action_statement_utf8() const override {
156  }
157 
159  const String_type &action_statement_utf8) override {
161  }
162 
163  /////////////////////////////////////////////////////////////////////////
164  // created.
165  /////////////////////////////////////////////////////////////////////////
166 
167  virtual timeval created() const override { return m_created; }
168 
169  virtual void set_created(timeval created) override { m_created = created; }
170 
171  /////////////////////////////////////////////////////////////////////////
172  // last altered.
173  /////////////////////////////////////////////////////////////////////////
174 
175  virtual timeval last_altered() const override { return m_last_altered; }
176 
177  virtual void set_last_altered(timeval last_altered) override {
179  }
180 
181  /////////////////////////////////////////////////////////////////////////
182  // sql_mode
183  /////////////////////////////////////////////////////////////////////////
184 
185  virtual ulonglong sql_mode() const override { return m_sql_mode; }
186 
187  virtual void set_sql_mode(ulonglong sql_mode) override {
189  }
190 
191  /////////////////////////////////////////////////////////////////////////
192  // definer.
193  /////////////////////////////////////////////////////////////////////////
194 
195  virtual const String_type &definer_user() const override {
196  return m_definer_user;
197  }
198 
199  virtual const String_type &definer_host() const override {
200  return m_definer_host;
201  }
202 
203  virtual void set_definer(const String_type &username,
204  const String_type &hostname) override {
205  m_definer_user = username;
206  m_definer_host = hostname;
207  }
208 
209  /////////////////////////////////////////////////////////////////////////
210  // collation.
211  /////////////////////////////////////////////////////////////////////////
212 
213  virtual Object_id client_collation_id() const override {
214  return m_client_collation_id;
215  }
216 
219  }
220 
221  virtual Object_id connection_collation_id() const override {
223  }
224 
228  }
229 
230  virtual Object_id schema_collation_id() const override {
231  return m_schema_collation_id;
232  }
233 
236  }
237 
238  // Fix "inherits ... via dominance" warnings
239  virtual Entity_object_impl *impl() override {
240  return Entity_object_impl::impl();
241  }
242 
243  virtual const Entity_object_impl *impl() const override {
244  return Entity_object_impl::impl();
245  }
246 
247  virtual Object_id id() const override { return Entity_object_impl::id(); }
248 
249  virtual bool is_persistent() const override {
251  }
252 
253  virtual const String_type &name() const override {
254  return Entity_object_impl::name();
255  }
256 
257  virtual void set_name(const String_type &name) override {
259  }
260 
261  public:
263  return new (std::nothrow) Trigger_impl(table);
264  }
265 
266  static Trigger_impl *clone(const Trigger_impl &other, Table_impl *table) {
267  return new (std::nothrow) Trigger_impl(other, table);
268  }
269 
270  private:
273 
274  /*
275  We use m_ordinal_position to help implement
276  add_trigger_following and add_trigger_preceding.
277  This is required mainly because we maintain a single
278  collection to maintain all triggers.
279  */
282 
284  timeval m_created;
285  timeval m_last_altered;
286 
291 
292  // References to tightly-coupled objects.
293 
295 
296  // References to loosely-coupled objects.
297 
301 };
302 
303 ///////////////////////////////////////////////////////////////////////////
304 
305 /**
306  Used to sort Triggers of the same table by action timing, event type and
307  action order.
308 */
309 
311  bool operator()(const dd::Trigger *t1, const dd::Trigger *t2) const {
312  return ((t1->action_timing() < t2->action_timing()) ||
313  (t1->action_timing() == t2->action_timing() &&
314  t1->event_type() < t2->event_type()) ||
315  (t1->action_timing() == t2->action_timing() &&
316  t1->event_type() == t2->event_type() &&
317  t1->action_order() < t2->action_order()));
318  }
319 };
320 
321 ///////////////////////////////////////////////////////////////////////////
322 } // namespace dd
323 
324 #endif // DD__TRIGGER_IMPL_INCLUDED
dd::Trigger_impl::schema_id
virtual Object_id schema_id() const override
Definition: trigger_impl.h:99
dd::Trigger_impl::definer_host
virtual const String_type & definer_host() const override
Definition: trigger_impl.h:199
dd::Trigger_impl::schema_collation_id
virtual Object_id schema_collation_id() const override
Definition: trigger_impl.h:230
dd::Trigger_impl::validate
virtual bool validate() const override
Definition: trigger_impl.cc:86
dd::Trigger_impl::m_action_order
uint m_action_order
Definition: trigger_impl.h:281
dd::Trigger_impl::impl
virtual const Entity_object_impl * impl() const override
Definition: trigger_impl.h:243
dd::Trigger::enum_action_timing
enum_action_timing
Definition: trigger.h:60
dd::String_type
Char_string_template< String_type_allocator > String_type
Definition: string_type.h:50
dd::Trigger_impl::is_persistent
virtual bool is_persistent() const override
Is dictionary object persistent in dictionary tables ?
Definition: trigger_impl.h:249
dd::Trigger_impl
Definition: trigger_impl.h:53
dd::Entity_object_impl::name
virtual const String_type & name() const override
Definition: entity_object_impl.h:61
dd::Trigger_impl::event_type
virtual enum_event_type event_type() const override
Definition: trigger_impl.h:107
dd::Trigger_impl::set_table
void set_table(Table_impl *parent)
Definition: trigger_impl.h:89
dd::Trigger_impl::m_sql_mode
ulonglong m_sql_mode
Definition: trigger_impl.h:283
dd::Trigger::action_order
virtual uint action_order() const =0
dd::Trigger::action_timing
virtual enum_action_timing action_timing() const =0
table_impl.h
raw_record.h
dd::Entity_object_impl::set_name
virtual void set_name(const String_type &name) override
Definition: entity_object_impl.h:63
dd::Trigger_impl::table_impl
Table_impl & table_impl()
Definition: trigger_impl.h:93
dd::Trigger_impl::m_schema_collation_id
Object_id m_schema_collation_id
Definition: trigger_impl.h:300
dd::Trigger_impl::impl
virtual Entity_object_impl * impl() override
Definition: trigger_impl.h:239
enum_event_type
enum_event_type
Enum values for the NESTING_EVENT_TYPE columns.
Definition: pfs_column_types.h:245
dd::Trigger_order_comparator
Used to sort Triggers of the same table by action timing, event type and action order.
Definition: trigger_impl.h:310
dd
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:39
dd::Trigger_impl::set_action_order
virtual void set_action_order(uint action_order) override
Definition: trigger_impl.h:137
dd::Trigger_impl::set_ordinal_position
void set_ordinal_position(uint ordinal_position)
Definition: trigger_impl.h:72
dd::Trigger_impl::set_definer
virtual void set_definer(const String_type &username, const String_type &hostname) override
Definition: trigger_impl.h:203
dd::Trigger_impl::set_event_type
virtual void set_event_type(enum_event_type event_type) override
Definition: trigger_impl.h:109
dd::Trigger_impl::set_action_statement_utf8
virtual void set_action_statement_utf8(const String_type &action_statement_utf8) override
Definition: trigger_impl.h:158
dd::Trigger_impl::set_name
virtual void set_name(const String_type &name) override
Definition: trigger_impl.h:257
Table
Definition: test_sql_stmt.cc:150
object_id.h
dd::Trigger_impl::set_schema_collation_id
virtual void set_schema_collation_id(Object_id schema_collation_id) override
Definition: trigger_impl.h:234
dd::Open_dictionary_tables_ctx
Auxiliary class for opening dictionary tables.
Definition: transaction_impl.h:75
dd::Trigger_impl::id
virtual Object_id id() const override
The unique dictionary object id.
Definition: trigger_impl.h:247
dd::Trigger_impl::m_ordinal_position
uint m_ordinal_position
Definition: trigger_impl.h:280
dd::Trigger_impl::set_sql_mode
virtual void set_sql_mode(ulonglong sql_mode) override
Definition: trigger_impl.h:187
dd::Trigger_impl::action_statement_utf8
virtual const String_type & action_statement_utf8() const override
Definition: trigger_impl.h:154
dd::Raw_record
Definition: raw_record.h:53
my_inttypes.h
dd::Table_impl::schema_id
virtual Object_id schema_id() const
Definition: table_impl.h:406
dd::Entity_object_impl::id
virtual Object_id id() const override
The unique dictionary object id.
Definition: entity_object_impl.h:48
dd::Trigger_impl::set_action_statement
virtual void set_action_statement(const String_type &action_statement) override
Definition: trigger_impl.h:149
dd::Trigger_impl::action_statement
virtual const String_type & action_statement() const override
Definition: trigger_impl.h:145
r
const mysql_service_registry_t * r
Definition: pfs_example_plugin_employee.cc:85
dd::Trigger_impl::m_action_statement
String_type m_action_statement
Definition: trigger_impl.h:288
dd::Trigger_impl::set_client_collation_id
virtual void set_client_collation_id(Object_id client_collation_id) override
Definition: trigger_impl.h:217
dd::Trigger
Class representing a Trigger in DD framework.
Definition: trigger.h:52
event_type
event_type
Definition: test_pfs_resource_group.cc:70
time.h
dd::Trigger_impl::store_attributes
virtual bool store_attributes(Raw_record *r) override
Definition: trigger_impl.cc:154
uint
unsigned int uint
Definition: uca-dump.cc:29
dd::Table_impl
Definition: table_impl.h:66
dd::Trigger_order_comparator::operator()
bool operator()(const dd::Trigger *t1, const dd::Trigger *t2) const
Definition: trigger_impl.h:311
dd::Trigger_impl::register_tables
static void register_tables(Open_dictionary_tables_ctx *otx)
Definition: trigger_impl.cc:233
string_type.h
dd::Trigger_impl::m_definer_host
String_type m_definer_host
Definition: trigger_impl.h:290
dd::Trigger_impl::Trigger_impl
Trigger_impl()
Definition: trigger_impl.cc:53
dd::Trigger_impl::m_last_altered
timeval m_last_altered
Definition: trigger_impl.h:285
dd::Trigger::event_type
virtual enum_event_type event_type() const =0
dd::Trigger_impl::restore_item
static Trigger_impl * restore_item(Table_impl *table)
Definition: trigger_impl.h:262
weak_object_impl.h
dd::Trigger_impl::m_definer_user
String_type m_definer_user
Definition: trigger_impl.h:289
dd::Table
Definition: table.h:45
dd::Trigger_impl::sql_mode
virtual ulonglong sql_mode() const override
Definition: trigger_impl.h:185
dd::Trigger_impl::name
virtual const String_type & name() const override
Definition: trigger_impl.h:253
entity_object_impl.h
dd::Trigger_impl::action_timing
virtual enum_action_timing action_timing() const override
Definition: trigger_impl.h:123
dd::Entity_object_impl::is_persistent
virtual bool is_persistent() const override
Is dictionary object persistent in dictionary tables ?
Definition: entity_object_impl.h:56
dd::Trigger_impl::m_created
timeval m_created
Definition: trigger_impl.h:284
dd::Object_id
unsigned long long Object_id
Definition: object_id.h:30
dd::INVALID_OBJECT_ID
const Object_id INVALID_OBJECT_ID
The default object ID which represents that the DD object is new and not persistent in dictionary tab...
Definition: object_id.h:36
dd::Trigger_impl::set_connection_collation_id
virtual void set_connection_collation_id(Object_id connection_collation_id) override
Definition: trigger_impl.h:225
dd::Trigger_impl::debug_print
virtual void debug_print(String_type &outb) const override
Definition: trigger_impl.cc:180
dd::Trigger_impl::ordinal_position
uint ordinal_position() const
Definition: trigger_impl.h:76
dd::Trigger_impl::set_last_altered
virtual void set_last_altered(timeval last_altered) override
Definition: trigger_impl.h:177
dd::Trigger_impl::set_action_timing
virtual void set_action_timing(enum_action_timing action_timing) override
Definition: trigger_impl.h:127
dd::Trigger_impl::clone
static Trigger_impl * clone(const Trigger_impl &other, Table_impl *table)
Definition: trigger_impl.h:266
dd::Trigger_impl::object_table
virtual const Object_table & object_table() const override
Definition: trigger_impl.cc:227
dd::Table_impl::id
virtual Object_id id() const
The unique dictionary object id.
Definition: table_impl.h:398
dd::Trigger_impl::table_impl
const Table_impl & table_impl() const
Definition: trigger_impl.h:91
dd::Trigger_impl::m_event_type
enum_event_type m_event_type
Definition: trigger_impl.h:271
dd::Trigger_impl::m_connection_collation_id
Object_id m_connection_collation_id
Definition: trigger_impl.h:299
dd::Trigger_impl::table
virtual const Table & table() const
Definition: trigger_impl.cc:80
dd::Entity_object_impl::impl
virtual Entity_object_impl * impl() override
Definition: entity_object_impl.h:71
dd::Object_table
This class represents all data dictionary table like mysql.tables, mysql.columns and more.
Definition: object_table.h:71
dd::Trigger_impl::m_table
Table_impl * m_table
Definition: trigger_impl.h:294
dd::Trigger_impl::set_created
virtual void set_created(timeval created) override
Definition: trigger_impl.h:169
ulonglong
unsigned long long int ulonglong
Definition: my_inttypes.h:55
dd::Entity_object_impl
Definition: entity_object_impl.h:42
dd::Trigger_impl::connection_collation_id
virtual Object_id connection_collation_id() const override
Definition: trigger_impl.h:221
dd::Trigger_impl::action_order
virtual uint action_order() const override
Definition: trigger_impl.h:135
dd::Trigger_impl::m_action_statement_utf8
String_type m_action_statement_utf8
Definition: trigger_impl.h:287
trigger.h
dd::Trigger_impl::m_action_timing
enum_action_timing m_action_timing
Definition: trigger_impl.h:272
dd::Trigger_impl::created
virtual timeval created() const override
Definition: trigger_impl.h:167
dd::Trigger_impl::table_id
virtual Object_id table_id() const override
Definition: trigger_impl.h:117
dd::Trigger_impl::client_collation_id
virtual Object_id client_collation_id() const override
Definition: trigger_impl.h:213
dd::Trigger_impl::m_client_collation_id
Object_id m_client_collation_id
Definition: trigger_impl.h:298
dd::Trigger_impl::last_altered
virtual timeval last_altered() const override
Definition: trigger_impl.h:175
dd::Trigger_impl::restore_attributes
virtual bool restore_attributes(const Raw_record &r) override
Definition: trigger_impl.cc:98
dd::Trigger_impl::definer_user
virtual const String_type & definer_user() const override
Definition: trigger_impl.h:195