Skip to content

Commit 80c7195

Browse files
committed
WL11450: New document _id generation support
1 parent 5939bf3 commit 80c7195

39 files changed

+481
-436
lines changed

cdk/cmake/protobuf.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ MACRO(USE_FULL_PROTOBUF)
184184
set(PROTOBUF_LITE OFF CACHE BOOL "Using lite version of Protobuf library" FORCE)
185185
ENDMACRO()
186186

187-
188187
# Standard PROTOBUF_GENERATE_CPP modified to our usage
189188

190189
FUNCTION(MYSQLX_PROTOBUF_GENERATE_CPP SRCS HDRS)
@@ -213,6 +212,7 @@ FUNCTION(MYSQLX_PROTOBUF_GENERATE_CPP SRCS HDRS)
213212
COMMAND ${PROTOBUF_PROTOC_EXECUTABLE}
214213
ARGS --cpp_out "${CMAKE_CURRENT_BINARY_DIR}/protobuf"
215214
-I ${ABS_PATH} ${ABS_FIL}
215+
--proto_path=${PROJECT_SOURCE_DIR}/protobuf/protobuf-2.6.1/src
216216
DEPENDS ${ABS_FIL} ${PROTOBUF_PROTOC_EXECUTABLE}
217217
COMMENT "Running C++ protocol buffer compiler (${PROTOBUF_PROTOC_EXECUTABLE}) on ${FIL}"
218218
VERBATIM)

cdk/include/mysql/cdk/mysqlx/result.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class Reply
5454

5555
mysqlx::Session* m_session;
5656
Diagnostic_arena m_da;
57+
std::vector<std::string> m_generated_ids;
5758
bool m_error;
5859

5960
Session& get_session()
@@ -119,6 +120,11 @@ class Reply
119120
return m_session->m_stmt_stats.last_insert_id;
120121
}
121122

123+
const std::vector<std::string>& generated_ids() const
124+
{
125+
return m_generated_ids;
126+
}
127+
122128
virtual void discard();
123129

124130
protected:

cdk/include/mysql/cdk/mysqlx/session.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,7 @@ class Session
692692
void row_stats(row_stats_t, row_count_t);
693693
void last_insert_id(insert_id_t);
694694
// TODO: void trx_event(trx_event_t);
695+
void generated_document_id(const std::string&);
695696

696697
/*
697698
Helper functions to send/receive protocol messages

cdk/include/mysql/cdk/protocol/mysqlx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,7 @@ class SessionState_processor
10721072
virtual void row_stats(row_stats_t, row_count_t) {}
10731073
virtual void last_insert_id(insert_id_t) {}
10741074
virtual void trx_event(trx_event_t) {}
1075+
virtual void generated_document_id(const std::string&) {}
10751076
};
10761077

10771078
template<>

cdk/include/mysql/cdk/reply.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ class Reply
7171
void skip_result() { m_impl.skip_result(); }
7272
row_count_t affected_rows() { return m_impl.affected_rows(); }
7373
row_count_t last_insert_id() { return m_impl.last_insert_id(); }
74+
const std::vector<std::string>& generated_ids() const
75+
{ return m_impl.generated_ids(); }
7476
void discard() { m_impl.discard(); }
7577

7678
// Diagnostics interface

cdk/mysqlx/session.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,13 @@ void Session::row_stats(row_stats_t stats, row_count_t val)
904904
}
905905
}
906906

907+
void Session::generated_document_id(const std::string& id)
908+
{
909+
if (m_current_reply)
910+
{
911+
m_current_reply->m_generated_ids.push_back(id);
912+
}
913+
}
907914

908915
void Session::send_cmd()
909916
{

cdk/protocol/mysqlx/CMakeLists.txt

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,33 @@ if(NOT use_full_protobuf)
7575
set(LITE "${CMAKE_CURRENT_BINARY_DIR}/lite")
7676
file(MAKE_DIRECTORY ${LITE})
7777

78+
UNSET(proto_mysqlx_defs_lite)
79+
7880
foreach(proto ${proto_mysqlx_defs})
7981
get_filename_component(name ${proto} NAME)
8082
#message("Generating lite version of protobuf source: ${name}")
8183
file(READ "${proto}" CONTENTS)
82-
string(REPLACE
83-
"syntax = \"proto2\""
84-
"syntax = \"proto2\";\noption optimize_for = LITE_RUNTIME"
85-
CONTENTS "${CONTENTS}")
86-
file(WRITE "${LITE}/${name}" "${CONTENTS}")
84+
unset(NEW_CONTENTS)
85+
FOREACH(LINE ${CONTENTS})
86+
STRING(REGEX REPLACE
87+
"([\\t ]*)//[\\t ]*ifdef[\\t ]+(PROTOBUF_LITE)[\\t ]*:[\\t ]*(.*)" "\\1\\3"
88+
LINE ${LINE}
89+
)
90+
LIST(APPEND NEW_CONTENTS "${LINE}")
91+
ENDFOREACH()
92+
93+
STRING(REGEX REPLACE
94+
"//[\\t ]+ifndef[\\t ]+PROTOBUF_LITE.*//[\\t ]+endif[\\t ]*" ""
95+
NEW_CONTENTS "${NEW_CONTENTS}")
96+
97+
STRING(REGEX REPLACE
98+
"(\r*\n)([^\r\n]*//[\\t ]+comment_out_if[\\t ]+PROTOBUF_LITE)" "\\1// \\2"
99+
NEW_CONTENTS "${NEW_CONTENTS}")
100+
101+
file(WRITE "${LITE}/${name}" "${NEW_CONTENTS}")
87102
#configure_file(lite_template.in "${LITE}/${name}" @ONLY)
88-
list(APPEND proto_mysqlx_defs_lite "${LITE}/${name}")
103+
104+
list(APPEND proto_mysqlx_defs_lite "${LITE}/${name}")
89105
endforeach()
90106

