You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by yx...@apache.org on 2022/04/30 15:52:55 UTC
[shardingsphere] branch master updated: Add StatementMemoryStrictlyFetchSizeSetterFactory (#17241)
This is an automated email from the ASF dual-hosted git repository.
yx9o 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 6613e520994 Add StatementMemoryStrictlyFetchSizeSetterFactory (#17241)
6613e520994 is described below
commit 6613e5209943c40b956db60003e53ba9bc0226c2
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sat Apr 30 23:52:50 2022 +0800
Add StatementMemoryStrictlyFetchSizeSetterFactory (#17241)
---
.../jdbc/statement/JDBCBackendStatement.java | 8 +---
...tementMemoryStrictlyFetchSizeSetterFactory.java | 46 ++++++++++++++++++++++
2 files changed, 47 insertions(+), 7 deletions(-)
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/statement/JDBCBackendStatement.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/statement/JDBCBackendStatement.java
index 682e7f358a5..039eca02d17 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/statement/JDBCBackendStatement.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/statement/JDBCBackendStatement.java
@@ -27,8 +27,6 @@ import org.apache.shardingsphere.infra.executor.sql.prepare.driver.jdbc.Executor
import org.apache.shardingsphere.infra.executor.sql.prepare.driver.jdbc.StatementOption;
import org.apache.shardingsphere.proxy.backend.communication.SQLStatementDatabaseHolder;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.spi.type.typed.TypedSPIRegistry;
import java.sql.Connection;
import java.sql.PreparedStatement;
@@ -45,10 +43,6 @@ import java.util.Optional;
@Setter
public final class JDBCBackendStatement implements ExecutorJDBCStatementManager {
- static {
- ShardingSphereServiceLoader.register(StatementMemoryStrictlyFetchSizeSetter.class);
- }
-
private String databaseName;
@Override
@@ -84,7 +78,7 @@ public final class JDBCBackendStatement implements ExecutorJDBCStatementManager
private void setFetchSize(final Statement statement) throws SQLException {
DatabaseType databaseType = ProxyContext.getInstance().getContextManager().getMetaDataContexts()
.getMetaData(null == databaseName ? SQLStatementDatabaseHolder.get() : databaseName).getResource().getDatabaseType();
- Optional<StatementMemoryStrictlyFetchSizeSetter> fetchSizeSetter = TypedSPIRegistry.findRegisteredService(StatementMemoryStrictlyFetchSizeSetter.class, databaseType.getName());
+ Optional<StatementMemoryStrictlyFetchSizeSetter> fetchSizeSetter = StatementMemoryStrictlyFetchSizeSetterFactory.newInstance(databaseType.getName());
if (fetchSizeSetter.isPresent()) {
fetchSizeSetter.get().setFetchSize(statement);
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/statement/StatementMemoryStrictlyFetchSizeSetterFactory.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/statement/StatementMemoryStrictlyFetchSizeSetterFactory.java
new file mode 100644
index 00000000000..32918aab4a8
--- /dev/null
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/statement/StatementMemoryStrictlyFetchSizeSetterFactory.java
@@ -0,0 +1,46 @@
+/*
+ * 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.communication.jdbc.statement;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.spi.type.typed.TypedSPIRegistry;
+
+import java.util.Optional;
+
+/**
+ * Statement memory strictly fetch size setter factory.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class StatementMemoryStrictlyFetchSizeSetterFactory {
+
+ static {
+ ShardingSphereServiceLoader.register(StatementMemoryStrictlyFetchSizeSetter.class);
+ }
+
+ /**
+ * Create new instance of statement memory strictly fetch size setter.
+ *
+ * @param databaseType database type
+ * @return new instance of statement memory strictly fetch size setter
+ */
+ public static Optional<StatementMemoryStrictlyFetchSizeSetter> newInstance(final String databaseType) {
+ return TypedSPIRegistry.findRegisteredService(StatementMemoryStrictlyFetchSizeSetter.class, databaseType);
+ }
+}