This is an automated email from the ASF dual-hosted git repository.
zhaojinchao 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 d66b8b5d655 Remove DataSourceAggregatableDatabaseType (#27279)
d66b8b5d655 is described below
commit d66b8b5d6554952eadceeb1f0413afe3a9177e7e
Author: Raigor <[email protected]>
AuthorDate: Wed Jul 19 08:28:43 2023 +0800
Remove DataSourceAggregatableDatabaseType (#27279)
---
.../pool/creator/DataSourcePoolCreator.java | 9 ++++----
.../type/DataSourceAggregatableDatabaseType.java | 24 ----------------------
.../infra/database/spi/DatabaseType.java | 9 ++++++++
.../infra/database/mysql/MySQLDatabaseType.java | 8 ++++++--
.../rql/storage/unit/ShowStorageUnitExecutor.java | 3 +--
5 files changed, 20 insertions(+), 33 deletions(-)
diff --git
a/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/pool/creator/DataSourcePoolCreator.java
b/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/pool/creator/DataSourcePoolCreator.java
index d78ebfa4dac..a3dd6cd5df6 100644
---
a/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/pool/creator/DataSourcePoolCreator.java
+++
b/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/pool/creator/DataSourcePoolCreator.java
@@ -20,11 +20,10 @@ package
org.apache.shardingsphere.infra.datasource.pool.creator;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.SneakyThrows;
-import
org.apache.shardingsphere.infra.database.core.url.UnrecognizedDatabaseURLException;
+import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeFactory;
import org.apache.shardingsphere.infra.database.core.url.JdbcUrl;
import org.apache.shardingsphere.infra.database.core.url.StandardJdbcUrlParser;
-import
org.apache.shardingsphere.infra.database.core.type.DataSourceAggregatableDatabaseType;
-import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeFactory;
+import
org.apache.shardingsphere.infra.database.core.url.UnrecognizedDatabaseURLException;
import org.apache.shardingsphere.infra.database.spi.DatabaseType;
import
org.apache.shardingsphere.infra.datasource.pool.destroyer.DataSourcePoolDestroyer;
import
org.apache.shardingsphere.infra.datasource.pool.metadata.DataSourcePoolMetaData;
@@ -119,7 +118,7 @@ public final class DataSourcePoolCreator {
private static void appendStorageUnit(final Map<String, StorageUnit>
storageUnits, final StorageNodeProperties storageNodeProperties,
final String unitName, final
DataSourceProperties dataSourceProps) {
String url =
dataSourceProps.getConnectionPropertySynonyms().getStandardProperties().get("url").toString();
- if (storageNodeProperties.getDatabaseType() instanceof
DataSourceAggregatableDatabaseType) {
+ if
(storageNodeProperties.getDatabaseType().isInstanceConnectionAvailable()) {
storageUnits.put(unitName, new StorageUnit(unitName,
storageNodeProperties.getName(), storageNodeProperties.getDatabase(), url));
} else {
storageUnits.put(unitName, new StorageUnit(unitName,
storageNodeProperties.getName(), url));
@@ -134,7 +133,7 @@ public final class DataSourcePoolCreator {
StorageNodeProperties storageNodeProperties;
try {
JdbcUrl jdbcUrl = new StandardJdbcUrlParser().parse(url);
- String nodeName = databaseType instanceof
DataSourceAggregatableDatabaseType ?
generateStorageNodeName(jdbcUrl.getHostname(), jdbcUrl.getPort(), username) :
dataSourceName;
+ String nodeName = databaseType.isInstanceConnectionAvailable() ?
generateStorageNodeName(jdbcUrl.getHostname(), jdbcUrl.getPort(), username) :
dataSourceName;
storageNodeProperties = new StorageNodeProperties(nodeName,
databaseType, dataSourceProperties, jdbcUrl.getDatabase());
} catch (final UnrecognizedDatabaseURLException ex) {
storageNodeProperties = new StorageNodeProperties(dataSourceName,
databaseType, dataSourceProperties, null);
diff --git
a/infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/type/DataSourceAggregatableDatabaseType.java
b/infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/type/DataSourceAggregatableDatabaseType.java
deleted file mode 100644
index 215273fe254..00000000000
---
a/infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/type/DataSourceAggregatableDatabaseType.java
+++ /dev/null
@@ -1,24 +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.infra.database.core.type;
-
-/**
- * Data source aggregatable database type.
- */
-public interface DataSourceAggregatableDatabaseType {
-}
diff --git
a/infra/database/spi/src/main/java/org/apache/shardingsphere/infra/database/spi/DatabaseType.java
b/infra/database/spi/src/main/java/org/apache/shardingsphere/infra/database/spi/DatabaseType.java
index 6c41b447ad3..fbc5f221e6a 100644
---
a/infra/database/spi/src/main/java/org/apache/shardingsphere/infra/database/spi/DatabaseType.java
+++
b/infra/database/spi/src/main/java/org/apache/shardingsphere/infra/database/spi/DatabaseType.java
@@ -146,6 +146,15 @@ public interface DatabaseType extends TypedSPI {
default void handleRollbackOnly(final boolean rollbackOnly, final
SQLStatement statement) throws SQLException {
}
+ /**
+ * Is instance connection available.
+ *
+ * @return true or false
+ */
+ default boolean isInstanceConnectionAvailable() {
+ return false;
+ }
+
@Override
String getType();
}
diff --git
a/infra/database/type/mysql/src/main/java/org/apache/shardingsphere/infra/database/mysql/MySQLDatabaseType.java
b/infra/database/type/mysql/src/main/java/org/apache/shardingsphere/infra/database/mysql/MySQLDatabaseType.java
index 6a3f73c122f..53528cb14f2 100644
---
a/infra/database/type/mysql/src/main/java/org/apache/shardingsphere/infra/database/mysql/MySQLDatabaseType.java
+++
b/infra/database/type/mysql/src/main/java/org/apache/shardingsphere/infra/database/mysql/MySQLDatabaseType.java
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.infra.database.mysql;
-import
org.apache.shardingsphere.infra.database.core.type.DataSourceAggregatableDatabaseType;
import org.apache.shardingsphere.infra.database.core.type.TrunkDatabaseType;
import org.apache.shardingsphere.sql.parser.sql.common.enums.QuoteCharacter;
@@ -32,7 +31,7 @@ import java.util.Set;
/**
* Database type of MySQL.
*/
-public final class MySQLDatabaseType implements TrunkDatabaseType,
DataSourceAggregatableDatabaseType {
+public final class MySQLDatabaseType implements TrunkDatabaseType {
private static final Set<String> RESERVED_WORDS = new
HashSet<>(Arrays.asList(
"ADD", "ALL", "ALTER", "ANALYZE", "AND", "AS", "ASC", "BEFORE",
"BETWEEN", "BIGINT", "BINARY", "BLOB", "BOTH", "BY", "CALL",
@@ -97,6 +96,11 @@ public final class MySQLDatabaseType implements
TrunkDatabaseType, DataSourceAgg
return SYSTEM_DATABASE_SCHEMA_MAP.keySet();
}
+ @Override
+ public boolean isInstanceConnectionAvailable() {
+ return true;
+ }
+
@Override
public String getType() {
return "MySQL";
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/storage/unit/ShowStorageUnitExecutor.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/storage/unit/ShowStorageUnitExecutor.java
index 438efa8fb79..f7ed85ec412 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/storage/unit/ShowStorageUnitExecutor.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/storage/unit/ShowStorageUnitExecutor.java
@@ -20,7 +20,6 @@ package
org.apache.shardingsphere.proxy.backend.handler.distsql.rql.storage.unit
import com.google.gson.Gson;
import org.apache.shardingsphere.distsql.handler.query.RQLExecutor;
import
org.apache.shardingsphere.distsql.parser.statement.rql.show.ShowStorageUnitsStatement;
-import
org.apache.shardingsphere.infra.database.core.type.DataSourceAggregatableDatabaseType;
import org.apache.shardingsphere.infra.database.spi.DataSourceMetaData;
import org.apache.shardingsphere.infra.database.spi.DatabaseType;
import
org.apache.shardingsphere.infra.datasource.ShardingSphereStorageDataSourceWrapper;
@@ -114,7 +113,7 @@ public final class ShowStorageUnitExecutor implements
RQLExecutor<ShowStorageUni
private DataSourceProperties getDataSourceProperties(final Map<String,
DataSourceProperties> dataSourcePropsMap, final String storageUnitName,
final DatabaseType
databaseType, final DataSource dataSource) {
DataSourceProperties result = getDataSourceProperties(dataSource);
- if (databaseType instanceof DataSourceAggregatableDatabaseType &&
dataSourcePropsMap.containsKey(storageUnitName)) {
+ if (databaseType.isInstanceConnectionAvailable() &&
dataSourcePropsMap.containsKey(storageUnitName)) {
DataSourceProperties unitDataSourceProperties =
dataSourcePropsMap.get(storageUnitName);
for (final Entry<String, Object> entry :
unitDataSourceProperties.getPoolPropertySynonyms().getStandardProperties().entrySet())
{
if (null != entry.getValue()) {