91107
set(proto_mysqlx_defs ${proto_mysqlx_defs_lite})

cdk/protocol/mysqlx/pb/mysqlx.proto

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
/*
2-
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
33
*
4-
* This program is free software; you can redistribute it and/or
5-
* modify it under the terms of the GNU General Public License as
6-
* published by the Free Software Foundation; version 2 of the
7-
* License.
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.
87
*
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+
*
915
* This program is distributed in the hope that it will be useful,
1016
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12-
* GNU General Public License for more details.
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU General Public License, version 2.0, for more details.
1319
*
1420
* You should have received a copy of the GNU General Public License
1521
* along with this program; if not, write to the Free Software
16-
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
17-
* 02110-1301 USA
22+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1823
*/
1924

2025
// tell protobuf 3.0 to use protobuf 2.x rules
@@ -23,15 +28,9 @@ syntax = "proto2";
2328
// ifdef PROTOBUF_LITE: option optimize_for = LITE_RUNTIME;
2429

2530
package Mysqlx;
26-
option java_package = "com.mysql.cj.mysqlx.protobuf";
31+
option java_package = "com.mysql.cj.x.protobuf";
2732

28-
import "mysqlx_sql.proto";
29-
import "mysqlx_resultset.proto";
30-
import "mysqlx_crud.proto";
31-
import "mysqlx_session.proto";
32-
import "mysqlx_connection.proto";
33-
import "mysqlx_expect.proto";
34-
import "mysqlx_notice.proto";
33+
import "google/protobuf/descriptor.proto"; // comment_out_if PROTOBUF_LITE
3534

3635
// style-guide:
3736
//
@@ -110,11 +109,18 @@ message ServerMessages {
110109
RESULTSET_FETCH_DONE_MORE_OUT_PARAMS = 18;
111110
};
112111
}
113-
112+
// ifndef PROTOBUF_LITE
113+
extend google.protobuf.MessageOptions {
114+
optional ClientMessages.Type client_message_id = 100001;
115+
optional ServerMessages.Type server_message_id = 100002;
116+
}
117+
// endif
114118

115119
// generic Ok message
116120
message Ok {
117121
optional string msg = 1;
122+
123+
option (server_message_id) = OK; // comment_out_if PROTOBUF_LITE
118124
}
119125

120126

@@ -141,4 +147,6 @@ message Error {
141147
ERROR = 0;
142148
FATAL = 1;
143149
};
150+
151+
option (server_message_id) = ERROR; // comment_out_if PROTOBUF_LITE
144152
}
Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
11
/*
2-
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
33
*
4-
* This program is free software; you can redistribute it and/or
5-
* modify it under the terms of the GNU General Public License as
6-
* published by the Free Software Foundation; version 2 of the
7-
* License.
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.
87
*
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+
*
915
* This program is distributed in the hope that it will be useful,
1016
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12-
* GNU General Public License for more details.
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU General Public License, version 2.0, for more details.
1319
*
1420
* You should have received a copy of the GNU General Public License
1521
* along with this program; if not, write to the Free Software
16-
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
17-
* 02110-1301 USA
22+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1823
*/
1924
syntax = "proto2";
2025

2126
// ifdef PROTOBUF_LITE: option optimize_for = LITE_RUNTIME;
2227

2328
import "mysqlx_datatypes.proto";
29+
import "mysqlx.proto"; // comment_out_if PROTOBUF_LITE
2430

2531
package Mysqlx.Connection;
26-
option java_package = "com.mysql.cj.mysqlx.protobuf";
32+
option java_package = "com.mysql.cj.x.protobuf";
2733

2834
// a Capability
2935
//
@@ -36,13 +42,16 @@ message Capability {
3642
// Capabilities
3743
message Capabilities {
3844
repeated Capability capabilities = 1;
45+
46+
option (server_message_id) = CONN_CAPABILITIES; // comment_out_if PROTOBUF_LITE
3947
}
4048

4149
// get supported connection capabilities and their current state
4250
//
4351
// :returns: :protobuf:msg:`Mysqlx.Connection::Capabilities` or :protobuf:msg:`Mysqlx::Error`
4452
//
4553
message CapabilitiesGet {
54+
option (client_message_id) = CON_CAPABILITIES_GET; // comment_out_if PROTOBUF_LITE
4655
};
4756

4857
// sets connection capabilities atomically
@@ -54,6 +63,8 @@ message CapabilitiesGet {
5463
// :returns: :protobuf:msg:`Mysqlx::Ok` or :protobuf:msg:`Mysqlx::Error`
5564
message CapabilitiesSet {
5665
required Capabilities capabilities = 1;
66+
67+
option (client_message_id) = CON_CAPABILITIES_SET; // comment_out_if PROTOBUF_LITE
5768
};
5869

5970
// announce to the server that the client wants to close the connection
@@ -62,5 +73,6 @@ message CapabilitiesSet {
6273
//
6374
// :Returns: :protobuf:msg:`Mysqlx::Ok`
6475
message Close {
76+
option (client_message_id) = CON_CLOSE; // comment_out_if PROTOBUF_LITE
6577
};
6678

0 commit comments

Comments
 (0)