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