MySQL 9.3.0
Source Code Documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
insert.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_INSERT_H_
27#define ROUTER_SRC_MYSQL_REST_SERVICE_SRC_MRS_DATABASE_JSON_MAPPER_INSERT_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>
49
50namespace mrs {
51namespace database {
52namespace dv {
53
55 protected:
56 friend class RowUpdate;
57
58 public:
59 RowInsert(std::shared_ptr<Operation> parent, std::shared_ptr<Table> table,
60 const ObjectRowOwnership &row_ownership, bool upsert)
61 : RowChangeOperation(parent, table, row_ownership), upsert_(upsert) {}
62
63 void run(MySQLSession *session) override;
64
65 virtual void on_pre_insert(MySQLSession *) {}
66 virtual void on_post_insert(MySQLSession *) {}
67
68 void process(JSONInputObject input) override;
69
70 protected:
72 JSONInputArray input) override;
73
74 std::shared_ptr<RowChangeOperation> add_dummy_update_referenced_from_this(
75 const ForeignKeyReference &fk, const PrimaryKeyColumnValues &pk) override;
76
77 protected:
79
82
83 protected:
86 bool upsert_ = false;
87};
88
90 public:
91 AutoIncRowInsert(std::shared_ptr<Operation> parent,
92 std::shared_ptr<Table> table, const Column *generated_column,
93 const ObjectRowOwnership &row_ownership, bool upsert)
94 : RowInsert(parent, table, row_ownership, upsert),
95 gen_id_column_(generated_column) {
96 assert(gen_id_column_);
97 }
98
99 void on_post_insert(MySQLSession *session) override;
100
101 private:
103};
104
106 public:
107 ReverseUuidRowInsert(std::shared_ptr<Operation> parent,
108 std::shared_ptr<Table> table,
109 const Column *generated_column,
110 const ObjectRowOwnership &row_ownership, bool upsert)
111 : RowInsert(parent, table, row_ownership, upsert),
112 gen_id_column_(generated_column) {
113 assert(gen_id_column_);
114 }
115
116 void on_pre_insert(MySQLSession *session) override;
117
118 static void set_generate_uuid(
119 std::function<mysqlrouter::sqlstring(MySQLSession *)> fn);
120
121 private:
123};
124
125std::shared_ptr<RowInsert> make_row_insert(
126 std::shared_ptr<JsonMappingUpdater::Operation> parent,
127 std::shared_ptr<Table> table, const ObjectRowOwnership &row_ownership);
128
129std::shared_ptr<RowInsert> make_row_upsert(
130 std::shared_ptr<JsonMappingUpdater::Operation> parent,
131 std::shared_ptr<Table> table, const ObjectRowOwnership &row_ownership);
132
133} // namespace dv
134} // namespace database
135} // namespace mrs
136
137#endif // ROUTER_SRC_MYSQL_REST_SERVICE_SRC_MRS_DATABASE_JSON_MAPPER_INSERT_H_
Definition: object_row_ownership.h:45
AutoIncRowInsert(std::shared_ptr< Operation > parent, std::shared_ptr< Table > table, const Column *generated_column, const ObjectRowOwnership &row_ownership, bool upsert)
Definition: insert.h:91
void on_post_insert(MySQLSession *session) override
Definition: insert.cc:157
const Column * gen_id_column_
Definition: insert.h:102
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
static void set_generate_uuid(std::function< mysqlrouter::sqlstring(MySQLSession *)> fn)
Definition: insert.cc:170
ReverseUuidRowInsert(std::shared_ptr< Operation > parent, std::shared_ptr< Table > table, const Column *generated_column, const ObjectRowOwnership &row_ownership, bool upsert)
Definition: insert.h:107
void on_pre_insert(MySQLSession *session) override
Definition: insert.cc:178
const Column * gen_id_column_
Definition: insert.h:122
Definition: insert.h:54
bool upsert_
Definition: insert.h:86
virtual void on_pre_insert(MySQLSession *)
Definition: insert.h:65
virtual void on_post_insert(MySQLSession *)
Definition: insert.h:66
void process_to_many(const ForeignKeyReference &fk, JSONInputArray input) override
Definition: insert.cc:76
mysqlrouter::sqlstring insert_sql() const
Definition: insert.cc:126
std::shared_ptr< RowChangeOperation > add_dummy_update_referenced_from_this(const ForeignKeyReference &fk, const PrimaryKeyColumnValues &pk) override
Definition: insert.cc:116
RowInsert(std::shared_ptr< Operation > parent, std::shared_ptr< Table > table, const ObjectRowOwnership &row_ownership, bool upsert)
Definition: insert.h:59
bool references_from_this_resolved_
Definition: insert.h:85
void run(MySQLSession *session) override
Definition: insert.cc:52
bool references_to_this_resolved_
Definition: insert.h:84
void process(JSONInputObject input) override
Definition: insert.cc:70
Definition: update.h:74
Definition: mysql_session.h:157
Definition: utils_sqlstring.h:67
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
std::shared_ptr< RowInsert > make_row_upsert(std::shared_ptr< JsonMappingUpdater::Operation > parent, std::shared_ptr< Table > table, const ObjectRowOwnership &row_ownership)
Definition: insert.cc:224
entry::Column Column
Definition: select.h:53
std::shared_ptr< RowInsert > make_row_insert(std::shared_ptr< JsonMappingUpdater::Operation > parent, std::shared_ptr< Table > table, const ObjectRowOwnership &row_ownership)
Definition: insert.cc:218
std::map< std::string, mysqlrouter::sqlstring > PrimaryKeyColumnValues
Definition: select.h:43
Definition: authorize_manager.h:48