This is an automated email from the ASF dual-hosted git repository.
panjuan 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 4d6525828af Remove DatabaseTypeChecker (#27373)
4d6525828af is described below
commit 4d6525828af80284e1b2bc16d040cb3c41d62630
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Jul 22 20:39:03 2023 +0800
Remove DatabaseTypeChecker (#27373)
---
.../EncryptOrderByItemTokenGeneratorTest.java | 7 +-
.../EncryptProjectionTokenGeneratorTest.java | 9 +-
.../WhereClauseShardingConditionEngineTest.java | 7 +-
.../dml/ShardingInsertStatementValidatorTest.java | 6 +-
.../sharding/rule/ShardingRuleTest.java | 6 +-
features/sharding/distsql/handler/pom.xml | 6 ++
infra/binder/pom.xml | 6 ++
.../binder/segment/table/TablesContextTest.java | 37 ++++----
.../props/DataSourcePropertiesValidator.java | 10 +--
.../props/DataSourcePropertiesValidatorTest.java | 3 +
.../infra/fixture/DatabaseTypeFixture.java | 33 +++++---
....shardingsphere.infra.database.spi.DatabaseType | 18 ++++
.../database/core/type/DatabaseTypeChecker.java | 98 ----------------------
.../database/core/type/DatabaseTypeFactory.java | 6 +-
.../core/type/UnsupportedStorageTypeException.java | 8 +-
.../core/type/DatabaseTypeFactoryTest.java | 3 +-
jdbc/core/pom.xml | 6 ++
.../jdbc/adapter/PreparedStatementAdapterTest.java | 4 +-
kernel/data-pipeline/dialect/mysql/pom.xml | 6 ++
.../mysql/ingest/MySQLIncrementalDumperTest.java | 2 +-
.../metadata/factory/ExternalMetaDataFactory.java | 6 +-
kernel/single/core/pom.xml | 6 ++
.../compiler/it/SQLStatementCompilerIT.java | 3 +-
kernel/transaction/core/pom.xml | 6 ++
mode/type/cluster/core/pom.xml | 6 ++
mode/type/standalone/core/pom.xml | 6 ++
.../admin/executor/ShowTablesExecutorTest.java | 5 +-
.../version/ShardingSphereProxyVersionTest.java | 14 ++--
.../infra/database/type/MockedDatabaseType.java | 2 +-
test/it/rewriter/pom.xml | 6 ++
30 files changed, 159 insertions(+), 182 deletions(-)
diff --git
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptOrderByItemTokenGeneratorTest.java
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptOrderByItemTokenGeneratorTest.java
index 937e8ab6137..906f55f0dcd 100644
---
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptOrderByItemTokenGeneratorTest.java
+++
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptOrderByItemTokenGeneratorTest.java
@@ -23,9 +23,10 @@ import
org.apache.shardingsphere.encrypt.rule.column.EncryptColumn;
import
org.apache.shardingsphere.infra.binder.segment.select.orderby.OrderByItem;
import org.apache.shardingsphere.infra.binder.segment.table.TablesContext;
import
org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
-import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeFactory;
-import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
import org.apache.shardingsphere.infra.database.enums.NullsOrderType;
+import org.apache.shardingsphere.infra.database.spi.DatabaseType;
+import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.sql.parser.sql.common.enums.OrderDirection;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.order.item.ColumnOrderByItemSegment;
@@ -84,7 +85,7 @@ class EncryptOrderByItemTokenGeneratorTest {
when(result.getOrderByContext().getItems()).thenReturn(Collections.singletonList(orderByItem));
when(result.getGroupByContext().getItems()).thenReturn(Collections.emptyList());
when(result.getSubqueryContexts().values()).thenReturn(Collections.emptyList());
- when(result.getTablesContext()).thenReturn(new
TablesContext(Collections.singletonList(simpleTableSegment),
DatabaseTypeFactory.get("MySQL")));
+ when(result.getTablesContext()).thenReturn(new
TablesContext(Collections.singletonList(simpleTableSegment),
TypedSPILoader.getService(DatabaseType.class, "FIXTURE")));
return result;
}
}
diff --git
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptProjectionTokenGeneratorTest.java
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptProjectionTokenGeneratorTest.java
index 980bebc5843..e22f6587f04 100644
---
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptProjectionTokenGeneratorTest.java
+++
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptProjectionTokenGeneratorTest.java
@@ -23,9 +23,10 @@ import
org.apache.shardingsphere.encrypt.rule.column.EncryptColumn;
import
org.apache.shardingsphere.infra.binder.segment.select.projection.impl.ColumnProjection;
import org.apache.shardingsphere.infra.binder.segment.table.TablesContext;
import
org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
-import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeFactory;
+import org.apache.shardingsphere.infra.database.spi.DatabaseType;
import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.SQLToken;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ColumnProjectionSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionsSegment;
@@ -86,7 +87,7 @@ class EncryptProjectionTokenGeneratorTest {
when(sqlStatementContext.getSqlStatement().getProjections()).thenReturn(projections);
when(sqlStatementContext.getSubqueryContexts().values()).thenReturn(Collections.emptyList());
SimpleTableSegment doctorOneTable = new SimpleTableSegment(new
TableNameSegment(0, 0, new IdentifierValue("doctor1")));
- when(sqlStatementContext.getTablesContext()).thenReturn(new
TablesContext(Arrays.asList(doctorTable, doctorOneTable),
DatabaseTypeFactory.get("MySQL")));
+ when(sqlStatementContext.getTablesContext()).thenReturn(new
TablesContext(Arrays.asList(doctorTable, doctorOneTable),
TypedSPILoader.getService(DatabaseType.class, "FIXTURE")));
when(sqlStatementContext.getProjectionsContext().getProjections()).thenReturn(Collections.singletonList(new
ColumnProjection("a", "mobile", null)));
Collection<SQLToken> actual =
generator.generateSQLTokens(sqlStatementContext);
assertThat(actual.size(), is(1));
@@ -104,7 +105,7 @@ class EncryptProjectionTokenGeneratorTest {
when(sqlStatementContext.getSqlStatement().getProjections()).thenReturn(projections);
when(sqlStatementContext.getSubqueryContexts().values()).thenReturn(Collections.emptyList());
SimpleTableSegment sameDoctorTable = new SimpleTableSegment(new
TableNameSegment(0, 0, new IdentifierValue("doctor")));
- when(sqlStatementContext.getTablesContext()).thenReturn(new
TablesContext(Arrays.asList(doctorTable, sameDoctorTable),
DatabaseTypeFactory.get("MySQL")));
+ when(sqlStatementContext.getTablesContext()).thenReturn(new
TablesContext(Arrays.asList(doctorTable, sameDoctorTable),
TypedSPILoader.getService(DatabaseType.class, "FIXTURE")));
when(sqlStatementContext.getProjectionsContext().getProjections()).thenReturn(Collections.singletonList(new
ColumnProjection("a", "mobile", null)));
Collection<SQLToken> actual =
generator.generateSQLTokens(sqlStatementContext);
assertThat(actual.size(), is(1));
@@ -121,7 +122,7 @@ class EncryptProjectionTokenGeneratorTest {
when(sqlStatementContext.getSubqueryContexts().values()).thenReturn(Collections.emptyList());
SimpleTableSegment doctorTable = new SimpleTableSegment(new
TableNameSegment(0, 0, new IdentifierValue("doctor")));
SimpleTableSegment doctorOneTable = new SimpleTableSegment(new
TableNameSegment(0, 0, new IdentifierValue("doctor1")));
- when(sqlStatementContext.getTablesContext()).thenReturn(new
TablesContext(Arrays.asList(doctorTable, doctorOneTable),
DatabaseTypeFactory.get("MySQL")));
+ when(sqlStatementContext.getTablesContext()).thenReturn(new
TablesContext(Arrays.asList(doctorTable, doctorOneTable),
TypedSPILoader.getService(DatabaseType.class, "FIXTURE")));
when(sqlStatementContext.getProjectionsContext().getProjections()).thenReturn(Collections.singletonList(new
ColumnProjection("doctor", "mobile", null)));
Collection<SQLToken> actual =
generator.generateSQLTokens(sqlStatementContext);
assertThat(actual.size(), is(1));
diff --git
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/WhereClauseShardingConditionEngineTest.java
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/WhereClauseShardingConditionEngineTest.java
index 85dbbce3159..b4b449ad8b9 100644
---
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/WhereClauseShardingConditionEngineTest.java
+++
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/WhereClauseShardingConditionEngineTest.java
@@ -21,7 +21,6 @@ import org.apache.groovy.util.Maps;
import org.apache.shardingsphere.infra.binder.segment.table.TablesContext;
import
org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
-import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeFactory;
import org.apache.shardingsphere.infra.database.spi.DatabaseType;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
@@ -76,11 +75,11 @@ class WhereClauseShardingConditionEngineTest {
@BeforeEach
void setUp() {
- shardingConditionEngine = new WhereClauseShardingConditionEngine(
- ShardingSphereDatabase.create("test_db",
DatabaseTypeFactory.get("MySQL"), new ConfigurationProperties(new
Properties())), shardingRule, mock(TimestampServiceRule.class));
+ shardingConditionEngine = new
WhereClauseShardingConditionEngine(ShardingSphereDatabase.create("test_db",
+ TypedSPILoader.getService(DatabaseType.class, "FIXTURE"), new
ConfigurationProperties(new Properties())), shardingRule,
mock(TimestampServiceRule.class));
when(sqlStatementContext.getWhereSegments()).thenReturn(Collections.singleton(whereSegment));
when(sqlStatementContext.getTablesContext()).thenReturn(tablesContext);
-
when(sqlStatementContext.getDatabaseType()).thenReturn(TypedSPILoader.getService(DatabaseType.class,
"MySQL"));
+
when(sqlStatementContext.getDatabaseType()).thenReturn(TypedSPILoader.getService(DatabaseType.class,
"FIXTURE"));
when(tablesContext.findTableNamesByColumnSegment(anyCollection(),
any())).thenReturn(Maps.of("foo_sharding_col", "table_1"));
}
diff --git
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingInsertStatementValidatorTest.java
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingInsertStatementValidatorTest.java
index cc2d7a7db86..fd641aeba06 100644
---
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingInsertStatementValidatorTest.java
+++
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingInsertStatementValidatorTest.java
@@ -22,7 +22,7 @@ import
org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import
org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementContext;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.database.core.DefaultDatabase;
-import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeFactory;
+import org.apache.shardingsphere.infra.database.spi.DatabaseType;
import org.apache.shardingsphere.infra.datanode.DataNode;
import org.apache.shardingsphere.infra.hint.HintValueContext;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
@@ -316,13 +316,13 @@ class ShardingInsertStatementValidatorTest {
private TablesContext createSingleTablesContext() {
List<SimpleTableSegment> result = new LinkedList<>();
result.add(new SimpleTableSegment(new TableNameSegment(0, 0, new
IdentifierValue("user"))));
- return new TablesContext(result, DatabaseTypeFactory.get("MySQL"));
+ return new TablesContext(result,
TypedSPILoader.getService(DatabaseType.class, "FIXTURE"));
}
private TablesContext createMultiTablesContext() {
List<SimpleTableSegment> result = new LinkedList<>();
result.add(new SimpleTableSegment(new TableNameSegment(0, 0, new
IdentifierValue("user"))));
result.add(new SimpleTableSegment(new TableNameSegment(0, 0, new
IdentifierValue("order"))));
- return new TablesContext(result, DatabaseTypeFactory.get("MySQL"));
+ return new TablesContext(result,
TypedSPILoader.getService(DatabaseType.class, "FIXTURE"));
}
}
diff --git
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java
index 2bbad3af50f..ff33614368c 100644
---
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java
+++
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java
@@ -23,7 +23,6 @@ import
org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementConte
import
org.apache.shardingsphere.infra.binder.statement.dml.UpdateStatementContext;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.database.core.DefaultDatabase;
-import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeFactory;
import org.apache.shardingsphere.infra.database.spi.DatabaseType;
import org.apache.shardingsphere.infra.datanode.DataNode;
import org.apache.shardingsphere.infra.instance.InstanceContext;
@@ -55,6 +54,7 @@ import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.OwnerSegm
import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.JoinTableSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableNameSegment;
+import
org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement;
import
org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLSelectStatement;
import org.apache.shardingsphere.test.util.PropertiesBuilder;
@@ -561,7 +561,7 @@ class ShardingRuleTest {
void assertIsAllBindingTableWithJoinQueryWithoutJoinCondition() {
SelectStatementContext sqlStatementContext =
mock(SelectStatementContext.class, RETURNS_DEEP_STUBS);
when(sqlStatementContext.isContainsJoinQuery()).thenReturn(true);
-
when(sqlStatementContext.getSqlStatement()).thenReturn(mock(MySQLSelectStatement.class));
+
when(sqlStatementContext.getSqlStatement()).thenReturn(mock(SelectStatement.class));
when(sqlStatementContext.getDatabaseType()).thenReturn(TypedSPILoader.getService(DatabaseType.class,
"FIXTURE"));
when(sqlStatementContext.getTablesContext().getSchemaName()).thenReturn(Optional.empty());
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class,
RETURNS_DEEP_STUBS);
@@ -607,7 +607,7 @@ class ShardingRuleTest {
Collection<SimpleTableSegment> tableSegments = Arrays.asList(
new SimpleTableSegment(new TableNameSegment(0, 0, new
IdentifierValue("LOGIC_TABLE"))),
new SimpleTableSegment(new TableNameSegment(0, 0, new
IdentifierValue("SUB_LOGIC_TABLE"))));
- TablesContext tablesContext = new TablesContext(tableSegments,
Collections.emptyMap(), DatabaseTypeFactory.get("MySQL"));
+ TablesContext tablesContext = new TablesContext(tableSegments,
Collections.emptyMap(), TypedSPILoader.getService(DatabaseType.class,
"FIXTURE"));
when(sqlStatementContext.getTablesContext()).thenReturn(tablesContext);
when(sqlStatementContext.getDatabaseType()).thenReturn(TypedSPILoader.getService(DatabaseType.class,
"FIXTURE"));
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class,
RETURNS_DEEP_STUBS);
diff --git a/features/sharding/distsql/handler/pom.xml
b/features/sharding/distsql/handler/pom.xml
index 822adbf0fa6..c5256f7eafd 100644
--- a/features/sharding/distsql/handler/pom.xml
+++ b/features/sharding/distsql/handler/pom.xml
@@ -54,6 +54,12 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-test-fixture-infra</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-test-util</artifactId>
diff --git a/infra/binder/pom.xml b/infra/binder/pom.xml
index 83c146739f3..d9038cff3f2 100644
--- a/infra/binder/pom.xml
+++ b/infra/binder/pom.xml
@@ -54,5 +54,11 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-test-fixture-infra</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
diff --git
a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/table/TablesContextTest.java
b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/table/TablesContextTest.java
index c74269a269a..7f80086dbe7 100644
---
a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/table/TablesContextTest.java
+++
b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/table/TablesContextTest.java
@@ -18,10 +18,11 @@
package org.apache.shardingsphere.infra.binder.segment.table;
import
org.apache.shardingsphere.infra.binder.segment.select.projection.impl.ColumnProjection;
-import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeFactory;
+import org.apache.shardingsphere.infra.database.spi.DatabaseType;
import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn;
import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable;
+import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.AliasSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.OwnerSegment;
@@ -51,7 +52,7 @@ class TablesContextTest {
@Test
void assertGetTableNames() {
TablesContext tablesContext = new
TablesContext(Arrays.asList(createTableSegment("table_1", "tbl_1"),
- createTableSegment("table_2", "tbl_2")),
DatabaseTypeFactory.get("MySQL"));
+ createTableSegment("table_2", "tbl_2")),
TypedSPILoader.getService(DatabaseType.class, "FIXTURE"));
assertThat(tablesContext.getTableNames(), is(new
HashSet<>(Arrays.asList("table_1", "table_2"))));
}
@@ -59,7 +60,7 @@ class TablesContextTest {
void assertInstanceCreatedWhenNoExceptionThrown() {
SimpleTableSegment tableSegment = new SimpleTableSegment(new
TableNameSegment(0, 10, new IdentifierValue("tbl")));
tableSegment.setOwner(new OwnerSegment(0, 0, new
IdentifierValue("schema")));
- TablesContext tablesContext = new
TablesContext(Collections.singleton(tableSegment),
DatabaseTypeFactory.get("MySQL"));
+ TablesContext tablesContext = new
TablesContext(Collections.singleton(tableSegment),
TypedSPILoader.getService(DatabaseType.class, "FIXTURE"));
assertThat(tablesContext.getDatabaseName(), is(Optional.of("schema")));
assertThat(tablesContext.getSchemaName(), is(Optional.of("schema")));
assertThat(tablesContext.getTableNames(),
is(Collections.singleton("tbl")));
@@ -70,7 +71,7 @@ class TablesContextTest {
void assertFindTableNameWhenSingleTable() {
SimpleTableSegment tableSegment = createTableSegment("table_1",
"tbl_1");
ColumnSegment columnSegment = createColumnSegment(null, "col");
- Map<String, String> actual = new
TablesContext(Collections.singletonList(tableSegment),
DatabaseTypeFactory.get("MySQL"))
+ Map<String, String> actual = new
TablesContext(Collections.singletonList(tableSegment),
TypedSPILoader.getService(DatabaseType.class, "FIXTURE"))
.findTableNamesByColumnSegment(Collections.singletonList(columnSegment),
mock(ShardingSphereSchema.class));
assertFalse(actual.isEmpty());
assertThat(actual.get("col"), is("table_1"));
@@ -81,7 +82,7 @@ class TablesContextTest {
SimpleTableSegment tableSegment1 = createTableSegment("table_1",
"tbl_1");
SimpleTableSegment tableSegment2 = createTableSegment("table_2",
"tbl_2");
ColumnSegment columnSegment = createColumnSegment("table_1", "col");
- Map<String, String> actual = new
TablesContext(Arrays.asList(tableSegment1, tableSegment2),
DatabaseTypeFactory.get("MySQL"))
+ Map<String, String> actual = new
TablesContext(Arrays.asList(tableSegment1, tableSegment2),
TypedSPILoader.getService(DatabaseType.class, "FIXTURE"))
.findTableNamesByColumnSegment(Collections.singletonList(columnSegment),
mock(ShardingSphereSchema.class));
assertFalse(actual.isEmpty());
assertThat(actual.get("table_1.col"), is("table_1"));
@@ -92,7 +93,7 @@ class TablesContextTest {
SimpleTableSegment tableSegment1 = createTableSegment("table_1",
"tbl_1");
SimpleTableSegment tableSegment2 = createTableSegment("table_2",
"tbl_2");
ColumnSegment columnSegment = createColumnSegment(null, "col");
- Map<String, String> actual = new
TablesContext(Arrays.asList(tableSegment1, tableSegment2),
DatabaseTypeFactory.get("MySQL"))
+ Map<String, String> actual = new
TablesContext(Arrays.asList(tableSegment1, tableSegment2),
TypedSPILoader.getService(DatabaseType.class, "FIXTURE"))
.findTableNamesByColumnSegment(Collections.singletonList(columnSegment),
mock(ShardingSphereSchema.class));
assertTrue(actual.isEmpty());
}
@@ -105,7 +106,7 @@ class TablesContextTest {
when(schema.getAllColumnNames("table_1")).thenReturn(Collections.singletonList("col"));
ColumnSegment columnSegment = createColumnSegment(null, "col");
Map<String, String> actual = new
TablesContext(Arrays.asList(tableSegment1, tableSegment2),
-
DatabaseTypeFactory.get("MySQL")).findTableNamesByColumnSegment(Collections.singletonList(columnSegment),
schema);
+ TypedSPILoader.getService(DatabaseType.class,
"FIXTURE")).findTableNamesByColumnSegment(Collections.singletonList(columnSegment),
schema);
assertFalse(actual.isEmpty());
assertThat(actual.get("col"), is("table_1"));
}
@@ -119,7 +120,7 @@ class TablesContextTest {
ShardingSphereSchema schema = new
ShardingSphereSchema(Stream.of(table).collect(Collectors.toMap(ShardingSphereTable::getName,
value -> value)), Collections.emptyMap());
ColumnSegment columnSegment = createColumnSegment(null, "COL");
Map<String, String> actual = new
TablesContext(Arrays.asList(tableSegment1, tableSegment2),
-
DatabaseTypeFactory.get("MySQL")).findTableNamesByColumnSegment(Collections.singletonList(columnSegment),
schema);
+ TypedSPILoader.getService(DatabaseType.class,
"FIXTURE")).findTableNamesByColumnSegment(Collections.singletonList(columnSegment),
schema);
assertFalse(actual.isEmpty());
assertThat(actual.get("col"), is("TABLE_1"));
}
@@ -128,7 +129,7 @@ class TablesContextTest {
void assertFindTableNameWhenColumnProjectionWhenSingleTable() {
SimpleTableSegment tableSegment = createTableSegment("table_1",
"tbl_1");
ColumnProjection columnProjection = new ColumnProjection(null, "col",
"cl");
- Map<String, String> actual = new
TablesContext(Collections.singletonList(tableSegment),
DatabaseTypeFactory.get("MySQL"))
+ Map<String, String> actual = new
TablesContext(Collections.singletonList(tableSegment),
TypedSPILoader.getService(DatabaseType.class, "FIXTURE"))
.findTableNamesByColumnProjection(Collections.singletonList(columnProjection),
mock(ShardingSphereSchema.class));
assertFalse(actual.isEmpty());
assertThat(actual.get("col"), is("table_1"));
@@ -139,7 +140,7 @@ class TablesContextTest {
SimpleTableSegment tableSegment1 = createTableSegment("table_1",
"tbl_1");
SimpleTableSegment tableSegment2 = createTableSegment("table_2",
"tbl_2");
ColumnProjection columnProjection = new ColumnProjection("table_1",
"col", "cl");
- Map<String, String> actual = new
TablesContext(Arrays.asList(tableSegment1, tableSegment2),
DatabaseTypeFactory.get("MySQL"))
+ Map<String, String> actual = new
TablesContext(Arrays.asList(tableSegment1, tableSegment2),
TypedSPILoader.getService(DatabaseType.class, "FIXTURE"))
.findTableNamesByColumnProjection(Collections.singletonList(columnProjection),
mock(ShardingSphereSchema.class));
assertFalse(actual.isEmpty());
assertThat(actual.get("table_1.col"), is("table_1"));
@@ -150,7 +151,7 @@ class TablesContextTest {
SimpleTableSegment tableSegment1 = createTableSegment("table_1",
"tbl_1");
SimpleTableSegment tableSegment2 = createTableSegment("table_2",
"tbl_2");
ColumnProjection columnProjection = new ColumnProjection(null, "col",
"cl");
- Map<String, String> actual = new
TablesContext(Arrays.asList(tableSegment1, tableSegment2),
DatabaseTypeFactory.get("MySQL"))
+ Map<String, String> actual = new
TablesContext(Arrays.asList(tableSegment1, tableSegment2),
TypedSPILoader.getService(DatabaseType.class, "FIXTURE"))
.findTableNamesByColumnProjection(Collections.singletonList(columnProjection),
mock(ShardingSphereSchema.class));
assertTrue(actual.isEmpty());
}
@@ -162,7 +163,7 @@ class TablesContextTest {
ShardingSphereSchema schema = mock(ShardingSphereSchema.class);
when(schema.getAllColumnNames("table_1")).thenReturn(Collections.singletonList("col"));
ColumnProjection columnProjection = new ColumnProjection(null, "col",
"cl");
- Map<String, String> actual = new
TablesContext(Arrays.asList(tableSegment1, tableSegment2),
DatabaseTypeFactory.get("MySQL"))
+ Map<String, String> actual = new
TablesContext(Arrays.asList(tableSegment1, tableSegment2),
TypedSPILoader.getService(DatabaseType.class, "FIXTURE"))
.findTableNamesByColumnProjection(Collections.singletonList(columnProjection),
schema);
assertFalse(actual.isEmpty());
assertThat(actual.get("col"), is("table_1"));
@@ -176,7 +177,7 @@ class TablesContextTest {
new ShardingSphereColumn("COL", 0, false, false, true, true,
false)), Collections.emptyList(), Collections.emptyList());
ShardingSphereSchema schema = new
ShardingSphereSchema(Stream.of(table).collect(Collectors.toMap(ShardingSphereTable::getName,
value -> value)), Collections.emptyMap());
ColumnProjection columnProjection = new ColumnProjection(null, "COL",
"CL");
- Map<String, String> actual = new
TablesContext(Arrays.asList(tableSegment1, tableSegment2),
DatabaseTypeFactory.get("MySQL"))
+ Map<String, String> actual = new
TablesContext(Arrays.asList(tableSegment1, tableSegment2),
TypedSPILoader.getService(DatabaseType.class, "FIXTURE"))
.findTableNamesByColumnProjection(Collections.singletonList(columnProjection),
schema);
assertFalse(actual.isEmpty());
assertThat(actual.get("col"), is("TABLE_1"));
@@ -203,7 +204,7 @@ class TablesContextTest {
tableSegment1.setOwner(new OwnerSegment(0, 0, new
IdentifierValue("sharding_db_1")));
SimpleTableSegment tableSegment2 = createTableSegment("table_1",
"tbl_1");
tableSegment2.setOwner(new OwnerSegment(0, 0, new
IdentifierValue("sharding_db_1")));
- TablesContext tablesContext = new
TablesContext(Arrays.asList(tableSegment1, tableSegment2),
DatabaseTypeFactory.get("MySQL"));
+ TablesContext tablesContext = new
TablesContext(Arrays.asList(tableSegment1, tableSegment2),
TypedSPILoader.getService(DatabaseType.class, "FIXTURE"));
assertTrue(tablesContext.getDatabaseName().isPresent());
assertThat(tablesContext.getDatabaseName().get(), is("sharding_db_1"));
}
@@ -214,7 +215,7 @@ class TablesContextTest {
tableSegment1.setOwner(new OwnerSegment(0, 0, new
IdentifierValue("sharding_db_1")));
SimpleTableSegment tableSegment2 = createTableSegment("table_2",
"tbl_2");
tableSegment2.setOwner(new OwnerSegment(0, 0, new
IdentifierValue("sharding_db_1")));
- TablesContext tablesContext = new
TablesContext(Arrays.asList(tableSegment1, tableSegment2),
DatabaseTypeFactory.get("MySQL"));
+ TablesContext tablesContext = new
TablesContext(Arrays.asList(tableSegment1, tableSegment2),
TypedSPILoader.getService(DatabaseType.class, "FIXTURE"));
assertTrue(tablesContext.getDatabaseName().isPresent());
assertThat(tablesContext.getDatabaseName().get(), is("sharding_db_1"));
}
@@ -225,7 +226,7 @@ class TablesContextTest {
tableSegment1.setOwner(new OwnerSegment(0, 0, new
IdentifierValue("sharding_db_1")));
SimpleTableSegment tableSegment2 = createTableSegment("table_1",
"tbl_1");
tableSegment2.setOwner(new OwnerSegment(0, 0, new
IdentifierValue("sharding_db_2")));
- assertThrows(IllegalStateException.class, () -> new
TablesContext(Arrays.asList(tableSegment1, tableSegment2),
DatabaseTypeFactory.get("MySQL")).getDatabaseName());
+ assertThrows(IllegalStateException.class, () -> new
TablesContext(Arrays.asList(tableSegment1, tableSegment2),
TypedSPILoader.getService(DatabaseType.class, "FIXTURE")).getDatabaseName());
}
@Test
@@ -234,7 +235,7 @@ class TablesContextTest {
tableSegment1.setOwner(new OwnerSegment(0, 0, new
IdentifierValue("sharding_db_1")));
SimpleTableSegment tableSegment2 = createTableSegment("table_2",
"tbl_2");
tableSegment2.setOwner(new OwnerSegment(0, 0, new
IdentifierValue("sharding_db_2")));
- assertThrows(IllegalStateException.class, () -> new
TablesContext(Arrays.asList(tableSegment1, tableSegment2),
DatabaseTypeFactory.get("MySQL")).getDatabaseName());
+ assertThrows(IllegalStateException.class, () -> new
TablesContext(Arrays.asList(tableSegment1, tableSegment2),
TypedSPILoader.getService(DatabaseType.class, "FIXTURE")).getDatabaseName());
}
@Test
@@ -243,7 +244,7 @@ class TablesContextTest {
tableSegment1.setOwner(new OwnerSegment(0, 0, new
IdentifierValue("sharding_db_1")));
SimpleTableSegment tableSegment2 = createTableSegment("table_2",
"tbl_2");
tableSegment2.setOwner(new OwnerSegment(0, 0, new
IdentifierValue("sharding_db_1")));
- TablesContext tablesContext = new
TablesContext(Arrays.asList(tableSegment1, tableSegment2),
DatabaseTypeFactory.get("MySQL"));
+ TablesContext tablesContext = new
TablesContext(Arrays.asList(tableSegment1, tableSegment2),
TypedSPILoader.getService(DatabaseType.class, "FIXTURE"));
assertTrue(tablesContext.getSchemaName().isPresent());
assertThat(tablesContext.getSchemaName().get(), is("sharding_db_1"));
}
diff --git
a/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/props/DataSourcePropertiesValidator.java
b/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/props/DataSourcePropertiesValidator.java
index edc3c7613ee..b04abb9494c 100644
---
a/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/props/DataSourcePropertiesValidator.java
+++
b/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/props/DataSourcePropertiesValidator.java
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.infra.datasource.props;
-import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeChecker;
import
org.apache.shardingsphere.infra.datasource.pool.creator.DataSourcePoolCreator;
import
org.apache.shardingsphere.infra.datasource.pool.destroyer.DataSourcePoolDestroyer;
import
org.apache.shardingsphere.infra.datasource.pool.metadata.DataSourcePoolMetaData;
@@ -74,7 +73,7 @@ public final class DataSourcePropertiesValidator {
DataSource dataSource = null;
try {
dataSource = DataSourcePoolCreator.create(dataSourceProps);
- checkFailFast(dataSourceName, dataSource);
+ checkFailFast(dataSource);
// CHECKSTYLE:OFF
} catch (final SQLException | RuntimeException ex) {
// CHECKSTYLE:ON
@@ -86,9 +85,10 @@ public final class DataSourcePropertiesValidator {
}
}
- private void checkFailFast(final String dataSourceName, final DataSource
dataSource) throws SQLException {
- try (Connection connection = dataSource.getConnection()) {
-
DatabaseTypeChecker.checkSupportedStorageType(connection.getMetaData().getURL(),
dataSourceName);
+ private void checkFailFast(final DataSource dataSource) throws
SQLException {
+ // CHECKSTYLE:OFF
+ try (Connection ignored = dataSource.getConnection()) {
+ // CHECKSTYLE:ON
}
}
}
diff --git
a/infra/common/src/test/java/org/apache/shardingsphere/infra/datasource/props/DataSourcePropertiesValidatorTest.java
b/infra/common/src/test/java/org/apache/shardingsphere/infra/datasource/props/DataSourcePropertiesValidatorTest.java
index fba1ecc52a8..ee512224a14 100644
---
a/infra/common/src/test/java/org/apache/shardingsphere/infra/datasource/props/DataSourcePropertiesValidatorTest.java
+++
b/infra/common/src/test/java/org/apache/shardingsphere/infra/datasource/props/DataSourcePropertiesValidatorTest.java
@@ -26,6 +26,8 @@ import org.apache.shardingsphere.test.mock.StaticMockSettings;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
import java.util.Collection;
import java.util.Collections;
@@ -39,6 +41,7 @@ import static org.mockito.Mockito.when;
@ExtendWith(AutoMockExtension.class)
@StaticMockSettings(DatabaseTypeFactory.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
class DataSourcePropertiesValidatorTest {
@BeforeAll
diff --git
a/test/fixture/infra/src/main/java/org/apache/shardingsphere/test/fixture/infra/database/type/MockedDatabaseType.java
b/infra/common/src/test/java/org/apache/shardingsphere/infra/fixture/DatabaseTypeFixture.java
similarity index 74%
copy from
test/fixture/infra/src/main/java/org/apache/shardingsphere/test/fixture/infra/database/type/MockedDatabaseType.java
copy to
infra/common/src/test/java/org/apache/shardingsphere/infra/fixture/DatabaseTypeFixture.java
index 279c27bd3a8..d325241ed70 100644
---
a/test/fixture/infra/src/main/java/org/apache/shardingsphere/test/fixture/infra/database/type/MockedDatabaseType.java
+++
b/infra/common/src/test/java/org/apache/shardingsphere/infra/fixture/DatabaseTypeFixture.java
@@ -15,27 +15,26 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.test.fixture.infra.database.type;
+package org.apache.shardingsphere.infra.fixture;
-import org.apache.shardingsphere.infra.database.spi.DataSourceMetaData;
-import org.apache.shardingsphere.infra.database.spi.DatabaseType;
import org.apache.shardingsphere.infra.database.enums.NullsOrderType;
import org.apache.shardingsphere.infra.database.enums.QuoteCharacter;
+import org.apache.shardingsphere.infra.database.spi.DataSourceMetaData;
+import org.apache.shardingsphere.infra.database.spi.DatabaseType;
import java.util.Collection;
import java.util.Collections;
+import java.util.HashMap;
import java.util.Map;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
-/**
- * Mocked database type.
- */
-public final class MockedDatabaseType implements DatabaseType {
+public final class DatabaseTypeFixture implements DatabaseType {
@Override
public QuoteCharacter getQuoteCharacter() {
- return QuoteCharacter.NONE;
+ return QuoteCharacter.BACK_QUOTE;
}
@Override
@@ -43,19 +42,24 @@ public final class MockedDatabaseType implements
DatabaseType {
return NullsOrderType.FIRST;
}
+ @Override
+ public boolean isReservedWord(final String identifier) {
+ return "SELECT".equalsIgnoreCase(identifier);
+ }
+
@Override
public Collection<String> getJdbcUrlPrefixes() {
- return Collections.singleton("jdbc:fixture");
+ return Collections.singleton("jdbc:mock:");
}
@Override
public DataSourceMetaData getDataSourceMetaData(final String url, final
String username) {
- return mock(DataSourceMetaData.class);
+ return mock(DataSourceMetaData.class, RETURNS_DEEP_STUBS);
}
@Override
public Map<String, Collection<String>> getSystemDatabaseSchemaMap() {
- return Collections.emptyMap();
+ return new HashMap<>();
}
@Override
@@ -65,6 +69,11 @@ public final class MockedDatabaseType implements
DatabaseType {
@Override
public String getType() {
- return "FIXTURE";
+ return "INFRA.COMMON.FIXTURE";
+ }
+
+ @Override
+ public boolean isDefault() {
+ return true;
}
}
diff --git
a/infra/common/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.database.spi.DatabaseType
b/infra/common/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.database.spi.DatabaseType
new file mode 100644
index 00000000000..ef7e10aca9c
--- /dev/null
+++
b/infra/common/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.database.spi.DatabaseType
@@ -0,0 +1,18 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+org.apache.shardingsphere.infra.fixture.DatabaseTypeFixture
diff --git
a/infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/type/DatabaseTypeChecker.java
b/infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/type/DatabaseTypeChecker.java
deleted file mode 100644
index 476f2da6ae9..00000000000
---
a/infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/type/DatabaseTypeChecker.java
+++ /dev/null
@@ -1,98 +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;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.infra.database.spi.DatabaseType;
-import
org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
-import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
-
-import javax.sql.DataSource;
-import java.sql.Connection;
-import java.sql.SQLException;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Map.Entry;
-
-/**
- * Database type checker.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class DatabaseTypeChecker {
-
- private static final Collection<String> MOCKED_URL_PREFIXES = new
HashSet<>(Arrays.asList("jdbc:fixture", "jdbc:mock", "mock:jdbc"));
-
- private static final Collection<String> UNSUPPORTED_URL_PREFIXES =
Collections.singletonList("jdbc:mysql:aws");
-
- private static final Collection<DatabaseType> SUPPORTED_STORAGE_TYPES =
new HashSet<>(8, 1F);
-
- private static volatile boolean isChecked;
-
- static {
- Arrays.asList("MySQL", "PostgreSQL", "openGauss", "Oracle",
"SQLServer", "H2", "MariaDB")
- .forEach(each ->
TypedSPILoader.findService(DatabaseType.class,
each).ifPresent(SUPPORTED_STORAGE_TYPES::add));
- }
-
- /**
- * Check supported storage types.
- *
- * @param dataSources data sources
- * @param databaseName database name
- * @param storageTypes storage types
- * @throws SQLException SQL exception
- */
- public static void checkSupportedStorageTypes(final Map<String,
DataSource> dataSources, final String databaseName, final Map<String,
DatabaseType> storageTypes) throws SQLException {
- if (isChecked || dataSources.isEmpty()) {
- return;
- }
- for (Entry<String, DataSource> entry : dataSources.entrySet()) {
- try (Connection connection = entry.getValue().getConnection()) {
- String url = connection.getMetaData().getURL();
- if (MOCKED_URL_PREFIXES.stream().anyMatch(url::startsWith)) {
- return;
- }
-
ShardingSpherePreconditions.checkState(UNSUPPORTED_URL_PREFIXES.stream()
- .noneMatch(url::startsWith), () -> new
UnsupportedStorageTypeException(databaseName, entry.getKey()));
- }
- }
- storageTypes.forEach((key, value) ->
ShardingSpherePreconditions.checkState(SUPPORTED_STORAGE_TYPES.stream()
- .anyMatch(each -> each.getClass().equals(value.getClass())),
() -> new UnsupportedStorageTypeException(databaseName, key)));
- isChecked = true;
- }
-
- /**
- * Check supported storage type.
- *
- * @param url URL
- * @param dataSourceName data source name
- */
- public static void checkSupportedStorageType(final String url, final
String dataSourceName) {
- if (MOCKED_URL_PREFIXES.stream().anyMatch(url::startsWith)) {
- return;
- }
-
ShardingSpherePreconditions.checkState(UNSUPPORTED_URL_PREFIXES.stream()
- .noneMatch(url::startsWith), () -> new
UnsupportedStorageTypeException(dataSourceName));
- ShardingSpherePreconditions.checkState(SUPPORTED_STORAGE_TYPES.stream()
- .flatMap(storageType ->
storageType.getJdbcUrlPrefixes().stream())
- .anyMatch(url::startsWith), () -> new
UnsupportedStorageTypeException(dataSourceName));
- }
-}
diff --git
a/infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/type/DatabaseTypeFactory.java
b/infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/type/DatabaseTypeFactory.java
index 3da5e85899f..7a5c47fc081 100644
---
a/infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/type/DatabaseTypeFactory.java
+++
b/infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/type/DatabaseTypeFactory.java
@@ -20,8 +20,8 @@ package org.apache.shardingsphere.infra.database.core.type;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.infra.database.spi.DatabaseType;
+import
org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import java.util.Collection;
import java.util.stream.Collectors;
@@ -40,9 +40,7 @@ public final class DatabaseTypeFactory {
*/
public static DatabaseType get(final String url) {
Collection<DatabaseType> databaseTypes =
ShardingSphereServiceLoader.getServiceInstances(DatabaseType.class).stream().filter(each
-> matchURLs(url, each)).collect(Collectors.toList());
- if (databaseTypes.isEmpty()) {
- return TypedSPILoader.getService(DatabaseType.class, null);
- }
+ ShardingSpherePreconditions.checkState(!databaseTypes.isEmpty(), () ->
new UnsupportedStorageTypeException(url));
for (DatabaseType each : databaseTypes) {
if (each.getTrunkDatabaseType().isPresent()) {
return each;
diff --git
a/infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/type/UnsupportedStorageTypeException.java
b/infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/type/UnsupportedStorageTypeException.java
index 6fd7d6d7df1..4f88090b3cf 100644
---
a/infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/type/UnsupportedStorageTypeException.java
+++
b/infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/type/UnsupportedStorageTypeException.java
@@ -27,11 +27,7 @@ public final class UnsupportedStorageTypeException extends
KernelSQLException {
private static final long serialVersionUID = 8981789100727786183L;
- public UnsupportedStorageTypeException(final String dataSourceName) {
- super(XOpenSQLState.FEATURE_NOT_SUPPORTED, 3, 40, "Unsupported storage
type of `%s`.", dataSourceName);
- }
-
- public UnsupportedStorageTypeException(final String databaseName, final
String dataSourceName) {
- super(XOpenSQLState.FEATURE_NOT_SUPPORTED, 3, 40, "Unsupported storage
type of `%s.%s`.", databaseName, dataSourceName);
+ public UnsupportedStorageTypeException(final String url) {
+ super(XOpenSQLState.FEATURE_NOT_SUPPORTED, 3, 40, "Unsupported storage
type of URL `%s`.", url);
}
}
diff --git
a/infra/database/core/src/test/java/org/apache/shardingsphere/infra/database/core/type/DatabaseTypeFactoryTest.java
b/infra/database/core/src/test/java/org/apache/shardingsphere/infra/database/core/type/DatabaseTypeFactoryTest.java
index 70744844d37..eb103842fdd 100644
---
a/infra/database/core/src/test/java/org/apache/shardingsphere/infra/database/core/type/DatabaseTypeFactoryTest.java
+++
b/infra/database/core/src/test/java/org/apache/shardingsphere/infra/database/core/type/DatabaseTypeFactoryTest.java
@@ -21,6 +21,7 @@ import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertThrows;
class DatabaseTypeFactoryTest {
@@ -36,6 +37,6 @@ class DatabaseTypeFactoryTest {
@Test
void assertGetDatabaseTypeWithUnrecognizedURL() {
- assertThat(DatabaseTypeFactory.get("jdbc:not-existed:test").getType(),
is("INFRA.TRUNK.FIXTURE"));
+ assertThrows(UnsupportedStorageTypeException.class, () ->
DatabaseTypeFactory.get("jdbc:not-existed:test"));
}
}
diff --git a/jdbc/core/pom.xml b/jdbc/core/pom.xml
index 1006ed61186..98713ef4abc 100644
--- a/jdbc/core/pom.xml
+++ b/jdbc/core/pom.xml
@@ -182,6 +182,12 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-test-fixture-infra</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.apache.commons</groupId>
diff --git
a/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/PreparedStatementAdapterTest.java
b/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/PreparedStatementAdapterTest.java
index 715293e000a..2eda4f858c2 100644
---
a/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/PreparedStatementAdapterTest.java
+++
b/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/PreparedStatementAdapterTest.java
@@ -74,9 +74,9 @@ class PreparedStatementAdapterTest {
new SQLFederationRule(new
DefaultSQLFederationRuleConfigurationBuilder().build(), Collections.emptyMap(),
mock(ConfigurationProperties.class)))));
when(connection.getContextManager().getMetaDataContexts().getMetaData().getProps()).thenReturn(new
ConfigurationProperties(new Properties()));
when(connection.getContextManager().getMetaDataContexts().getMetaData().getDatabase(
-
connection.getDatabaseName()).getProtocolType()).thenReturn(TypedSPILoader.getService(DatabaseType.class,
"FIXTURE"));
+
connection.getDatabaseName()).getProtocolType()).thenReturn(TypedSPILoader.getService(DatabaseType.class,
"MySQL"));
when(connection.getContextManager().getMetaDataContexts().getMetaData().getDatabase(connection.getDatabaseName()).getResourceMetaData().getStorageTypes())
- .thenReturn(Collections.singletonMap("ds_0",
TypedSPILoader.getService(DatabaseType.class, "FIXTURE")));
+ .thenReturn(Collections.singletonMap("ds_0",
TypedSPILoader.getService(DatabaseType.class, "MySQL")));
shardingSpherePreparedStatement = new
ShardingSpherePreparedStatement(connection, "SELECT 1");
}
diff --git a/kernel/data-pipeline/dialect/mysql/pom.xml
b/kernel/data-pipeline/dialect/mysql/pom.xml
index efa6e9cf724..75427b7ef80 100644
--- a/kernel/data-pipeline/dialect/mysql/pom.xml
+++ b/kernel/data-pipeline/dialect/mysql/pom.xml
@@ -44,6 +44,12 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-test-fixture-infra</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>com.h2database</groupId>
diff --git
a/kernel/data-pipeline/dialect/mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/MySQLIncrementalDumperTest.java
b/kernel/data-pipeline/dialect/mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/MySQLIncrementalDumperTest.java
index c5c15e83856..9a8c137f5bb 100644
---
a/kernel/data-pipeline/dialect/mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/MySQLIncrementalDumperTest.java
+++
b/kernel/data-pipeline/dialect/mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/MySQLIncrementalDumperTest.java
@@ -88,7 +88,7 @@ class MySQLIncrementalDumperTest {
void setUp() {
dumperConfig = mockDumperConfiguration();
initTableData(dumperConfig);
- dumperConfig.setDataSourceConfig(new
StandardPipelineDataSourceConfiguration("mock:mysql://127.0.0.1:3306/test",
"root", "root"));
+ dumperConfig.setDataSourceConfig(new
StandardPipelineDataSourceConfiguration("jdbc:mock://127.0.0.1:3306/test",
"root", "root"));
PipelineTableMetaDataLoader metaDataLoader =
mock(PipelineTableMetaDataLoader.class);
SimpleMemoryPipelineChannel channel = new
SimpleMemoryPipelineChannel(10000, new EmptyAckCallback());
incrementalDumper = new MySQLIncrementalDumper(dumperConfig, new
BinlogPosition("binlog-000001", 4L, 0L), channel, metaDataLoader);
diff --git
a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/factory/ExternalMetaDataFactory.java
b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/factory/ExternalMetaDataFactory.java
index c6bdc73082e..906f719b857 100644
---
a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/factory/ExternalMetaDataFactory.java
+++
b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/factory/ExternalMetaDataFactory.java
@@ -21,10 +21,8 @@ import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.infra.config.database.DatabaseConfiguration;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
-import org.apache.shardingsphere.infra.database.spi.DatabaseType;
import org.apache.shardingsphere.infra.database.DatabaseTypeEngine;
-import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeChecker;
-import org.apache.shardingsphere.infra.datasource.state.DataSourceStateManager;
+import org.apache.shardingsphere.infra.database.spi.DatabaseType;
import org.apache.shardingsphere.infra.instance.InstanceContext;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
@@ -81,8 +79,6 @@ public final class ExternalMetaDataFactory {
String databaseName = entry.getKey();
if (!entry.getValue().getDataSources().isEmpty() ||
!protocolType.getSystemSchemas().contains(databaseName)) {
Map<String, DatabaseType> storageTypes =
DatabaseTypeEngine.getStorageTypes(entry.getKey(), entry.getValue());
-
DatabaseTypeChecker.checkSupportedStorageTypes(DataSourceStateManager.getInstance()
- .getEnabledDataSourceMap(databaseName,
entry.getValue().getDataSources()), databaseName, storageTypes);
result.put(databaseName.toLowerCase(),
ShardingSphereDatabase.create(databaseName, protocolType, storageTypes,
entry.getValue(), props, instanceContext));
}
}
diff --git a/kernel/single/core/pom.xml b/kernel/single/core/pom.xml
index e3f5b6fb14f..0d3acc5a060 100644
--- a/kernel/single/core/pom.xml
+++ b/kernel/single/core/pom.xml
@@ -60,5 +60,11 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-test-fixture-infra</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
diff --git
a/kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/compiler/it/SQLStatementCompilerIT.java
b/kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/compiler/it/SQLStatementCompilerIT.java
index 6dc2baa37c8..74198d51e58 100644
---
a/kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/compiler/it/SQLStatementCompilerIT.java
+++
b/kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/compiler/it/SQLStatementCompilerIT.java
@@ -27,7 +27,6 @@ import org.apache.calcite.rel.type.RelDataTypeFactory;
import org.apache.calcite.rex.RexBuilder;
import org.apache.calcite.sql.validate.SqlValidator;
import org.apache.calcite.sql2rel.SqlToRelConverter;
-import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeFactory;
import org.apache.shardingsphere.infra.database.spi.DatabaseType;
import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn;
import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
@@ -235,7 +234,7 @@ class SQLStatementCompilerIT {
private SqlToRelConverter createSqlToRelConverter(final
ShardingSphereSchema schema) {
CalciteConnectionConfig connectionConfig = new
CalciteConnectionConfigImpl(new Properties());
RelDataTypeFactory relDataTypeFactory = new JavaTypeFactoryImpl();
- DatabaseType databaseType = DatabaseTypeFactory.get("H2");
+ DatabaseType databaseType =
TypedSPILoader.getService(DatabaseType.class, "H2");
SQLFederationSchema sqlFederationSchema = new
SQLFederationSchema(SCHEMA_NAME, schema, databaseType, new
JavaTypeFactoryImpl());
CalciteCatalogReader catalogReader =
SQLFederationPlannerUtils.createCatalogReader(SCHEMA_NAME, sqlFederationSchema,
relDataTypeFactory, connectionConfig);
SqlValidator validator =
SQLFederationPlannerUtils.createSqlValidator(catalogReader, relDataTypeFactory,
databaseType, connectionConfig);
diff --git a/kernel/transaction/core/pom.xml b/kernel/transaction/core/pom.xml
index a102051a725..12006599630 100644
--- a/kernel/transaction/core/pom.xml
+++ b/kernel/transaction/core/pom.xml
@@ -45,5 +45,11 @@
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-test-fixture-infra</artifactId>
+ <version>${project.parent.version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
diff --git a/mode/type/cluster/core/pom.xml b/mode/type/cluster/core/pom.xml
index 4d282203d28..cffdaeb7527 100644
--- a/mode/type/cluster/core/pom.xml
+++ b/mode/type/cluster/core/pom.xml
@@ -59,6 +59,12 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-test-fixture-infra</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-test-util</artifactId>
diff --git a/mode/type/standalone/core/pom.xml
b/mode/type/standalone/core/pom.xml
index f74e04cd61c..a8e523ac0cc 100644
--- a/mode/type/standalone/core/pom.xml
+++ b/mode/type/standalone/core/pom.xml
@@ -44,6 +44,12 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-test-fixture-infra</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-test-util</artifactId>
diff --git
a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowTablesExecutorTest.java
b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowTablesExecutorTest.java
index 3a23edcf973..77d6cfca2bf 100644
---
a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowTablesExecutorTest.java
+++
b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/ShowTablesExecutorTest.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
-import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeFactory;
import org.apache.shardingsphere.infra.database.spi.DatabaseType;
import
org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResultMetaData;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
@@ -70,7 +69,7 @@ class ShowTablesExecutorTest {
@Test
void assertShowTablesExecutorWithoutFilter() throws SQLException {
- ShowTablesExecutor executor = new ShowTablesExecutor(new
MySQLShowTablesStatement(), DatabaseTypeFactory.get("MySQL"));
+ ShowTablesExecutor executor = new ShowTablesExecutor(new
MySQLShowTablesStatement(), TypedSPILoader.getService(DatabaseType.class,
"MySQL"));
Map<String, ShardingSphereDatabase> databases = getDatabases();
ContextManager contextManager = mockContextManager(databases);
when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager);
@@ -92,7 +91,7 @@ class ShowTablesExecutorTest {
void assertShowTablesExecutorWithFull() throws SQLException {
MySQLShowTablesStatement showTablesStatement =
mock(MySQLShowTablesStatement.class);
when(showTablesStatement.isContainsFull()).thenReturn(true);
- ShowTablesExecutor executor = new
ShowTablesExecutor(showTablesStatement, DatabaseTypeFactory.get("MySQL"));
+ ShowTablesExecutor executor = new
ShowTablesExecutor(showTablesStatement,
TypedSPILoader.getService(DatabaseType.class, "MySQL"));
Map<String, ShardingSphereDatabase> databases = getDatabases();
ContextManager contextManager = mockContextManager(databases);
when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager);
diff --git
a/proxy/bootstrap/src/test/java/org/apache/shardingsphere/proxy/version/ShardingSphereProxyVersionTest.java
b/proxy/bootstrap/src/test/java/org/apache/shardingsphere/proxy/version/ShardingSphereProxyVersionTest.java
index ddbb6fcdec1..c02e88acd02 100644
---
a/proxy/bootstrap/src/test/java/org/apache/shardingsphere/proxy/version/ShardingSphereProxyVersionTest.java
+++
b/proxy/bootstrap/src/test/java/org/apache/shardingsphere/proxy/version/ShardingSphereProxyVersionTest.java
@@ -60,26 +60,26 @@ class ShardingSphereProxyVersionTest {
assertThat(DatabaseProtocolServerInfo.getProtocolVersion("foo_db",
TypedSPILoader.getService(DatabaseType.class, "MySQL")), startsWith("5.7.22"));
}
- private ContextManager mockContextManager(final String databaseType, final
String databaseProductVersion) throws SQLException {
+ private ContextManager mockContextManager(final String
databaseProductName, final String databaseProductVersion) throws SQLException {
ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS);
- ShardingSphereDatabase database = mockDatabase(databaseType,
databaseProductVersion);
+ ShardingSphereDatabase database = mockDatabase(databaseProductName,
databaseProductVersion);
when(result.getMetaDataContexts().getMetaData().getDatabases()).thenReturn(Collections.singletonMap("foo_db",
database));
return result;
}
- private ShardingSphereDatabase mockDatabase(final String databaseType,
final String databaseProductVersion) throws SQLException {
+ private ShardingSphereDatabase mockDatabase(final String
databaseProductName, final String databaseProductVersion) throws SQLException {
ShardingSphereDatabase result = mock(ShardingSphereDatabase.class);
when(result.getName()).thenReturn("foo_db");
when(result.getProtocolType()).thenReturn(TypedSPILoader.getService(DatabaseType.class,
"MySQL"));
- ShardingSphereResourceMetaData resourceMetaData =
mockResourceMetaData(databaseType, databaseProductVersion);
+ ShardingSphereResourceMetaData resourceMetaData =
mockResourceMetaData(databaseProductName, databaseProductVersion);
when(result.getResourceMetaData()).thenReturn(resourceMetaData);
return result;
}
- private ShardingSphereResourceMetaData mockResourceMetaData(final String
databaseType, final String databaseProductVersion) throws SQLException {
+ private ShardingSphereResourceMetaData mockResourceMetaData(final String
databaseProductName, final String databaseProductVersion) throws SQLException {
ShardingSphereResourceMetaData result =
mock(ShardingSphereResourceMetaData.class);
-
when(result.getStorageTypes()).thenReturn(Collections.singletonMap("foo_ds",
TypedSPILoader.getService(DatabaseType.class, databaseType)));
- DataSource dataSource = createDataSource(databaseType,
databaseProductVersion);
+
when(result.getStorageTypes()).thenReturn(Collections.singletonMap("foo_ds",
TypedSPILoader.getService(DatabaseType.class, databaseProductName)));
+ DataSource dataSource = createDataSource(databaseProductName,
databaseProductVersion);
when(result.getDataSources()).thenReturn(Collections.singletonMap("foo_ds",
dataSource));
return result;
}
diff --git
a/test/fixture/infra/src/main/java/org/apache/shardingsphere/test/fixture/infra/database/type/MockedDatabaseType.java
b/test/fixture/infra/src/main/java/org/apache/shardingsphere/test/fixture/infra/database/type/MockedDatabaseType.java
index 279c27bd3a8..47c851810ba 100644
---
a/test/fixture/infra/src/main/java/org/apache/shardingsphere/test/fixture/infra/database/type/MockedDatabaseType.java
+++
b/test/fixture/infra/src/main/java/org/apache/shardingsphere/test/fixture/infra/database/type/MockedDatabaseType.java
@@ -45,7 +45,7 @@ public final class MockedDatabaseType implements DatabaseType
{
@Override
public Collection<String> getJdbcUrlPrefixes() {
- return Collections.singleton("jdbc:fixture");
+ return Collections.singleton("jdbc:mock");
}
@Override
diff --git a/test/it/rewriter/pom.xml b/test/it/rewriter/pom.xml
index 8abf8a8ed5d..762772d8832 100644
--- a/test/it/rewriter/pom.xml
+++ b/test/it/rewriter/pom.xml
@@ -33,6 +33,12 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-test-fixture-infra</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-single-core</artifactId>