1 /*
2  * Copyright (c) 2015, 2021, 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 also distributed 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 included with MySQL.
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
23  * 02110-1301  USA
24  */
25 
26 #ifndef _XPL_CRUD_CMD_HANDLER_H_
27 #define _XPL_CRUD_CMD_HANDLER_H_
28 
29 #include "ngs/error_code.h"
30 #include "ngs/protocol_fwd.h"
31 #include "query_string_builder.h"
32 #include "sql_data_context.h"
33 #include "xpl_session_status_variables.h"
34 
35 
36 namespace xpl
37 {
38 class Session;
39 
40 class Crud_command_handler
41 {
42 public:
Crud_command_handler()43   Crud_command_handler() : m_qb(1024) {}
44 
45   ngs::Error_code execute_crud_insert(Session &session,
46                                       const Mysqlx::Crud::Insert &msg);
47   ngs::Error_code execute_crud_update(Session &session,
48                                       const Mysqlx::Crud::Update &msg);
49   ngs::Error_code execute_crud_find(Session &session,
50                                     const Mysqlx::Crud::Find &msg);
51   ngs::Error_code execute_crud_delete(Session &session,
52                                       const Mysqlx::Crud::Delete &msg);
53 
54   ngs::Error_code execute_create_view(Session &session,
55                                       const Mysqlx::Crud::CreateView &msg);
56   ngs::Error_code execute_modify_view(Session &session,
57                                       const Mysqlx::Crud::ModifyView &msg);
58   ngs::Error_code execute_drop_view(Session &session,
59                                     const Mysqlx::Crud::DropView &msg);
60 
61 private:
62  typedef Common_status_variables::Variable
63      Common_status_variables::*Status_variable;
64 
65   template <typename B, typename M>
66   ngs::Error_code execute(Session &session, const B &builder, const M &msg,
67                           Status_variable variable,
68                           bool (ngs::Protocol_encoder::*send_ok)());
69 
70   template <typename M>
error_handling(const ngs::Error_code & error,const M &)71   ngs::Error_code error_handling(const ngs::Error_code &error,
72                                  const M & /*msg*/) const
73   {
74     return error;
75   }
76 
77   template <typename M>
78   void notice_handling(Session &session,
79                        const Sql_data_context::Result_info &info,
80                        const M &msg) const;
81 
82   void notice_handling_common(Session &session,
83                               const Sql_data_context::Result_info &info) const;
84 
85   template <typename M>
86   ngs::Error_code sql_execute(Session &session,
87                               Sql_data_context::Result_info &info) const;
88 
89   Query_string_builder m_qb;
90 };
91 
92 } // namespace xpl
93 
94 #endif // _XPL_CRUD_CMD_HANDLER_H_
95