1 /* Copyright (c) 2014, 2019, 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__PARTITION_INCLUDED
24 #define DD__PARTITION_INCLUDED
25 
26 #include "my_inttypes.h"
27 #include "sql/dd/sdi_fwd.h"              // dd::Sdi_wcontext
28 #include "sql/dd/types/entity_object.h"  // dd::Entity_object
29 #include "sql/dd/types/table.h"          // Table::Partition_collection
30 
31 namespace dd {
32 
33 ///////////////////////////////////////////////////////////////////////////
34 
35 class Index;
36 class Partition_impl;
37 class Partition_index;
38 class Partition_value;
39 class Properties;
40 class Table;
41 template <typename T>
42 class Collection;
43 
44 namespace tables {
45 class Table_partitions;
46 }
47 
48 ///////////////////////////////////////////////////////////////////////////
49 
50 class Partition : virtual public Entity_object {
51  public:
52   typedef Collection<Partition_index *> Partition_indexes;
53   typedef Collection<Partition_value *> Partition_values;
54   typedef Partition_impl Impl;
55   typedef tables::Table_partitions DD_table;
56 
57  public:
~Partition()58   virtual ~Partition() {}
59 
60   /////////////////////////////////////////////////////////////////////////
61   // Table.
62   /////////////////////////////////////////////////////////////////////////
63 
64   virtual const Table &table() const = 0;
65 
66   virtual Table &table() = 0;
67 
68   /////////////////////////////////////////////////////////////////////////
69   // parent_partition.
70   /////////////////////////////////////////////////////////////////////////
71 
72   virtual const Partition *parent_partition() const = 0;
73 
74   virtual Partition *parent_partition() = 0;
75 
76   /////////////////////////////////////////////////////////////////////////
77   // parent_partition_id.
78   /////////////////////////////////////////////////////////////////////////
79 
80   virtual Object_id parent_partition_id() const = 0;
81   virtual void set_parent_partition_id(Object_id parent_partition_id) = 0;
82 
83   /////////////////////////////////////////////////////////////////////////
84   // number.
85   /////////////////////////////////////////////////////////////////////////
86 
87   virtual uint number() const = 0;
88   virtual void set_number(uint number) = 0;
89 
90   /////////////////////////////////////////////////////////////////////////
91   // description_utf8.
92   /////////////////////////////////////////////////////////////////////////
93 
94   virtual const String_type &description_utf8() const = 0;
95   virtual void set_description_utf8(const String_type &description_utf8) = 0;
96 
97   /////////////////////////////////////////////////////////////////////////
98   // engine.
99   /////////////////////////////////////////////////////////////////////////
100 
101   virtual const String_type &engine() const = 0;
102   virtual void set_engine(const String_type &engine) = 0;
103 
104   /////////////////////////////////////////////////////////////////////////
105   // Comment.
106   /////////////////////////////////////////////////////////////////////////
107 
108   virtual const String_type &comment() const = 0;
109   virtual void set_comment(const String_type &comment) = 0;
110 
111   /////////////////////////////////////////////////////////////////////////
112   // Options.
113   /////////////////////////////////////////////////////////////////////////
114 
115   virtual const Properties &options() const = 0;
116 
117   virtual Properties &options() = 0;
118   virtual bool set_options(const Properties &options) = 0;
119   virtual bool set_options(const String_type &options_raw) = 0;
120 
121   /////////////////////////////////////////////////////////////////////////
122   // se_private_data.
123   /////////////////////////////////////////////////////////////////////////
124 
125   virtual const Properties &se_private_data() const = 0;
126 
127   virtual Properties &se_private_data() = 0;
128 
129   virtual bool set_se_private_data(const String_type &se_private_data_raw) = 0;
130 
131   virtual bool set_se_private_data(const Properties &se_private_data) = 0;
132 
133   /////////////////////////////////////////////////////////////////////////
134   // se_private_id.
135   /////////////////////////////////////////////////////////////////////////
136 
137   virtual Object_id se_private_id() const = 0;
138   virtual void set_se_private_id(Object_id se_private_id) = 0;
139 
140   /////////////////////////////////////////////////////////////////////////
141   // Tablespace.
142   /////////////////////////////////////////////////////////////////////////
143 
144   virtual Object_id tablespace_id() const = 0;
145   virtual void set_tablespace_id(Object_id tablespace_id) = 0;
146 
147   /////////////////////////////////////////////////////////////////////////
148   // Partition-value collection.
149   /////////////////////////////////////////////////////////////////////////
150 
151   virtual Partition_value *add_value() = 0;
152 
153   virtual const Partition_values &values() const = 0;
154 
155   /////////////////////////////////////////////////////////////////////////
156   // Partition-index collection.
157   /////////////////////////////////////////////////////////////////////////
158 
159   virtual Partition_index *add_index(Index *idx) = 0;
160 
161   virtual const Partition_indexes &indexes() const = 0;
162 
163   virtual Partition_indexes *indexes() = 0;
164 
165   /////////////////////////////////////////////////////////////////////////
166   // Sub Partition collection.
167   /////////////////////////////////////////////////////////////////////////
168 
169   /// Add a subpartition to a parent partition.
170   virtual Partition *add_subpartition() = 0;
171 
172   /// Return reference to const collection of sub partitions.
173   virtual const Table::Partition_collection &subpartitions() const = 0;
174 
175   /// Return non-const point to collection of sub partitions.
176   virtual Table::Partition_collection *subpartitions() = 0;
177 
178   /////////////////////////////////////////////////////////////////////////
179   // Parent partition for subpartitions (NULL otherwise).
180   /////////////////////////////////////////////////////////////////////////
181   virtual const Partition *parent() const = 0;
182   virtual void set_parent(const Partition *parent) = 0;
183 
184   /**
185     Converts *this into json.
186 
187     Converts all member variables that are to be included in the sdi
188     into json by transforming them appropriately and passing them to
189     the rapidjson writer provided.
190 
191     @param wctx opaque context for data needed by serialization
192     @param w rapidjson writer which will perform conversion to json
193 
194   */
195 
196   virtual void serialize(Sdi_wcontext *wctx, Sdi_writer *w) const = 0;
197 
198   /**
199     Re-establishes the state of *this by reading sdi information from
200     the rapidjson DOM subobject provided.
201 
202     Cross-references encountered within this object are tracked in
203     sdictx, so that they can be updated when the entire object graph
204     has been established.
205 
206     @param rctx stores book-keeping information for the
207     deserialization process
208     @param val subobject of rapidjson DOM containing json
209     representation of this object
210   */
211 
212   virtual bool deserialize(Sdi_rcontext *rctx, const RJ_Value &val) = 0;
213 };
214 
215 ///////////////////////////////////////////////////////////////////////////
216 
217 }  // namespace dd
218 
219 #endif  // DD__PARTITION_INCLUDED
220