MySQL 8.0.40
Source Code Documentation
entity_object_impl.h
Go to the documentation of this file.
1/* Copyright (c) 2014, 2024, 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 designed to work 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 either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef DD__ENTITY_OBJECT_IMPL_INCLUDED
25#define DD__ENTITY_OBJECT_IMPL_INCLUDED
26
28#include "sql/dd/impl/types/weak_object_impl.h" // Weak_object_impl
29#include "sql/dd/object_id.h"
30#include "sql/dd/sdi_fwd.h"
31#include "sql/dd/string_type.h"
32#include "sql/dd/types/entity_object.h" // Entity_object
34
35namespace dd {
36
37///////////////////////////////////////////////////////////////////////////
38
39class Object_key;
40class Sdi_rcontext;
41class Sdi_wcontext;
42
43class Entity_object_impl : virtual public Entity_object,
44 public Weak_object_impl {
45 public:
47
48 public:
49 Object_id id() const override { return m_id; }
50
51 /* non-virtual */ void set_id(Object_id id) {
52 m_id = id;
54 }
55
56 /* purecov: begin deadcode */
57 bool is_persistent() const override { return (m_id != INVALID_OBJECT_ID); }
58 /* purecov: end */
59
60 const String_type &name() const override { return m_name; }
61
62 void set_name(const String_type &name) override { m_name = name; }
63
64 Object_key *create_primary_key() const override;
65
66 bool has_new_primary_key() const override { return m_has_new_primary_key; }
67
68 Entity_object_impl *impl() override { return this; }
69 const Entity_object_impl *impl() const override { return this; }
70
71 protected:
72 void set_primary_key_value(const Raw_new_record &r) override;
73
74 void fix_has_new_primary_key() override {
76 }
77
78 void restore_id(const Raw_record &r, int field_idx);
79 void restore_name(const Raw_record &r, int field_idx);
80
81 bool store_id(Raw_record *r, int field_idx);
82 bool store_name(Raw_record *r, int field_idx);
83 bool store_name(Raw_record *r, int field_idx, bool is_null);
84
85 void serialize(Sdi_wcontext *wctx, Sdi_writer *w) const;
86 bool deserialize(Sdi_rcontext *rctx, const RJ_Value &val);
87
88 private:
89 // NOTE: ID and Name attributes *must* remain private so that we can track
90 // changes in them and prevent abuse.
91
93
95
96 /**
97 Indicates that object is guaranteed to have ID which doesn't exist in
98 database because it will be or just was generated using auto-increment.
99 Main difference of this member from result of m_id == INVALID_OBJECT_ID
100 check is that we delay resetting of this flag until end of store() method
101 while m_id is updated right after object was inserted into the table.
102 This is necessary to let entity's children figure out that their parent
103 has new ID which was not used before (and hence their primary keys based
104 on this ID will be new too) while still giving access to the exact value
105 of new ID.
106 */
108
109 protected:
110 // The generated copy constructor could have been used,
111 // but by adding this we force derived classes which define
112 // their own copy constructor to also invoke the Entity_object_impl
113 // copy constructor in the initializer list.
114 // Note that we must copy the m_has_new_primary_key property to make sure
115 // the clone is handled correctly if storing it persistently as part of
116 // updating a DD object.
118 : Weak_object(src),
119 m_id(src.m_id),
120 m_name(src.m_name),
122};
123
124///////////////////////////////////////////////////////////////////////////
125
126} // namespace dd
127
128#endif // DD__ENTITY_OBJECT_IMPL_INCLUDED
Definition: entity_object_impl.h:44
Entity_object_impl()
Definition: entity_object_impl.h:46
Object_key * create_primary_key() const override
Definition: entity_object_impl.cc:62
void set_name(const String_type &name) override
Definition: entity_object_impl.h:62
bool store_id(Raw_record *r, int field_idx)
Definition: entity_object_impl.cc:80
bool m_has_new_primary_key
Indicates that object is guaranteed to have ID which doesn't exist in database because it will be or ...
Definition: entity_object_impl.h:107
void set_primary_key_value(const Raw_new_record &r) override
Definition: entity_object_impl.cc:46
Entity_object_impl(const Entity_object_impl &src)
Definition: entity_object_impl.h:117
bool has_new_primary_key() const override
Indicates that object is guaranteed to have primary key value which doesn't exist in database (e....
Definition: entity_object_impl.h:66
void set_id(Object_id id)
Definition: entity_object_impl.h:51
void fix_has_new_primary_key() override
Definition: entity_object_impl.h:74
void restore_name(const Raw_record &r, int field_idx)
Definition: entity_object_impl.cc:75
Object_id id() const override
The unique dictionary object id.
Definition: entity_object_impl.h:49
void serialize(Sdi_wcontext *wctx, Sdi_writer *w) const
Definition: entity_object_impl.cc:99
void restore_id(const Raw_record &r, int field_idx)
Definition: entity_object_impl.cc:68
const String_type & name() const override
Definition: entity_object_impl.h:60
const Entity_object_impl * impl() const override
Definition: entity_object_impl.h:69
Entity_object_impl * impl() override
Definition: entity_object_impl.h:68
String_type m_name
Definition: entity_object_impl.h:94
Object_id m_id
Definition: entity_object_impl.h:92
bool deserialize(Sdi_rcontext *rctx, const RJ_Value &val)
Definition: entity_object_impl.cc:105
bool store_name(Raw_record *r, int field_idx)
Definition: entity_object_impl.cc:93
bool is_persistent() const override
Is dictionary object persistent in dictionary tables ?
Definition: entity_object_impl.h:57
Base class for dictionary objects which has single column integer primary key.
Definition: entity_object.h:48
Definition: object_key.h:38
Definition: raw_record.h:141
Definition: raw_record.h:46
Opaque context which keeps reusable resoureces needed during deserialization.
Definition: sdi.cc:231
Opaque context which keeps reusable resources needed during serialization.
Definition: sdi.cc:129
Definition: weak_object_impl.h:48
Base class for all data dictionary objects.
Definition: weak_object.h:42
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:43
RJ_Writer Sdi_writer
Alias for the rapidjson Writer type to use in serialization.
Definition: sdi_fwd.h:64
unsigned long long Object_id
Definition: object_id.h:31
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:37
rapidjson::GenericValue< RJ_Encoding, RJ_Allocator > RJ_Value
Definition: sdi_fwd.h:49
Char_string_template< String_type_allocator > String_type
Definition: string_type.h:51
const mysql_service_registry_t * r
Definition: pfs_example_plugin_employee.cc:86
This header provides Rapidjson Type Aliases.