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 a997ee36c6e Refactor SessionVariableRecordExecutor (#27360)
a997ee36c6e is described below
commit a997ee36c6e81a94a70b302aafac1fe9e35bd429
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Jul 22 06:02:26 2023 +0800
Refactor SessionVariableRecordExecutor (#27360)
* Add SetCharsetExecutor
* Refactor SessionVariableHandler
* Refactor SessionVariableReplayExecutor
* Refactor SessionVariableReplayExecutor
* Refactor SessionVariableReplayExecutor
* Rename SessionVariableRecordExecutor
* Rename ReplayedSessionVariableProvider
* Refactor CharsetSetExecutor
* Refactor CharsetSetExecutor
---
.../executor/DefaultSessionVariableHandler.java | 58 -----------------
.../variable/charset/CharsetSetExecutor.java | 69 ++++++++++++++++++++
.../charset/CharsetVariableProvider.java} | 28 +++++---
.../session/ReplayedSessionVariableProvider.java} | 15 ++---
.../session/SessionVariableRecordExecutor.java | 74 ++++++++++++++++++++++
.../handler/admin/MySQLAdminExecutorCreator.java | 1 +
.../handler/admin/MySQLSessionVariableHandler.java | 28 --------
.../MySQLSetVariableAdminExecutor.java | 15 ++---
.../charset}/MySQLSetCharsetExecutor.java | 38 +++++------
.../MySQLReplayedSessionVariableProvider.java} | 17 ++---
...cutor.variable.charset.CharsetVariableProvider} | 3 +-
...riable.session.ReplayedSessionVariableProvider} | 3 +-
.../MySQLAdminExecutorCreatorTest.java | 21 ++++--
.../DefaultMySQLSessionVariableHandlerTest.java | 65 -------------------
.../MySQLSetVariableAdminExecutorTest.java | 2 +-
.../admin/PostgreSQLAdminExecutorCreator.java | 3 +
.../PostgreSQLDefaultSessionVariableHandler.java | 30 ---------
.../admin/PostgreSQLSessionVariableHandler.java | 28 --------
.../PostgreSQLResetVariableAdminExecutor.java | 11 +++-
.../PostgreSQLSetVariableAdminExecutor.java | 11 +++-
.../PostgreSQLShowVariableExecutor.java | 2 +-
.../variable/charset}/PostgreSQLCharacterSets.java | 2 +-
.../charset}/PostgreSQLSetCharsetExecutor.java | 29 +++++----
...cutor.variable.charset.CharsetVariableProvider} | 3 +-
.../admin/PostgreSQLAdminExecutorCreatorTest.java | 3 +
.../PostgreSQLResetVariableAdminExecutorTest.java | 41 ------------
.../PostgreSQLResetVariableAdminExecutorTest.java} | 38 ++++++-----
.../PostgreSQLSetVariableAdminExecutorTest.java | 26 ++++++--
.../PostgreSQLShowVariableExecutorTest.java | 2 +-
.../charset}/PostgreSQLCharacterSetsTest.java | 2 +-
.../OpenGaussAuthenticationEngine.java | 2 +-
.../PostgreSQLAuthenticationEngine.java | 2 +-
32 files changed, 304 insertions(+), 368 deletions(-)
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/DefaultSessionVariableHandler.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/DefaultSessionVariableHandler.java
deleted file mode 100644
index 68e7215ad92..00000000000
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/DefaultSessionVariableHandler.java
+++ /dev/null
@@ -1,58 +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.proxy.backend.handler.admin.executor;
-
-import lombok.extern.slf4j.Slf4j;
-import
org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPILoader;
-import org.apache.shardingsphere.infra.database.spi.DatabaseType;
-import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
-import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
-
-import java.util.Collections;
-
-/**
- * Default session variable handler.
- */
-@Slf4j
-public abstract class DefaultSessionVariableHandler implements
SessionVariableHandler {
-
- private final DatabaseType databaseType;
-
- protected DefaultSessionVariableHandler(final String databaseType) {
- this.databaseType = TypedSPILoader.getService(DatabaseType.class,
databaseType);
- }
-
- @Override
- public final void handle(final ConnectionSession connectionSession, final
String variableName, final String assignValue) {
- if
(DatabaseTypedSPILoader.findService(ReplayedSessionVariablesProvider.class,
databaseType).map(ReplayedSessionVariablesProvider::getVariables).orElseGet(Collections::emptySet)
- .contains(variableName) || isNeedHandle(variableName)) {
-
connectionSession.getRequiredSessionVariableRecorder().setVariable(variableName,
assignValue);
- } else {
- log.debug("Set statement {} = {} was discarded.", variableName,
assignValue);
- }
- }
-
- protected boolean isNeedHandle(final String variableName) {
- return false;
- }
-
- @Override
- public final boolean isDefault() {
- return true;
- }
-}
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/variable/charset/CharsetSetExecutor.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/variable/charset/CharsetSetExecutor.java
new file mode 100644
index 00000000000..1f71b7f0f8a
--- /dev/null
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/variable/charset/CharsetSetExecutor.java
@@ -0,0 +1,69 @@
+/*
+ * 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.proxy.backend.handler.admin.executor.variable.charset;
+
+import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.db.protocol.constant.CommonConstants;
+import
org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPILoader;
+import org.apache.shardingsphere.infra.database.spi.DatabaseType;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
+
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Optional;
+
+/**
+ * Set charset executor.
+ */
+@RequiredArgsConstructor
+public final class CharsetSetExecutor {
+
+ private final DatabaseType databaseType;
+
+ private final ConnectionSession connectionSession;
+
+ /**
+ * Set charset.
+ *
+ * @param variableName variable name
+ * @param assignValue assign value
+ */
+ public void set(final String variableName, final String assignValue) {
+ Optional<CharsetVariableProvider> charsetVariableProvider =
DatabaseTypedSPILoader.findService(CharsetVariableProvider.class, databaseType);
+ if (charsetVariableProvider.isPresent() &&
charsetVariableProvider.get().isCharsetVariable(variableName)) {
+
connectionSession.getAttributeMap().attr(CommonConstants.CHARSET_ATTRIBUTE_KEY).set(charsetVariableProvider.get().parseCharset(assignValue));
+ }
+ }
+
+ /**
+ * Set charset.
+ *
+ * @param variables variables
+ */
+ public void set(final Map<String, String> variables) {
+ Optional<CharsetVariableProvider> charsetVariableProvider =
DatabaseTypedSPILoader.findService(CharsetVariableProvider.class, databaseType);
+ if (!charsetVariableProvider.isPresent()) {
+ return;
+ }
+ for (Entry<String, String> entry : variables.entrySet()) {
+ if
(charsetVariableProvider.get().isCharsetVariable(entry.getKey())) {
+
connectionSession.getAttributeMap().attr(CommonConstants.CHARSET_ATTRIBUTE_KEY).set(charsetVariableProvider.get().parseCharset(entry.getValue()));
+ }
+ }
+ }
+}
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/SessionVariableHandler.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/variable/charset/CharsetVariableProvider.java
similarity index 59%
rename from
proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/SessionVariableHandler.java
rename to
proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/variable/charset/CharsetVariableProvider.java
index 76de604a9e6..5a9dae97318 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/SessionVariableHandler.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/variable/charset/CharsetVariableProvider.java
@@ -15,22 +15,32 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.handler.admin.executor;
+package
org.apache.shardingsphere.proxy.backend.handler.admin.executor.variable.charset;
-import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
-import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPI;
+import org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPI;
+import org.apache.shardingsphere.infra.util.spi.annotation.SingletonSPI;
+
+import java.nio.charset.Charset;
/**
- * Session variable handler.
+ * Charset variable provider.
*/
-public interface SessionVariableHandler extends TypedSPI {
+@SingletonSPI
+public interface CharsetVariableProvider extends DatabaseTypedSPI {
/**
- * Handle session variable for specific connection session.
+ * Judge whether charset variable name.
*
- * @param connectionSession connection session
* @param variableName variable name
- * @param assignValue assign value
+ * @return is charset variable or not
+ */
+ boolean isCharsetVariable(String variableName);
+
+ /**
+ * Parse charset from variable.
+ *
+ * @param variableValue variable value
+ * @return charset
*/
- void handle(ConnectionSession connectionSession, String variableName,
String assignValue);
+ Charset parseCharset(String variableValue);
}
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/ReplayedSessionVariablesProvider.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/variable/session/ReplayedSessionVariableProvider.java
similarity index 74%
rename from
proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/ReplayedSessionVariablesProvider.java
rename to
proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/variable/session/ReplayedSessionVariableProvider.java
index a17f9f43478..cff76372f29 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/ReplayedSessionVariablesProvider.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/variable/session/ReplayedSessionVariableProvider.java
@@ -15,23 +15,22 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.handler.admin.executor;
+package
org.apache.shardingsphere.proxy.backend.handler.admin.executor.variable.session;
import org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPI;
import org.apache.shardingsphere.infra.util.spi.annotation.SingletonSPI;
-import java.util.Collection;
-
/**
- * Provide session variables need to be replayed on session connected.
+ * Provide session variable need to be replayed on session connected.
*/
@SingletonSPI
-public interface ReplayedSessionVariablesProvider extends DatabaseTypedSPI {
+public interface ReplayedSessionVariableProvider extends DatabaseTypedSPI {
/**
- * Get need to be replayed session variables.
+ * Judge variable whether to need replay.
*
- * @return variables
+ * @param variableName variable name to be judged
+ * @return variable need to replay or not
*/
- Collection<String> getVariables();
+ boolean isNeedToReplay(String variableName);
}
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/variable/session/SessionVariableRecordExecutor.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/variable/session/SessionVariableRecordExecutor.java
new file mode 100644
index 00000000000..ecee3dff595
--- /dev/null
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/executor/variable/session/SessionVariableRecordExecutor.java
@@ -0,0 +1,74 @@
+/*
+ * 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.proxy.backend.handler.admin.executor.variable.session;
+
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import
org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPILoader;
+import org.apache.shardingsphere.infra.database.spi.DatabaseType;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
+
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Optional;
+
+/**
+ * Session variable record executor.
+ */
+@RequiredArgsConstructor
+@Slf4j
+public final class SessionVariableRecordExecutor {
+
+ private final DatabaseType databaseType;
+
+ private final ConnectionSession connectionSession;
+
+ /**
+ * Record replayed variable.
+ *
+ * @param variableName variable name
+ * @param assignValue assign value
+ */
+ public void record(final String variableName, final String assignValue) {
+ if
(DatabaseTypedSPILoader.findService(ReplayedSessionVariableProvider.class,
databaseType).map(optional ->
optional.isNeedToReplay(variableName)).orElse(false)) {
+
connectionSession.getRequiredSessionVariableRecorder().setVariable(variableName,
assignValue);
+ } else {
+ log.debug("Set statement {} = {} was discarded.", variableName,
assignValue);
+ }
+ }
+
+ /**
+ * Record replayed variable.
+ *
+ * @param variables variables
+ */
+ public void record(final Map<String, String> variables) {
+ Optional<ReplayedSessionVariableProvider>
replayedSessionVariableProvider =
DatabaseTypedSPILoader.findService(ReplayedSessionVariableProvider.class,
databaseType);
+ if (!replayedSessionVariableProvider.isPresent()) {
+ log.debug("Set statement {} was discarded.", variables);
+ return;
+ }
+ for (Entry<String, String> entry : variables.entrySet()) {
+ if
(replayedSessionVariableProvider.get().isNeedToReplay(entry.getKey())) {
+
connectionSession.getRequiredSessionVariableRecorder().setVariable(entry.getKey(),
entry.getValue());
+ } else {
+ log.debug("Set statement {} = {} was discarded.",
entry.getKey(), entry.getValue());
+ }
+ }
+ }
+}
diff --git
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLAdminExecutorCreator.java
b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLAdminExecutorCreator.java
index 71394816c48..acd77b954de 100644
---
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLAdminExecutorCreator.java
+++
b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLAdminExecutorCreator.java
@@ -22,6 +22,7 @@ import
org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminExecutor;
import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminExecutorCreator;
import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.KillProcessExecutor;
+import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.MySQLSetVariableAdminExecutor;
import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.MySQLSystemVariableQueryExecutor;
import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.NoResourceShowExecutor;
import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.ShowConnectionIdExecutor;
diff --git
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLSessionVariableHandler.java
b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLSessionVariableHandler.java
deleted file mode 100644
index d9c880af820..00000000000
---
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLSessionVariableHandler.java
+++ /dev/null
@@ -1,28 +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.proxy.backend.mysql.handler.admin;
-
-import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.SessionVariableHandler;
-import org.apache.shardingsphere.infra.util.spi.annotation.SingletonSPI;
-
-/**
- * Session variable handler for MySQL.
- */
-@SingletonSPI
-public interface MySQLSessionVariableHandler extends SessionVariableHandler {
-}
diff --git
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLSetVariableAdminExecutor.java
b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/MySQLSetVariableAdminExecutor.java
similarity index 91%
rename from
proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLSetVariableAdminExecutor.java
rename to
proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/MySQLSetVariableAdminExecutor.java
index 333369ec626..1c2cc24c0d5 100644
---
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLSetVariableAdminExecutor.java
+++
b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/MySQLSetVariableAdminExecutor.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.mysql.handler.admin;
+package org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor;
import lombok.RequiredArgsConstructor;
import
org.apache.shardingsphere.dialect.mysql.exception.UnknownSystemVariableException;
@@ -29,6 +29,8 @@ import org.apache.shardingsphere.parser.rule.SQLParserRule;
import
org.apache.shardingsphere.proxy.backend.connector.DatabaseConnectorFactory;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminExecutor;
+import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.variable.charset.CharsetSetExecutor;
+import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.variable.session.SessionVariableRecordExecutor;
import
org.apache.shardingsphere.proxy.backend.handler.data.DatabaseBackendHandler;
import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.sysvar.MySQLSystemVariable;
import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.sysvar.Scope;
@@ -42,8 +44,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
-import java.util.Map.Entry;
-import java.util.function.Function;
import java.util.stream.Collectors;
/**
@@ -52,17 +52,16 @@ import java.util.stream.Collectors;
@RequiredArgsConstructor
public final class MySQLSetVariableAdminExecutor implements
DatabaseAdminExecutor {
+ private final DatabaseType databaseType =
TypedSPILoader.getService(DatabaseType.class, "MySQL");
+
private final SetStatement setStatement;
@Override
public void execute(final ConnectionSession connectionSession) throws
SQLException {
Map<String, String> sessionVariables = extractSessionVariables();
validateSessionVariables(sessionVariables.keySet());
- Map<String, MySQLSessionVariableHandler> handlers =
sessionVariables.keySet().stream()
- .collect(Collectors.toMap(Function.identity(), value ->
TypedSPILoader.getService(MySQLSessionVariableHandler.class, value)));
- for (Entry<String, MySQLSessionVariableHandler> entry :
handlers.entrySet()) {
- entry.getValue().handle(connectionSession, entry.getKey(),
sessionVariables.get(entry.getKey()));
- }
+ new CharsetSetExecutor(databaseType,
connectionSession).set(sessionVariables);
+ new SessionVariableRecordExecutor(databaseType,
connectionSession).record(sessionVariables);
executeSetGlobalVariablesIfPresent(connectionSession);
}
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/variable/charset/MySQLSetCharsetExecutor.java
similarity index 55%
rename from
proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/MySQLSetCharsetExecutor.java
rename to
proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/variable/charset/MySQLSetCharsetExecutor.java
index 11e47ee7586..f583e223aee 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/variable/charset/MySQLSetCharsetExecutor.java
@@ -15,58 +15,50 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor;
+package
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.variable.charset;
-import org.apache.shardingsphere.db.protocol.constant.CommonConstants;
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;
import org.apache.shardingsphere.infra.util.quote.QuoteCharacter;
+import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.variable.charset.CharsetVariableProvider;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
-import java.util.Collection;
-import java.util.Collections;
import java.util.Locale;
/**
* Set charset executor of MySQL.
*/
-public final class MySQLSetCharsetExecutor implements
MySQLSessionVariableHandler {
+public final class MySQLSetCharsetExecutor implements CharsetVariableProvider {
@Override
- public void handle(final ConnectionSession connectionSession, final String
variableName, final String assignValue) {
- String value = formatValue(assignValue);
-
connectionSession.getAttributeMap().attr(CommonConstants.CHARSET_ATTRIBUTE_KEY).set(parseCharset(value));
+ public boolean isCharsetVariable(final String variableName) {
+ return "charset".equalsIgnoreCase(variableName) ||
"character_set_client".equalsIgnoreCase(variableName);
}
- private String formatValue(final String value) {
- return QuoteCharacter.SINGLE_QUOTE.isWrapped(value) ||
QuoteCharacter.QUOTE.isWrapped(value) ? value.substring(1, value.length() - 1)
: value.trim();
- }
-
- private Charset parseCharset(final String value) {
- switch (value.toLowerCase(Locale.ROOT)) {
+ @Override
+ public Charset parseCharset(final String variableValue) {
+ String formattedValue = formatValue(variableValue);
+ switch (formattedValue.toLowerCase(Locale.ROOT)) {
case "default":
return MySQLConstants.DEFAULT_CHARSET.getCharset();
case "utf8mb4":
return StandardCharsets.UTF_8;
default:
try {
- return Charset.forName(value);
+ return Charset.forName(formattedValue);
} catch (final IllegalArgumentException ex) {
- throw new UnknownCharsetException(value.toLowerCase());
+ throw new
UnknownCharsetException(formattedValue.toLowerCase(Locale.ROOT));
}
}
}
- @Override
- public String getType() {
- return "charset";
+ private String formatValue(final String variableValue) {
+ return QuoteCharacter.SINGLE_QUOTE.isWrapped(variableValue) ||
QuoteCharacter.QUOTE.isWrapped(variableValue) ? variableValue.substring(1,
variableValue.length() - 1) : variableValue.trim();
}
@Override
- public Collection<Object> getTypeAliases() {
- return Collections.singleton("character_set_client");
+ public String getDatabaseType() {
+ return "MySQL";
}
}
diff --git
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLDefaultSessionVariableHandler.java
b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/variable/session/MySQLReplayedSessionVariableProvider.java
similarity index 73%
rename from
proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLDefaultSessionVariableHandler.java
rename to
proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/variable/session/MySQLReplayedSessionVariableProvider.java
index 49653638fc0..474ea52fee5 100644
---
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLDefaultSessionVariableHandler.java
+++
b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/variable/session/MySQLReplayedSessionVariableProvider.java
@@ -15,21 +15,22 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.mysql.handler.admin;
+package
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.variable.session;
-import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.DefaultSessionVariableHandler;
+import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.variable.session.ReplayedSessionVariableProvider;
/**
- * Default session variable handler for MySQL.
+ * Replayed session variables provider of MySQL.
*/
-public final class MySQLDefaultSessionVariableHandler extends
DefaultSessionVariableHandler implements MySQLSessionVariableHandler {
+public final class MySQLReplayedSessionVariableProvider implements
ReplayedSessionVariableProvider {
- public MySQLDefaultSessionVariableHandler() {
- super("MySQL");
+ @Override
+ public boolean isNeedToReplay(final String variableName) {
+ return variableName.startsWith("@");
}
@Override
- protected boolean isNeedHandle(final String variableName) {
- return variableName.startsWith("@");
+ public String getDatabaseType() {
+ return "MySQL";
}
}
diff --git
a/proxy/backend/type/mysql/src/main/resources/META-INF/services/org.apache.shardingsphere.proxy.backend.mysql.handler.admin.MySQLSessionVariableHandler
b/proxy/backend/type/mysql/src/main/resources/META-INF/services/org.apache.shardingsphere.proxy.backend.handler.admin.executor.variable.charset.CharsetVariableProvider
similarity index 87%
copy from
proxy/backend/type/mysql/src/main/resources/META-INF/services/org.apache.shardingsphere.proxy.backend.mysql.handler.admin.MySQLSessionVariableHandler
copy to
proxy/backend/type/mysql/src/main/resources/META-INF/services/org.apache.shardingsphere.proxy.backend.handler.admin.executor.variable.charset.CharsetVariableProvider
index 268ad484de0..8f750f65a35 100644
---
a/proxy/backend/type/mysql/src/main/resources/META-INF/services/org.apache.shardingsphere.proxy.backend.mysql.handler.admin.MySQLSessionVariableHandler
+++
b/proxy/backend/type/mysql/src/main/resources/META-INF/services/org.apache.shardingsphere.proxy.backend.handler.admin.executor.variable.charset.CharsetVariableProvider
@@ -15,5 +15,4 @@
# limitations under the License.
#
-org.apache.shardingsphere.proxy.backend.mysql.handler.admin.MySQLDefaultSessionVariableHandler
-org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.MySQLSetCharsetExecutor
+org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.variable.charset.MySQLSetCharsetExecutor
diff --git
a/proxy/backend/type/mysql/src/main/resources/META-INF/services/org.apache.shardingsphere.proxy.backend.mysql.handler.admin.MySQLSessionVariableHandler
b/proxy/backend/type/mysql/src/main/resources/META-INF/services/org.apache.shardingsphere.proxy.backend.handler.admin.executor.variable.session.ReplayedSessionVariableProvider
similarity index 87%
rename from
proxy/backend/type/mysql/src/main/resources/META-INF/services/org.apache.shardingsphere.proxy.backend.mysql.handler.admin.MySQLSessionVariableHandler
rename to
proxy/backend/type/mysql/src/main/resources/META-INF/services/org.apache.shardingsphere.proxy.backend.handler.admin.executor.variable.session.ReplayedSessionVariableProvider
index 268ad484de0..91d0a0f79fc 100644
---
a/proxy/backend/type/mysql/src/main/resources/META-INF/services/org.apache.shardingsphere.proxy.backend.mysql.handler.admin.MySQLSessionVariableHandler
+++
b/proxy/backend/type/mysql/src/main/resources/META-INF/services/org.apache.shardingsphere.proxy.backend.handler.admin.executor.variable.session.ReplayedSessionVariableProvider
@@ -15,5 +15,4 @@
# limitations under the License.
#
-org.apache.shardingsphere.proxy.backend.mysql.handler.admin.MySQLDefaultSessionVariableHandler
-org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.MySQLSetCharsetExecutor
+org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.variable.session.MySQLReplayedSessionVariableProvider
diff --git
a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/MySQLAdminExecutorCreatorTest.java
b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLAdminExecutorCreatorTest.java
similarity index 94%
rename from
proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/MySQLAdminExecutorCreatorTest.java
rename to
proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLAdminExecutorCreatorTest.java
index 401788ca18e..52e919f7f59 100644
---
a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/MySQLAdminExecutorCreatorTest.java
+++
b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLAdminExecutorCreatorTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor;
+package org.apache.shardingsphere.proxy.backend.mysql.handler.admin;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
@@ -24,14 +24,27 @@ import
org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResourceMetaData;
import
org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
+import org.apache.shardingsphere.metadata.persist.MetaDataPersistService;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
-import org.apache.shardingsphere.metadata.persist.MetaDataPersistService;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.AbstractDatabaseMetaDataExecutor.DefaultDatabaseMetaDataExecutor;
import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminExecutor;
-import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.MySQLAdminExecutorCreator;
-import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.MySQLSetVariableAdminExecutor;
+import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.MySQLSetVariableAdminExecutor;
+import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.MySQLSystemVariableQueryExecutor;
+import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.NoResourceShowExecutor;
+import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.ShowConnectionIdExecutor;
+import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.ShowCreateDatabaseExecutor;
+import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.ShowCurrentDatabaseExecutor;
+import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.ShowCurrentUserExecutor;
+import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.ShowDatabasesExecutor;
+import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.ShowFunctionStatusExecutor;
+import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.ShowProcedureStatusExecutor;
+import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.ShowProcessListExecutor;
+import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.ShowTablesExecutor;
+import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.ShowVersionExecutor;
+import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.UnicastResourceShowExecutor;
+import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.UseDatabaseExecutor;
import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.information.SelectInformationSchemataExecutor;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dal.VariableSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ExpressionProjectionSegment;
diff --git
a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/DefaultMySQLSessionVariableHandlerTest.java
b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/DefaultMySQLSessionVariableHandlerTest.java
deleted file mode 100644
index fa82abccef5..00000000000
---
a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/DefaultMySQLSessionVariableHandlerTest.java
+++ /dev/null
@@ -1,65 +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.proxy.backend.mysql.handler.admin.executor;
-
-import
org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPILoader;
-import org.apache.shardingsphere.infra.database.spi.DatabaseType;
-import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
-import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.ReplayedSessionVariablesProvider;
-import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.MySQLDefaultSessionVariableHandler;
-import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.MySQLSessionVariableHandler;
-import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
-import
org.apache.shardingsphere.proxy.backend.session.RequiredSessionVariableRecorder;
-import org.junit.jupiter.api.Test;
-import org.mockito.MockedStatic;
-
-import java.util.Collections;
-import java.util.Optional;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.mockStatic;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoInteractions;
-import static org.mockito.Mockito.when;
-
-class DefaultMySQLSessionVariableHandlerTest {
-
- @Test
- void assertHandleDiscard() {
- ConnectionSession connectionSession = mock(ConnectionSession.class);
- TypedSPILoader.getService(MySQLSessionVariableHandler.class,
null).handle(connectionSession, "", "");
- verifyNoInteractions(connectionSession);
- }
-
- @Test
- void assertHandleRecord() {
- ConnectionSession connectionSession = mock(ConnectionSession.class);
-
when(connectionSession.getRequiredSessionVariableRecorder()).thenReturn(mock(RequiredSessionVariableRecorder.class));
- try (MockedStatic<DatabaseTypedSPILoader> databaseTypedSPILoader =
mockStatic(DatabaseTypedSPILoader.class)) {
- ReplayedSessionVariablesProvider variablesProvider =
mock(ReplayedSessionVariablesProvider.class);
-
when(variablesProvider.getVariables()).thenReturn(Collections.singleton("sql_mode"));
- databaseTypedSPILoader.when(() ->
DatabaseTypedSPILoader.findService(
- ReplayedSessionVariablesProvider.class,
TypedSPILoader.getService(DatabaseType.class,
"MySQL"))).thenReturn(Optional.of(variablesProvider));
- final MySQLDefaultSessionVariableHandler
defaultSessionVariableHandler = new MySQLDefaultSessionVariableHandler();
- defaultSessionVariableHandler.handle(connectionSession,
"sql_mode", "''");
-
verify(connectionSession.getRequiredSessionVariableRecorder()).setVariable("sql_mode",
"''");
- defaultSessionVariableHandler.handle(connectionSession,
"@variable_name", "'variable_value'");
-
verify(connectionSession.getRequiredSessionVariableRecorder()).setVariable("@variable_name",
"'variable_value'");
- }
- }
-}
diff --git
a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLSetVariableAdminExecutorTest.java
b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/MySQLSetVariableAdminExecutorTest.java
similarity index 99%
rename from
proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLSetVariableAdminExecutorTest.java
rename to
proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/MySQLSetVariableAdminExecutorTest.java
index 87e2d8bb7b8..56876bf300c 100644
---
a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLSetVariableAdminExecutorTest.java
+++
b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/MySQLSetVariableAdminExecutorTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.mysql.handler.admin;
+package org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor;
import io.netty.util.DefaultAttributeMap;
import org.apache.shardingsphere.db.protocol.constant.CommonConstants;
diff --git
a/proxy/backend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLAdminExecutorCreator.java
b/proxy/backend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLAdminExecutorCreator.java
index bc015a732b1..07da42c6811 100644
---
a/proxy/backend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLAdminExecutorCreator.java
+++
b/proxy/backend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLAdminExecutorCreator.java
@@ -20,6 +20,9 @@ package
org.apache.shardingsphere.proxy.backend.postgresql.handler.admin;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminExecutor;
import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminExecutorCreator;
+import
org.apache.shardingsphere.proxy.backend.postgresql.handler.admin.executor.PostgreSQLResetVariableAdminExecutor;
+import
org.apache.shardingsphere.proxy.backend.postgresql.handler.admin.executor.PostgreSQLSetVariableAdminExecutor;
+import
org.apache.shardingsphere.proxy.backend.postgresql.handler.admin.executor.PostgreSQLShowVariableExecutor;
import
org.apache.shardingsphere.sql.parser.sql.common.extractor.TableExtractor;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SubqueryTableSegment;
diff --git
a/proxy/backend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLDefaultSessionVariableHandler.java
b/proxy/backend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLDefaultSessionVariableHandler.java
deleted file mode 100644
index 5723cbf016e..00000000000
---
a/proxy/backend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLDefaultSessionVariableHandler.java
+++ /dev/null
@@ -1,30 +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.proxy.backend.postgresql.handler.admin;
-
-import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.DefaultSessionVariableHandler;
-
-/**
- * Default session variable handler for PostgreSQL.
- */
-public final class PostgreSQLDefaultSessionVariableHandler extends
DefaultSessionVariableHandler implements PostgreSQLSessionVariableHandler {
-
- public PostgreSQLDefaultSessionVariableHandler() {
- super("PostgreSQL");
- }
-}
diff --git
a/proxy/backend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLSessionVariableHandler.java
b/proxy/backend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLSessionVariableHandler.java
deleted file mode 100644
index 1a0d711aa2a..00000000000
---
a/proxy/backend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLSessionVariableHandler.java
+++ /dev/null
@@ -1,28 +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.proxy.backend.postgresql.handler.admin;
-
-import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.SessionVariableHandler;
-import org.apache.shardingsphere.infra.util.spi.annotation.SingletonSPI;
-
-/**
- * Session variable handler for PostgreSQL.
- */
-@SingletonSPI
-public interface PostgreSQLSessionVariableHandler extends
SessionVariableHandler {
-}
diff --git
a/proxy/backend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLResetVariableAdminExecutor.java
b/proxy/backend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/executor/PostgreSQLResetVariableAdminExecutor.java
similarity index 73%
rename from
proxy/backend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLResetVariableAdminExecutor.java
rename to
proxy/backend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/executor/PostgreSQLResetVariableAdminExecutor.java
index 643ebb0cc0b..fe924136076 100644
---
a/proxy/backend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLResetVariableAdminExecutor.java
+++
b/proxy/backend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/executor/PostgreSQLResetVariableAdminExecutor.java
@@ -15,11 +15,14 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.postgresql.handler.admin;
+package
org.apache.shardingsphere.proxy.backend.postgresql.handler.admin.executor;
import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.infra.database.spi.DatabaseType;
import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminExecutor;
+import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.variable.charset.CharsetSetExecutor;
+import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.variable.session.SessionVariableRecordExecutor;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.dal.ResetParameterStatement;
@@ -31,12 +34,14 @@ public final class PostgreSQLResetVariableAdminExecutor
implements DatabaseAdmin
private static final String DEFAULT = "DEFAULT";
+ private final DatabaseType databaseType =
TypedSPILoader.getService(DatabaseType.class, "PostgreSQL");
+
private final ResetParameterStatement resetParameterStatement;
@Override
public void execute(final ConnectionSession connectionSession) {
String variableName =
resetParameterStatement.getConfigurationParameter();
- PostgreSQLSessionVariableHandler variableHandler =
TypedSPILoader.getService(PostgreSQLSessionVariableHandler.class, variableName);
- variableHandler.handle(connectionSession, variableName, DEFAULT);
+ new CharsetSetExecutor(databaseType,
connectionSession).set(variableName, DEFAULT);
+ new SessionVariableRecordExecutor(databaseType,
connectionSession).record(variableName, DEFAULT);
}
}
diff --git
a/proxy/backend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLSetVariableAdminExecutor.java
b/proxy/backend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/executor/PostgreSQLSetVariableAdminExecutor.java
similarity index 75%
rename from
proxy/backend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLSetVariableAdminExecutor.java
rename to
proxy/backend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/executor/PostgreSQLSetVariableAdminExecutor.java
index 38b68e5193e..e1f56e7e5f7 100644
---
a/proxy/backend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLSetVariableAdminExecutor.java
+++
b/proxy/backend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/executor/PostgreSQLSetVariableAdminExecutor.java
@@ -15,11 +15,14 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.postgresql.handler.admin;
+package
org.apache.shardingsphere.proxy.backend.postgresql.handler.admin.executor;
import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.infra.database.spi.DatabaseType;
import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminExecutor;
+import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.variable.charset.CharsetSetExecutor;
+import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.variable.session.SessionVariableRecordExecutor;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dal.VariableAssignSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.dal.SetStatement;
@@ -30,6 +33,8 @@ import
org.apache.shardingsphere.sql.parser.sql.common.statement.dal.SetStatemen
@RequiredArgsConstructor
public final class PostgreSQLSetVariableAdminExecutor implements
DatabaseAdminExecutor {
+ private final DatabaseType databaseType =
TypedSPILoader.getService(DatabaseType.class, "PostgreSQL");
+
private final SetStatement setStatement;
@Override
@@ -37,7 +42,7 @@ public final class PostgreSQLSetVariableAdminExecutor
implements DatabaseAdminEx
VariableAssignSegment variableAssignSegment =
setStatement.getVariableAssigns().iterator().next();
String variableName =
variableAssignSegment.getVariable().getVariable().toLowerCase();
String assignValue = variableAssignSegment.getAssignValue();
- PostgreSQLSessionVariableHandler variableHandler =
TypedSPILoader.getService(PostgreSQLSessionVariableHandler.class, variableName);
- variableHandler.handle(connectionSession, variableName, assignValue);
+ new CharsetSetExecutor(databaseType,
connectionSession).set(variableName, assignValue);
+ new SessionVariableRecordExecutor(databaseType,
connectionSession).record(variableName, assignValue);
}
}
diff --git
a/proxy/backend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLShowVariableExecutor.java
b/proxy/backend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/executor/PostgreSQLShowVariableExecutor.java
similarity index 99%
rename from
proxy/backend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLShowVariableExecutor.java
rename to
proxy/backend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/executor/PostgreSQLShowVariableExecutor.java
index a62d68e003d..d1cb726792f 100644
---
a/proxy/backend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLShowVariableExecutor.java
+++
b/proxy/backend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/executor/PostgreSQLShowVariableExecutor.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.postgresql.handler.admin;
+package
org.apache.shardingsphere.proxy.backend.postgresql.handler.admin.executor;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
diff --git
a/proxy/backend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLCharacterSets.java
b/proxy/backend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/executor/variable/charset/PostgreSQLCharacterSets.java
similarity index 99%
rename from
proxy/backend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLCharacterSets.java
rename to
proxy/backend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/executor/variable/charset/PostgreSQLCharacterSets.java
index 417813f3bc9..64f94af2aa1 100644
---
a/proxy/backend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLCharacterSets.java
+++
b/proxy/backend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/executor/variable/charset/PostgreSQLCharacterSets.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.postgresql.handler.admin;
+package
org.apache.shardingsphere.proxy.backend.postgresql.handler.admin.executor.variable.charset;
import org.apache.shardingsphere.infra.util.quote.QuoteCharacter;
diff --git
a/proxy/backend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/executor/PostgreSQLSetCharsetExecutor.java
b/proxy/backend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/executor/variable/charset/PostgreSQLSetCharsetExecutor.java
similarity index 60%
rename from
proxy/backend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/executor/PostgreSQLSetCharsetExecutor.java
rename to
proxy/backend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/executor/variable/charset/PostgreSQLSetCharsetExecutor.java
index ad57b2ed3c1..374f1c72c7d 100644
---
a/proxy/backend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/executor/PostgreSQLSetCharsetExecutor.java
+++
b/proxy/backend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/executor/variable/charset/PostgreSQLSetCharsetExecutor.java
@@ -15,13 +15,10 @@
* limitations under the License.
*/
-package
org.apache.shardingsphere.proxy.backend.postgresql.handler.admin.executor;
+package
org.apache.shardingsphere.proxy.backend.postgresql.handler.admin.executor.variable.charset;
-import org.apache.shardingsphere.db.protocol.constant.CommonConstants;
import
org.apache.shardingsphere.dialect.exception.data.InvalidParameterValueException;
-import
org.apache.shardingsphere.proxy.backend.postgresql.handler.admin.PostgreSQLCharacterSets;
-import
org.apache.shardingsphere.proxy.backend.postgresql.handler.admin.PostgreSQLSessionVariableHandler;
-import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
+import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.variable.charset.CharsetVariableProvider;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
@@ -30,24 +27,30 @@ import java.util.Locale;
/**
* Set charset executor of PostgreSQL.
*/
-public final class PostgreSQLSetCharsetExecutor implements
PostgreSQLSessionVariableHandler {
+public final class PostgreSQLSetCharsetExecutor implements
CharsetVariableProvider {
@Override
- public void handle(final ConnectionSession connectionSession, final String
variableName, final String assignValue) {
-
connectionSession.getAttributeMap().attr(CommonConstants.CHARSET_ATTRIBUTE_KEY).set(parseCharset(assignValue.trim()));
+ public boolean isCharsetVariable(final String variableName) {
+ return "client_encoding".equalsIgnoreCase(variableName);
}
- private Charset parseCharset(final String value) {
+ @Override
+ public Charset parseCharset(final String variableValue) {
+ String formattedValue = formatValue(variableValue);
try {
- String result = value.toLowerCase(Locale.ROOT);
+ String result = formattedValue.toLowerCase(Locale.ROOT);
return "default".equals(result) ? StandardCharsets.UTF_8 :
PostgreSQLCharacterSets.findCharacterSet(result);
} catch (final IllegalArgumentException ignored) {
- throw new InvalidParameterValueException("client_encoding",
value.toLowerCase(Locale.ROOT));
+ throw new InvalidParameterValueException("client_encoding",
formattedValue.toLowerCase(Locale.ROOT));
}
}
+ private String formatValue(final String variableValue) {
+ return variableValue.trim();
+ }
+
@Override
- public String getType() {
- return "client_encoding";
+ public String getDatabaseType() {
+ return "PostgreSQL";
}
}
diff --git
a/proxy/backend/type/postgresql/src/main/resources/META-INF/services/org.apache.shardingsphere.proxy.backend.postgresql.handler.admin.PostgreSQLSessionVariableHandler
b/proxy/backend/type/postgresql/src/main/resources/META-INF/services/org.apache.shardingsphere.proxy.backend.handler.admin.executor.variable.charset.CharsetVariableProvider
similarity index 85%
rename from
proxy/backend/type/postgresql/src/main/resources/META-INF/services/org.apache.shardingsphere.proxy.backend.postgresql.handler.admin.PostgreSQLSessionVariableHandler
rename to
proxy/backend/type/postgresql/src/main/resources/META-INF/services/org.apache.shardingsphere.proxy.backend.handler.admin.executor.variable.charset.CharsetVariableProvider
index b8f21712648..9b6cf14605a 100644
---
a/proxy/backend/type/postgresql/src/main/resources/META-INF/services/org.apache.shardingsphere.proxy.backend.postgresql.handler.admin.PostgreSQLSessionVariableHandler
+++
b/proxy/backend/type/postgresql/src/main/resources/META-INF/services/org.apache.shardingsphere.proxy.backend.handler.admin.executor.variable.charset.CharsetVariableProvider
@@ -15,5 +15,4 @@
# limitations under the License.
#
-org.apache.shardingsphere.proxy.backend.postgresql.handler.admin.PostgreSQLDefaultSessionVariableHandler
-org.apache.shardingsphere.proxy.backend.postgresql.handler.admin.executor.PostgreSQLSetCharsetExecutor
+org.apache.shardingsphere.proxy.backend.postgresql.handler.admin.executor.variable.charset.PostgreSQLSetCharsetExecutor
diff --git
a/proxy/backend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLAdminExecutorCreatorTest.java
b/proxy/backend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLAdminExecutorCreatorTest.java
index 9b94bdc51f4..86ead895bc3 100644
---
a/proxy/backend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLAdminExecutorCreatorTest.java
+++
b/proxy/backend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLAdminExecutorCreatorTest.java
@@ -25,6 +25,9 @@ import
org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.parser.config.SQLParserRuleConfiguration;
import org.apache.shardingsphere.parser.rule.SQLParserRule;
import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminExecutor;
+import
org.apache.shardingsphere.proxy.backend.postgresql.handler.admin.executor.PostgreSQLResetVariableAdminExecutor;
+import
org.apache.shardingsphere.proxy.backend.postgresql.handler.admin.executor.PostgreSQLSetVariableAdminExecutor;
+import
org.apache.shardingsphere.proxy.backend.postgresql.handler.admin.executor.PostgreSQLShowVariableExecutor;
import org.apache.shardingsphere.sql.parser.api.CacheOption;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement;
diff --git
a/proxy/backend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLResetVariableAdminExecutorTest.java
b/proxy/backend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLResetVariableAdminExecutorTest.java
deleted file mode 100644
index dfb6edc892a..00000000000
---
a/proxy/backend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLResetVariableAdminExecutorTest.java
+++ /dev/null
@@ -1,41 +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.proxy.backend.postgresql.handler.admin;
-
-import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
-import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.dal.PostgreSQLResetParameterStatement;
-import org.junit.jupiter.api.Test;
-import org.mockito.MockedStatic;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.mockStatic;
-import static org.mockito.Mockito.verify;
-
-class PostgreSQLResetVariableAdminExecutorTest {
-
- @Test
- void assertExecute() {
- PostgreSQLResetVariableAdminExecutor executor = new
PostgreSQLResetVariableAdminExecutor(new
PostgreSQLResetParameterStatement("key"));
- try (MockedStatic<TypedSPILoader> mockStatic =
mockStatic(TypedSPILoader.class)) {
- PostgreSQLSessionVariableHandler mockHandler =
mock(PostgreSQLSessionVariableHandler.class);
- mockStatic.when(() ->
TypedSPILoader.getService(PostgreSQLSessionVariableHandler.class,
"key")).thenReturn(mockHandler);
- executor.execute(null);
- verify(mockHandler).handle(null, "key", "DEFAULT");
- }
- }
-}
diff --git
a/proxy/backend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLDefaultSessionVariableHandlerTest.java
b/proxy/backend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/executor/PostgreSQLResetVariableAdminExecutorTest.java
similarity index 56%
rename from
proxy/backend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLDefaultSessionVariableHandlerTest.java
rename to
proxy/backend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/executor/PostgreSQLResetVariableAdminExecutorTest.java
index 12ac997fa2c..5a981193ac6 100644
---
a/proxy/backend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLDefaultSessionVariableHandlerTest.java
+++
b/proxy/backend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/executor/PostgreSQLResetVariableAdminExecutorTest.java
@@ -15,46 +15,44 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.postgresql.handler.admin;
+package
org.apache.shardingsphere.proxy.backend.postgresql.handler.admin.executor;
import
org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPILoader;
import org.apache.shardingsphere.infra.database.spi.DatabaseType;
import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
-import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.ReplayedSessionVariablesProvider;
+import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.variable.charset.CharsetVariableProvider;
+import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.variable.session.ReplayedSessionVariableProvider;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import
org.apache.shardingsphere.proxy.backend.session.RequiredSessionVariableRecorder;
+import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.dal.PostgreSQLResetParameterStatement;
import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;
-import java.util.Collections;
import java.util.Optional;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
-class PostgreSQLDefaultSessionVariableHandlerTest {
+class PostgreSQLResetVariableAdminExecutorTest {
- @Test
- void assertHandleDiscard() {
- ConnectionSession connectionSession = mock(ConnectionSession.class);
- new
PostgreSQLDefaultSessionVariableHandler().handle(connectionSession, "", "");
- verifyNoInteractions(connectionSession);
- }
+ private final DatabaseType databaseType =
TypedSPILoader.getService(DatabaseType.class, "PostgreSQL");
@Test
- void assertHandleRecord() {
- ConnectionSession connectionSession = mock(ConnectionSession.class);
-
when(connectionSession.getRequiredSessionVariableRecorder()).thenReturn(mock(RequiredSessionVariableRecorder.class));
+ void assertExecute() {
+ PostgreSQLResetVariableAdminExecutor executor = new
PostgreSQLResetVariableAdminExecutor(new
PostgreSQLResetParameterStatement("key"));
+ ConnectionSession connectionSession = mock(ConnectionSession.class,
RETURNS_DEEP_STUBS);
+ RequiredSessionVariableRecorder requiredSessionVariableRecorder =
mock(RequiredSessionVariableRecorder.class);
+
when(connectionSession.getRequiredSessionVariableRecorder()).thenReturn(requiredSessionVariableRecorder);
try (MockedStatic<DatabaseTypedSPILoader> databaseTypedSPILoader =
mockStatic(DatabaseTypedSPILoader.class)) {
- ReplayedSessionVariablesProvider variablesProvider =
mock(ReplayedSessionVariablesProvider.class);
-
when(variablesProvider.getVariables()).thenReturn(Collections.singleton("datestyle"));
- databaseTypedSPILoader.when(() ->
DatabaseTypedSPILoader.findService(
- ReplayedSessionVariablesProvider.class,
TypedSPILoader.getService(DatabaseType.class,
"PostgreSQL"))).thenReturn(Optional.of(variablesProvider));
- new
PostgreSQLDefaultSessionVariableHandler().handle(connectionSession,
"datestyle", "postgres");
-
verify(connectionSession.getRequiredSessionVariableRecorder()).setVariable("datestyle",
"postgres");
+ databaseTypedSPILoader.when(() ->
DatabaseTypedSPILoader.findService(CharsetVariableProvider.class,
databaseType)).thenReturn(Optional.empty());
+ ReplayedSessionVariableProvider replayedSessionVariableProvider =
mock(ReplayedSessionVariableProvider.class);
+
when(replayedSessionVariableProvider.isNeedToReplay("key")).thenReturn(true);
+ databaseTypedSPILoader.when(() ->
DatabaseTypedSPILoader.findService(ReplayedSessionVariableProvider.class,
databaseType)).thenReturn(Optional.of(replayedSessionVariableProvider));
+ executor.execute(connectionSession);
+ verify(requiredSessionVariableRecorder).setVariable("key",
"DEFAULT");
}
}
}
diff --git
a/proxy/backend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLSetVariableAdminExecutorTest.java
b/proxy/backend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/executor/PostgreSQLSetVariableAdminExecutorTest.java
similarity index 56%
rename from
proxy/backend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLSetVariableAdminExecutorTest.java
rename to
proxy/backend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/executor/PostgreSQLSetVariableAdminExecutorTest.java
index d049ab866b1..75877f1677b 100644
---
a/proxy/backend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLSetVariableAdminExecutorTest.java
+++
b/proxy/backend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/executor/PostgreSQLSetVariableAdminExecutorTest.java
@@ -15,21 +15,31 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.postgresql.handler.admin;
+package
org.apache.shardingsphere.proxy.backend.postgresql.handler.admin.executor;
+import
org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPILoader;
+import org.apache.shardingsphere.infra.database.spi.DatabaseType;
import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
+import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.variable.session.ReplayedSessionVariableProvider;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
+import
org.apache.shardingsphere.proxy.backend.session.RequiredSessionVariableRecorder;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dal.VariableAssignSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dal.VariableSegment;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.dal.PostgreSQLSetStatement;
import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;
+import java.util.Optional;
+
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
class PostgreSQLSetVariableAdminExecutorTest {
+ private final DatabaseType databaseType =
TypedSPILoader.getService(DatabaseType.class, "PostgreSQL");
+
@Test
void assertExecute() {
VariableAssignSegment variableAssignSegment = new
VariableAssignSegment();
@@ -39,11 +49,15 @@ class PostgreSQLSetVariableAdminExecutorTest {
PostgreSQLSetStatement setStatement = new PostgreSQLSetStatement();
setStatement.getVariableAssigns().add(variableAssignSegment);
PostgreSQLSetVariableAdminExecutor executor = new
PostgreSQLSetVariableAdminExecutor(setStatement);
- try (MockedStatic<TypedSPILoader> mockStatic =
mockStatic(TypedSPILoader.class)) {
- PostgreSQLSessionVariableHandler mockHandler =
mock(PostgreSQLSessionVariableHandler.class);
- mockStatic.when(() ->
TypedSPILoader.getService(PostgreSQLSessionVariableHandler.class,
"key")).thenReturn(mockHandler);
- executor.execute(null);
- verify(mockHandler).handle(null, "key", "value");
+ ConnectionSession connectionSession = mock(ConnectionSession.class);
+ RequiredSessionVariableRecorder requiredSessionVariableRecorder =
mock(RequiredSessionVariableRecorder.class);
+
when(connectionSession.getRequiredSessionVariableRecorder()).thenReturn(requiredSessionVariableRecorder);
+ try (MockedStatic<DatabaseTypedSPILoader> databaseTypedSPILoader =
mockStatic(DatabaseTypedSPILoader.class)) {
+ ReplayedSessionVariableProvider replayedSessionVariableProvider =
mock(ReplayedSessionVariableProvider.class);
+
when(replayedSessionVariableProvider.isNeedToReplay("key")).thenReturn(true);
+ databaseTypedSPILoader.when(() ->
DatabaseTypedSPILoader.findService(ReplayedSessionVariableProvider.class,
databaseType)).thenReturn(Optional.of(replayedSessionVariableProvider));
+ executor.execute(connectionSession);
+ verify(requiredSessionVariableRecorder).setVariable("key",
"value");
}
}
}
diff --git
a/proxy/backend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLShowVariableExecutorTest.java
b/proxy/backend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/executor/PostgreSQLShowVariableExecutorTest.java
similarity index 99%
rename from
proxy/backend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLShowVariableExecutorTest.java
rename to
proxy/backend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/executor/PostgreSQLShowVariableExecutorTest.java
index 0704e7e3f2b..c23abfa4b3a 100644
---
a/proxy/backend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLShowVariableExecutorTest.java
+++
b/proxy/backend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/executor/PostgreSQLShowVariableExecutorTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.postgresql.handler.admin;
+package
org.apache.shardingsphere.proxy.backend.postgresql.handler.admin.executor;
import org.apache.shardingsphere.infra.autogen.version.ShardingSphereVersion;
import
org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResultMetaData;
diff --git
a/proxy/backend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLCharacterSetsTest.java
b/proxy/backend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/executor/variable/charset/PostgreSQLCharacterSetsTest.java
similarity index 98%
rename from
proxy/backend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLCharacterSetsTest.java
rename to
proxy/backend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/executor/variable/charset/PostgreSQLCharacterSetsTest.java
index 4b1ed8d4499..6958f0d7f75 100644
---
a/proxy/backend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLCharacterSetsTest.java
+++
b/proxy/backend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/executor/variable/charset/PostgreSQLCharacterSetsTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.postgresql.handler.admin;
+package
org.apache.shardingsphere.proxy.backend.postgresql.handler.admin.executor.variable.charset;
import org.junit.jupiter.api.Test;
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 81db90c2e9e..93dba9a641a 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
@@ -53,7 +53,7 @@ import
org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import
org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import
org.apache.shardingsphere.proxy.backend.postgresql.handler.admin.PostgreSQLCharacterSets;
+import
org.apache.shardingsphere.proxy.backend.postgresql.handler.admin.executor.variable.charset.PostgreSQLCharacterSets;
import
org.apache.shardingsphere.proxy.frontend.authentication.AuthenticationEngine;
import
org.apache.shardingsphere.proxy.frontend.authentication.AuthenticationResult;
import
org.apache.shardingsphere.proxy.frontend.authentication.AuthenticationResultBuilder;
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 625037e3580..8c30b77187f 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
@@ -51,7 +51,7 @@ import
org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import
org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import
org.apache.shardingsphere.proxy.backend.postgresql.handler.admin.PostgreSQLCharacterSets;
+import
org.apache.shardingsphere.proxy.backend.postgresql.handler.admin.executor.variable.charset.PostgreSQLCharacterSets;
import
org.apache.shardingsphere.proxy.frontend.authentication.AuthenticationEngine;
import
org.apache.shardingsphere.proxy.frontend.authentication.AuthenticationResult;
import
org.apache.shardingsphere.proxy.frontend.authentication.AuthenticationResultBuilder;