This is an automated email from the ASF dual-hosted git repository.
sunnianjun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 9836c0956d4 Add DatabaseProtocolServerInfo and
DatabaseProtocolDefaultVersionProvider (#25542)
9836c0956d4 is described below
commit 9836c0956d4fcb91632ae94594aabe2c67dd2092
Author: Liang Zhang <[email protected]>
AuthorDate: Wed May 10 01:17:16 2023 +0800
Add DatabaseProtocolServerInfo and DatabaseProtocolDefaultVersionProvider
(#25542)
* Rename MySQLSystemVariableValueProvider
* Add DatabaseProtocolServerInfo and DatabaseProtocolDefaultVersionProvider
---
.../DatabaseProtocolDefaultVersionProvider.java | 26 +++-----
.../constant/DatabaseProtocolServerInfo.java | 64 +++++++++++++++++++
.../constant/DatabaseProtocolServerInfoTest.java} | 13 ++--
...tureDatabaseProtocolDefaultVersionProvider.java | 28 +++-----
...constant.DatabaseProtocolDefaultVersionProvider | 18 ++++++
.../db/protocol/mysql/constant/MySQLConstants.java | 7 ++
.../MySQLProtocolDefaultVersionProvider.java} | 27 ++++----
.../protocol/mysql/constant/MySQLServerInfo.java | 74 ----------------------
.../packet/handshake/MySQLHandshakePacket.java | 9 +--
...constant.DatabaseProtocolDefaultVersionProvider | 18 ++++++
.../query/MySQLColumnDefinition41PacketTest.java | 6 +-
.../packet/handshake/MySQLHandshakePacketTest.java | 31 ++++-----
.../MySQLHandshakeResponse41PacketTest.java | 34 +++++-----
.../OpenGaussProtocolDefaultVersionProvider.java | 27 ++++----
...constant.DatabaseProtocolDefaultVersionProvider | 18 ++++++
.../PostgreSQLProtocolDefaultVersionProvider.java | 27 ++++----
.../postgresql/constant/PostgreSQLServerInfo.java | 62 ------------------
...constant.DatabaseProtocolDefaultVersionProvider | 18 ++++++
...ReadwriteSplittingRuleStatementUpdaterTest.java | 1 -
.../connector/sane/MySQLSaneQueryResultEngine.java | 4 +-
.../admin/executor/MySQLSetCharsetExecutor.java | 4 +-
.../executor/MySQLSystemVariableQueryExecutor.java | 8 +--
.../admin/executor/ShowVersionExecutor.java | 6 +-
...ystemVariable.java => MySQLSystemVariable.java} | 30 ++++-----
....java => MySQLSystemVariableValueProvider.java} | 8 +--
.../TransactionIsolationValueProvider.java | 8 +--
.../provider/TransactionReadOnlyValueProvider.java | 8 +--
.../sysvar/provider/VersionValueProvider.java | 12 ++--
...MySQLMySQLSystemVariableQueryExecutorTest.java} | 10 +--
.../admin/executor/ShowVersionExecutorTest.java | 10 +--
.../TransactionIsolationValueProviderTest.java | 14 ++--
.../TransactionReadOnlyValueProviderTest.java | 14 ++--
.../sysvar/provider/VersionValueProviderTest.java | 12 ++--
.../version/ShardingSphereProxyVersionTest.java | 6 +-
.../proxy/frontend/mysql/MySQLFrontendEngine.java | 4 +-
.../frontend/mysql/MySQLFrontendEngineTest.java | 6 +-
.../opengauss/OpenGaussFrontendEngine.java | 4 +-
.../OpenGaussAuthenticationEngine.java | 4 +-
.../postgresql/PostgreSQLFrontendEngine.java | 4 +-
.../PostgreSQLAuthenticationEngine.java | 4 +-
40 files changed, 332 insertions(+), 356 deletions(-)
diff --git
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/sysvar/SystemVariableValueProvider.java
b/db-protocol/core/src/main/java/org/apache/shardingsphere/db/protocol/constant/DatabaseProtocolDefaultVersionProvider.java
similarity index 55%
copy from
proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/sysvar/SystemVariableValueProvider.java
copy to
db-protocol/core/src/main/java/org/apache/shardingsphere/db/protocol/constant/DatabaseProtocolDefaultVersionProvider.java
index d499115a6ce..f9065b65a2e 100644
---
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/sysvar/SystemVariableValueProvider.java
+++
b/db-protocol/core/src/main/java/org/apache/shardingsphere/db/protocol/constant/DatabaseProtocolDefaultVersionProvider.java
@@ -15,27 +15,21 @@
* limitations under the License.
*/
-package
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.sysvar;
+package org.apache.shardingsphere.db.protocol.constant;
-import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
+import org.apache.shardingsphere.infra.util.spi.annotation.SingletonSPI;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPI;
/**
- * System variable getter.
+ * Database protocol default version provider.
*/
-public interface SystemVariableValueProvider {
-
- SystemVariableValueProvider DEFAULT_VALUE_PROVIDER = new
SystemVariableValueProvider() {
- };
+@SingletonSPI
+public interface DatabaseProtocolDefaultVersionProvider extends TypedSPI {
/**
- * Get variable.
- *
- * @param scope scope
- * @param connectionSession connection session
- * @param variable variable
- * @return value of variable
+ * Provide default database version.
+ *
+ * @return default database version
*/
- default String get(Scope scope, ConnectionSession connectionSession,
SystemVariable variable) {
- return variable.getDefaultValue();
- }
+ String provide();
}
diff --git
a/db-protocol/core/src/main/java/org/apache/shardingsphere/db/protocol/constant/DatabaseProtocolServerInfo.java
b/db-protocol/core/src/main/java/org/apache/shardingsphere/db/protocol/constant/DatabaseProtocolServerInfo.java
new file mode 100644
index 00000000000..123d0e161a6
--- /dev/null
+++
b/db-protocol/core/src/main/java/org/apache/shardingsphere/db/protocol/constant/DatabaseProtocolServerInfo.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.db.protocol.constant;
+
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Database protocol server info.
+ */
+public final class DatabaseProtocolServerInfo {
+
+ private static final String SERVER_INFORMATION_PATTERN =
"%s-ShardingSphere-Proxy %s";
+
+ private static final Map<String, String> SERVER_INFORMATION_MAP = new
ConcurrentHashMap<>();
+
+ /**
+ * Set protocol version.
+ *
+ * @param databaseName database name
+ * @param protocolVersion protocol version
+ */
+ public static void setProtocolVersion(final String databaseName, final
String protocolVersion) {
+ SERVER_INFORMATION_MAP.put(databaseName,
String.format(SERVER_INFORMATION_PATTERN, protocolVersion,
CommonConstants.PROXY_VERSION.get()));
+ }
+
+ /**
+ * Get protocol version.
+ *
+ * @param databaseName database name
+ * @param databaseType database type
+ * @return protocol version
+ */
+ public static String getProtocolVersion(final String databaseName, final
String databaseType) {
+ return null == databaseName ? getDefaultProtocolVersion(databaseType)
: SERVER_INFORMATION_MAP.getOrDefault(databaseName,
getDefaultProtocolVersion(databaseType));
+ }
+
+ /**
+ * Get default protocol version.
+ *
+ * @param databaseType database type
+ * @return default protocol version
+ */
+ public static String getDefaultProtocolVersion(final String databaseType) {
+ return String.format(SERVER_INFORMATION_PATTERN,
TypedSPILoader.getService(DatabaseProtocolDefaultVersionProvider.class,
databaseType).provide(), CommonConstants.PROXY_VERSION.get());
+ }
+}
diff --git
a/db-protocol/postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/constant/PostgreSQLServerInfoTest.java
b/db-protocol/core/src/test/java/org/apache/shardingsphere/db/protocol/constant/DatabaseProtocolServerInfoTest.java
similarity index 70%
rename from
db-protocol/postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/constant/PostgreSQLServerInfoTest.java
rename to
db-protocol/core/src/test/java/org/apache/shardingsphere/db/protocol/constant/DatabaseProtocolServerInfoTest.java
index a7f0ed7caa6..ce15e28b142 100644
---
a/db-protocol/postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/constant/PostgreSQLServerInfoTest.java
+++
b/db-protocol/core/src/test/java/org/apache/shardingsphere/db/protocol/constant/DatabaseProtocolServerInfoTest.java
@@ -15,26 +15,25 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.db.protocol.postgresql.constant;
+package org.apache.shardingsphere.db.protocol.constant;
-import org.apache.shardingsphere.db.protocol.constant.CommonConstants;
import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-class PostgreSQLServerInfoTest {
+class DatabaseProtocolServerInfoTest {
@Test
- void assertSetServerVersion() {
+ void assertGetServerVersionWithDatabase() {
CommonConstants.PROXY_VERSION.set("5.0.0");
- PostgreSQLServerInfo.setServerVersion("foo_db", "13.2");
- assertThat(PostgreSQLServerInfo.getServerVersion("foo_db"),
is("13.2-ShardingSphere-Proxy 5.0.0"));
+ DatabaseProtocolServerInfo.setProtocolVersion("foo_db", "2.0");
+ assertThat(DatabaseProtocolServerInfo.getProtocolVersion("foo_db",
"FIXTURE"), is("2.0-ShardingSphere-Proxy 5.0.0"));
}
@Test
void assertGetServerVersionWithoutDatabase() {
CommonConstants.PROXY_VERSION.set("5.0.0");
- assertThat(PostgreSQLServerInfo.getServerVersion(null),
is("12.3-ShardingSphere-Proxy 5.0.0"));
+ assertThat(DatabaseProtocolServerInfo.getProtocolVersion(null,
"FIXTURE"), is("1.0-ShardingSphere-Proxy 5.0.0"));
}
}
diff --git
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/sysvar/SystemVariableValueProvider.java
b/db-protocol/core/src/test/java/org/apache/shardingsphere/db/protocol/constant/fixture/FixtureDatabaseProtocolDefaultVersionProvider.java
similarity index 55%
copy from
proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/sysvar/SystemVariableValueProvider.java
copy to
db-protocol/core/src/test/java/org/apache/shardingsphere/db/protocol/constant/fixture/FixtureDatabaseProtocolDefaultVersionProvider.java
index d499115a6ce..a25b50a6db2 100644
---
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/sysvar/SystemVariableValueProvider.java
+++
b/db-protocol/core/src/test/java/org/apache/shardingsphere/db/protocol/constant/fixture/FixtureDatabaseProtocolDefaultVersionProvider.java
@@ -15,27 +15,19 @@
* limitations under the License.
*/
-package
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.sysvar;
+package org.apache.shardingsphere.db.protocol.constant.fixture;
-import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
+import
org.apache.shardingsphere.db.protocol.constant.DatabaseProtocolDefaultVersionProvider;
-/**
- * System variable getter.
- */
-public interface SystemVariableValueProvider {
+public final class FixtureDatabaseProtocolDefaultVersionProvider implements
DatabaseProtocolDefaultVersionProvider {
- SystemVariableValueProvider DEFAULT_VALUE_PROVIDER = new
SystemVariableValueProvider() {
- };
+ @Override
+ public String provide() {
+ return "1.0";
+ }
- /**
- * Get variable.
- *
- * @param scope scope
- * @param connectionSession connection session
- * @param variable variable
- * @return value of variable
- */
- default String get(Scope scope, ConnectionSession connectionSession,
SystemVariable variable) {
- return variable.getDefaultValue();
+ @Override
+ public String getType() {
+ return "FIXTURE";
}
}
diff --git
a/db-protocol/core/src/test/resources/META-INF/services/org.apache.shardingsphere.db.protocol.constant.DatabaseProtocolDefaultVersionProvider
b/db-protocol/core/src/test/resources/META-INF/services/org.apache.shardingsphere.db.protocol.constant.DatabaseProtocolDefaultVersionProvider
new file mode 100644
index 00000000000..5bfab4ded79
--- /dev/null
+++
b/db-protocol/core/src/test/resources/META-INF/services/org.apache.shardingsphere.db.protocol.constant.DatabaseProtocolDefaultVersionProvider
@@ -0,0 +1,18 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+org.apache.shardingsphere.db.protocol.constant.fixture.FixtureDatabaseProtocolDefaultVersionProvider
diff --git
a/db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLConstants.java
b/db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLConstants.java
index b23e35e8390..dcb39bb8623 100644
---
a/db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLConstants.java
+++
b/db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLConstants.java
@@ -34,4 +34,11 @@ public final class MySQLConstants {
public static final AttributeKey<MySQLCharacterSet>
MYSQL_CHARACTER_SET_ATTRIBUTE_KEY =
AttributeKey.valueOf(MySQLCharacterSet.class.getName());
public static final AttributeKey<Integer> MYSQL_OPTION_MULTI_STATEMENTS =
AttributeKey.valueOf("MYSQL_OPTION_MULTI_STATEMENTS");
+
+ /**
+ * Protocol version is always 0x0A.
+ */
+ public static final int PROTOCOL_VERSION = 0x0A;
+
+ public static final MySQLCharacterSet DEFAULT_CHARSET =
MySQLCharacterSet.UTF8MB4_GENERAL_CI;
}
diff --git
a/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLServerInfoTest.java
b/db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLProtocolDefaultVersionProvider.java
similarity index 54%
rename from
db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLServerInfoTest.java
rename to
db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLProtocolDefaultVersionProvider.java
index 837c7ccf9d2..1a1f3cd5c7f 100644
---
a/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLServerInfoTest.java
+++
b/db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLProtocolDefaultVersionProvider.java
@@ -17,25 +17,20 @@
package org.apache.shardingsphere.db.protocol.mysql.constant;
-import org.apache.shardingsphere.db.protocol.constant.CommonConstants;
-import org.junit.jupiter.api.Test;
+import
org.apache.shardingsphere.db.protocol.constant.DatabaseProtocolDefaultVersionProvider;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-class MySQLServerInfoTest {
+/**
+ * Default protocol version provider for MySQL.
+ */
+public final class MySQLProtocolDefaultVersionProvider implements
DatabaseProtocolDefaultVersionProvider {
- @Test
- void assertSetServerVersion() {
- String schemaName = "test";
- CommonConstants.PROXY_VERSION.set("5.0.0");
- MySQLServerInfo.setServerVersion(schemaName, "5.1.47");
- assertThat(MySQLServerInfo.getServerVersion(schemaName),
is("5.1.47-ShardingSphere-Proxy 5.0.0"));
+ @Override
+ public String provide() {
+ return "5.7.22";
}
- @Test
- void assertGetDefaultServerVersion() {
- CommonConstants.PROXY_VERSION.set("5.0.0");
- assertThat(MySQLServerInfo.getDefaultServerVersion(),
is("5.7.22-ShardingSphere-Proxy 5.0.0"));
+ @Override
+ public String getType() {
+ return "MySQL";
}
}
diff --git
a/db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLServerInfo.java
b/db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLServerInfo.java
deleted file mode 100644
index c92b7af3587..00000000000
---
a/db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLServerInfo.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.db.protocol.mysql.constant;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.db.protocol.constant.CommonConstants;
-
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * ShardingSphere-Proxy's information for MySQL.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class MySQLServerInfo {
-
- /**
- * Protocol version is always 0x0A.
- */
- public static final int PROTOCOL_VERSION = 0x0A;
-
- public static final MySQLCharacterSet DEFAULT_CHARSET =
MySQLCharacterSet.UTF8MB4_GENERAL_CI;
-
- private static final String SERVER_VERSION_PATTERN =
"%s-ShardingSphere-Proxy %s";
-
- private static final String DEFAULT_MYSQL_VERSION = "5.7.22";
-
- private static final Map<String, String> SERVER_VERSIONS = new
ConcurrentHashMap<>();
-
- /**
- * Set server version.
- *
- * @param databaseName database name
- * @param serverVersion server version
- */
- public static void setServerVersion(final String databaseName, final
String serverVersion) {
- SERVER_VERSIONS.put(databaseName,
String.format(SERVER_VERSION_PATTERN, serverVersion,
CommonConstants.PROXY_VERSION.get()));
- }
-
- /**
- * Get server version.
- *
- * @param databaseName database name
- * @return server version
- */
- public static String getServerVersion(final String databaseName) {
- return null == databaseName ? getDefaultServerVersion() :
SERVER_VERSIONS.getOrDefault(databaseName, getDefaultServerVersion());
- }
-
- /**
- * Get default server version.
- *
- * @return server version
- */
- public static String getDefaultServerVersion() {
- return String.format(SERVER_VERSION_PATTERN, DEFAULT_MYSQL_VERSION,
CommonConstants.PROXY_VERSION.get());
- }
-}
diff --git
a/db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/handshake/MySQLHandshakePacket.java
b/db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/handshake/MySQLHandshakePacket.java
index 6c1aa9ef31d..5dea48306e1 100644
---
a/db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/handshake/MySQLHandshakePacket.java
+++
b/db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/handshake/MySQLHandshakePacket.java
@@ -19,9 +19,10 @@ package
org.apache.shardingsphere.db.protocol.mysql.packet.handshake;
import com.google.common.base.Preconditions;
import lombok.Getter;
+import
org.apache.shardingsphere.db.protocol.constant.DatabaseProtocolServerInfo;
import
org.apache.shardingsphere.db.protocol.mysql.constant.MySQLAuthenticationMethod;
import
org.apache.shardingsphere.db.protocol.mysql.constant.MySQLCapabilityFlag;
-import org.apache.shardingsphere.db.protocol.mysql.constant.MySQLServerInfo;
+import org.apache.shardingsphere.db.protocol.mysql.constant.MySQLConstants;
import org.apache.shardingsphere.db.protocol.mysql.constant.MySQLStatusFlag;
import org.apache.shardingsphere.db.protocol.mysql.packet.MySQLPacket;
import org.apache.shardingsphere.db.protocol.mysql.payload.MySQLPacketPayload;
@@ -34,7 +35,7 @@ import
org.apache.shardingsphere.db.protocol.mysql.payload.MySQLPacketPayload;
@Getter
public final class MySQLHandshakePacket implements MySQLPacket {
- private final int protocolVersion = MySQLServerInfo.PROTOCOL_VERSION;
+ private final int protocolVersion = MySQLConstants.PROTOCOL_VERSION;
private final String serverVersion;
@@ -53,10 +54,10 @@ public final class MySQLHandshakePacket implements
MySQLPacket {
private String authPluginName;
public MySQLHandshakePacket(final int connectionId, final boolean
sslEnabled, final MySQLAuthenticationPluginData authPluginData) {
- serverVersion = MySQLServerInfo.getDefaultServerVersion();
+ serverVersion =
DatabaseProtocolServerInfo.getDefaultProtocolVersion("MySQL");
this.connectionId = connectionId;
capabilityFlagsLower =
MySQLCapabilityFlag.calculateHandshakeCapabilityFlagsLower() | (sslEnabled ?
MySQLCapabilityFlag.CLIENT_SSL.getValue() : 0);
- characterSet = MySQLServerInfo.DEFAULT_CHARSET.getId();
+ characterSet = MySQLConstants.DEFAULT_CHARSET.getId();
statusFlag = MySQLStatusFlag.SERVER_STATUS_AUTOCOMMIT;
capabilityFlagsUpper =
MySQLCapabilityFlag.calculateHandshakeCapabilityFlagsUpper();
this.authPluginData = authPluginData;
diff --git
a/db-protocol/mysql/src/main/resources/META-INF/services/org.apache.shardingsphere.db.protocol.constant.DatabaseProtocolDefaultVersionProvider
b/db-protocol/mysql/src/main/resources/META-INF/services/org.apache.shardingsphere.db.protocol.constant.DatabaseProtocolDefaultVersionProvider
new file mode 100644
index 00000000000..f20be549cf6
--- /dev/null
+++
b/db-protocol/mysql/src/main/resources/META-INF/services/org.apache.shardingsphere.db.protocol.constant.DatabaseProtocolDefaultVersionProvider
@@ -0,0 +1,18 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+org.apache.shardingsphere.db.protocol.mysql.constant.MySQLProtocolDefaultVersionProvider
diff --git
a/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/packet/command/query/MySQLColumnDefinition41PacketTest.java
b/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/packet/command/query/MySQLColumnDefinition41PacketTest.java
index 4132c244fa4..46e2f0456cd 100644
---
a/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/packet/command/query/MySQLColumnDefinition41PacketTest.java
+++
b/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/packet/command/query/MySQLColumnDefinition41PacketTest.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.db.protocol.mysql.packet.command.query;
import
org.apache.shardingsphere.db.protocol.mysql.constant.MySQLBinaryColumnType;
-import org.apache.shardingsphere.db.protocol.mysql.constant.MySQLServerInfo;
+import org.apache.shardingsphere.db.protocol.mysql.constant.MySQLConstants;
import org.apache.shardingsphere.db.protocol.mysql.payload.MySQLPacketPayload;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -38,7 +38,7 @@ class MySQLColumnDefinition41PacketTest {
@Test
void assertWriteWithPayload() {
when(payload.readInt1()).thenReturn(MySQLBinaryColumnType.MYSQL_TYPE_LONG.getValue(),
0);
-
when(payload.readInt2()).thenReturn(MySQLServerInfo.DEFAULT_CHARSET.getId(), 0);
+
when(payload.readInt2()).thenReturn(MySQLConstants.DEFAULT_CHARSET.getId(), 0);
when(payload.readInt4()).thenReturn(10);
when(payload.readIntLenenc()).thenReturn(0x0cL);
when(payload.readStringLenenc()).thenReturn("def", "logic_db", "tbl",
"tbl", "id", "id");
@@ -53,7 +53,7 @@ class MySQLColumnDefinition41PacketTest {
verify(payload, times(2)).writeStringLenenc("tbl");
verify(payload, times(2)).writeStringLenenc("id");
verify(payload).writeIntLenenc(0x0c);
- verify(payload).writeInt2(MySQLServerInfo.DEFAULT_CHARSET.getId());
+ verify(payload).writeInt2(MySQLConstants.DEFAULT_CHARSET.getId());
verify(payload).writeInt4(10);
verify(payload).writeInt1(MySQLBinaryColumnType.MYSQL_TYPE_LONG.getValue());
verify(payload).writeInt2(0);
diff --git
a/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/packet/handshake/MySQLHandshakePacketTest.java
b/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/packet/handshake/MySQLHandshakePacketTest.java
index b21861d819a..d7a7906985b 100644
---
a/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/packet/handshake/MySQLHandshakePacketTest.java
+++
b/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/packet/handshake/MySQLHandshakePacketTest.java
@@ -17,9 +17,10 @@
package org.apache.shardingsphere.db.protocol.mysql.packet.handshake;
+import
org.apache.shardingsphere.db.protocol.constant.DatabaseProtocolServerInfo;
import
org.apache.shardingsphere.db.protocol.mysql.constant.MySQLAuthenticationMethod;
import
org.apache.shardingsphere.db.protocol.mysql.constant.MySQLCapabilityFlag;
-import org.apache.shardingsphere.db.protocol.mysql.constant.MySQLServerInfo;
+import org.apache.shardingsphere.db.protocol.mysql.constant.MySQLConstants;
import org.apache.shardingsphere.db.protocol.mysql.constant.MySQLStatusFlag;
import org.apache.shardingsphere.db.protocol.mysql.payload.MySQLPacketPayload;
import org.junit.jupiter.api.Test;
@@ -44,17 +45,17 @@ class MySQLHandshakePacketTest {
@Test
void assertNewWithPayload() {
- when(payload.readInt1()).thenReturn(MySQLServerInfo.PROTOCOL_VERSION,
MySQLServerInfo.DEFAULT_CHARSET.getId(), 0);
-
when(payload.readStringNul()).thenReturn(MySQLServerInfo.getDefaultServerVersion());
+ when(payload.readInt1()).thenReturn(MySQLConstants.PROTOCOL_VERSION,
MySQLConstants.DEFAULT_CHARSET.getId(), 0);
+
when(payload.readStringNul()).thenReturn(DatabaseProtocolServerInfo.getDefaultProtocolVersion("MySQL"));
when(payload.readStringNulByBytes()).thenReturn(part1, part2);
when(payload.readInt4()).thenReturn(1000);
when(payload.readInt2()).thenReturn(
MySQLCapabilityFlag.calculateHandshakeCapabilityFlagsLower(),
MySQLStatusFlag.SERVER_STATUS_AUTOCOMMIT.getValue(),
MySQLCapabilityFlag.calculateHandshakeCapabilityFlagsUpper());
MySQLHandshakePacket actual = new MySQLHandshakePacket(payload);
- assertThat(actual.getServerVersion(),
is(MySQLServerInfo.getDefaultServerVersion()));
+ assertThat(actual.getServerVersion(),
is(DatabaseProtocolServerInfo.getDefaultProtocolVersion("MySQL")));
assertThat(actual.getCapabilityFlagsLower(),
is(MySQLCapabilityFlag.calculateHandshakeCapabilityFlagsLower()));
assertThat(actual.getConnectionId(), is(1000));
- assertThat(actual.getCharacterSet(),
is(MySQLServerInfo.DEFAULT_CHARSET.getId()));
+ assertThat(actual.getCharacterSet(),
is(MySQLConstants.DEFAULT_CHARSET.getId()));
assertThat(actual.getStatusFlag(),
is(MySQLStatusFlag.SERVER_STATUS_AUTOCOMMIT));
assertThat(actual.getCapabilityFlagsUpper(),
is(MySQLCapabilityFlag.calculateHandshakeCapabilityFlagsUpper()));
assertThat(actual.getAuthPluginData().getAuthenticationPluginDataPart1(),
is(part1));
@@ -64,17 +65,17 @@ class MySQLHandshakePacketTest {
@Test
void assertNewWithClientPluginAuthPayload() {
- when(payload.readInt1()).thenReturn(MySQLServerInfo.PROTOCOL_VERSION,
MySQLServerInfo.DEFAULT_CHARSET.getId(), 0);
-
when(payload.readStringNul()).thenReturn(MySQLServerInfo.getDefaultServerVersion(),
MySQLAuthenticationMethod.NATIVE.getMethodName());
+ when(payload.readInt1()).thenReturn(MySQLConstants.PROTOCOL_VERSION,
MySQLConstants.DEFAULT_CHARSET.getId(), 0);
+
when(payload.readStringNul()).thenReturn(DatabaseProtocolServerInfo.getDefaultProtocolVersion("MySQL"),
MySQLAuthenticationMethod.NATIVE.getMethodName());
when(payload.readStringNulByBytes()).thenReturn(part1, part2);
when(payload.readInt4()).thenReturn(1000);
when(payload.readInt2()).thenReturn(
MySQLCapabilityFlag.calculateHandshakeCapabilityFlagsLower(),
MySQLStatusFlag.SERVER_STATUS_AUTOCOMMIT.getValue(),
MySQLCapabilityFlag.CLIENT_PLUGIN_AUTH.getValue() >> 16);
MySQLHandshakePacket actual = new MySQLHandshakePacket(payload);
- assertThat(actual.getServerVersion(),
is(MySQLServerInfo.getDefaultServerVersion()));
+ assertThat(actual.getServerVersion(),
is(DatabaseProtocolServerInfo.getDefaultProtocolVersion("MySQL")));
assertThat(actual.getCapabilityFlagsLower(),
is(MySQLCapabilityFlag.calculateHandshakeCapabilityFlagsLower()));
assertThat(actual.getConnectionId(), is(1000));
- assertThat(actual.getCharacterSet(),
is(MySQLServerInfo.DEFAULT_CHARSET.getId()));
+ assertThat(actual.getCharacterSet(),
is(MySQLConstants.DEFAULT_CHARSET.getId()));
assertThat(actual.getStatusFlag(),
is(MySQLStatusFlag.SERVER_STATUS_AUTOCOMMIT));
assertThat(actual.getCapabilityFlagsUpper(),
is(MySQLCapabilityFlag.CLIENT_PLUGIN_AUTH.getValue() >> 16));
assertThat(actual.getAuthPluginData().getAuthenticationPluginDataPart1(),
is(part1));
@@ -99,12 +100,12 @@ class MySQLHandshakePacketTest {
void assertWrite() {
MySQLAuthenticationPluginData authPluginData = new
MySQLAuthenticationPluginData(part1, part2);
new MySQLHandshakePacket(1000, false, authPluginData).write(payload);
- verify(payload).writeInt1(MySQLServerInfo.PROTOCOL_VERSION);
-
verify(payload).writeStringNul(MySQLServerInfo.getDefaultServerVersion());
+ verify(payload).writeInt1(MySQLConstants.PROTOCOL_VERSION);
+
verify(payload).writeStringNul(DatabaseProtocolServerInfo.getDefaultProtocolVersion("MySQL"));
verify(payload).writeInt4(1000);
verify(payload).writeStringNul(new
String(authPluginData.getAuthenticationPluginDataPart1()));
verify(payload).writeInt2(MySQLCapabilityFlag.calculateHandshakeCapabilityFlagsLower());
- verify(payload).writeInt1(MySQLServerInfo.DEFAULT_CHARSET.getId());
+ verify(payload).writeInt1(MySQLConstants.DEFAULT_CHARSET.getId());
verify(payload).writeInt2(MySQLStatusFlag.SERVER_STATUS_AUTOCOMMIT.getValue());
verify(payload).writeInt2(MySQLCapabilityFlag.calculateHandshakeCapabilityFlagsUpper());
verify(payload).writeInt1(authPluginData.getAuthenticationPluginData().length +
1);
@@ -118,12 +119,12 @@ class MySQLHandshakePacketTest {
MySQLHandshakePacket actual = new MySQLHandshakePacket(1000, false,
authPluginData);
actual.setAuthPluginName(MySQLAuthenticationMethod.NATIVE);
actual.write(payload);
- verify(payload).writeInt1(MySQLServerInfo.PROTOCOL_VERSION);
-
verify(payload).writeStringNul(MySQLServerInfo.getDefaultServerVersion());
+ verify(payload).writeInt1(MySQLConstants.PROTOCOL_VERSION);
+
verify(payload).writeStringNul(DatabaseProtocolServerInfo.getDefaultProtocolVersion("MySQL"));
verify(payload).writeInt4(1000);
verify(payload).writeStringNul(new
String(authPluginData.getAuthenticationPluginDataPart1()));
verify(payload).writeInt2(MySQLCapabilityFlag.calculateHandshakeCapabilityFlagsLower());
- verify(payload).writeInt1(MySQLServerInfo.DEFAULT_CHARSET.getId());
+ verify(payload).writeInt1(MySQLConstants.DEFAULT_CHARSET.getId());
verify(payload).writeInt2(MySQLStatusFlag.SERVER_STATUS_AUTOCOMMIT.getValue());
verify(payload).writeInt2(MySQLCapabilityFlag.CLIENT_PLUGIN_AUTH.getValue() >>
16);
verify(payload).writeInt1(authPluginData.getAuthenticationPluginData().length +
1);
diff --git
a/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/packet/handshake/MySQLHandshakeResponse41PacketTest.java
b/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/packet/handshake/MySQLHandshakeResponse41PacketTest.java
index 47764825b78..911071d588b 100644
---
a/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/packet/handshake/MySQLHandshakeResponse41PacketTest.java
+++
b/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/packet/handshake/MySQLHandshakeResponse41PacketTest.java
@@ -19,7 +19,7 @@ package
org.apache.shardingsphere.db.protocol.mysql.packet.handshake;
import
org.apache.shardingsphere.db.protocol.mysql.constant.MySQLAuthenticationMethod;
import
org.apache.shardingsphere.db.protocol.mysql.constant.MySQLCapabilityFlag;
-import org.apache.shardingsphere.db.protocol.mysql.constant.MySQLServerInfo;
+import org.apache.shardingsphere.db.protocol.mysql.constant.MySQLConstants;
import org.apache.shardingsphere.db.protocol.mysql.payload.MySQLPacketPayload;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -40,13 +40,13 @@ class MySQLHandshakeResponse41PacketTest {
@Test
void assertNewWithPayloadWithDatabase() {
-
when(payload.readInt1()).thenReturn(MySQLServerInfo.DEFAULT_CHARSET.getId());
+
when(payload.readInt1()).thenReturn(MySQLConstants.DEFAULT_CHARSET.getId());
when(payload.readInt4()).thenReturn(MySQLCapabilityFlag.CLIENT_CONNECT_WITH_DB.getValue(),
1000);
when(payload.readStringNul()).thenReturn("root", "sharding_db");
when(payload.readStringNulByBytes()).thenReturn(new byte[]{1});
MySQLHandshakeResponse41Packet actual = new
MySQLHandshakeResponse41Packet(payload);
assertThat(actual.getMaxPacketSize(), is(1000));
- assertThat(actual.getCharacterSet(),
is(MySQLServerInfo.DEFAULT_CHARSET.getId()));
+ assertThat(actual.getCharacterSet(),
is(MySQLConstants.DEFAULT_CHARSET.getId()));
assertThat(actual.getUsername(), is("root"));
assertThat(actual.getAuthResponse(), is(new byte[]{1}));
assertThat(actual.getCapabilityFlags(),
is(MySQLCapabilityFlag.CLIENT_CONNECT_WITH_DB.getValue()));
@@ -57,13 +57,13 @@ class MySQLHandshakeResponse41PacketTest {
@Test
void assertNewWithPayloadWithAuthPluginName() {
-
when(payload.readInt1()).thenReturn(MySQLServerInfo.DEFAULT_CHARSET.getId());
+
when(payload.readInt1()).thenReturn(MySQLConstants.DEFAULT_CHARSET.getId());
when(payload.readInt4()).thenReturn(MySQLCapabilityFlag.CLIENT_PLUGIN_AUTH.getValue(),
1000);
when(payload.readStringNul()).thenReturn("root",
MySQLAuthenticationMethod.NATIVE.getMethodName());
when(payload.readStringNulByBytes()).thenReturn(new byte[]{1});
MySQLHandshakeResponse41Packet actual = new
MySQLHandshakeResponse41Packet(payload);
assertThat(actual.getMaxPacketSize(), is(1000));
- assertThat(actual.getCharacterSet(),
is(MySQLServerInfo.DEFAULT_CHARSET.getId()));
+ assertThat(actual.getCharacterSet(),
is(MySQLConstants.DEFAULT_CHARSET.getId()));
assertThat(actual.getUsername(), is("root"));
assertThat(actual.getAuthResponse(), is(new byte[]{1}));
assertThat(actual.getCapabilityFlags(),
is(MySQLCapabilityFlag.CLIENT_PLUGIN_AUTH.getValue()));
@@ -74,13 +74,13 @@ class MySQLHandshakeResponse41PacketTest {
@Test
void assertNewWithPayloadWithClientPluginAuthLenencClientData() {
-
when(payload.readInt1()).thenReturn(MySQLServerInfo.DEFAULT_CHARSET.getId());
+
when(payload.readInt1()).thenReturn(MySQLConstants.DEFAULT_CHARSET.getId());
when(payload.readInt4()).thenReturn(MySQLCapabilityFlag.CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA.getValue(),
1000);
when(payload.readStringNul()).thenReturn("root");
when(payload.readStringLenencByBytes()).thenReturn(new byte[]{1});
MySQLHandshakeResponse41Packet actual = new
MySQLHandshakeResponse41Packet(payload);
assertThat(actual.getMaxPacketSize(), is(1000));
- assertThat(actual.getCharacterSet(),
is(MySQLServerInfo.DEFAULT_CHARSET.getId()));
+ assertThat(actual.getCharacterSet(),
is(MySQLConstants.DEFAULT_CHARSET.getId()));
assertThat(actual.getUsername(), is("root"));
assertThat(actual.getAuthResponse(), is(new byte[]{1}));
assertThat(actual.getCapabilityFlags(),
is(MySQLCapabilityFlag.CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA.getValue()));
@@ -91,13 +91,13 @@ class MySQLHandshakeResponse41PacketTest {
@Test
void assertNewWithPayloadWithClientSecureConnection() {
-
when(payload.readInt1()).thenReturn(MySQLServerInfo.DEFAULT_CHARSET.getId(), 1);
+
when(payload.readInt1()).thenReturn(MySQLConstants.DEFAULT_CHARSET.getId(), 1);
when(payload.readInt4()).thenReturn(MySQLCapabilityFlag.CLIENT_SECURE_CONNECTION.getValue(),
1000);
when(payload.readStringNul()).thenReturn("root");
when(payload.readStringFixByBytes(1)).thenReturn(new byte[]{1});
MySQLHandshakeResponse41Packet actual = new
MySQLHandshakeResponse41Packet(payload);
assertThat(actual.getMaxPacketSize(), is(1000));
- assertThat(actual.getCharacterSet(),
is(MySQLServerInfo.DEFAULT_CHARSET.getId()));
+ assertThat(actual.getCharacterSet(),
is(MySQLConstants.DEFAULT_CHARSET.getId()));
assertThat(actual.getUsername(), is("root"));
assertThat(actual.getAuthResponse(), is(new byte[]{1}));
assertThat(actual.getCapabilityFlags(),
is(MySQLCapabilityFlag.CLIENT_SECURE_CONNECTION.getValue()));
@@ -108,13 +108,13 @@ class MySQLHandshakeResponse41PacketTest {
@Test
void assertWriteWithDatabase() {
- MySQLHandshakeResponse41Packet actual = new
MySQLHandshakeResponse41Packet(100, MySQLServerInfo.DEFAULT_CHARSET.getId(),
"root");
+ MySQLHandshakeResponse41Packet actual = new
MySQLHandshakeResponse41Packet(100, MySQLConstants.DEFAULT_CHARSET.getId(),
"root");
actual.setAuthResponse(new byte[]{1});
actual.setDatabase("sharding_db");
actual.write(payload);
verify(payload).writeInt4(MySQLCapabilityFlag.CLIENT_CONNECT_WITH_DB.getValue());
verify(payload).writeInt4(100);
- verify(payload).writeInt1(MySQLServerInfo.DEFAULT_CHARSET.getId());
+ verify(payload).writeInt1(MySQLConstants.DEFAULT_CHARSET.getId());
verify(payload).writeReserved(23);
verify(payload).writeStringNul("root");
verify(payload).writeStringNul(new String(new byte[]{1}));
@@ -123,13 +123,13 @@ class MySQLHandshakeResponse41PacketTest {
@Test
void assertWriteWithAuthPluginName() {
- MySQLHandshakeResponse41Packet actual = new
MySQLHandshakeResponse41Packet(100, MySQLServerInfo.DEFAULT_CHARSET.getId(),
"root");
+ MySQLHandshakeResponse41Packet actual = new
MySQLHandshakeResponse41Packet(100, MySQLConstants.DEFAULT_CHARSET.getId(),
"root");
actual.setAuthResponse(new byte[]{1});
actual.setAuthPluginName(MySQLAuthenticationMethod.NATIVE);
actual.write(payload);
verify(payload).writeInt4(MySQLCapabilityFlag.CLIENT_PLUGIN_AUTH.getValue());
verify(payload).writeInt4(100);
- verify(payload).writeInt1(MySQLServerInfo.DEFAULT_CHARSET.getId());
+ verify(payload).writeInt1(MySQLConstants.DEFAULT_CHARSET.getId());
verify(payload).writeReserved(23);
verify(payload).writeStringNul("root");
verify(payload).writeStringNul(new String(new byte[]{1}));
@@ -138,13 +138,13 @@ class MySQLHandshakeResponse41PacketTest {
@Test
void assertWriteWithClientPluginAuthLenencClientData() {
- MySQLHandshakeResponse41Packet actual = new
MySQLHandshakeResponse41Packet(100, MySQLServerInfo.DEFAULT_CHARSET.getId(),
"root");
+ MySQLHandshakeResponse41Packet actual = new
MySQLHandshakeResponse41Packet(100, MySQLConstants.DEFAULT_CHARSET.getId(),
"root");
actual.setCapabilityFlags(MySQLCapabilityFlag.CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA.getValue());
actual.setAuthResponse(new byte[]{1});
actual.write(payload);
verify(payload).writeInt4(MySQLCapabilityFlag.CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA.getValue());
verify(payload).writeInt4(100);
- verify(payload).writeInt1(MySQLServerInfo.DEFAULT_CHARSET.getId());
+ verify(payload).writeInt1(MySQLConstants.DEFAULT_CHARSET.getId());
verify(payload).writeReserved(23);
verify(payload).writeStringNul("root");
verify(payload).writeStringLenenc(new String(new byte[]{1}));
@@ -152,13 +152,13 @@ class MySQLHandshakeResponse41PacketTest {
@Test
void assertWriteWithClientSecureConnection() {
- MySQLHandshakeResponse41Packet actual = new
MySQLHandshakeResponse41Packet(100, MySQLServerInfo.DEFAULT_CHARSET.getId(),
"root");
+ MySQLHandshakeResponse41Packet actual = new
MySQLHandshakeResponse41Packet(100, MySQLConstants.DEFAULT_CHARSET.getId(),
"root");
actual.setCapabilityFlags(MySQLCapabilityFlag.CLIENT_SECURE_CONNECTION.getValue());
actual.setAuthResponse(new byte[]{1});
actual.write(payload);
verify(payload).writeInt4(MySQLCapabilityFlag.CLIENT_SECURE_CONNECTION.getValue());
verify(payload).writeInt4(100);
- verify(payload).writeInt1(MySQLServerInfo.DEFAULT_CHARSET.getId());
+ verify(payload).writeInt1(MySQLConstants.DEFAULT_CHARSET.getId());
verify(payload).writeReserved(23);
verify(payload).writeStringNul("root");
verify(payload).writeInt1(1);
diff --git
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/sysvar/SystemVariableValueProvider.java
b/db-protocol/opengauss/src/main/java/org/apache/shardingsphere/db/protocol/opengauss/constant/OpenGaussProtocolDefaultVersionProvider.java
similarity index 55%
copy from
proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/sysvar/SystemVariableValueProvider.java
copy to
db-protocol/opengauss/src/main/java/org/apache/shardingsphere/db/protocol/opengauss/constant/OpenGaussProtocolDefaultVersionProvider.java
index d499115a6ce..a41c787d99f 100644
---
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/sysvar/SystemVariableValueProvider.java
+++
b/db-protocol/opengauss/src/main/java/org/apache/shardingsphere/db/protocol/opengauss/constant/OpenGaussProtocolDefaultVersionProvider.java
@@ -15,27 +15,22 @@
* limitations under the License.
*/
-package
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.sysvar;
+package org.apache.shardingsphere.db.protocol.opengauss.constant;
-import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
+import
org.apache.shardingsphere.db.protocol.constant.DatabaseProtocolDefaultVersionProvider;
/**
- * System variable getter.
+ * Default protocol version provider for openGauss.
*/
-public interface SystemVariableValueProvider {
+public final class OpenGaussProtocolDefaultVersionProvider implements
DatabaseProtocolDefaultVersionProvider {
- SystemVariableValueProvider DEFAULT_VALUE_PROVIDER = new
SystemVariableValueProvider() {
- };
+ @Override
+ public String provide() {
+ return "12.3";
+ }
- /**
- * Get variable.
- *
- * @param scope scope
- * @param connectionSession connection session
- * @param variable variable
- * @return value of variable
- */
- default String get(Scope scope, ConnectionSession connectionSession,
SystemVariable variable) {
- return variable.getDefaultValue();
+ @Override
+ public String getType() {
+ return "openGauss";
}
}
diff --git
a/db-protocol/opengauss/src/main/resources/META-INF/services/org.apache.shardingsphere.db.protocol.constant.DatabaseProtocolDefaultVersionProvider
b/db-protocol/opengauss/src/main/resources/META-INF/services/org.apache.shardingsphere.db.protocol.constant.DatabaseProtocolDefaultVersionProvider
new file mode 100644
index 00000000000..c7bf9e29a87
--- /dev/null
+++
b/db-protocol/opengauss/src/main/resources/META-INF/services/org.apache.shardingsphere.db.protocol.constant.DatabaseProtocolDefaultVersionProvider
@@ -0,0 +1,18 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+org.apache.shardingsphere.db.protocol.opengauss.constant.OpenGaussProtocolDefaultVersionProvider
diff --git
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/sysvar/SystemVariableValueProvider.java
b/db-protocol/postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/constant/PostgreSQLProtocolDefaultVersionProvider.java
similarity index 55%
copy from
proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/sysvar/SystemVariableValueProvider.java
copy to
db-protocol/postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/constant/PostgreSQLProtocolDefaultVersionProvider.java
index d499115a6ce..6db77fbd24d 100644
---
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/sysvar/SystemVariableValueProvider.java
+++
b/db-protocol/postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/constant/PostgreSQLProtocolDefaultVersionProvider.java
@@ -15,27 +15,22 @@
* limitations under the License.
*/
-package
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.sysvar;
+package org.apache.shardingsphere.db.protocol.postgresql.constant;
-import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
+import
org.apache.shardingsphere.db.protocol.constant.DatabaseProtocolDefaultVersionProvider;
/**
- * System variable getter.
+ * Default protocol version provider for PostgreSQL.
*/
-public interface SystemVariableValueProvider {
+public final class PostgreSQLProtocolDefaultVersionProvider implements
DatabaseProtocolDefaultVersionProvider {
- SystemVariableValueProvider DEFAULT_VALUE_PROVIDER = new
SystemVariableValueProvider() {
- };
+ @Override
+ public String provide() {
+ return "12.3";
+ }
- /**
- * Get variable.
- *
- * @param scope scope
- * @param connectionSession connection session
- * @param variable variable
- * @return value of variable
- */
- default String get(Scope scope, ConnectionSession connectionSession,
SystemVariable variable) {
- return variable.getDefaultValue();
+ @Override
+ public String getType() {
+ return "PostgreSQL";
}
}
diff --git
a/db-protocol/postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/constant/PostgreSQLServerInfo.java
b/db-protocol/postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/constant/PostgreSQLServerInfo.java
deleted file mode 100644
index b61044a2251..00000000000
---
a/db-protocol/postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/constant/PostgreSQLServerInfo.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.db.protocol.postgresql.constant;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.db.protocol.constant.CommonConstants;
-
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * ShardingSphere-Proxy's information for PostgreSQL.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class PostgreSQLServerInfo {
-
- private static final String SERVER_VERSION_PATTERN =
"%s-ShardingSphere-Proxy %s";
-
- private static final String DEFAULT_POSTGRESQL_VERSION = "12.3";
-
- private static final Map<String, String> SERVER_VERSIONS = new
ConcurrentHashMap<>();
-
- /**
- * Set server version.
- *
- * @param databaseName database name
- * @param serverVersion server version
- */
- public static void setServerVersion(final String databaseName, final
String serverVersion) {
- SERVER_VERSIONS.put(databaseName,
String.format(SERVER_VERSION_PATTERN, serverVersion,
CommonConstants.PROXY_VERSION.get()));
- }
-
- /**
- * Get server version.
- *
- * @param databaseName database name
- * @return server version
- */
- public static String getServerVersion(final String databaseName) {
- return null == databaseName ? getDefaultServerVersion() :
SERVER_VERSIONS.getOrDefault(databaseName, getDefaultServerVersion());
- }
-
- private static String getDefaultServerVersion() {
- return String.format(SERVER_VERSION_PATTERN,
DEFAULT_POSTGRESQL_VERSION, CommonConstants.PROXY_VERSION.get());
- }
-}
diff --git
a/db-protocol/postgresql/src/main/resources/META-INF/services/org.apache.shardingsphere.db.protocol.constant.DatabaseProtocolDefaultVersionProvider
b/db-protocol/postgresql/src/main/resources/META-INF/services/org.apache.shardingsphere.db.protocol.constant.DatabaseProtocolDefaultVersionProvider
new file mode 100644
index 00000000000..abb89100262
--- /dev/null
+++
b/db-protocol/postgresql/src/main/resources/META-INF/services/org.apache.shardingsphere.db.protocol.constant.DatabaseProtocolDefaultVersionProvider
@@ -0,0 +1,18 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+org.apache.shardingsphere.db.protocol.postgresql.constant.PostgreSQLProtocolDefaultVersionProvider
diff --git
a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/CreateReadwriteSplittingRuleStatementUpdaterTest.java
b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/CreateReadwriteSplittingRuleStatementUpdaterTest.java
index aac2a9d86b7..f628b643d7b 100644
---
a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/CreateReadwriteSplittingRuleStatementUpdaterTest.java
+++
b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/CreateReadwriteSplittingRuleStatementUpdaterTest.java
@@ -151,7 +151,6 @@ class CreateReadwriteSplittingRuleStatementUpdaterTest {
DataSourceContainedRule dataSourceContainedRule =
mock(DataSourceContainedRule.class);
when(dataSourceContainedRule.getDataSourceMapper()).thenReturn(Collections.singletonMap("ms_group",
Collections.singleton("ds_0")));
when(database.getRuleMetaData().findRules(DataSourceContainedRule.class)).thenReturn(Collections.singleton(dataSourceContainedRule));
-
when(TypedSPILoader.contains(ReadQueryLoadBalanceAlgorithm.class,
"TEST")).thenReturn(true);
ReadwriteSplittingRuleSegment staticSegment = new
ReadwriteSplittingRuleSegment("static_rule", "write_ds_0",
Arrays.asList("read_ds_0", "read_ds_1"),
new AlgorithmSegment("TEST", new Properties()));
diff --git
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/connector/sane/MySQLSaneQueryResultEngine.java
b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/connector/sane/MySQLSaneQueryResultEngine.java
index 5820c7ffdca..7ffef70b221 100644
---
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/connector/sane/MySQLSaneQueryResultEngine.java
+++
b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/connector/sane/MySQLSaneQueryResultEngine.java
@@ -25,7 +25,7 @@ import
org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.ra
import
org.apache.shardingsphere.infra.executor.sql.execute.result.query.type.memory.row.MemoryQueryResultDataRow;
import
org.apache.shardingsphere.infra.executor.sql.execute.result.update.UpdateResult;
import
org.apache.shardingsphere.proxy.backend.connector.sane.SaneQueryResultEngine;
-import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.sysvar.SystemVariable;
+import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.sysvar.MySQLSystemVariable;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dal.VariableSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ExpressionProjectionSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionSegment;
@@ -78,7 +78,7 @@ public final class MySQLSaneQueryResultEngine implements
SaneQueryResultEngine {
String alias =
expressionProjection.getAlias().orElse(expressionProjection.getText());
queryResultColumnMetaDataList.add(createRawQueryResultColumnMetaData(text,
alias));
String value = expressionProjection.getExpr() instanceof
VariableSegment
- ? SystemVariable.findSystemVariable(((VariableSegment)
expressionProjection.getExpr()).getVariable()).map(SystemVariable::getDefaultValue).orElse("1")
+ ?
MySQLSystemVariable.findSystemVariable(((VariableSegment)
expressionProjection.getExpr()).getVariable()).map(MySQLSystemVariable::getDefaultValue).orElse("1")
: "1";
data.add(value);
}
diff --git
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/MySQLSetCharsetExecutor.java
b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/MySQLSetCharsetExecutor.java
index 4d84c7d2646..996ced9a680 100644
---
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/MySQLSetCharsetExecutor.java
+++
b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/MySQLSetCharsetExecutor.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor;
import org.apache.shardingsphere.db.protocol.constant.CommonConstants;
-import org.apache.shardingsphere.db.protocol.mysql.constant.MySQLServerInfo;
+import org.apache.shardingsphere.db.protocol.mysql.constant.MySQLConstants;
import
org.apache.shardingsphere.dialect.mysql.exception.UnknownCharsetException;
import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.MySQLSessionVariableHandler;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
@@ -54,7 +54,7 @@ public final class MySQLSetCharsetExecutor implements
MySQLSessionVariableHandle
private Charset parseCharset(final String value) {
switch (value.toLowerCase(Locale.ROOT)) {
case "default":
- return MySQLServerInfo.DEFAULT_CHARSET.getCharset();
+ return MySQLConstants.DEFAULT_CHARSET.getCharset();
case "utf8mb4":
return StandardCharsets.UTF_8;
default:
diff --git
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/MySQLSystemVariableQueryExecutor.java
b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/MySQLSystemVariableQueryExecutor.java
index 101791e3af2..3bfc63b6db6 100644
---
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/MySQLSystemVariableQueryExecutor.java
+++
b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/MySQLSystemVariableQueryExecutor.java
@@ -29,7 +29,7 @@ import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryRes
import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminExecutor;
import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminQueryExecutor;
import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.sysvar.Scope;
-import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.sysvar.SystemVariable;
+import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.sysvar.MySQLSystemVariable;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dal.VariableSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ExpressionProjectionSegment;
@@ -51,7 +51,7 @@ public final class MySQLSystemVariableQueryExecutor
implements DatabaseAdminQuer
private final List<ExpressionProjectionSegment> projections;
- private final List<SystemVariable> variables;
+ private final List<MySQLSystemVariable> variables;
@Getter
private QueryResultMetaData queryResultMetaData;
@@ -84,7 +84,7 @@ public final class MySQLSystemVariableQueryExecutor
implements DatabaseAdminQuer
public static Optional<DatabaseAdminExecutor>
tryGetSystemVariableQueryExecutor(final SelectStatement selectStatement) {
Collection<ProjectionSegment> projections =
selectStatement.getProjections().getProjections();
List<ExpressionProjectionSegment> expressionProjectionSegments = new
ArrayList<>(projections.size());
- List<SystemVariable> variables = new ArrayList<>(projections.size());
+ List<MySQLSystemVariable> variables = new
ArrayList<>(projections.size());
for (ProjectionSegment each : projections) {
ExpressionProjectionSegment expression;
if (!(each instanceof ExpressionProjectionSegment) ||
!((expression = (ExpressionProjectionSegment) each).getExpr() instanceof
VariableSegment)) {
@@ -92,7 +92,7 @@ public final class MySQLSystemVariableQueryExecutor
implements DatabaseAdminQuer
}
expressionProjectionSegments.add(expression);
VariableSegment variable = (VariableSegment) expression.getExpr();
- Optional<SystemVariable> systemVariable =
SystemVariable.findSystemVariable(variable.getVariable());
+ Optional<MySQLSystemVariable> systemVariable =
MySQLSystemVariable.findSystemVariable(variable.getVariable());
if (!systemVariable.isPresent()) {
return Optional.empty();
}
diff --git
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowVersionExecutor.java
b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowVersionExecutor.java
index 461442a24e1..314b674312c 100644
---
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowVersionExecutor.java
+++
b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowVersionExecutor.java
@@ -19,15 +19,15 @@ package
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.db.protocol.mysql.constant.MySQLServerInfo;
+import
org.apache.shardingsphere.db.protocol.constant.DatabaseProtocolServerInfo;
import
org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResultMetaData;
import
org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.raw.metadata.RawQueryResultColumnMetaData;
import
org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.raw.metadata.RawQueryResultMetaData;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataMergedResult;
import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminQueryExecutor;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ExpressionProjectionSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement;
@@ -49,7 +49,7 @@ public final class ShowVersionExecutor implements
DatabaseAdminQueryExecutor {
@Override
public void execute(final ConnectionSession connectionSession) {
- mergedResult = new LocalDataMergedResult(Collections.singleton(new
LocalDataQueryResultRow(MySQLServerInfo.getServerVersion(connectionSession.getDatabaseName()))));
+ mergedResult = new LocalDataMergedResult(Collections.singleton(new
LocalDataQueryResultRow(DatabaseProtocolServerInfo.getProtocolVersion(connectionSession.getDatabaseName(),
"MySQL"))));
}
@Override
diff --git
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/sysvar/SystemVariable.java
b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/sysvar/MySQLSystemVariable.java
similarity index 96%
rename from
proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/sysvar/SystemVariable.java
rename to
proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/sysvar/MySQLSystemVariable.java
index 65ababb894e..764e2ce57f4 100644
---
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/sysvar/SystemVariable.java
+++
b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/sysvar/MySQLSystemVariable.java
@@ -19,7 +19,7 @@ package
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.sys
import lombok.Getter;
import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.db.protocol.mysql.constant.MySQLServerInfo;
+import
org.apache.shardingsphere.db.protocol.constant.DatabaseProtocolServerInfo;
import
org.apache.shardingsphere.dialect.mysql.exception.IncorrectGlobalLocalVariableException;
import
org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.sysvar.provider.TransactionIsolationValueProvider;
@@ -37,7 +37,7 @@ import java.util.stream.Collectors;
* MySQL system variable.
*/
@RequiredArgsConstructor
-public enum SystemVariable {
+public enum MySQLSystemVariable {
ACTIVATE_ALL_ROLES_ON_LOGIN(Flag.GLOBAL, "0"),
@@ -986,7 +986,7 @@ public enum SystemVariable {
VALIDATE_USER_PLUGINS(Flag.GLOBAL | Flag.READONLY | Flag.INVISIBLE, "1"),
- VERSION(Flag.GLOBAL | Flag.READONLY,
MySQLServerInfo.getDefaultServerVersion(), new VersionValueProvider()),
+ VERSION(Flag.GLOBAL | Flag.READONLY,
DatabaseProtocolServerInfo.getDefaultProtocolVersion("MySQL"), new
VersionValueProvider()),
VERSION_COMMENT(Flag.GLOBAL | Flag.READONLY, "Source distribution"),
@@ -1074,26 +1074,26 @@ public enum SystemVariable {
TIMED_MUTEXES(Flag.GLOBAL, "0");
- private static final Map<String, SystemVariable> ALL_VARIABLES =
Arrays.stream(values()).collect(Collectors.toMap(Enum::name,
Function.identity()));
+ private static final Map<String, MySQLSystemVariable> ALL_VARIABLES =
Arrays.stream(values()).collect(Collectors.toMap(Enum::name,
Function.identity()));
private final int flag;
@Getter
private final String defaultValue;
- private final SystemVariableValueProvider variableValueProvider;
+ private final MySQLSystemVariableValueProvider variableValueProvider;
- SystemVariable(final int flag, final String defaultValue) {
- this(flag, defaultValue,
SystemVariableValueProvider.DEFAULT_VALUE_PROVIDER);
+ MySQLSystemVariable(final int flag, final String defaultValue) {
+ this(flag, defaultValue,
MySQLSystemVariableValueProvider.DEFAULT_PROVIDER);
}
/**
* Find system variable by name.
*
- * @param name name
- * @return optional system variable
+ * @param name variable name
+ * @return system variable
*/
- public static Optional<SystemVariable> findSystemVariable(final String
name) {
+ public static Optional<MySQLSystemVariable> findSystemVariable(final
String name) {
return Optional.ofNullable(ALL_VARIABLES.get(name.toUpperCase()));
}
@@ -1105,18 +1105,16 @@ public enum SystemVariable {
* @return value
*/
public String getValue(final Scope scope, final ConnectionSession
connectionSession) {
- validateGetValue(scope);
+ validateScope(scope);
return variableValueProvider.get(scope, connectionSession, this);
}
- private void validateGetValue(final Scope scope) {
+ private void validateScope(final Scope scope) {
if (Scope.GLOBAL == scope) {
- ShardingSpherePreconditions.checkState(0 == (Flag.ONLY_SESSION &
scope()),
- () -> new
IncorrectGlobalLocalVariableException(this.name().toLowerCase(),
Scope.SESSION.name()));
+ ShardingSpherePreconditions.checkState(0 == (Flag.ONLY_SESSION &
scope()), () -> new IncorrectGlobalLocalVariableException(name().toLowerCase(),
Scope.SESSION.name()));
}
if (Scope.SESSION == scope) {
- ShardingSpherePreconditions.checkState(0 != ((Flag.SESSION |
Flag.ONLY_SESSION) & scope()),
- () -> new
IncorrectGlobalLocalVariableException(this.name().toLowerCase(),
Scope.GLOBAL.name()));
+ ShardingSpherePreconditions.checkState(0 != ((Flag.SESSION |
Flag.ONLY_SESSION) & scope()), () -> new
IncorrectGlobalLocalVariableException(name().toLowerCase(),
Scope.GLOBAL.name()));
}
}
diff --git
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/sysvar/SystemVariableValueProvider.java
b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/sysvar/MySQLSystemVariableValueProvider.java
similarity index 84%
rename from
proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/sysvar/SystemVariableValueProvider.java
rename to
proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/sysvar/MySQLSystemVariableValueProvider.java
index d499115a6ce..73ca2f8b1e6 100644
---
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/sysvar/SystemVariableValueProvider.java
+++
b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/sysvar/MySQLSystemVariableValueProvider.java
@@ -20,11 +20,11 @@ package
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.sys
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
/**
- * System variable getter.
+ * System variable value provider for MySQL.
*/
-public interface SystemVariableValueProvider {
+public interface MySQLSystemVariableValueProvider {
- SystemVariableValueProvider DEFAULT_VALUE_PROVIDER = new
SystemVariableValueProvider() {
+ MySQLSystemVariableValueProvider DEFAULT_PROVIDER = new
MySQLSystemVariableValueProvider() {
};
/**
@@ -35,7 +35,7 @@ public interface SystemVariableValueProvider {
* @param variable variable
* @return value of variable
*/
- default String get(Scope scope, ConnectionSession connectionSession,
SystemVariable variable) {
+ default String get(Scope scope, ConnectionSession connectionSession,
MySQLSystemVariable variable) {
return variable.getDefaultValue();
}
}
diff --git
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/sysvar/provider/TransactionIsolationValueProvider.java
b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/sysvar/provider/TransactionIsolationValueProvider.java
index 4b3c9e5f8c6..0f92ab21fa7 100644
---
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/sysvar/provider/TransactionIsolationValueProvider.java
+++
b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/sysvar/provider/TransactionIsolationValueProvider.java
@@ -18,8 +18,8 @@
package
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.sysvar.provider;
import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.sysvar.Scope;
-import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.sysvar.SystemVariable;
-import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.sysvar.SystemVariableValueProvider;
+import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.sysvar.MySQLSystemVariable;
+import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.sysvar.MySQLSystemVariableValueProvider;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import
org.apache.shardingsphere.sql.parser.sql.common.enums.TransactionIsolationLevel;
@@ -28,10 +28,10 @@ import java.util.Optional;
/**
* Transaction isolation value provider.
*/
-public final class TransactionIsolationValueProvider implements
SystemVariableValueProvider {
+public final class TransactionIsolationValueProvider implements
MySQLSystemVariableValueProvider {
@Override
- public String get(final Scope scope, final ConnectionSession
connectionSession, final SystemVariable variable) {
+ public String get(final Scope scope, final ConnectionSession
connectionSession, final MySQLSystemVariable variable) {
return Scope.GLOBAL == scope ? variable.getDefaultValue()
:
Optional.ofNullable(connectionSession.getIsolationLevel()).map(TransactionIsolationLevel::getIsolationLevel).orElseGet(TransactionIsolationLevel.REPEATABLE_READ::getIsolationLevel);
}
diff --git
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/sysvar/provider/TransactionReadOnlyValueProvider.java
b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/sysvar/provider/TransactionReadOnlyValueProvider.java
index 375cccf204b..e670481468a 100644
---
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/sysvar/provider/TransactionReadOnlyValueProvider.java
+++
b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/sysvar/provider/TransactionReadOnlyValueProvider.java
@@ -18,17 +18,17 @@
package
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.sysvar.provider;
import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.sysvar.Scope;
-import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.sysvar.SystemVariable;
-import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.sysvar.SystemVariableValueProvider;
+import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.sysvar.MySQLSystemVariable;
+import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.sysvar.MySQLSystemVariableValueProvider;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
/**
* Transaction read only.
*/
-public final class TransactionReadOnlyValueProvider implements
SystemVariableValueProvider {
+public final class TransactionReadOnlyValueProvider implements
MySQLSystemVariableValueProvider {
@Override
- public String get(final Scope scope, final ConnectionSession
connectionSession, final SystemVariable variable) {
+ public String get(final Scope scope, final ConnectionSession
connectionSession, final MySQLSystemVariable variable) {
if (Scope.GLOBAL == scope) {
return variable.getDefaultValue();
}
diff --git
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/sysvar/provider/VersionValueProvider.java
b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/sysvar/provider/VersionValueProvider.java
index 7e9a74fbfe9..a45d7051595 100644
---
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/sysvar/provider/VersionValueProvider.java
+++
b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/sysvar/provider/VersionValueProvider.java
@@ -17,19 +17,19 @@
package
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.sysvar.provider;
-import org.apache.shardingsphere.db.protocol.mysql.constant.MySQLServerInfo;
+import
org.apache.shardingsphere.db.protocol.constant.DatabaseProtocolServerInfo;
+import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.sysvar.MySQLSystemVariable;
+import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.sysvar.MySQLSystemVariableValueProvider;
import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.sysvar.Scope;
-import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.sysvar.SystemVariable;
-import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.sysvar.SystemVariableValueProvider;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
/**
* MySQL version provider.
*/
-public final class VersionValueProvider implements SystemVariableValueProvider
{
+public final class VersionValueProvider implements
MySQLSystemVariableValueProvider {
@Override
- public String get(final Scope scope, final ConnectionSession
connectionSession, final SystemVariable variable) {
- return
MySQLServerInfo.getServerVersion(connectionSession.getDefaultDatabaseName());
+ public String get(final Scope scope, final ConnectionSession
connectionSession, final MySQLSystemVariable variable) {
+ return
DatabaseProtocolServerInfo.getProtocolVersion(connectionSession.getDefaultDatabaseName(),
"MySQL");
}
}
diff --git
a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/MySQLSystemVariableQueryExecutorTest.java
b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/MySQLMySQLSystemVariableQueryExecutorTest.java
similarity index 93%
rename from
proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/MySQLSystemVariableQueryExecutorTest.java
rename to
proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/MySQLMySQLSystemVariableQueryExecutorTest.java
index 99f89db859f..2f20736d564 100644
---
a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/MySQLSystemVariableQueryExecutorTest.java
+++
b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/MySQLMySQLSystemVariableQueryExecutorTest.java
@@ -21,7 +21,7 @@ import
org.apache.shardingsphere.dialect.mysql.exception.IncorrectGlobalLocalVar
import
org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResultMetaData;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminExecutor;
-import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.sysvar.SystemVariable;
+import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.sysvar.MySQLSystemVariable;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dal.VariableSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ColumnProjectionSegment;
@@ -41,7 +41,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
-class MySQLSystemVariableQueryExecutorTest {
+class MySQLMySQLSystemVariableQueryExecutorTest {
@Test
void
assertTryGetSystemVariableQueryExecutorWithOtherExpressionProjection() {
@@ -86,9 +86,9 @@ class MySQLSystemVariableQueryExecutorTest {
assertThat(actualMetaData.getColumnLabel(3),
is("@@max_allowed_packet"));
MergedResult actualResult = queryExecutor.getMergedResult();
assertTrue(actualResult.next());
- assertThat(actualResult.getValue(1, String.class),
is(SystemVariable.MAX_CONNECTIONS.getDefaultValue()));
- assertThat(actualResult.getValue(2, String.class),
is(SystemVariable.WARNING_COUNT.getDefaultValue()));
- assertThat(actualResult.getValue(3, String.class),
is(SystemVariable.MAX_ALLOWED_PACKET.getDefaultValue()));
+ assertThat(actualResult.getValue(1, String.class),
is(MySQLSystemVariable.MAX_CONNECTIONS.getDefaultValue()));
+ assertThat(actualResult.getValue(2, String.class),
is(MySQLSystemVariable.WARNING_COUNT.getDefaultValue()));
+ assertThat(actualResult.getValue(3, String.class),
is(MySQLSystemVariable.MAX_ALLOWED_PACKET.getDefaultValue()));
assertFalse(actualResult.next());
}
diff --git
a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowVersionExecutorTest.java
b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowVersionExecutorTest.java
index 64f6272f1e6..c8de4fb74ab 100644
---
a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowVersionExecutorTest.java
+++
b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowVersionExecutorTest.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor;
-import org.apache.shardingsphere.db.protocol.mysql.constant.MySQLServerInfo;
+import
org.apache.shardingsphere.db.protocol.constant.DatabaseProtocolServerInfo;
import
org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResultMetaData;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ExpressionProjectionSegment;
@@ -42,13 +42,13 @@ class ShowVersionExecutorTest {
@BeforeEach
void setUp() {
- previousVersion = MySQLServerInfo.getServerVersion("foo_db");
- MySQLServerInfo.setServerVersion("foo_db", "8.0.26");
+ previousVersion =
DatabaseProtocolServerInfo.getProtocolVersion("foo_db", "MySQL");
+ DatabaseProtocolServerInfo.setProtocolVersion("foo_db", "8.0.26");
}
@AfterEach
void tearDown() {
- MySQLServerInfo.setServerVersion("foo_db", previousVersion);
+ DatabaseProtocolServerInfo.setProtocolVersion("foo_db",
previousVersion);
}
@Test
@@ -96,7 +96,7 @@ class ShowVersionExecutorTest {
assertThat(actualQueryResultMetaData.getColumnName(1),
is(ShowVersionExecutor.FUNCTION_NAME));
assertThat(actualQueryResultMetaData.getColumnLabel(1),
is(expectedColumnLabel));
while (executor.getMergedResult().next()) {
- assertThat(executor.getMergedResult().getValue(1, Object.class),
is(MySQLServerInfo.getServerVersion("foo_db")));
+ assertThat(executor.getMergedResult().getValue(1, Object.class),
is(DatabaseProtocolServerInfo.getProtocolVersion("foo_db", "MySQL")));
}
}
}
diff --git
a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/sysvar/provider/TransactionIsolationValueProviderTest.java
b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/sysvar/provider/TransactionIsolationValueProviderTest.java
index 7621ddc3890..97c08b77711 100644
---
a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/sysvar/provider/TransactionIsolationValueProviderTest.java
+++
b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/sysvar/provider/TransactionIsolationValueProviderTest.java
@@ -20,7 +20,7 @@ package
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.sys
import io.netty.util.DefaultAttributeMap;
import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.sysvar.Scope;
-import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.sysvar.SystemVariable;
+import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.sysvar.MySQLSystemVariable;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import
org.apache.shardingsphere.sql.parser.sql.common.enums.TransactionIsolationLevel;
import org.apache.shardingsphere.transaction.api.TransactionType;
@@ -33,17 +33,17 @@ class TransactionIsolationValueProviderTest {
@Test
void assertGetGlobalValue() {
- assertThat(new TransactionIsolationValueProvider().get(Scope.GLOBAL,
null, SystemVariable.TRANSACTION_ISOLATION), is("REPEATABLE-READ"));
- assertThat(new TransactionIsolationValueProvider().get(Scope.GLOBAL,
null, SystemVariable.TX_ISOLATION), is("REPEATABLE-READ"));
+ assertThat(new TransactionIsolationValueProvider().get(Scope.GLOBAL,
null, MySQLSystemVariable.TRANSACTION_ISOLATION), is("REPEATABLE-READ"));
+ assertThat(new TransactionIsolationValueProvider().get(Scope.GLOBAL,
null, MySQLSystemVariable.TX_ISOLATION), is("REPEATABLE-READ"));
}
@Test
void assertGetSessionValue() {
ConnectionSession connectionSession = new ConnectionSession(new
MySQLDatabaseType(), TransactionType.LOCAL, new DefaultAttributeMap());
- assertThat(new TransactionIsolationValueProvider().get(Scope.SESSION,
connectionSession, SystemVariable.TRANSACTION_ISOLATION),
is("REPEATABLE-READ"));
- assertThat(new TransactionIsolationValueProvider().get(Scope.SESSION,
connectionSession, SystemVariable.TX_ISOLATION), is("REPEATABLE-READ"));
+ assertThat(new TransactionIsolationValueProvider().get(Scope.SESSION,
connectionSession, MySQLSystemVariable.TRANSACTION_ISOLATION),
is("REPEATABLE-READ"));
+ assertThat(new TransactionIsolationValueProvider().get(Scope.SESSION,
connectionSession, MySQLSystemVariable.TX_ISOLATION), is("REPEATABLE-READ"));
connectionSession.setIsolationLevel(TransactionIsolationLevel.READ_COMMITTED);
- assertThat(new TransactionIsolationValueProvider().get(Scope.SESSION,
connectionSession, SystemVariable.TRANSACTION_ISOLATION), is("READ-COMMITTED"));
- assertThat(new TransactionIsolationValueProvider().get(Scope.SESSION,
connectionSession, SystemVariable.TX_ISOLATION), is("READ-COMMITTED"));
+ assertThat(new TransactionIsolationValueProvider().get(Scope.SESSION,
connectionSession, MySQLSystemVariable.TRANSACTION_ISOLATION),
is("READ-COMMITTED"));
+ assertThat(new TransactionIsolationValueProvider().get(Scope.SESSION,
connectionSession, MySQLSystemVariable.TX_ISOLATION), is("READ-COMMITTED"));
}
}
diff --git
a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/sysvar/provider/TransactionReadOnlyValueProviderTest.java
b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/sysvar/provider/TransactionReadOnlyValueProviderTest.java
index be7a9e6e909..e6c4656d32d 100644
---
a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/sysvar/provider/TransactionReadOnlyValueProviderTest.java
+++
b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/sysvar/provider/TransactionReadOnlyValueProviderTest.java
@@ -20,7 +20,7 @@ package
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.sys
import io.netty.util.DefaultAttributeMap;
import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.sysvar.Scope;
-import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.sysvar.SystemVariable;
+import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.sysvar.MySQLSystemVariable;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.transaction.api.TransactionType;
import org.junit.jupiter.api.Test;
@@ -32,17 +32,17 @@ class TransactionReadOnlyValueProviderTest {
@Test
void assertGetGlobalValue() {
- assertThat(new TransactionReadOnlyValueProvider().get(Scope.GLOBAL,
null, SystemVariable.TX_READ_ONLY), is("0"));
- assertThat(new TransactionReadOnlyValueProvider().get(Scope.GLOBAL,
null, SystemVariable.TRANSACTION_READ_ONLY), is("0"));
+ assertThat(new TransactionReadOnlyValueProvider().get(Scope.GLOBAL,
null, MySQLSystemVariable.TX_READ_ONLY), is("0"));
+ assertThat(new TransactionReadOnlyValueProvider().get(Scope.GLOBAL,
null, MySQLSystemVariable.TRANSACTION_READ_ONLY), is("0"));
}
@Test
void assertGetSessionValue() {
ConnectionSession connectionSession = new ConnectionSession(new
MySQLDatabaseType(), TransactionType.LOCAL, new DefaultAttributeMap());
- assertThat(new TransactionReadOnlyValueProvider().get(Scope.SESSION,
connectionSession, SystemVariable.TX_READ_ONLY), is("0"));
- assertThat(new TransactionReadOnlyValueProvider().get(Scope.SESSION,
connectionSession, SystemVariable.TRANSACTION_READ_ONLY), is("0"));
+ assertThat(new TransactionReadOnlyValueProvider().get(Scope.SESSION,
connectionSession, MySQLSystemVariable.TX_READ_ONLY), is("0"));
+ assertThat(new TransactionReadOnlyValueProvider().get(Scope.SESSION,
connectionSession, MySQLSystemVariable.TRANSACTION_READ_ONLY), is("0"));
connectionSession.setReadOnly(true);
- assertThat(new TransactionReadOnlyValueProvider().get(Scope.SESSION,
connectionSession, SystemVariable.TX_READ_ONLY), is("1"));
- assertThat(new TransactionReadOnlyValueProvider().get(Scope.SESSION,
connectionSession, SystemVariable.TRANSACTION_READ_ONLY), is("1"));
+ assertThat(new TransactionReadOnlyValueProvider().get(Scope.SESSION,
connectionSession, MySQLSystemVariable.TX_READ_ONLY), is("1"));
+ assertThat(new TransactionReadOnlyValueProvider().get(Scope.SESSION,
connectionSession, MySQLSystemVariable.TRANSACTION_READ_ONLY), is("1"));
}
}
diff --git
a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/sysvar/provider/VersionValueProviderTest.java
b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/sysvar/provider/VersionValueProviderTest.java
index 3e34cc156ce..acd06096a29 100644
---
a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/sysvar/provider/VersionValueProviderTest.java
+++
b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/sysvar/provider/VersionValueProviderTest.java
@@ -18,27 +18,27 @@
package
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.sysvar.provider;
import io.netty.util.DefaultAttributeMap;
-import org.apache.shardingsphere.db.protocol.mysql.constant.MySQLServerInfo;
+import
org.apache.shardingsphere.db.protocol.constant.DatabaseProtocolServerInfo;
import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
+import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.sysvar.MySQLSystemVariable;
import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.sysvar.Scope;
-import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.sysvar.SystemVariable;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.transaction.api.TransactionType;
-import org.hamcrest.MatcherAssert;
import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
class VersionValueProviderTest {
@Test
void assertGetValue() {
- try (MockedStatic<MySQLServerInfo> mockedStatic =
Mockito.mockStatic(MySQLServerInfo.class)) {
- mockedStatic.when(() ->
MySQLServerInfo.getServerVersion(null)).thenReturn("8.0");
+ try (MockedStatic<DatabaseProtocolServerInfo> mockedStatic =
Mockito.mockStatic(DatabaseProtocolServerInfo.class)) {
+ mockedStatic.when(() ->
DatabaseProtocolServerInfo.getProtocolVersion(null, "MySQL")).thenReturn("8.0");
ConnectionSession connectionSession = new ConnectionSession(new
MySQLDatabaseType(), TransactionType.LOCAL, new DefaultAttributeMap());
- MatcherAssert.assertThat(new
VersionValueProvider().get(Scope.GLOBAL, connectionSession,
SystemVariable.VERSION), is("8.0"));
+ assertThat(new VersionValueProvider().get(Scope.GLOBAL,
connectionSession, MySQLSystemVariable.VERSION), is("8.0"));
}
}
}
diff --git
a/proxy/bootstrap/src/test/java/org/apache/shardingsphere/proxy/version/ShardingSphereProxyVersionTest.java
b/proxy/bootstrap/src/test/java/org/apache/shardingsphere/proxy/version/ShardingSphereProxyVersionTest.java
index caee9fc6182..5cdbcb33ed4 100644
---
a/proxy/bootstrap/src/test/java/org/apache/shardingsphere/proxy/version/ShardingSphereProxyVersionTest.java
+++
b/proxy/bootstrap/src/test/java/org/apache/shardingsphere/proxy/version/ShardingSphereProxyVersionTest.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.proxy.version;
-import org.apache.shardingsphere.db.protocol.mysql.constant.MySQLServerInfo;
+import
org.apache.shardingsphere.db.protocol.constant.DatabaseProtocolServerInfo;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResourceMetaData;
@@ -51,13 +51,13 @@ class ShardingSphereProxyVersionTest {
@Test
void assertSetVersionWhenStorageTypeSameWithProtocolType() throws
SQLException {
ShardingSphereProxyVersion.setVersion(mockContextManager("MySQL",
"5.7.22"));
- assertThat(MySQLServerInfo.getServerVersion("foo_db"),
startsWith("5.7.22"));
+ assertThat(DatabaseProtocolServerInfo.getProtocolVersion("foo_db",
"MySQL"), startsWith("5.7.22"));
}
@Test
void assertSetVersionWhenStorageTypeDifferentWithProtocolType() throws
SQLException {
ShardingSphereProxyVersion.setVersion(mockContextManager("Oracle",
"12.0.0"));
- assertThat(MySQLServerInfo.getServerVersion("foo_db"),
startsWith("5.7.22"));
+ assertThat(DatabaseProtocolServerInfo.getProtocolVersion("foo_db",
"MySQL"), startsWith("5.7.22"));
}
private ContextManager mockContextManager(final String databaseType, final
String databaseProductVersion) throws SQLException {
diff --git
a/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLFrontendEngine.java
b/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLFrontendEngine.java
index 95ee7fc5069..a06e9a30c6f 100644
---
a/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLFrontendEngine.java
+++
b/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLFrontendEngine.java
@@ -20,9 +20,9 @@ package org.apache.shardingsphere.proxy.frontend.mysql;
import io.netty.channel.Channel;
import lombok.Getter;
import org.apache.shardingsphere.db.protocol.codec.DatabasePacketCodecEngine;
+import
org.apache.shardingsphere.db.protocol.constant.DatabaseProtocolServerInfo;
import
org.apache.shardingsphere.db.protocol.mysql.codec.MySQLPacketCodecEngine;
import org.apache.shardingsphere.db.protocol.mysql.constant.MySQLConstants;
-import org.apache.shardingsphere.db.protocol.mysql.constant.MySQLServerInfo;
import
org.apache.shardingsphere.db.protocol.mysql.netty.MySQLSequenceIdInboundHandler;
import org.apache.shardingsphere.db.protocol.mysql.packet.MySQLPacket;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
@@ -56,7 +56,7 @@ public final class MySQLFrontendEngine implements
DatabaseProtocolFrontendEngine
@Override
public void setDatabaseVersion(final String databaseName, final String
databaseVersion) {
- MySQLServerInfo.setServerVersion(databaseName, databaseVersion);
+ DatabaseProtocolServerInfo.setProtocolVersion(databaseName,
databaseVersion);
}
@Override
diff --git
a/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLFrontendEngineTest.java
b/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLFrontendEngineTest.java
index 6e234a5ed3e..9559dd2c2a5 100644
---
a/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLFrontendEngineTest.java
+++
b/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLFrontendEngineTest.java
@@ -18,8 +18,8 @@
package org.apache.shardingsphere.proxy.frontend.mysql;
import io.netty.channel.Channel;
+import
org.apache.shardingsphere.db.protocol.constant.DatabaseProtocolServerInfo;
import org.apache.shardingsphere.db.protocol.mysql.constant.MySQLConstants;
-import org.apache.shardingsphere.db.protocol.mysql.constant.MySQLServerInfo;
import
org.apache.shardingsphere.db.protocol.mysql.netty.MySQLSequenceIdInboundHandler;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
@@ -73,9 +73,9 @@ class MySQLFrontendEngineTest {
void assertSetDatabaseVersion() {
String databaseName = "db";
String databaseVersion = "version";
- try (MockedStatic<MySQLServerInfo> mockedStatic =
mockStatic(MySQLServerInfo.class)) {
+ try (MockedStatic<DatabaseProtocolServerInfo> mockedStatic =
mockStatic(DatabaseProtocolServerInfo.class)) {
engine.setDatabaseVersion(databaseName, databaseVersion);
- mockedStatic.verify(() ->
MySQLServerInfo.setServerVersion(databaseName, databaseVersion));
+ mockedStatic.verify(() ->
DatabaseProtocolServerInfo.setProtocolVersion(databaseName, databaseVersion));
}
}
diff --git
a/proxy/frontend/type/opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/OpenGaussFrontendEngine.java
b/proxy/frontend/type/opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/OpenGaussFrontendEngine.java
index dfec2fb6253..889b9b99c00 100644
---
a/proxy/frontend/type/opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/OpenGaussFrontendEngine.java
+++
b/proxy/frontend/type/opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/OpenGaussFrontendEngine.java
@@ -19,8 +19,8 @@ package org.apache.shardingsphere.proxy.frontend.opengauss;
import lombok.AccessLevel;
import lombok.Getter;
+import
org.apache.shardingsphere.db.protocol.constant.DatabaseProtocolServerInfo;
import
org.apache.shardingsphere.db.protocol.opengauss.codec.OpenGaussPacketCodecEngine;
-import
org.apache.shardingsphere.db.protocol.postgresql.constant.PostgreSQLServerInfo;
import
org.apache.shardingsphere.dialect.exception.transaction.InTransactionException;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import
org.apache.shardingsphere.proxy.frontend.opengauss.authentication.OpenGaussAuthenticationEngine;
@@ -45,7 +45,7 @@ public final class OpenGaussFrontendEngine implements
DatabaseProtocolFrontendEn
@Override
public void setDatabaseVersion(final String databaseName, final String
databaseVersion) {
- PostgreSQLServerInfo.setServerVersion(databaseName, databaseVersion);
+ DatabaseProtocolServerInfo.setProtocolVersion(databaseName,
databaseVersion);
}
@Override
diff --git
a/proxy/frontend/type/opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationEngine.java
b/proxy/frontend/type/opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationEngine.java
index 4488ff242eb..0a9b1e3af19 100644
---
a/proxy/frontend/type/opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationEngine.java
+++
b/proxy/frontend/type/opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationEngine.java
@@ -23,12 +23,12 @@ import io.netty.handler.ssl.SslHandler;
import org.apache.shardingsphere.authority.checker.AuthorityChecker;
import org.apache.shardingsphere.authority.rule.AuthorityRule;
import org.apache.shardingsphere.db.protocol.constant.CommonConstants;
+import
org.apache.shardingsphere.db.protocol.constant.DatabaseProtocolServerInfo;
import
org.apache.shardingsphere.db.protocol.opengauss.constant.OpenGaussProtocolVersion;
import
org.apache.shardingsphere.db.protocol.opengauss.packet.authentication.OpenGaussAuthenticationHexData;
import
org.apache.shardingsphere.db.protocol.opengauss.packet.authentication.OpenGaussAuthenticationSCRAMSha256Packet;
import org.apache.shardingsphere.db.protocol.payload.PacketPayload;
import
org.apache.shardingsphere.db.protocol.postgresql.constant.PostgreSQLAuthenticationMethod;
-import
org.apache.shardingsphere.db.protocol.postgresql.constant.PostgreSQLServerInfo;
import
org.apache.shardingsphere.db.protocol.postgresql.packet.generic.PostgreSQLReadyForQueryPacket;
import
org.apache.shardingsphere.db.protocol.postgresql.packet.handshake.PostgreSQLAuthenticationOKPacket;
import
org.apache.shardingsphere.db.protocol.postgresql.packet.handshake.PostgreSQLComStartupPacket;
@@ -119,7 +119,7 @@ public final class OpenGaussAuthenticationEngine implements
AuthenticationEngine
PostgreSQLPasswordMessagePacket passwordMessagePacket = new
PostgreSQLPasswordMessagePacket(payload);
login(rule, passwordMessagePacket.getDigest());
context.write(new PostgreSQLAuthenticationOKPacket());
- context.write(new PostgreSQLParameterStatusPacket("server_version",
PostgreSQLServerInfo.getServerVersion(currentAuthResult.getDatabase())));
+ context.write(new PostgreSQLParameterStatusPacket("server_version",
DatabaseProtocolServerInfo.getProtocolVersion(currentAuthResult.getDatabase(),
"openGauss")));
context.write(new PostgreSQLParameterStatusPacket("client_encoding",
clientEncoding));
context.write(new PostgreSQLParameterStatusPacket("server_encoding",
"UTF8"));
context.write(new PostgreSQLParameterStatusPacket("integer_datetimes",
"on"));
diff --git
a/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/PostgreSQLFrontendEngine.java
b/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/PostgreSQLFrontendEngine.java
index a23842ec89a..414d4666dc4 100644
---
a/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/PostgreSQLFrontendEngine.java
+++
b/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/PostgreSQLFrontendEngine.java
@@ -19,8 +19,8 @@ package org.apache.shardingsphere.proxy.frontend.postgresql;
import lombok.Getter;
import org.apache.shardingsphere.db.protocol.codec.DatabasePacketCodecEngine;
+import
org.apache.shardingsphere.db.protocol.constant.DatabaseProtocolServerInfo;
import
org.apache.shardingsphere.db.protocol.postgresql.codec.PostgreSQLPacketCodecEngine;
-import
org.apache.shardingsphere.db.protocol.postgresql.constant.PostgreSQLServerInfo;
import
org.apache.shardingsphere.db.protocol.postgresql.packet.PostgreSQLPacket;
import
org.apache.shardingsphere.dialect.exception.transaction.InTransactionException;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
@@ -45,7 +45,7 @@ public final class PostgreSQLFrontendEngine implements
DatabaseProtocolFrontendE
@Override
public void setDatabaseVersion(final String databaseName, final String
databaseVersion) {
- PostgreSQLServerInfo.setServerVersion(databaseName, databaseVersion);
+ DatabaseProtocolServerInfo.setProtocolVersion(databaseName,
databaseVersion);
}
@Override
diff --git
a/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationEngine.java
b/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationEngine.java
index 0e21d08a5be..55f2c291906 100644
---
a/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationEngine.java
+++
b/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationEngine.java
@@ -23,9 +23,9 @@ import io.netty.handler.ssl.SslHandler;
import org.apache.shardingsphere.authority.checker.AuthorityChecker;
import org.apache.shardingsphere.authority.rule.AuthorityRule;
import org.apache.shardingsphere.db.protocol.constant.CommonConstants;
+import
org.apache.shardingsphere.db.protocol.constant.DatabaseProtocolServerInfo;
import org.apache.shardingsphere.db.protocol.payload.PacketPayload;
import
org.apache.shardingsphere.db.protocol.postgresql.constant.PostgreSQLAuthenticationMethod;
-import
org.apache.shardingsphere.db.protocol.postgresql.constant.PostgreSQLServerInfo;
import
org.apache.shardingsphere.db.protocol.postgresql.packet.generic.PostgreSQLReadyForQueryPacket;
import
org.apache.shardingsphere.db.protocol.postgresql.packet.handshake.PostgreSQLAuthenticationOKPacket;
import
org.apache.shardingsphere.db.protocol.postgresql.packet.handshake.PostgreSQLComStartupPacket;
@@ -108,7 +108,7 @@ public final class PostgreSQLAuthenticationEngine
implements AuthenticationEngin
login(currentAuthResult.getDatabase(),
currentAuthResult.getUsername(), md5Salt, passwordMessagePacket.getDigest(),
rule);
// TODO implement PostgreSQLServerInfo like MySQLServerInfo
context.write(new PostgreSQLAuthenticationOKPacket());
- context.write(new PostgreSQLParameterStatusPacket("server_version",
PostgreSQLServerInfo.getServerVersion(currentAuthResult.getDatabase())));
+ context.write(new PostgreSQLParameterStatusPacket("server_version",
DatabaseProtocolServerInfo.getProtocolVersion(currentAuthResult.getDatabase(),
"PostgreSQL")));
context.write(new PostgreSQLParameterStatusPacket("client_encoding",
clientEncoding));
context.write(new PostgreSQLParameterStatusPacket("server_encoding",
"UTF8"));
context.write(new PostgreSQLParameterStatusPacket("integer_datetimes",
"on"));