MySQL 9.3.0
Source Code Documentation
update.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024, 2025, Oracle and/or its affiliates.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2.0,
6 * as published by the Free Software Foundation.
7 *
8 * This program is designed to work with certain software (including
9 * but not limited to OpenSSL) that is licensed under separate terms,
10 * as designated in a particular file or component or in included license
11 * documentation. The authors of MySQL hereby grant you an additional
12 * permission to link the program and your derivative works with the
13 * separately licensed software that they have either included with
14 * the program or referenced in the documentation.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
19 * the GNU General Public License, version 2.0, for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26#ifndef ROUTER_SRC_MYSQL_REST_SERVICE_SRC_MRS_DATABASE_JSON_MAPPER_VIEW_UPDATE_H_
27#define ROUTER_SRC_MYSQL_REST_SERVICE_SRC_MRS_DATABASE_JSON_MAPPER_VIEW_UPDATE_H_
28
29#ifdef RAPIDJSON_NO_SIZETYPEDEFINE
30#include "my_rapidjson_size_t.h"
31#endif
32
33#include <rapidjson/document.h>
34#include <list>
35#include <map>
36#include <memory>
37#include <string>
38#include <utility>
39#include <vector>
50
51namespace mrs {
52namespace database {
53namespace dv {
54
56 public:
57 RowUpdateBase(std::shared_ptr<JsonMappingUpdater::Operation> parent,
58 std::shared_ptr<Table> table, const PrimaryKeyColumnValues &pk,
59 const ObjectRowOwnership &row_ownership);
60
61 RowUpdateBase(std::shared_ptr<JsonMappingUpdater::Operation> parent,
62 std::shared_ptr<Table> table,
63 const ObjectRowOwnership &row_ownership);
64
66 JSONInputArray input) override;
67
68 void run(MySQLSession *session) override;
69
70 protected:
71 virtual void do_update(MySQLSession *session) = 0;
72};
73
74class RowUpdate : public RowUpdateBase {
75 public:
76 RowUpdate(std::shared_ptr<JsonMappingUpdater::Operation> parent,
77 std::shared_ptr<Table> table, const PrimaryKeyColumnValues &pk,
78 const ObjectRowOwnership &row_ownership);
79
80 void on_value(const Column &column,
82
83 void on_value(const Column &column,
84 const mysqlrouter::sqlstring &value) override;
85
86 void on_no_value(const Column &column,
87 const JSONInputObject::MemberReference &) override;
88
90 const ForeignKeyReference &fk, const JSONInputObject &input,
91 std::optional<PrimaryKeyColumnValues> child_pk) override;
92
94
95 protected:
96 void do_update(MySQLSession *session) override;
97
99 const char *separator) const;
100
101 RowUpdate(std::shared_ptr<JsonMappingUpdater::Operation> parent,
102 std::shared_ptr<Table> table,
103 const ObjectRowOwnership &row_ownership)
104 : RowUpdateBase(parent, table, row_ownership) {}
105
106 private:
107 // whether to error if affected rows = 0
109
111};
112
114 public:
115 RowUpdateReferencing(std::shared_ptr<JsonMappingUpdater::Operation> parent,
116 std::shared_ptr<Table> table,
117 const ObjectRowOwnership &row_ownership);
118
119 protected:
120 void do_update(MySQLSession *session) override;
121
123};
124
126 public:
127 RowNoUpdateOrIgnore(std::shared_ptr<JsonMappingUpdater::Operation> parent,
128 std::shared_ptr<Table> table,
129 const PrimaryKeyColumnValues &pk,
130 const ObjectRowOwnership &row_ownership)
131 : RowUpdateBase(parent, table, pk, row_ownership) {}
132
133 protected:
134 void do_update([[maybe_unused]] MySQLSession *session) override { /* no-op */
135 }
136};
137
139 public:
140 RowNoUpdateOrError(std::shared_ptr<JsonMappingUpdater::Operation> parent,
141 std::shared_ptr<Table> table,
142 const PrimaryKeyColumnValues &pk,
143 const ObjectRowOwnership &row_ownership)
144 : RowUpdate(parent, table, pk, row_ownership) {}
145
146 protected:
147 void do_update(MySQLSession *session) override;
148
149 private:
151
152 void on_row(const ResultRow &r) override;
153
155};
156
157std::shared_ptr<RowUpdate> make_row_update(
158 std::shared_ptr<JsonMappingUpdater::Operation> parent,
159 std::shared_ptr<Table> table, const PrimaryKeyColumnValues &pk,
160 const ObjectRowOwnership &row_ownership);
161
162std::shared_ptr<RowNoUpdateOrIgnore> make_row_no_update_or_ignore(
163 std::shared_ptr<JsonMappingUpdater::Operation> parent,
164 std::shared_ptr<Table> table, const PrimaryKeyColumnValues &pk,
165 const ObjectRowOwnership &row_ownership);
166
167std::shared_ptr<RowNoUpdateOrError> make_row_no_update_or_error(
168 std::shared_ptr<JsonMappingUpdater::Operation> parent,
169 std::shared_ptr<Table> table, const PrimaryKeyColumnValues &pk,
170 const ObjectRowOwnership &row_ownership);
171
172} // namespace dv
173} // namespace database
174} // namespace mrs
175
176#endif // ROUTER_SRC_MYSQL_REST_SERVICE_SRC_MRS_DATABASE_JSON_MAPPER_VIEW_UPDATE_H_
Definition: object_row_ownership.h:45
MySQLSession::ResultRow ResultRow
Definition: query.h:41
Definition: json_input.h:157
Definition: json_input.h:61
std::shared_ptr< Operation > parent() const
Definition: change.h:82
const std::shared_ptr< Table > & table() const
Definition: change.h:80
RowNoUpdateOrError(std::shared_ptr< JsonMappingUpdater::Operation > parent, std::shared_ptr< Table > table, const PrimaryKeyColumnValues &pk, const ObjectRowOwnership &row_ownership)
Definition: update.h:140
mysqlrouter::sqlstring update_sql() const
Definition: update.cc:322
bool input_matches_row_
Definition: update.h:154
void do_update(MySQLSession *session) override
Definition: update.cc:336
void on_row(const ResultRow &r) override
Definition: update.cc:347
void do_update(MySQLSession *session) override
Definition: update.h:134
RowNoUpdateOrIgnore(std::shared_ptr< JsonMappingUpdater::Operation > parent, std::shared_ptr< Table > table, const PrimaryKeyColumnValues &pk, const ObjectRowOwnership &row_ownership)
Definition: update.h:127
Definition: update.h:55
void process_to_many(const ForeignKeyReference &fk, JSONInputArray input) override
Definition: update.cc:60
virtual void do_update(MySQLSession *session)=0
void run(MySQLSession *session) override
Definition: update.cc:48
RowUpdateBase(std::shared_ptr< JsonMappingUpdater::Operation > parent, std::shared_ptr< Table > table, const PrimaryKeyColumnValues &pk, const ObjectRowOwnership &row_ownership)
Definition: update.cc:35
RowUpdateReferencing(std::shared_ptr< JsonMappingUpdater::Operation > parent, std::shared_ptr< Table > table, const ObjectRowOwnership &row_ownership)
Definition: update.cc:283
mysqlrouter::sqlstring update_sql() const
Definition: update.cc:293
void do_update(MySQLSession *session) override
Definition: update.cc:288
Definition: update.h:74
bool feed_columns(mysqlrouter::sqlstring &sql, bool is_null, const char *separator) const
Definition: update.cc:240
void set_error_if_not_found(bool flag)
Definition: update.h:93
mysqlrouter::sqlstring update_sql() const
Definition: update.cc:268
void on_value(const Column &column, const JSONInputObject::MemberReference &value) override
Definition: update.cc:207
void on_no_value(const Column &column, const JSONInputObject::MemberReference &) override
Definition: update.cc:232
void on_referenced_row(const ForeignKeyReference &fk, const JSONInputObject &input, std::optional< PrimaryKeyColumnValues > child_pk) override
Definition: update.cc:157
void do_update(MySQLSession *session) override
Definition: update.cc:144
RowUpdate(std::shared_ptr< JsonMappingUpdater::Operation > parent, std::shared_ptr< Table > table, const PrimaryKeyColumnValues &pk, const ObjectRowOwnership &row_ownership)
Definition: update.cc:128
bool error_if_not_found_
Definition: update.h:108
RowUpdate(std::shared_ptr< JsonMappingUpdater::Operation > parent, std::shared_ptr< Table > table, const ObjectRowOwnership &row_ownership)
Definition: update.h:101
Definition: mysql_session.h:157
Definition: utils_sqlstring.h:67
static int flag
Definition: hp_test1.cc:40
static const char separator
Definition: item_func.cc:4454
Define rapidjson::SizeType to be std::uint64_t.
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
entry::ForeignKeyReference ForeignKeyReference
Definition: select.h:54
entry::Column Column
Definition: select.h:53
std::shared_ptr< RowNoUpdateOrError > make_row_no_update_or_error(std::shared_ptr< JsonMappingUpdater::Operation > parent, std::shared_ptr< Table > table, const PrimaryKeyColumnValues &pk, const ObjectRowOwnership &row_ownership)
Definition: update.cc:366
std::shared_ptr< RowUpdate > make_row_update(std::shared_ptr< JsonMappingUpdater::Operation > parent, std::shared_ptr< Table > table, const PrimaryKeyColumnValues &pk, const ObjectRowOwnership &row_ownership)
Definition: update.cc:351
std::shared_ptr< RowNoUpdateOrIgnore > make_row_no_update_or_ignore(std::shared_ptr< JsonMappingUpdater::Operation > parent, std::shared_ptr< Table > table, const PrimaryKeyColumnValues &pk, const ObjectRowOwnership &row_ownership)
Definition: update.cc:358
ValueType value(const std::optional< ValueType > &v)
Definition: gtid.h:83
std::map< std::string, mysqlrouter::sqlstring > PrimaryKeyColumnValues
Definition: select.h:43
Definition: authorize_manager.h:48
bool is_null(poly_thread thread, poly_value value)
Definition: jit_executor_type_conversion.cc:46
const mysql_service_registry_t * r
Definition: pfs_example_plugin_employee.cc:86