MySQL  8.0.19
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) {
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 
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
dd::Column
Definition: column.h:86
abstract_table.h
dd::Properties
The Properties class defines an interface for storing key=value pairs, where both key and value may b...
Definition: properties.h:73
dd::Abstract_table_impl::store_attributes
virtual bool store_attributes(Raw_record *r)
Definition: abstract_table_impl.cc:157
dd::Abstract_table_impl::impl
virtual const Entity_object_impl * impl() const
Definition: abstract_table_impl.h:174
dd::String_type
Char_string_template< String_type_allocator > String_type
Definition: string_type.h:50
properties_impl.h
dd::Entity_object_impl::name
virtual const String_type & name() const override
Definition: entity_object_impl.h:61
dd::Abstract_table_impl::set_options
virtual bool set_options(const Properties &options)
Definition: abstract_table_impl.h:115
dd::Abstract_table_impl::m_columns
Column_collection m_columns
Definition: abstract_table_impl.h:208
dd::RJ_Value
rapidjson::GenericValue< RJ_Encoding, RJ_Allocator > RJ_Value
Definition: sdi_fwd.h:48
my_dbug.h
raw_record.h
dd::Collection
Definition: collection.h:45
dd::Abstract_table_impl::options
virtual Properties & options()
Definition: abstract_table_impl.h:113
dd::Entity_object_impl::set_name
virtual void set_name(const String_type &name) override
Definition: entity_object_impl.h:63
dd::Abstract_table_impl::restore_children
virtual bool restore_children(Open_dictionary_tables_ctx *otx)
Definition: abstract_table_impl.cc:118
dd::Abstract_table_impl::hidden
virtual enum_hidden_type hidden() const
Definition: abstract_table_impl.h:150
dd::Abstract_table_impl::is_persistent
virtual bool is_persistent() const
Is dictionary object persistent in dictionary tables ?
Definition: abstract_table_impl.h:178
dd::Sdi_rcontext
Opaque context which keeps reusable resoureces needed during deserialization.
Definition: sdi.cc:229
dd
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:39
dd::Abstract_table_impl::columns
virtual Column_collection * columns()
Definition: abstract_table_impl.h:162
dd::Abstract_table_impl::set_last_altered
virtual void set_last_altered(ulonglong last_altered)
Definition: abstract_table_impl.h:142
dd::Abstract_table_impl::m_options
Properties_impl m_options
Definition: abstract_table_impl.h:204
dd::Abstract_table_impl::store_children
virtual bool store_children(Open_dictionary_tables_ctx *otx)
Definition: abstract_table_impl.cc:125
dd::Abstract_table_impl::deserialize
bool deserialize(Sdi_rcontext *rctx, const RJ_Value &val)
Definition: abstract_table_impl.cc:213
dd::Abstract_table_impl::m_schema_id
Object_id m_schema_id
Definition: abstract_table_impl.h:212
dd::Abstract_table_impl::mysql_version_id
virtual uint mysql_version_id() const
Definition: abstract_table_impl.h:99
object_id.h
dd::Properties_impl::insert_values
virtual bool insert_values(const Properties &properties)
Insert key/value pairs from a different property object.
Definition: properties_impl.cc:103
dd::Abstract_table_impl::columns
virtual const Column_collection & columns() const
Definition: abstract_table_impl.h:160
dd::Open_dictionary_tables_ctx
Auxiliary class for opening dictionary tables.
Definition: transaction_impl.h:75
dd::Abstract_table_impl::created
virtual ulonglong created(bool convert_time) const
Definition: abstract_table_impl.h:127
dd::Abstract_table_impl::drop_children
virtual bool drop_children(Open_dictionary_tables_ctx *otx) const
Definition: abstract_table_impl.cc:131
dd::Abstract_table_impl::m_last_altered
ulonglong m_last_altered
Definition: abstract_table_impl.h:200
dd::Abstract_table_impl::restore_attributes
virtual bool restore_attributes(const Raw_record &r)
Definition: abstract_table_impl.cc:138
dd::Raw_record
Definition: raw_record.h:53
my_inttypes.h
dd::Properties_impl
The Properties_impl class implements the Properties interface.
Definition: properties_impl.h:75
dd::Entity_object_impl::id
virtual Object_id id() const override
The unique dictionary object id.
Definition: entity_object_impl.h:48
r
const mysql_service_registry_t * r
Definition: pfs_example_plugin_employee.cc:85
dd::Abstract_table
Abstract base class for tables and views.
Definition: abstract_table.h:68
dd::Abstract_table_impl::impl
virtual Entity_object_impl * impl()
Definition: abstract_table_impl.h:173
dd::Abstract_table_impl::Abstract_table_impl
Abstract_table_impl()
Definition: abstract_table_impl.cc:95
uint
unsigned int uint
Definition: uca-dump.cc:29
dd::Sdi_writer
RJ_Writer Sdi_writer
Alias for the rapidjson Writer type to use in serialization.
Definition: sdi_fwd.h:63
dd::Abstract_table_impl::debug_print
virtual void debug_print(String_type &outb) const
Definition: abstract_table_impl.cc:235
column.h
string_type.h
dd::Abstract_table_impl::id
virtual Object_id id() const
The unique dictionary object id.
Definition: abstract_table_impl.h:177
dd::Abstract_table_impl::serialize
void serialize(Sdi_wcontext *wctx, Sdi_writer *w) const
Definition: abstract_table_impl.cc:199
gmt_time_to_local_time
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:794
weak_object_impl.h
sql_time.h
dd::Sdi_wcontext
Opaque context which keeps reusable resources needed during serialization.
Definition: sdi.cc:126
dd::Abstract_table_impl::set_hidden
virtual void set_hidden(enum_hidden_type hidden)
Definition: abstract_table_impl.h:152
dd::Abstract_table_impl::~Abstract_table_impl
virtual ~Abstract_table_impl()
Definition: abstract_table_impl.h:189
dd::Abstract_table_impl::add_column
virtual Column * add_column()
Definition: abstract_table_impl.cc:266
dd::Abstract_table_impl::set_created
virtual void set_created(ulonglong created)
Definition: abstract_table_impl.h:131
dd::Abstract_table_impl::schema_id
virtual Object_id schema_id() const
Definition: abstract_table_impl.h:88
entity_object_impl.h
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
Time_zone
This class represents abstract time zone and provides basic interface for MYSQL_TIME <-> my_time_t co...
Definition: tztime.h:51
dd::Object_id
unsigned long long Object_id
Definition: object_id.h:30
dd::Abstract_table_impl::m_hidden
enum_hidden_type m_hidden
Definition: abstract_table_impl.h:202
sdi_fwd.h
dd::Abstract_table_impl::object_table
virtual const Object_table & object_table() const
Definition: abstract_table_impl.cc:320
dd::Abstract_table::enum_hidden_type
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
dd::Abstract_table_impl::validate
virtual bool validate() const
Definition: abstract_table_impl.cc:106
dd::Abstract_table_impl::set_name
virtual void set_name(const String_type &name)
Definition: abstract_table_impl.h:182
dd::Abstract_table_impl::name
virtual const String_type & name() const
Definition: abstract_table_impl.h:181
dd::Entity_object_impl::impl
virtual Entity_object_impl * impl() override
Definition: entity_object_impl.h:71
dd::Abstract_table_impl
Definition: abstract_table_impl.h:56
dd::Object_table
This class represents all data dictionary table like mysql.tables, mysql.columns and more.
Definition: object_table.h:71
dd::Abstract_table_impl::last_altered
virtual ulonglong last_altered(bool convert_time) const
Definition: abstract_table_impl.h:137
ulonglong
unsigned long long int ulonglong
Definition: my_inttypes.h:55
dd::Entity_object_impl
Definition: entity_object_impl.h:42
properties.h
dd::Abstract_table_impl::set_schema_id
virtual void set_schema_id(Object_id schema_id)
Definition: abstract_table_impl.h:90
dd::Abstract_table_impl::m_mysql_version_id
uint m_mysql_version_id
Definition: abstract_table_impl.h:194
dd::Abstract_table_impl::options
virtual const Properties & options() const
Definition: abstract_table_impl.h:111
dd::Abstract_table_impl::set_options
virtual bool set_options(const String_type &options_raw)
Definition: abstract_table_impl.h:119
dd::Abstract_table_impl::register_tables
static void register_tables(Open_dictionary_tables_ctx *otx)
Definition: abstract_table_impl.cc:326
dd::Abstract_table_impl::m_created
ulonglong m_created
Definition: abstract_table_impl.h:199
dd::Abstract_table_impl::get_column
const Column * get_column(Object_id column_id) const
Definition: abstract_table_impl.cc:284