MySQL  8.0.21
Source Code Documentation
abstract_table_impl.h
Go to the documentation of this file.
1 /* Copyright (c) 2014, 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__ABSTRACT_TABLE_IMPL_INCLUDED
24 #define DD__ABSTRACT_TABLE_IMPL_INCLUDED
25 
26 #include <stddef.h>
27 #include <sys/types.h>
28 #include <memory> // std::unique_ptr
29 
30 #include "my_dbug.h"
31 #include "my_inttypes.h"
32 #include "sql/dd/impl/properties_impl.h" // Properties_impl
34 #include "sql/dd/impl/types/entity_object_impl.h" // dd::Entity_object_impl
36 #include "sql/dd/object_id.h"
37 #include "sql/dd/properties.h"
38 #include "sql/dd/sdi_fwd.h"
39 #include "sql/dd/string_type.h"
40 #include "sql/dd/types/abstract_table.h" // dd::Abstract_table
41 #include "sql/dd/types/column.h" // IWYU pragma: keep
42 #include "sql/sql_time.h" // gmt_time_to_local_time
43 
44 class Time_zone;
45 
46 namespace dd {
47 
48 ///////////////////////////////////////////////////////////////////////////
49 
50 class Object_table;
51 class Open_dictionary_tables_ctx;
52 class Sdi_rcontext;
53 class Sdi_wcontext;
54 class Weak_object;
55 
57  virtual public Abstract_table {
58  public:
59  virtual const Object_table &object_table() const;
60 
62 
63  virtual bool validate() const;
64 
66 
67  virtual bool store_children(Open_dictionary_tables_ctx *otx);
68 
69  virtual bool drop_children(Open_dictionary_tables_ctx *otx) const;
70 
71  virtual bool restore_attributes(const Raw_record &r);
72 
73  virtual bool store_attributes(Raw_record *r);
74 
75  protected:
76  void serialize(Sdi_wcontext *wctx, Sdi_writer *w) const;
77 
78  bool deserialize(Sdi_rcontext *rctx, const RJ_Value &val);
79 
80  public:
81  virtual void debug_print(String_type &outb) const;
82 
83  public:
84  /////////////////////////////////////////////////////////////////////////
85  // schema.
86  /////////////////////////////////////////////////////////////////////////
87 
88  virtual Object_id schema_id() const { return m_schema_id; }
89 
91 
92  /////////////////////////////////////////////////////////////////////////
93  // mysql_version_id.
94  // Primarily intended for debugging, but can be used as a last-resort
95  // version check for SE data and other items, but in general other
96  // mechanisms should be preferred.
97  /////////////////////////////////////////////////////////////////////////
98 
99  virtual uint mysql_version_id() const { return m_mysql_version_id; }
100 
101  // TODO: Commented out as it is not needed as we either use the value
102  // assigned by the constructor, or restore a value from the TABLES
103  // table. It may be necessary when implementing upgrade.
104  // virtual void set_mysql_version_id(uint mysql_version_id)
105  //{ m_mysql_version_id= mysql_version_id; }
106 
107  /////////////////////////////////////////////////////////////////////////
108  // options.
109  /////////////////////////////////////////////////////////////////////////
110 
111  virtual const Properties &options() const { return m_options; }
112 
113  virtual Properties &options() { return m_options; }
114 
115  virtual bool set_options(const Properties &options) {
116  return m_options.insert_values(options);
117  }
118 
119  virtual bool set_options(const String_type &options_raw) {
120  return m_options.insert_values(options_raw);
121  }
122 
123  /////////////////////////////////////////////////////////////////////////
124  // created.
125  /////////////////////////////////////////////////////////////////////////
126 
127  virtual ulonglong created(bool convert_time) const {
128  return convert_time ? gmt_time_to_local_time(m_created) : m_created;
129  }
130 
132 
133  /////////////////////////////////////////////////////////////////////////
134  // last altered.
135  /////////////////////////////////////////////////////////////////////////
136 
137  virtual ulonglong last_altered(bool convert_time) const {
138  return convert_time ? gmt_time_to_local_time(m_last_altered)
139  : m_last_altered;
140  }
141 
144  }
145 
146  /////////////////////////////////////////////////////////////////////////
147  // hidden.
148  /////////////////////////////////////////////////////////////////////////
149 
150  virtual enum_hidden_type hidden() const { return m_hidden; }
151 
153 
154  /////////////////////////////////////////////////////////////////////////
155  // Column collection.
156  /////////////////////////////////////////////////////////////////////////
157 
158  virtual Column *add_column();
159 
160  virtual const Column_collection &columns() const { return m_columns; }
161 
162  virtual Column_collection *columns() { return &m_columns; }
163 
164  const Column *get_column(Object_id column_id) const;
165 
166  Column *get_column(Object_id column_id);
167 
168  const Column *get_column(const String_type &name) const;
169 
170  Column *get_column(const String_type &name);
171 
172  // Fix "inherits ... via dominance" warnings
174  virtual const Entity_object_impl *impl() const {
175  return Entity_object_impl::impl();
176  }
177  virtual Object_id id() const { return Entity_object_impl::id(); }
178  virtual bool is_persistent() const {
180  }
181  virtual const String_type &name() const { return Entity_object_impl::name(); }
182  virtual void set_name(const String_type &name) {
184  }
185 
186  protected:
188 
189  virtual ~Abstract_table_impl() {}
190 
191  private:
192  // Fields.
193 
195 
196  // TODO-POST-MERGE-TO-TRUNK:
197  // Add new field m_last_checked_for_upgrade
198 
201 
203 
205 
206  // References to tightly-coupled objects.
207 
209 
210  // References to other objects.
211 
213 
214  protected:
216 };
217 
218 ///////////////////////////////////////////////////////////////////////////
219 
220 } // namespace dd
221 
222 #endif // DD__ABSTRACT_TABLE_IMPL_INCLUDED
bool deserialize(Sdi_rcontext *rctx, const RJ_Value &val)
Definition: abstract_table_impl.cc:213
unsigned long long int ulonglong
Definition: my_inttypes.h:55
Column_collection m_columns
Definition: abstract_table_impl.h:208
Definition: entity_object_impl.h:42
virtual const Properties & options() const
Definition: abstract_table_impl.h:111
virtual ulonglong created(bool convert_time) const
Definition: abstract_table_impl.h:127
ulonglong m_last_altered
Definition: abstract_table_impl.h:200
virtual const String_type & name() const
Definition: abstract_table_impl.h:181
const Column * get_column(Object_id column_id) const
Definition: abstract_table_impl.cc:284
Some integer typedefs for easier portability.
Char_string_template< String_type_allocator > String_type
Definition: string_type.h:50
virtual const Entity_object_impl * impl() const
Definition: abstract_table_impl.h:174
Object_id m_schema_id
Definition: abstract_table_impl.h:212
virtual uint mysql_version_id() const
Definition: abstract_table_impl.h:99
virtual void debug_print(String_type &outb) const
Definition: abstract_table_impl.cc:235
virtual bool set_options(const Properties &options)
Definition: abstract_table_impl.h:115
This header provides Rapidjson Type Aliases.
uint m_mysql_version_id
Definition: abstract_table_impl.h:194
virtual Entity_object_impl * impl() override
Definition: entity_object_impl.h:71
virtual bool drop_children(Open_dictionary_tables_ctx *otx) const
Definition: abstract_table_impl.cc:131
virtual bool set_options(const String_type &options_raw)
Definition: abstract_table_impl.h:119
static void register_tables(Open_dictionary_tables_ctx *otx)
Definition: abstract_table_impl.cc:326
virtual bool restore_attributes(const Raw_record &r)
Definition: abstract_table_impl.cc:138
This class represents abstract time zone and provides basic interface for MYSQL_TIME <-> my_time_t co...
Definition: tztime.h:51
virtual void set_hidden(enum_hidden_type hidden)
Definition: abstract_table_impl.h:152
virtual Properties & options()
Definition: abstract_table_impl.h:113
virtual Column * add_column()
Definition: abstract_table_impl.cc:266
virtual void set_created(ulonglong created)
Definition: abstract_table_impl.h:131
virtual bool restore_children(Open_dictionary_tables_ctx *otx)
Definition: abstract_table_impl.cc:118
virtual Entity_object_impl * impl()
Definition: abstract_table_impl.h:173
Definition: column.h:87
virtual enum_hidden_type hidden() const
Definition: abstract_table_impl.h:150
Opaque context which keeps reusable resources needed during serialization.
Definition: sdi.cc:127
virtual bool is_persistent() const override
Is dictionary object persistent in dictionary tables ?
Definition: entity_object_impl.h:56
virtual bool is_persistent() const
Is dictionary object persistent in dictionary tables ?
Definition: abstract_table_impl.h:178
virtual bool store_attributes(Raw_record *r)
Definition: abstract_table_impl.cc:157
ulonglong gmt_time_to_local_time(ulonglong gmt_time)
This function gets GMT time and adds value of time_zone to get the local time.
Definition: sql_time.cc:792
rapidjson::GenericValue< RJ_Encoding, RJ_Allocator > RJ_Value
Definition: sdi_fwd.h:48
virtual ulonglong last_altered(bool convert_time) const
Definition: abstract_table_impl.h:137
The Properties_impl class implements the Properties interface.
Definition: properties_impl.h:75
unsigned int uint
Definition: uca-dump.cc:29
Interface for server time utilities.
enum_hidden_type m_hidden
Definition: abstract_table_impl.h:202
unsigned long long Object_id
Definition: object_id.h:30
virtual Column_collection * columns()
Definition: abstract_table_impl.h:162
The Properties class defines an interface for storing key=value pairs, where both key and value may b...
Definition: properties.h:73
virtual const String_type & name() const override
Definition: entity_object_impl.h:61
virtual bool insert_values(const Properties &properties)
Insert key/value pairs from a different property object.
Definition: properties_impl.cc:103
Abstract base class for tables and views.
Definition: abstract_table.h:68
Opaque context which keeps reusable resoureces needed during deserialization.
Definition: sdi.cc:230
virtual Object_id id() const override
The unique dictionary object id.
Definition: entity_object_impl.h:48
virtual void set_name(const String_type &name) override
Definition: entity_object_impl.h:63
virtual void set_name(const String_type &name)
Definition: abstract_table_impl.h:182
ulonglong m_created
Definition: abstract_table_impl.h:199
virtual const Column_collection & columns() const
Definition: abstract_table_impl.h:160
enum_hidden_type
Enumeration type which indicates whether the table is hidden, and if yes then which type of hidden ta...
Definition: abstract_table.h:102
Auxiliary class for opening dictionary tables.
Definition: transaction_impl.h:75
const mysql_service_registry_t * r
Definition: pfs_example_plugin_employee.cc:85
void serialize(Sdi_wcontext *wctx, Sdi_writer *w) const
Definition: abstract_table_impl.cc:199
This class represents all data dictionary table like mysql.tables, mysql.columns and more...
Definition: object_table.h:71
Definition: collection.h:45
virtual Object_id schema_id() const
Definition: abstract_table_impl.h:88
virtual void set_schema_id(Object_id schema_id)
Definition: abstract_table_impl.h:90
Abstract_table_impl()
Definition: abstract_table_impl.cc:95
RJ_Writer Sdi_writer
Alias for the rapidjson Writer type to use in serialization.
Definition: sdi_fwd.h:63
virtual const Object_table & object_table() const
Definition: abstract_table_impl.cc:320
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:39
virtual Object_id id() const
The unique dictionary object id.
Definition: abstract_table_impl.h:177
virtual bool validate() const
Definition: abstract_table_impl.cc:106
Definition: abstract_table_impl.h:56
Definition: raw_record.h:53
virtual ~Abstract_table_impl()
Definition: abstract_table_impl.h:189
virtual void set_last_altered(ulonglong last_altered)
Definition: abstract_table_impl.h:142
Properties_impl m_options
Definition: abstract_table_impl.h:204
virtual bool store_children(Open_dictionary_tables_ctx *otx)
Definition: abstract_table_impl.cc:125