You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2021/02/07 10:34:14 UTC
[shardingsphere] branch master updated: Merge
DatabaseMetaDataDialectHandler into DatabaseType (#9370)
This is an automated email from the ASF dual-hosted git repository.
zhangyonglun 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 a8bc665 Merge DatabaseMetaDataDialectHandler into DatabaseType (#9370)
a8bc665 is described below
commit a8bc665d95f6d7bddd65d0016f5eb55f49a81ee7
Author: Liang Zhang <te...@163.com>
AuthorDate: Sun Feb 7 18:33:45 2021 +0800
Merge DatabaseMetaDataDialectHandler into DatabaseType (#9370)
* Merge DatabaseMetaDataDialectHandler into DatabaseType
* Simplify test cases
* Fix test cases
* Fix test case
* Refactor SchemaBuilderTest
* Refactor database type
* Fix test case
* Fix test case
---
.../metadata/EncryptTableMetaDataBuilderTest.java | 4 +-
.../impl/EncryptProjectionTokenGenerator.java | 8 +-
.../infra/database/type/DatabaseType.java | 35 ++++
.../database/type/dialect/H2DatabaseType.java | 6 +
.../database/type/dialect/MariaDBDatabaseType.java | 6 +
.../database/type/dialect/MySQLDatabaseType.java | 6 +
.../database/type/dialect/OracleDatabaseType.java | 24 +++
.../type/dialect/PostgreSQLDatabaseType.java | 6 +
.../database/type/dialect/SQL92DatabaseType.java | 6 +
.../type/dialect/SQLServerDatabaseType.java | 6 +
.../builder/loader/ColumnMetaDataLoader.java | 6 +-
.../builder/loader/SchemaMetaDataLoader.java | 3 +-
.../schema/builder/loader/TableMetaDataLoader.java | 7 +-
.../adapter/MetaDataLoaderConnectionAdapter.java | 13 +-
.../dialect/DatabaseMetaDataDialectHandler.java | 64 -------
.../DatabaseMetaDataDialectHandlerFactory.java | 53 ------
.../impl/H2DatabaseMetaDataDialectHandler.java | 37 ----
.../MariaDBDatabaseMetaDataDialectHandler.java | 37 ----
.../impl/MySQLDatabaseMetaDataDialectHandler.java | 37 ----
.../impl/OracleDatabaseMetaDataDialectHandler.java | 56 ------
.../PostgreSQLDatabaseMetaDataDialectHandler.java | 37 ----
.../impl/SQL92DatabaseMetaDataDialectHandler.java | 37 ----
.../SQLServerDatabaseMetaDataDialectHandler.java | 37 ----
...r.loader.dialect.DatabaseMetaDataDialectHandler | 24 ---
.../database/type/dialect/H2DatabaseTypeTest.java | 24 +++
.../type/dialect/MariaDBDatabaseTypeTest.java | 24 +++
.../type/dialect/MySQLDatabaseTypeTest.java | 24 +++
.../type/dialect/OracleDatabaseTypeTest.java | 25 +++
.../type/dialect/PostgreSQLDatabaseTypeTest.java | 24 +++
.../type/dialect/SQL92DatabaseTypeTest.java | 24 +++
.../type/dialect/SQLServerDatabaseTypeTest.java | 24 +++
.../metadata/schema/builder/SchemaBuilderTest.java | 24 +--
.../builder/loader/ColumnMetaDataLoaderTest.java | 3 +-
.../builder/loader/TableMetaDataLoaderTest.java | 7 +-
...AbstractDatabaseMetaDataDialectHandlerTest.java | 66 -------
.../DatabaseMetaDataDialectHandlerFactoryTest.java | 35 ----
.../DatabaseMetaDataDialectHandlerTest.java | 201 ---------------------
.../impl/H2DatabaseMetaDataDialectHandlerTest.java | 52 ------
.../MariaDBDatabaseMetaDataDialectHandlerTest.java | 52 ------
.../MySQLDatabaseMetaDataDialectHandlerTest.java | 52 ------
.../OracleDatabaseMetaDataDialectHandlerTest.java | 53 ------
...stgreSQLDatabaseMetaDataDialectHandlerTest.java | 52 ------
.../SQL92DatabaseMetaDataDialectHandlerTest.java | 52 ------
...QLServerDatabaseMetaDataDialectHandlerTest.java | 60 ------
.../frontend/fixture/FixtureDatabaseType.java | 6 +
.../env/dataset/DataSetEnvironmentManager.java | 18 +-
46 files changed, 303 insertions(+), 1154 deletions(-)
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/metadata/EncryptTableMetaDataBuilderTest.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/metadata/EncryptTableMetaDataBuilderTest.java
index d26e88a..dd7580d 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/metadata/EncryptTableMetaDataBuilderTest.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/metadata/EncryptTableMetaDataBuilderTest.java
@@ -30,6 +30,7 @@ import org.apache.shardingsphere.infra.spi.ordered.OrderedSPIRegistry;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
@@ -61,7 +62,7 @@ public final class EncryptTableMetaDataBuilderTest {
ShardingSphereServiceLoader.register(RuleBasedTableMetaDataBuilder.class);
}
- @Mock
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
private DatabaseType databaseType;
@Mock
@@ -98,6 +99,7 @@ public final class EncryptTableMetaDataBuilderTest {
public void assertLoadByExistedTable() throws SQLException {
EncryptRule rule = createEncryptRule();
EncryptTableMetaDataBuilder loader = (EncryptTableMetaDataBuilder) OrderedSPIRegistry.getRegisteredServices(Collections.singletonList(rule), RuleBasedTableMetaDataBuilder.class).get(rule);
+ when(databaseType.formatTableNamePattern(TABLE_NAME)).thenReturn(TABLE_NAME);
Optional<TableMetaData> actual = loader.load(TABLE_NAME, databaseType, Collections.singletonMap("logic_db", dataSource), new DataNodes(Collections.singletonList(rule)), rule, props);
assertTrue(actual.isPresent());
assertThat(actual.get().getColumnMetaData(0).getName(), is("id"));
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptProjectionTokenGenerator.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptProjectionTokenGenerator.java
index a2706f3..0eee6de 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptProjectionTokenGenerator.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-rewrite/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptProjectionTokenGenerator.java
@@ -29,15 +29,13 @@ import org.apache.shardingsphere.infra.binder.segment.select.projection.impl.Sho
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import org.apache.shardingsphere.infra.metadata.schema.builder.loader.dialect.DatabaseMetaDataDialectHandler;
-import org.apache.shardingsphere.infra.metadata.schema.builder.loader.dialect.DatabaseMetaDataDialectHandlerFactory;
+import org.apache.shardingsphere.infra.rewrite.sql.token.generator.CollectionSQLTokenGenerator;
+import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.generic.SubstitutableColumnNameToken;
import org.apache.shardingsphere.sql.parser.sql.common.constant.QuoteCharacter;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ColumnProjectionSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionsSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ShorthandProjectionSegment;
-import org.apache.shardingsphere.infra.rewrite.sql.token.generator.CollectionSQLTokenGenerator;
-import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.generic.SubstitutableColumnNameToken;
import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.OwnerSegment;
import java.util.Collection;
@@ -106,7 +104,7 @@ public final class EncryptProjectionTokenGenerator extends BaseEncryptSQLTokenGe
private SubstitutableColumnNameToken generateSQLToken(final ShorthandProjectionSegment segment,
final ShorthandProjection shorthandProjection, final String tableName, final EncryptTable encryptTable, final DatabaseType databaseType) {
- QuoteCharacter quoteCharacter = DatabaseMetaDataDialectHandlerFactory.findHandler(databaseType).map(DatabaseMetaDataDialectHandler::getQuoteCharacter).orElse(QuoteCharacter.NONE);
+ QuoteCharacter quoteCharacter = databaseType.getQuoteCharacter();
List<String> shorthandExtensionProjections = new LinkedList<>();
for (ColumnProjection each : shorthandProjection.getActualColumns()) {
if (encryptTable.getLogicColumns().contains(each.getName())) {
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/DatabaseType.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/DatabaseType.java
index ca047dd..c751147 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/DatabaseType.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/DatabaseType.java
@@ -18,7 +18,10 @@
package org.apache.shardingsphere.infra.database.type;
import org.apache.shardingsphere.infra.database.metadata.DataSourceMetaData;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.QuoteCharacter;
+import java.sql.Connection;
+import java.sql.SQLException;
import java.util.Collection;
/**
@@ -34,6 +37,13 @@ public interface DatabaseType {
String getName();
/**
+ * Get quote character.
+ *
+ * @return quote character
+ */
+ QuoteCharacter getQuoteCharacter();
+
+ /**
* Get alias of JDBC URL prefixes.
*
* @return Alias of JDBC URL prefixes
@@ -48,4 +58,29 @@ public interface DatabaseType {
* @return data source meta data
*/
DataSourceMetaData getDataSourceMetaData(String url, String username);
+
+ /**
+ * Get schema.
+ *
+ * @param connection connection
+ * @return schema
+ */
+ @SuppressWarnings("ReturnOfNull")
+ default String getSchema(final Connection connection) {
+ try {
+ return connection.getSchema();
+ } catch (final SQLException ignored) {
+ return null;
+ }
+ }
+
+ /**
+ * Format table name pattern.
+ *
+ * @param tableNamePattern table name pattern
+ * @return formatted table name pattern
+ */
+ default String formatTableNamePattern(final String tableNamePattern) {
+ return tableNamePattern;
+ }
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/H2DatabaseType.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/H2DatabaseType.java
index b11988b..c5fb44a 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/H2DatabaseType.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/H2DatabaseType.java
@@ -21,6 +21,7 @@ import org.apache.shardingsphere.infra.database.metadata.dialect.H2DataSourceMet
import org.apache.shardingsphere.infra.database.type.BranchDatabaseType;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeRegistry;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.QuoteCharacter;
import java.util.Collection;
import java.util.Collections;
@@ -36,6 +37,11 @@ public final class H2DatabaseType implements BranchDatabaseType {
}
@Override
+ public QuoteCharacter getQuoteCharacter() {
+ return QuoteCharacter.QUOTE;
+ }
+
+ @Override
public Collection<String> getJdbcUrlPrefixes() {
return Collections.singleton(String.format("jdbc:%s:", getName().toLowerCase()));
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/MariaDBDatabaseType.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/MariaDBDatabaseType.java
index 66d8576..d8e2d96 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/MariaDBDatabaseType.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/MariaDBDatabaseType.java
@@ -21,6 +21,7 @@ import org.apache.shardingsphere.infra.database.metadata.dialect.MariaDBDataSour
import org.apache.shardingsphere.infra.database.type.BranchDatabaseType;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeRegistry;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.QuoteCharacter;
import java.util.Collection;
import java.util.Collections;
@@ -36,6 +37,11 @@ public final class MariaDBDatabaseType implements BranchDatabaseType {
}
@Override
+ public QuoteCharacter getQuoteCharacter() {
+ return QuoteCharacter.BACK_QUOTE;
+ }
+
+ @Override
public Collection<String> getJdbcUrlPrefixes() {
return Collections.singleton(String.format("jdbc:%s:", getName().toLowerCase()));
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/MySQLDatabaseType.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/MySQLDatabaseType.java
index 95bf20b..62d8956 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/MySQLDatabaseType.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/MySQLDatabaseType.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.infra.database.type.dialect;
import org.apache.shardingsphere.infra.database.metadata.dialect.MySQLDataSourceMetaData;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.QuoteCharacter;
import java.util.Arrays;
import java.util.Collection;
@@ -34,6 +35,11 @@ public final class MySQLDatabaseType implements DatabaseType {
}
@Override
+ public QuoteCharacter getQuoteCharacter() {
+ return QuoteCharacter.BACK_QUOTE;
+ }
+
+ @Override
public Collection<String> getJdbcUrlPrefixes() {
return Arrays.asList("jdbc:mysql:", "jdbc:mysqlx:");
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/OracleDatabaseType.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/OracleDatabaseType.java
index 22a5c0f..82777dc 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/OracleDatabaseType.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/OracleDatabaseType.java
@@ -19,9 +19,13 @@ package org.apache.shardingsphere.infra.database.type.dialect;
import org.apache.shardingsphere.infra.database.metadata.dialect.OracleDataSourceMetaData;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.QuoteCharacter;
+import java.sql.Connection;
+import java.sql.SQLException;
import java.util.Collection;
import java.util.Collections;
+import java.util.Optional;
/**
* Database type of Oracle.
@@ -34,6 +38,11 @@ public final class OracleDatabaseType implements DatabaseType {
}
@Override
+ public QuoteCharacter getQuoteCharacter() {
+ return QuoteCharacter.QUOTE;
+ }
+
+ @Override
public Collection<String> getJdbcUrlPrefixes() {
return Collections.singleton(String.format("jdbc:%s:", getName().toLowerCase()));
}
@@ -42,4 +51,19 @@ public final class OracleDatabaseType implements DatabaseType {
public OracleDataSourceMetaData getDataSourceMetaData(final String url, final String username) {
return new OracleDataSourceMetaData(url, username);
}
+
+ @SuppressWarnings("ReturnOfNull")
+ @Override
+ public String getSchema(final Connection connection) {
+ try {
+ return Optional.ofNullable(connection.getMetaData().getUserName()).map(String::toUpperCase).orElse(null);
+ } catch (final SQLException ignored) {
+ return null;
+ }
+ }
+
+ @Override
+ public String formatTableNamePattern(final String tableNamePattern) {
+ return tableNamePattern.toUpperCase();
+ }
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/PostgreSQLDatabaseType.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/PostgreSQLDatabaseType.java
index 8d3960e..4148880 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/PostgreSQLDatabaseType.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/PostgreSQLDatabaseType.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.infra.database.type.dialect;
import org.apache.shardingsphere.infra.database.metadata.dialect.PostgreSQLDataSourceMetaData;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.QuoteCharacter;
import java.util.Collection;
import java.util.Collections;
@@ -34,6 +35,11 @@ public final class PostgreSQLDatabaseType implements DatabaseType {
}
@Override
+ public QuoteCharacter getQuoteCharacter() {
+ return QuoteCharacter.QUOTE;
+ }
+
+ @Override
public Collection<String> getJdbcUrlPrefixes() {
return Collections.singleton(String.format("jdbc:%s:", getName().toLowerCase()));
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/SQL92DatabaseType.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/SQL92DatabaseType.java
index 73b4ff9..d9e2910 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/SQL92DatabaseType.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/SQL92DatabaseType.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.infra.database.type.dialect;
import org.apache.shardingsphere.infra.database.metadata.dialect.SQL92DataSourceMetaData;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.QuoteCharacter;
import java.util.Collection;
import java.util.Collections;
@@ -34,6 +35,11 @@ public final class SQL92DatabaseType implements DatabaseType {
}
@Override
+ public QuoteCharacter getQuoteCharacter() {
+ return QuoteCharacter.QUOTE;
+ }
+
+ @Override
public Collection<String> getJdbcUrlPrefixes() {
return Collections.emptyList();
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/SQLServerDatabaseType.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/SQLServerDatabaseType.java
index d95871e..45fbf45 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/SQLServerDatabaseType.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/database/type/dialect/SQLServerDatabaseType.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.infra.database.type.dialect;
import org.apache.shardingsphere.infra.database.metadata.dialect.SQLServerDataSourceMetaData;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.QuoteCharacter;
import java.util.Collection;
import java.util.Collections;
@@ -34,6 +35,11 @@ public final class SQLServerDatabaseType implements DatabaseType {
}
@Override
+ public QuoteCharacter getQuoteCharacter() {
+ return QuoteCharacter.BRACKETS;
+ }
+
+ @Override
public Collection<String> getJdbcUrlPrefixes() {
return Collections.singletonList("jdbc:microsoft:sqlserver:");
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/ColumnMetaDataLoader.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/ColumnMetaDataLoader.java
index 22a1310..e979184 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/ColumnMetaDataLoader.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/ColumnMetaDataLoader.java
@@ -20,10 +20,7 @@ package org.apache.shardingsphere.infra.metadata.schema.builder.loader;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import org.apache.shardingsphere.infra.metadata.schema.builder.loader.dialect.DatabaseMetaDataDialectHandler;
-import org.apache.shardingsphere.infra.metadata.schema.builder.loader.dialect.DatabaseMetaDataDialectHandlerFactory;
import org.apache.shardingsphere.infra.metadata.schema.model.ColumnMetaData;
-import org.apache.shardingsphere.sql.parser.sql.common.constant.QuoteCharacter;
import java.sql.Connection;
import java.sql.ResultSet;
@@ -91,8 +88,7 @@ public final class ColumnMetaDataLoader {
}
private static String generateEmptyResultSQL(final String table, final DatabaseType databaseType) {
- QuoteCharacter quoteCharacter = DatabaseMetaDataDialectHandlerFactory.findHandler(databaseType).map(DatabaseMetaDataDialectHandler::getQuoteCharacter).orElse(QuoteCharacter.NONE);
- return String.format("SELECT * FROM %s WHERE 1 != 1", quoteCharacter.wrap(table));
+ return String.format("SELECT * FROM %s WHERE 1 != 1", databaseType.getQuoteCharacter().wrap(table));
}
private static Collection<String> loadPrimaryKeys(final Connection connection, final String table) throws SQLException {
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/SchemaMetaDataLoader.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/SchemaMetaDataLoader.java
index 95bca17..9558557 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/SchemaMetaDataLoader.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/SchemaMetaDataLoader.java
@@ -28,7 +28,6 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;
import java.util.LinkedList;
-import java.util.List;
/**
* Schema meta data loader.
@@ -57,7 +56,7 @@ public final class SchemaMetaDataLoader {
}
private static Collection<String> loadAllTableNames(final Connection connection) throws SQLException {
- List<String> result = new LinkedList<>();
+ Collection<String> result = new LinkedList<>();
try (ResultSet resultSet = connection.getMetaData().getTables(connection.getCatalog(), connection.getSchema(), null, new String[]{TABLE_TYPE, VIEW_TYPE})) {
while (resultSet.next()) {
String table = resultSet.getString(TABLE_NAME);
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/TableMetaDataLoader.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/TableMetaDataLoader.java
index 5267571..8601c22 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/TableMetaDataLoader.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/TableMetaDataLoader.java
@@ -21,7 +21,6 @@ import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.metadata.schema.builder.loader.adapter.MetaDataLoaderConnectionAdapter;
-import org.apache.shardingsphere.infra.metadata.schema.builder.loader.dialect.DatabaseMetaDataDialectHandlerFactory;
import org.apache.shardingsphere.infra.metadata.schema.model.TableMetaData;
import javax.sql.DataSource;
@@ -47,7 +46,7 @@ public final class TableMetaDataLoader {
*/
public static Optional<TableMetaData> load(final DataSource dataSource, final String tableNamePattern, final DatabaseType databaseType) throws SQLException {
try (MetaDataLoaderConnectionAdapter connectionAdapter = new MetaDataLoaderConnectionAdapter(databaseType, dataSource.getConnection())) {
- String formattedTableNamePattern = formatTableNamePattern(tableNamePattern, databaseType);
+ String formattedTableNamePattern = databaseType.formatTableNamePattern(tableNamePattern);
return isTableExist(connectionAdapter, formattedTableNamePattern)
? Optional.of(new TableMetaData(ColumnMetaDataLoader.load(
connectionAdapter, formattedTableNamePattern, databaseType), IndexMetaDataLoader.load(connectionAdapter, formattedTableNamePattern)))
@@ -55,10 +54,6 @@ public final class TableMetaDataLoader {
}
}
- private static String formatTableNamePattern(final String tableNamePattern, final DatabaseType databaseType) {
- return DatabaseMetaDataDialectHandlerFactory.findHandler(databaseType).map(handler -> handler.formatTableNamePattern(tableNamePattern)).orElse(tableNamePattern);
- }
-
private static boolean isTableExist(final Connection connection, final String tableNamePattern) throws SQLException {
try (ResultSet resultSet = connection.getMetaData().getTables(connection.getCatalog(), connection.getSchema(), tableNamePattern, null)) {
return resultSet.next();
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/adapter/MetaDataLoaderConnectionAdapter.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/adapter/MetaDataLoaderConnectionAdapter.java
index e8c4c2d..2657a60 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/adapter/MetaDataLoaderConnectionAdapter.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/adapter/MetaDataLoaderConnectionAdapter.java
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.infra.metadata.schema.builder.loader.adapter;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import org.apache.shardingsphere.infra.metadata.schema.builder.loader.dialect.DatabaseMetaDataDialectHandlerFactory;
import java.sql.Array;
import java.sql.Blob;
@@ -36,7 +35,6 @@ import java.sql.SQLXML;
import java.sql.Savepoint;
import java.sql.Statement;
import java.sql.Struct;
-
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.Executor;
@@ -68,16 +66,7 @@ public final class MetaDataLoaderConnectionAdapter implements Connection {
@Override
public String getSchema() {
- return DatabaseMetaDataDialectHandlerFactory.findHandler(databaseType).map(handler -> handler.getSchema(connection)).orElse(getSchema(connection));
- }
-
- @SuppressWarnings("ReturnOfNull")
- private String getSchema(final Connection connection) {
- try {
- return connection.getSchema();
- } catch (final SQLException ex) {
- return null;
- }
+ return databaseType.getSchema(connection);
}
@Override
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/DatabaseMetaDataDialectHandler.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/DatabaseMetaDataDialectHandler.java
deleted file mode 100644
index def41c4..0000000
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/DatabaseMetaDataDialectHandler.java
+++ /dev/null
@@ -1,64 +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.metadata.schema.builder.loader.dialect;
-
-import org.apache.shardingsphere.infra.spi.typed.TypedSPI;
-import org.apache.shardingsphere.sql.parser.sql.common.constant.QuoteCharacter;
-
-import java.sql.Connection;
-import java.sql.SQLException;
-
-/**
- * Database meta data dialect handler.
- */
-public interface DatabaseMetaDataDialectHandler extends TypedSPI {
-
- /**
- * Get schema.
- *
- * @param connection connection
- * @return schema
- */
- @SuppressWarnings("ReturnOfNull")
- default String getSchema(final Connection connection) {
- try {
- return connection.getSchema();
- } catch (final SQLException ignored) {
- return null;
- }
- }
-
- /**
- * Format table name pattern.
- *
- * @param tableNamePattern table name pattern
- * @return formatted table name pattern
- */
- default String formatTableNamePattern(final String tableNamePattern) {
- return tableNamePattern;
- }
-
- /**
- * Get quote character.
- *
- * @return quote character
- */
- default QuoteCharacter getQuoteCharacter() {
- return QuoteCharacter.NONE;
- }
-}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/DatabaseMetaDataDialectHandlerFactory.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/DatabaseMetaDataDialectHandlerFactory.java
deleted file mode 100644
index d2d895c..0000000
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/DatabaseMetaDataDialectHandlerFactory.java
+++ /dev/null
@@ -1,53 +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.metadata.schema.builder.loader.dialect;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.spi.exception.ServiceProviderNotFoundException;
-import org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
-
-import java.util.Optional;
-import java.util.Properties;
-
-/**
- * Database meta data dialect handler factory.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class DatabaseMetaDataDialectHandlerFactory {
-
- static {
- ShardingSphereServiceLoader.register(DatabaseMetaDataDialectHandler.class);
- }
-
- /**
- * Find database meta data dialect handler.
- *
- * @param databaseType database type
- * @return database meta data dialect handler
- */
- public static Optional<DatabaseMetaDataDialectHandler> findHandler(final DatabaseType databaseType) {
- try {
- return Optional.of(TypedSPIRegistry.getRegisteredService(DatabaseMetaDataDialectHandler.class, databaseType.getName(), new Properties()));
- } catch (final ServiceProviderNotFoundException ignored) {
- return Optional.empty();
- }
- }
-}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/impl/H2DatabaseMetaDataDialectHandler.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/impl/H2DatabaseMetaDataDialectHandler.java
deleted file mode 100644
index 0f19cc9..0000000
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/impl/H2DatabaseMetaDataDialectHandler.java
+++ /dev/null
@@ -1,37 +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.metadata.schema.builder.loader.dialect.impl;
-
-import org.apache.shardingsphere.infra.metadata.schema.builder.loader.dialect.DatabaseMetaDataDialectHandler;
-import org.apache.shardingsphere.sql.parser.sql.common.constant.QuoteCharacter;
-
-/**
- * Database meta data dialect handler of H2.
- */
-public final class H2DatabaseMetaDataDialectHandler implements DatabaseMetaDataDialectHandler {
-
- @Override
- public QuoteCharacter getQuoteCharacter() {
- return QuoteCharacter.QUOTE;
- }
-
- @Override
- public String getType() {
- return "H2";
- }
-}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/impl/MariaDBDatabaseMetaDataDialectHandler.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/impl/MariaDBDatabaseMetaDataDialectHandler.java
deleted file mode 100644
index 2370f6d..0000000
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/impl/MariaDBDatabaseMetaDataDialectHandler.java
+++ /dev/null
@@ -1,37 +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.metadata.schema.builder.loader.dialect.impl;
-
-import org.apache.shardingsphere.infra.metadata.schema.builder.loader.dialect.DatabaseMetaDataDialectHandler;
-import org.apache.shardingsphere.sql.parser.sql.common.constant.QuoteCharacter;
-
-/**
- * Database meta data dialect handler of MariaDB.
- */
-public final class MariaDBDatabaseMetaDataDialectHandler implements DatabaseMetaDataDialectHandler {
-
- @Override
- public QuoteCharacter getQuoteCharacter() {
- return QuoteCharacter.BACK_QUOTE;
- }
-
- @Override
- public String getType() {
- return "MariaDB";
- }
-}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/impl/MySQLDatabaseMetaDataDialectHandler.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/impl/MySQLDatabaseMetaDataDialectHandler.java
deleted file mode 100644
index 3f5c8c4..0000000
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/impl/MySQLDatabaseMetaDataDialectHandler.java
+++ /dev/null
@@ -1,37 +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.metadata.schema.builder.loader.dialect.impl;
-
-import org.apache.shardingsphere.infra.metadata.schema.builder.loader.dialect.DatabaseMetaDataDialectHandler;
-import org.apache.shardingsphere.sql.parser.sql.common.constant.QuoteCharacter;
-
-/**
- * Database meta data dialect handler of MySQL.
- */
-public final class MySQLDatabaseMetaDataDialectHandler implements DatabaseMetaDataDialectHandler {
-
- @Override
- public QuoteCharacter getQuoteCharacter() {
- return QuoteCharacter.BACK_QUOTE;
- }
-
- @Override
- public String getType() {
- return "MySQL";
- }
-}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/impl/OracleDatabaseMetaDataDialectHandler.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/impl/OracleDatabaseMetaDataDialectHandler.java
deleted file mode 100644
index 430cb17..0000000
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/impl/OracleDatabaseMetaDataDialectHandler.java
+++ /dev/null
@@ -1,56 +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.metadata.schema.builder.loader.dialect.impl;
-
-import org.apache.shardingsphere.infra.metadata.schema.builder.loader.dialect.DatabaseMetaDataDialectHandler;
-import org.apache.shardingsphere.sql.parser.sql.common.constant.QuoteCharacter;
-
-import java.sql.Connection;
-import java.sql.SQLException;
-import java.util.Optional;
-
-/**
- * Database meta data dialect handler of Oracle.
- */
-public final class OracleDatabaseMetaDataDialectHandler implements DatabaseMetaDataDialectHandler {
-
- @SuppressWarnings("ReturnOfNull")
- @Override
- public String getSchema(final Connection connection) {
- try {
- return Optional.ofNullable(connection.getMetaData().getUserName()).map(String::toUpperCase).orElse(null);
- } catch (final SQLException ignored) {
- return null;
- }
- }
-
- @Override
- public String formatTableNamePattern(final String tableNamePattern) {
- return tableNamePattern.toUpperCase();
- }
-
- @Override
- public QuoteCharacter getQuoteCharacter() {
- return QuoteCharacter.QUOTE;
- }
-
- @Override
- public String getType() {
- return "Oracle";
- }
-}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/impl/PostgreSQLDatabaseMetaDataDialectHandler.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/impl/PostgreSQLDatabaseMetaDataDialectHandler.java
deleted file mode 100644
index 732dc15..0000000
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/impl/PostgreSQLDatabaseMetaDataDialectHandler.java
+++ /dev/null
@@ -1,37 +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.metadata.schema.builder.loader.dialect.impl;
-
-import org.apache.shardingsphere.infra.metadata.schema.builder.loader.dialect.DatabaseMetaDataDialectHandler;
-import org.apache.shardingsphere.sql.parser.sql.common.constant.QuoteCharacter;
-
-/**
- * Database meta data dialect handler of PostgreSQL.
- */
-public final class PostgreSQLDatabaseMetaDataDialectHandler implements DatabaseMetaDataDialectHandler {
-
- @Override
- public QuoteCharacter getQuoteCharacter() {
- return QuoteCharacter.QUOTE;
- }
-
- @Override
- public String getType() {
- return "PostgreSQL";
- }
-}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/impl/SQL92DatabaseMetaDataDialectHandler.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/impl/SQL92DatabaseMetaDataDialectHandler.java
deleted file mode 100644
index e39db9f..0000000
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/impl/SQL92DatabaseMetaDataDialectHandler.java
+++ /dev/null
@@ -1,37 +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.metadata.schema.builder.loader.dialect.impl;
-
-import org.apache.shardingsphere.infra.metadata.schema.builder.loader.dialect.DatabaseMetaDataDialectHandler;
-import org.apache.shardingsphere.sql.parser.sql.common.constant.QuoteCharacter;
-
-/**
- * Database meta data dialect handler of SQL92.
- */
-public final class SQL92DatabaseMetaDataDialectHandler implements DatabaseMetaDataDialectHandler {
-
- @Override
- public QuoteCharacter getQuoteCharacter() {
- return QuoteCharacter.QUOTE;
- }
-
- @Override
- public String getType() {
- return "SQL92";
- }
-}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/impl/SQLServerDatabaseMetaDataDialectHandler.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/impl/SQLServerDatabaseMetaDataDialectHandler.java
deleted file mode 100644
index 500b4c5..0000000
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/impl/SQLServerDatabaseMetaDataDialectHandler.java
+++ /dev/null
@@ -1,37 +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.metadata.schema.builder.loader.dialect.impl;
-
-import org.apache.shardingsphere.infra.metadata.schema.builder.loader.dialect.DatabaseMetaDataDialectHandler;
-import org.apache.shardingsphere.sql.parser.sql.common.constant.QuoteCharacter;
-
-/**
- * Database meta data dialect handler of SQLServer.
- */
-public final class SQLServerDatabaseMetaDataDialectHandler implements DatabaseMetaDataDialectHandler {
-
- @Override
- public QuoteCharacter getQuoteCharacter() {
- return QuoteCharacter.BRACKETS;
- }
-
- @Override
- public String getType() {
- return "SQLServer";
- }
-}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.metadata.schema.builder.loader.dialect.DatabaseMetaDataDialectHandler b/shardingsphere-infra/shardingsphere-infra-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.metadata.schema.builder.loader.dialect.DatabaseMetaDataDialectHandler
deleted file mode 100644
index a70fa95..0000000
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.metadata.schema.builder.loader.dialect.DatabaseMetaDataDialectHandler
+++ /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.
-#
-
-org.apache.shardingsphere.infra.metadata.schema.builder.loader.dialect.impl.H2DatabaseMetaDataDialectHandler
-org.apache.shardingsphere.infra.metadata.schema.builder.loader.dialect.impl.MariaDBDatabaseMetaDataDialectHandler
-org.apache.shardingsphere.infra.metadata.schema.builder.loader.dialect.impl.MySQLDatabaseMetaDataDialectHandler
-org.apache.shardingsphere.infra.metadata.schema.builder.loader.dialect.impl.OracleDatabaseMetaDataDialectHandler
-org.apache.shardingsphere.infra.metadata.schema.builder.loader.dialect.impl.PostgreSQLDatabaseMetaDataDialectHandler
-org.apache.shardingsphere.infra.metadata.schema.builder.loader.dialect.impl.SQL92DatabaseMetaDataDialectHandler
-org.apache.shardingsphere.infra.metadata.schema.builder.loader.dialect.impl.SQLServerDatabaseMetaDataDialectHandler
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/H2DatabaseTypeTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/H2DatabaseTypeTest.java
index 6e70f70..f9df900 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/H2DatabaseTypeTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/H2DatabaseTypeTest.java
@@ -18,13 +18,18 @@
package org.apache.shardingsphere.infra.database.type.dialect;
import org.apache.shardingsphere.infra.database.metadata.dialect.H2DataSourceMetaData;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.QuoteCharacter;
import org.junit.Test;
+import java.sql.Connection;
+import java.sql.SQLException;
import java.util.Collections;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
public final class H2DatabaseTypeTest {
@@ -48,4 +53,23 @@ public final class H2DatabaseTypeTest {
public void assertGetTrunkDatabaseType() {
assertThat(new H2DatabaseType().getTrunkDatabaseType().getName(), is("MySQL"));
}
+
+ @Test
+ public void assertGetSchema() throws SQLException {
+ Connection connection = mock(Connection.class);
+ when(connection.getSchema()).thenReturn("ds");
+ assertThat(new H2DatabaseType().getSchema(connection), is("ds"));
+ }
+
+ @Test
+ public void assertFormatTableNamePattern() {
+ assertThat(new H2DatabaseType().formatTableNamePattern("tbl"), is("tbl"));
+ }
+
+ @Test
+ public void assertGetQuoteCharacter() {
+ QuoteCharacter actual = new H2DatabaseType().getQuoteCharacter();
+ assertThat(actual.getStartDelimiter(), is("\""));
+ assertThat(actual.getEndDelimiter(), is("\""));
+ }
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/MariaDBDatabaseTypeTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/MariaDBDatabaseTypeTest.java
index 77ed10c..f74ae2c 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/MariaDBDatabaseTypeTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/MariaDBDatabaseTypeTest.java
@@ -18,13 +18,18 @@
package org.apache.shardingsphere.infra.database.type.dialect;
import org.apache.shardingsphere.infra.database.metadata.dialect.MariaDBDataSourceMetaData;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.QuoteCharacter;
import org.junit.Test;
+import java.sql.Connection;
+import java.sql.SQLException;
import java.util.Collections;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
public final class MariaDBDatabaseTypeTest {
@@ -48,4 +53,23 @@ public final class MariaDBDatabaseTypeTest {
public void assertGetTrunkDatabaseType() {
assertThat(new MariaDBDatabaseType().getTrunkDatabaseType().getName(), is("MySQL"));
}
+
+ @Test
+ public void assertGetSchema() throws SQLException {
+ Connection connection = mock(Connection.class);
+ when(connection.getSchema()).thenReturn("ds");
+ assertThat(new MariaDBDatabaseType().getSchema(connection), is("ds"));
+ }
+
+ @Test
+ public void assertFormatTableNamePattern() {
+ assertThat(new MariaDBDatabaseType().formatTableNamePattern("tbl"), is("tbl"));
+ }
+
+ @Test
+ public void assertGetQuoteCharacter() {
+ QuoteCharacter actual = new MariaDBDatabaseType().getQuoteCharacter();
+ assertThat(actual.getStartDelimiter(), is("`"));
+ assertThat(actual.getEndDelimiter(), is("`"));
+ }
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/MySQLDatabaseTypeTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/MySQLDatabaseTypeTest.java
index c5be68e..06bd6a6 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/MySQLDatabaseTypeTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/MySQLDatabaseTypeTest.java
@@ -18,13 +18,18 @@
package org.apache.shardingsphere.infra.database.type.dialect;
import org.apache.shardingsphere.infra.database.metadata.dialect.MySQLDataSourceMetaData;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.QuoteCharacter;
import org.junit.Test;
+import java.sql.Connection;
+import java.sql.SQLException;
import java.util.Arrays;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
public final class MySQLDatabaseTypeTest {
@@ -42,4 +47,23 @@ public final class MySQLDatabaseTypeTest {
public void assertGetDataSourceMetaData() {
assertThat(new MySQLDatabaseType().getDataSourceMetaData("jdbc:mysql://127.0.0.1/ds", "root"), instanceOf(MySQLDataSourceMetaData.class));
}
+
+ @Test
+ public void assertGetSchema() throws SQLException {
+ Connection connection = mock(Connection.class);
+ when(connection.getSchema()).thenReturn("ds");
+ assertThat(new MySQLDatabaseType().getSchema(connection), is("ds"));
+ }
+
+ @Test
+ public void assertFormatTableNamePattern() {
+ assertThat(new MySQLDatabaseType().formatTableNamePattern("tbl"), is("tbl"));
+ }
+
+ @Test
+ public void assertGetQuoteCharacter() {
+ QuoteCharacter actual = new MySQLDatabaseType().getQuoteCharacter();
+ assertThat(actual.getStartDelimiter(), is("`"));
+ assertThat(actual.getEndDelimiter(), is("`"));
+ }
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/OracleDatabaseTypeTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/OracleDatabaseTypeTest.java
index 0ef5241..7d0248a 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/OracleDatabaseTypeTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/OracleDatabaseTypeTest.java
@@ -18,13 +18,19 @@
package org.apache.shardingsphere.infra.database.type.dialect;
import org.apache.shardingsphere.infra.database.metadata.dialect.OracleDataSourceMetaData;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.QuoteCharacter;
import org.junit.Test;
+import java.sql.Connection;
+import java.sql.SQLException;
import java.util.Collections;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
public final class OracleDatabaseTypeTest {
@@ -42,4 +48,23 @@ public final class OracleDatabaseTypeTest {
public void assertOracleDataSourceMetaData() {
assertThat(new OracleDatabaseType().getDataSourceMetaData("jdbc:oracle:oci:@127.0.0.1/ds_0", "scott"), instanceOf(OracleDataSourceMetaData.class));
}
+
+ @Test
+ public void assertGetSchema() throws SQLException {
+ Connection connection = mock(Connection.class, RETURNS_DEEP_STUBS);
+ when(connection.getMetaData().getUserName()).thenReturn("scott");
+ assertThat(new OracleDatabaseType().getSchema(connection), is("SCOTT"));
+ }
+
+ @Test
+ public void assertFormatTableNamePattern() {
+ assertThat(new OracleDatabaseType().formatTableNamePattern("tbl"), is("TBL"));
+ }
+
+ @Test
+ public void assertGetQuoteCharacter() {
+ QuoteCharacter actual = new OracleDatabaseType().getQuoteCharacter();
+ assertThat(actual.getStartDelimiter(), is("\""));
+ assertThat(actual.getEndDelimiter(), is("\""));
+ }
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/PostgreSQLDatabaseTypeTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/PostgreSQLDatabaseTypeTest.java
index 72d74ed..014b6d6 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/PostgreSQLDatabaseTypeTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/PostgreSQLDatabaseTypeTest.java
@@ -18,13 +18,18 @@
package org.apache.shardingsphere.infra.database.type.dialect;
import org.apache.shardingsphere.infra.database.metadata.dialect.PostgreSQLDataSourceMetaData;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.QuoteCharacter;
import org.junit.Test;
+import java.sql.Connection;
+import java.sql.SQLException;
import java.util.Collections;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
public final class PostgreSQLDatabaseTypeTest {
@@ -42,4 +47,23 @@ public final class PostgreSQLDatabaseTypeTest {
public void assertGetDataSourceMetaData() {
assertThat(new PostgreSQLDatabaseType().getDataSourceMetaData("jdbc:postgresql://localhost:5432/demo_ds_0", "postgres"), instanceOf(PostgreSQLDataSourceMetaData.class));
}
+
+ @Test
+ public void assertGetSchema() throws SQLException {
+ Connection connection = mock(Connection.class);
+ when(connection.getSchema()).thenReturn("ds");
+ assertThat(new PostgreSQLDatabaseType().getSchema(connection), is("ds"));
+ }
+
+ @Test
+ public void assertFormatTableNamePattern() {
+ assertThat(new PostgreSQLDatabaseType().formatTableNamePattern("tbl"), is("tbl"));
+ }
+
+ @Test
+ public void assertGetQuoteCharacter() {
+ QuoteCharacter actual = new PostgreSQLDatabaseType().getQuoteCharacter();
+ assertThat(actual.getStartDelimiter(), is("\""));
+ assertThat(actual.getEndDelimiter(), is("\""));
+ }
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/SQL92DatabaseTypeTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/SQL92DatabaseTypeTest.java
index 6f295a5..18e4c8e 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/SQL92DatabaseTypeTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/SQL92DatabaseTypeTest.java
@@ -18,13 +18,18 @@
package org.apache.shardingsphere.infra.database.type.dialect;
import org.apache.shardingsphere.infra.database.metadata.dialect.SQL92DataSourceMetaData;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.QuoteCharacter;
import org.junit.Test;
+import java.sql.Connection;
+import java.sql.SQLException;
import java.util.Collections;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
public final class SQL92DatabaseTypeTest {
@@ -47,4 +52,23 @@ public final class SQL92DatabaseTypeTest {
assertThat(new SQL92DatabaseType().getDataSourceMetaData("jdbc:oracle:oci:@127.0.0.1/demo_ds_0", "scott"), instanceOf(SQL92DataSourceMetaData.class));
assertThat(new SQL92DatabaseType().getDataSourceMetaData("jdbc:microsoft:sqlserver://127.0.0.1;DatabaseName=ds_0", "sa"), instanceOf(SQL92DataSourceMetaData.class));
}
+
+ @Test
+ public void assertGetSchema() throws SQLException {
+ Connection connection = mock(Connection.class);
+ when(connection.getSchema()).thenReturn("ds");
+ assertThat(new SQL92DatabaseType().getSchema(connection), is("ds"));
+ }
+
+ @Test
+ public void assertFormatTableNamePattern() {
+ assertThat(new SQL92DatabaseType().formatTableNamePattern("tbl"), is("tbl"));
+ }
+
+ @Test
+ public void assertGetQuoteCharacter() {
+ QuoteCharacter actual = new SQL92DatabaseType().getQuoteCharacter();
+ assertThat(actual.getStartDelimiter(), is("\""));
+ assertThat(actual.getEndDelimiter(), is("\""));
+ }
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/SQLServerDatabaseTypeTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/SQLServerDatabaseTypeTest.java
index aeeb0d7..aff5472 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/SQLServerDatabaseTypeTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/SQLServerDatabaseTypeTest.java
@@ -18,13 +18,18 @@
package org.apache.shardingsphere.infra.database.type.dialect;
import org.apache.shardingsphere.infra.database.metadata.dialect.SQLServerDataSourceMetaData;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.QuoteCharacter;
import org.junit.Test;
+import java.sql.Connection;
+import java.sql.SQLException;
import java.util.Collections;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
public final class SQLServerDatabaseTypeTest {
@@ -43,4 +48,23 @@ public final class SQLServerDatabaseTypeTest {
assertThat(new SQLServerDatabaseType().getDataSourceMetaData("jdbc:sqlserver://127.0.0.1;DatabaseName=ds_0", "root"), instanceOf(SQLServerDataSourceMetaData.class));
assertThat(new SQLServerDatabaseType().getDataSourceMetaData("jdbc:microsoft:sqlserver://127.0.0.1;DatabaseName=ds_0", "sa"), instanceOf(SQLServerDataSourceMetaData.class));
}
+
+ @Test
+ public void assertGetSchema() throws SQLException {
+ Connection connection = mock(Connection.class);
+ when(connection.getSchema()).thenReturn("ds");
+ assertThat(new SQLServerDatabaseType().getSchema(connection), is("ds"));
+ }
+
+ @Test
+ public void assertFormatTableNamePattern() {
+ assertThat(new SQLServerDatabaseType().formatTableNamePattern("tbl"), is("tbl"));
+ }
+
+ @Test
+ public void assertGetQuoteCharacter() {
+ QuoteCharacter actual = new SQLServerDatabaseType().getQuoteCharacter();
+ assertThat(actual.getStartDelimiter(), is("["));
+ assertThat(actual.getEndDelimiter(), is("]"));
+ }
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/SchemaBuilderTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/SchemaBuilderTest.java
index 074d8a7..71dbdb2 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/SchemaBuilderTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/SchemaBuilderTest.java
@@ -41,6 +41,7 @@ import java.util.Collections;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -57,7 +58,7 @@ public final class SchemaBuilderTest {
private static final String TABLE_NAME = "TABLE_NAME";
- private final String[] unConfiguredTableNames = {"unconfigured_table1", "unconfigured_table2"};
+ private final String[] singleTableNames = {"single_table1", "single_table2"};
private SchemaBuilderMaterials schemaBuilderMaterials;
@@ -93,28 +94,29 @@ public final class SchemaBuilderTest {
@Test
@SneakyThrows(SQLException.class)
- public void assertBuildOfShardingTablesAndUnConfiguredTables() {
+ public void assertBuildOfShardingTablesAndSingleTables() {
ResultSet resultSet = mock(ResultSet.class, Answers.RETURNS_DEEP_STUBS);
DatabaseMetaData databaseMetaData = mock(DatabaseMetaData.class, Answers.RETURNS_DEEP_STUBS);
- Connection connection = mock(Connection.class, Answers.RETURNS_DEEP_STUBS);
+ Connection connection = mock(Connection.class, RETURNS_DEEP_STUBS);
when(dataSource.getConnection()).thenReturn(connection);
when(connection.getMetaData()).thenReturn(databaseMetaData);
when(connection.getCatalog()).thenReturn(TEST_CATALOG);
when(connection.getSchema()).thenReturn(TEST_SCHEMA);
+ when(databaseType.getSchema(connection)).thenReturn(TEST_SCHEMA);
when(databaseMetaData.getTables(connection.getCatalog(), connection.getSchema(), null, new String[]{TABLE_TYPE, VIEW_TYPE})).thenReturn(resultSet);
when(resultSet.next()).thenReturn(true, true, true, true, true, true, false);
- String[] mockReturnTables = {unConfiguredTableNames[1], "data_node_routed_table1_0", "data_node_routed_table1_1", "data_node_routed_table2_0", "data_node_routed_table2_1"};
- when(resultSet.getString(TABLE_NAME)).thenReturn(unConfiguredTableNames[0], mockReturnTables);
+ String[] mockReturnTables = {singleTableNames[1], "data_node_routed_table1_0", "data_node_routed_table1_1", "data_node_routed_table2_0", "data_node_routed_table2_1"};
+ when(resultSet.getString(TABLE_NAME)).thenReturn(singleTableNames[0], mockReturnTables);
ShardingSphereSchema actual = SchemaBuilder.build(schemaBuilderMaterials);
assertThat(actual.getAllTableNames().size(), is(4));
- assertSchemaOfShardingTablesAndUnConfiguredTables(actual);
+ assertSchemaOfShardingTablesAndSingleTables(actual);
}
- private void assertSchemaOfShardingTablesAndUnConfiguredTables(final ShardingSphereSchema actual) {
+ private void assertSchemaOfShardingTablesAndSingleTables(final ShardingSphereSchema actual) {
assertSchemaOfShardingTables(actual);
- assertTrue(actual.containsTable(unConfiguredTableNames[0]));
- assertThat(actual.get(unConfiguredTableNames[0]).getColumns().size(), is(0));
- assertTrue(actual.containsTable(unConfiguredTableNames[1]));
- assertThat(actual.get(unConfiguredTableNames[1]).getColumns().size(), is(0));
+ assertTrue(actual.containsTable(singleTableNames[0]));
+ assertThat(actual.get(singleTableNames[0]).getColumns().size(), is(0));
+ assertTrue(actual.containsTable(singleTableNames[1]));
+ assertThat(actual.get(singleTableNames[1]).getColumns().size(), is(0));
}
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/ColumnMetaDataLoaderTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/ColumnMetaDataLoaderTest.java
index 0e780bb..d703c6c 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/ColumnMetaDataLoaderTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/ColumnMetaDataLoaderTest.java
@@ -37,6 +37,7 @@ import java.util.Iterator;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -79,7 +80,7 @@ public final class ColumnMetaDataLoaderTest {
@Test
public void assertLoad() throws SQLException {
- Collection<ColumnMetaData> actual = ColumnMetaDataLoader.load(connection, "tbl", mock(DatabaseType.class));
+ Collection<ColumnMetaData> actual = ColumnMetaDataLoader.load(connection, "tbl", mock(DatabaseType.class, RETURNS_DEEP_STUBS));
assertThat(actual.size(), is(2));
Iterator<ColumnMetaData> columnMetaDataIterator = actual.iterator();
assertColumnMetaData(columnMetaDataIterator.next(), "pk_col", Types.INTEGER, "INT", true, true);
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/TableMetaDataLoaderTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/TableMetaDataLoaderTest.java
index 811f4c5..bfaba2f 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/TableMetaDataLoaderTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/TableMetaDataLoaderTest.java
@@ -41,6 +41,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -101,7 +102,9 @@ public final class TableMetaDataLoaderTest {
@Test
public void assertLoadWithExistedTable() throws SQLException {
- Optional<TableMetaData> actual = TableMetaDataLoader.load(dataSource, TEST_TABLE, mock(DatabaseType.class));
+ DatabaseType databaseType = mock(DatabaseType.class, RETURNS_DEEP_STUBS);
+ when(databaseType.formatTableNamePattern(TEST_TABLE)).thenReturn(TEST_TABLE);
+ Optional<TableMetaData> actual = TableMetaDataLoader.load(dataSource, TEST_TABLE, databaseType);
assertTrue(actual.isPresent());
Map<String, ColumnMetaData> columnMetaDataMap = actual.get().getColumns();
assertThat(columnMetaDataMap.size(), is(2));
@@ -122,8 +125,6 @@ public final class TableMetaDataLoaderTest {
@Test
public void assertLoadWithNotExistedTable() throws SQLException {
- when(dataSource.getConnection().getMetaData().getTables(TEST_CATALOG, null, TEST_TABLE, null)).thenReturn(tableNotExistResultSet);
- when(tableNotExistResultSet.next()).thenReturn(false);
assertFalse(TableMetaDataLoader.load(dataSource, TEST_TABLE, mock(DatabaseType.class)).isPresent());
}
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/AbstractDatabaseMetaDataDialectHandlerTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/AbstractDatabaseMetaDataDialectHandlerTest.java
deleted file mode 100644
index 1282978..0000000
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/AbstractDatabaseMetaDataDialectHandlerTest.java
+++ /dev/null
@@ -1,66 +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.metadata.schema.builder.loader.dialect;
-
-import lombok.Getter;
-import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import org.apache.shardingsphere.sql.parser.sql.common.constant.QuoteCharacter;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-
-import java.sql.Connection;
-import java.sql.DatabaseMetaData;
-import java.sql.SQLException;
-
-@Getter
-@RunWith(MockitoJUnitRunner.class)
-public abstract class AbstractDatabaseMetaDataDialectHandlerTest {
-
- protected static final String DATABASE_NAME = "demo_ds";
-
- protected static final String TABLE_NAME_PATTERN = "t_order_0";
-
- protected static final String USER_NAME = "demo_user";
-
- @Mock
- private Connection connection;
-
- @Mock
- private DatabaseMetaData databaseMetaData;
-
- protected QuoteCharacter getQuoteCharacter(final DatabaseType databaseType) {
- return DatabaseMetaDataDialectHandlerFactory.findHandler(databaseType).map(DatabaseMetaDataDialectHandler::getQuoteCharacter).orElse(QuoteCharacter.NONE);
- }
-
- protected String formatTableNamePattern(final DatabaseType databaseType) {
- return DatabaseMetaDataDialectHandlerFactory.findHandler(databaseType).map(handler -> handler.formatTableNamePattern(TABLE_NAME_PATTERN)).orElse(TABLE_NAME_PATTERN);
- }
-
- protected String getSchema(final DatabaseType databaseType) {
- return DatabaseMetaDataDialectHandlerFactory.findHandler(databaseType).map(handler -> handler.getSchema(connection)).orElse(getSchema(connection));
- }
-
- private String getSchema(final Connection connection) {
- try {
- return connection.getSchema();
- } catch (final SQLException ignored) {
- return null;
- }
- }
-}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/DatabaseMetaDataDialectHandlerFactoryTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/DatabaseMetaDataDialectHandlerFactoryTest.java
deleted file mode 100644
index 257975c..0000000
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/DatabaseMetaDataDialectHandlerFactoryTest.java
+++ /dev/null
@@ -1,35 +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.metadata.schema.builder.loader.dialect;
-
-import org.apache.shardingsphere.infra.database.type.DatabaseTypeRegistry;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.junit.MockitoJUnitRunner;
-
-import static org.junit.Assert.assertTrue;
-
-@RunWith(MockitoJUnitRunner.class)
-public final class DatabaseMetaDataDialectHandlerFactoryTest {
-
- @Test
- public void assertFindHandler() {
- assertTrue(DatabaseMetaDataDialectHandlerFactory.findHandler(DatabaseTypeRegistry.getTrunkDatabaseType("Oracle")).isPresent());
- assertTrue(DatabaseMetaDataDialectHandlerFactory.findHandler(DatabaseTypeRegistry.getTrunkDatabaseType("MySQL")).isPresent());
- }
-}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/DatabaseMetaDataDialectHandlerTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/DatabaseMetaDataDialectHandlerTest.java
deleted file mode 100644
index 9a35d77c..0000000
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/DatabaseMetaDataDialectHandlerTest.java
+++ /dev/null
@@ -1,201 +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.metadata.schema.builder.loader.dialect;
-
-import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import org.apache.shardingsphere.infra.database.type.dialect.H2DatabaseType;
-import org.apache.shardingsphere.infra.database.type.dialect.MariaDBDatabaseType;
-import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
-import org.apache.shardingsphere.infra.database.type.dialect.OracleDatabaseType;
-import org.apache.shardingsphere.infra.database.type.dialect.PostgreSQLDatabaseType;
-import org.apache.shardingsphere.infra.database.type.dialect.SQL92DatabaseType;
-import org.apache.shardingsphere.infra.database.type.dialect.SQLServerDatabaseType;
-import org.apache.shardingsphere.sql.parser.sql.common.constant.QuoteCharacter;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-
-import java.sql.Connection;
-import java.sql.DatabaseMetaData;
-import java.sql.SQLException;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.when;
-
-@RunWith(MockitoJUnitRunner.class)
-public final class DatabaseMetaDataDialectHandlerTest {
-
- private static final String USER_NAME = "root";
-
- private static final String TABLE_NAME_PATTERN = "t_order_0";
-
- @Mock
- private Connection connection;
-
- @Mock
- private DatabaseMetaData databaseMetaData;
-
- @Before
- public void setUp() throws SQLException {
- when(connection.getMetaData()).thenReturn(databaseMetaData);
- when(databaseMetaData.getUserName()).thenReturn(USER_NAME);
- when(connection.getSchema()).thenReturn(USER_NAME);
- }
-
- @Test
- public void assertGetMySQLSchema() {
- assertThat(getSchema(new MySQLDatabaseType()), is(USER_NAME));
- }
-
- @Test
- public void assertGetMariaDBSchema() {
- assertThat(getSchema(new MariaDBDatabaseType()), is(USER_NAME));
- }
-
- @Test
- public void assertGetH2Schema() {
- assertThat(getSchema(new H2DatabaseType()), is(USER_NAME));
- }
-
- @Test
- public void assertGetPostgreSQLSchema() {
- assertThat(getSchema(new PostgreSQLDatabaseType()), is(USER_NAME));
- }
-
- @Test
- public void assertSQLServerSchemaSchema() {
- assertThat(getSchema(new SQLServerDatabaseType()), is(USER_NAME));
- }
-
- @Test
- public void assertGetOracleSchema() {
- assertThat(getSchema(new OracleDatabaseType()), is(USER_NAME.toUpperCase()));
- }
-
- @Test
- public void assertGetSQL92Schema() {
- assertThat(getSchema(new SQL92DatabaseType()), is(USER_NAME));
- }
-
- private String getSchema(final DatabaseType databaseType) {
- return DatabaseMetaDataDialectHandlerFactory.findHandler(databaseType).map(handler -> handler.getSchema(connection)).orElse(getSchema(connection));
- }
-
- private String getSchema(final Connection connection) {
- try {
- return connection.getSchema();
- } catch (final SQLException ex) {
- return null;
- }
- }
-
- @Test
- public void assertGetTableNamePatternForMySQL() {
- assertThat(getTableNamePattern(new MySQLDatabaseType()), is(TABLE_NAME_PATTERN));
- }
-
- @Test
- public void assertGetTableNamePatternForMariaDB() {
- assertThat(getTableNamePattern(new MariaDBDatabaseType()), is(TABLE_NAME_PATTERN));
- }
-
- @Test
- public void assertGetTableNamePatternForH2() {
- assertThat(getTableNamePattern(new H2DatabaseType()), is(TABLE_NAME_PATTERN));
- }
-
- @Test
- public void assertGetTableNamePatternForPostgreSQL() {
- assertThat(getTableNamePattern(new PostgreSQLDatabaseType()), is(TABLE_NAME_PATTERN));
- }
-
- @Test
- public void assertGetTableNamePatternForSQLServer() {
- assertThat(getTableNamePattern(new SQLServerDatabaseType()), is(TABLE_NAME_PATTERN));
- }
-
- @Test
- public void assertGetTableNamePatternForOracle() {
- assertThat(getTableNamePattern(new OracleDatabaseType()), is(TABLE_NAME_PATTERN.toUpperCase()));
- }
-
- @Test
- public void assertGetTableNamePatternForSQL92() {
- assertThat(getTableNamePattern(new SQL92DatabaseType()), is(TABLE_NAME_PATTERN));
- }
-
- private String getTableNamePattern(final DatabaseType databaseType) {
- return DatabaseMetaDataDialectHandlerFactory.findHandler(databaseType).map(handler -> handler.formatTableNamePattern(TABLE_NAME_PATTERN)).orElse(TABLE_NAME_PATTERN);
- }
-
- @Test
- public void assertGetQuoteCharacterForMySQL() {
- QuoteCharacter actual = findQuoteCharacter(new MySQLDatabaseType());
- assertThat(actual.getStartDelimiter(), is("`"));
- assertThat(actual.getEndDelimiter(), is("`"));
- }
-
- @Test
- public void assertGetQuoteCharacterForMariaDB() {
- QuoteCharacter actual = findQuoteCharacter(new MariaDBDatabaseType());
- assertThat(actual.getStartDelimiter(), is("`"));
- assertThat(actual.getEndDelimiter(), is("`"));
- }
-
- @Test
- public void assertGetQuoteCharacterForH2() {
- QuoteCharacter actual = findQuoteCharacter(new H2DatabaseType());
- assertThat(actual.getStartDelimiter(), is("\""));
- assertThat(actual.getEndDelimiter(), is("\""));
- }
-
- @Test
- public void assertGetQuoteCharacterForPostgreSQL() {
- QuoteCharacter actual = findQuoteCharacter(new PostgreSQLDatabaseType());
- assertThat(actual.getStartDelimiter(), is("\""));
- assertThat(actual.getEndDelimiter(), is("\""));
- }
-
- @Test
- public void assertGetQuoteCharacterForSQLServer() {
- QuoteCharacter actual = findQuoteCharacter(new SQLServerDatabaseType());
- assertThat(actual.getStartDelimiter(), is("["));
- assertThat(actual.getEndDelimiter(), is("]"));
- }
-
- @Test
- public void assertGetQuoteCharacterOracle() {
- QuoteCharacter actual = findQuoteCharacter(new OracleDatabaseType());
- assertThat(actual.getStartDelimiter(), is("\""));
- assertThat(actual.getEndDelimiter(), is("\""));
- }
-
- @Test
- public void assertGetQuoteCharacterForSQL92() {
- QuoteCharacter actual = findQuoteCharacter(new SQL92DatabaseType());
- assertThat(actual.getStartDelimiter(), is("\""));
- assertThat(actual.getEndDelimiter(), is("\""));
- }
-
- private QuoteCharacter findQuoteCharacter(final DatabaseType databaseType) {
- return DatabaseMetaDataDialectHandlerFactory.findHandler(databaseType).map(DatabaseMetaDataDialectHandler::getQuoteCharacter).orElse(QuoteCharacter.NONE);
- }
-}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/impl/H2DatabaseMetaDataDialectHandlerTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/impl/H2DatabaseMetaDataDialectHandlerTest.java
deleted file mode 100644
index a2fbbd5..0000000
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/impl/H2DatabaseMetaDataDialectHandlerTest.java
+++ /dev/null
@@ -1,52 +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.metadata.schema.builder.loader.dialect.impl;
-
-import org.apache.shardingsphere.infra.database.type.dialect.H2DatabaseType;
-import org.apache.shardingsphere.infra.metadata.schema.builder.loader.dialect.AbstractDatabaseMetaDataDialectHandlerTest;
-import org.apache.shardingsphere.sql.parser.sql.common.constant.QuoteCharacter;
-import org.junit.Test;
-
-import java.sql.SQLException;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.when;
-
-public final class H2DatabaseMetaDataDialectHandlerTest extends AbstractDatabaseMetaDataDialectHandlerTest {
-
- @Test
- public void assertGetSchema() throws SQLException {
- when(getConnection().getSchema()).thenReturn(DATABASE_NAME);
- String h2Schema = getSchema(new H2DatabaseType());
- assertThat(h2Schema, is(DATABASE_NAME));
- }
-
- @Test
- public void assertFormatTableNamePattern() {
- String h2TableNamePattern = formatTableNamePattern(new H2DatabaseType());
- assertThat(h2TableNamePattern, is(TABLE_NAME_PATTERN));
- }
-
- @Test
- public void assertGetQuoteCharacter() {
- QuoteCharacter h2QuoteCharacter = getQuoteCharacter(new H2DatabaseType());
- assertThat(h2QuoteCharacter.getStartDelimiter(), is("\""));
- assertThat(h2QuoteCharacter.getEndDelimiter(), is("\""));
- }
-}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/impl/MariaDBDatabaseMetaDataDialectHandlerTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/impl/MariaDBDatabaseMetaDataDialectHandlerTest.java
deleted file mode 100644
index 08f3f11..0000000
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/impl/MariaDBDatabaseMetaDataDialectHandlerTest.java
+++ /dev/null
@@ -1,52 +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.metadata.schema.builder.loader.dialect.impl;
-
-import org.apache.shardingsphere.infra.database.type.dialect.MariaDBDatabaseType;
-import org.apache.shardingsphere.infra.metadata.schema.builder.loader.dialect.AbstractDatabaseMetaDataDialectHandlerTest;
-import org.apache.shardingsphere.sql.parser.sql.common.constant.QuoteCharacter;
-import org.junit.Test;
-
-import java.sql.SQLException;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.when;
-
-public final class MariaDBDatabaseMetaDataDialectHandlerTest extends AbstractDatabaseMetaDataDialectHandlerTest {
-
- @Test
- public void assertGetSchema() throws SQLException {
- when(getConnection().getSchema()).thenReturn(DATABASE_NAME);
- String mariadbSchema = getSchema(new MariaDBDatabaseType());
- assertThat(mariadbSchema, is(DATABASE_NAME));
- }
-
- @Test
- public void assertFormatTableNamePattern() {
- String mariadbTableNamePattern = formatTableNamePattern(new MariaDBDatabaseType());
- assertThat(mariadbTableNamePattern, is(TABLE_NAME_PATTERN));
- }
-
- @Test
- public void assertGetQuoteCharacter() {
- QuoteCharacter mariadbQuoteCharacter = getQuoteCharacter(new MariaDBDatabaseType());
- assertThat(mariadbQuoteCharacter.getStartDelimiter(), is("`"));
- assertThat(mariadbQuoteCharacter.getEndDelimiter(), is("`"));
- }
-}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/impl/MySQLDatabaseMetaDataDialectHandlerTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/impl/MySQLDatabaseMetaDataDialectHandlerTest.java
deleted file mode 100644
index e21276a..0000000
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/impl/MySQLDatabaseMetaDataDialectHandlerTest.java
+++ /dev/null
@@ -1,52 +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.metadata.schema.builder.loader.dialect.impl;
-
-import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
-import org.apache.shardingsphere.infra.metadata.schema.builder.loader.dialect.AbstractDatabaseMetaDataDialectHandlerTest;
-import org.apache.shardingsphere.sql.parser.sql.common.constant.QuoteCharacter;
-import org.junit.Test;
-
-import java.sql.SQLException;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.when;
-
-public final class MySQLDatabaseMetaDataDialectHandlerTest extends AbstractDatabaseMetaDataDialectHandlerTest {
-
- @Test
- public void assertGetSchema() throws SQLException {
- when(getConnection().getSchema()).thenReturn(DATABASE_NAME);
- String mysqlSchema = getSchema(new MySQLDatabaseType());
- assertThat(mysqlSchema, is(DATABASE_NAME));
- }
-
- @Test
- public void assertFormatTableNamePattern() {
- String mysqlTableNamePattern = formatTableNamePattern(new MySQLDatabaseType());
- assertThat(mysqlTableNamePattern, is(TABLE_NAME_PATTERN));
- }
-
- @Test
- public void assertGetQuoteCharacter() {
- QuoteCharacter mysqlQuoteCharacter = getQuoteCharacter(new MySQLDatabaseType());
- assertThat(mysqlQuoteCharacter.getStartDelimiter(), is("`"));
- assertThat(mysqlQuoteCharacter.getEndDelimiter(), is("`"));
- }
-}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/impl/OracleDatabaseMetaDataDialectHandlerTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/impl/OracleDatabaseMetaDataDialectHandlerTest.java
deleted file mode 100644
index 71f8179..0000000
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/impl/OracleDatabaseMetaDataDialectHandlerTest.java
+++ /dev/null
@@ -1,53 +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.metadata.schema.builder.loader.dialect.impl;
-
-import org.apache.shardingsphere.infra.database.type.dialect.OracleDatabaseType;
-import org.apache.shardingsphere.infra.metadata.schema.builder.loader.dialect.AbstractDatabaseMetaDataDialectHandlerTest;
-import org.apache.shardingsphere.sql.parser.sql.common.constant.QuoteCharacter;
-import org.junit.Test;
-
-import java.sql.SQLException;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.when;
-
-public final class OracleDatabaseMetaDataDialectHandlerTest extends AbstractDatabaseMetaDataDialectHandlerTest {
-
- @Test
- public void assertGetSchema() throws SQLException {
- when(getConnection().getSchema()).thenReturn(USER_NAME);
- when(getConnection().getMetaData()).thenReturn(getDatabaseMetaData());
- String oracleSchema = getSchema(new OracleDatabaseType());
- assertThat(oracleSchema, is(USER_NAME));
- }
-
- @Test
- public void assertFormatTableNamePattern() {
- String oracleTableNamePattern = formatTableNamePattern(new OracleDatabaseType());
- assertThat(oracleTableNamePattern, is(TABLE_NAME_PATTERN.toUpperCase()));
- }
-
- @Test
- public void assertGetQuoteCharacter() {
- QuoteCharacter oracleQuoteCharacter = getQuoteCharacter(new OracleDatabaseType());
- assertThat(oracleQuoteCharacter.getStartDelimiter(), is("\""));
- assertThat(oracleQuoteCharacter.getEndDelimiter(), is("\""));
- }
-}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/impl/PostgreSQLDatabaseMetaDataDialectHandlerTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/impl/PostgreSQLDatabaseMetaDataDialectHandlerTest.java
deleted file mode 100644
index d179237..0000000
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/impl/PostgreSQLDatabaseMetaDataDialectHandlerTest.java
+++ /dev/null
@@ -1,52 +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.metadata.schema.builder.loader.dialect.impl;
-
-import org.apache.shardingsphere.infra.database.type.dialect.PostgreSQLDatabaseType;
-import org.apache.shardingsphere.infra.metadata.schema.builder.loader.dialect.AbstractDatabaseMetaDataDialectHandlerTest;
-import org.apache.shardingsphere.sql.parser.sql.common.constant.QuoteCharacter;
-import org.junit.Test;
-
-import java.sql.SQLException;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.when;
-
-public final class PostgreSQLDatabaseMetaDataDialectHandlerTest extends AbstractDatabaseMetaDataDialectHandlerTest {
-
- @Test
- public void assertGetSchema() throws SQLException {
- when(getConnection().getSchema()).thenReturn(DATABASE_NAME);
- String postgresqlSchema = getSchema(new PostgreSQLDatabaseType());
- assertThat(postgresqlSchema, is(DATABASE_NAME));
- }
-
- @Test
- public void assertFormatTableNamePattern() {
- String postgresqlTableNamePattern = formatTableNamePattern(new PostgreSQLDatabaseType());
- assertThat(postgresqlTableNamePattern, is(TABLE_NAME_PATTERN));
- }
-
- @Test
- public void assertGetQuoteCharacter() {
- QuoteCharacter postgresqlQuoteCharacter = getQuoteCharacter(new PostgreSQLDatabaseType());
- assertThat(postgresqlQuoteCharacter.getStartDelimiter(), is("\""));
- assertThat(postgresqlQuoteCharacter.getEndDelimiter(), is("\""));
- }
-}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/impl/SQL92DatabaseMetaDataDialectHandlerTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/impl/SQL92DatabaseMetaDataDialectHandlerTest.java
deleted file mode 100644
index c86213d..0000000
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/impl/SQL92DatabaseMetaDataDialectHandlerTest.java
+++ /dev/null
@@ -1,52 +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.metadata.schema.builder.loader.dialect.impl;
-
-import org.apache.shardingsphere.infra.database.type.dialect.SQL92DatabaseType;
-import org.apache.shardingsphere.infra.metadata.schema.builder.loader.dialect.AbstractDatabaseMetaDataDialectHandlerTest;
-import org.apache.shardingsphere.sql.parser.sql.common.constant.QuoteCharacter;
-import org.junit.Test;
-
-import java.sql.SQLException;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.when;
-
-public final class SQL92DatabaseMetaDataDialectHandlerTest extends AbstractDatabaseMetaDataDialectHandlerTest {
-
- @Test
- public void assertGetSchema() throws SQLException {
- when(getConnection().getSchema()).thenReturn(DATABASE_NAME);
- String sql92Schema = getSchema(new SQL92DatabaseType());
- assertThat(sql92Schema, is(DATABASE_NAME));
- }
-
- @Test
- public void assertFormatTableNamePattern() {
- String sql92TableNamePattern = formatTableNamePattern(new SQL92DatabaseType());
- assertThat(sql92TableNamePattern, is(TABLE_NAME_PATTERN));
- }
-
- @Test
- public void assertGetQuoteCharacter() {
- QuoteCharacter sql92QuoteCharacter = getQuoteCharacter(new SQL92DatabaseType());
- assertThat(sql92QuoteCharacter.getStartDelimiter(), is("\""));
- assertThat(sql92QuoteCharacter.getEndDelimiter(), is("\""));
- }
-}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/impl/SQLServerDatabaseMetaDataDialectHandlerTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/impl/SQLServerDatabaseMetaDataDialectHandlerTest.java
deleted file mode 100644
index 3befc7f..0000000
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/builder/loader/dialect/impl/SQLServerDatabaseMetaDataDialectHandlerTest.java
+++ /dev/null
@@ -1,60 +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.metadata.schema.builder.loader.dialect.impl;
-
-import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import org.apache.shardingsphere.infra.database.type.dialect.SQLServerDatabaseType;
-import org.apache.shardingsphere.infra.metadata.schema.builder.loader.dialect.AbstractDatabaseMetaDataDialectHandlerTest;
-import org.apache.shardingsphere.sql.parser.sql.common.constant.QuoteCharacter;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.sql.SQLException;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.when;
-
-public final class SQLServerDatabaseMetaDataDialectHandlerTest extends AbstractDatabaseMetaDataDialectHandlerTest {
-
- private DatabaseType sqlServerDatabaseType;
-
- @Before
- public void setUp() {
- sqlServerDatabaseType = new SQLServerDatabaseType();
- }
-
- @Test
- public void assertGetSchema() throws SQLException {
- when(getConnection().getSchema()).thenReturn(DATABASE_NAME);
- String actualSQLServerSchema = getSchema(sqlServerDatabaseType);
- assertThat(actualSQLServerSchema, is(DATABASE_NAME));
- }
-
- @Test
- public void assertFormatTableNamePattern() {
- assertThat(formatTableNamePattern(sqlServerDatabaseType), is(TABLE_NAME_PATTERN));
- }
-
- @Test
- public void assertGetQuoteCharacter() {
- QuoteCharacter actualSQLServerQuoteCharacter = getQuoteCharacter(sqlServerDatabaseType);
- assertThat(actualSQLServerQuoteCharacter.getStartDelimiter(), is("["));
- assertThat(actualSQLServerQuoteCharacter.getEndDelimiter(), is("]"));
- }
-}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/fixture/FixtureDatabaseType.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/fixture/FixtureDatabaseType.java
index 01357da..2ed5583 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/fixture/FixtureDatabaseType.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/fixture/FixtureDatabaseType.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.proxy.frontend.fixture;
import org.apache.shardingsphere.infra.database.metadata.DataSourceMetaData;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.QuoteCharacter;
import java.util.Collection;
import java.util.Collections;
@@ -33,6 +34,11 @@ public final class FixtureDatabaseType implements DatabaseType {
}
@Override
+ public QuoteCharacter getQuoteCharacter() {
+ return QuoteCharacter.NONE;
+ }
+
+ @Override
public Collection<String> getJdbcUrlPrefixes() {
return Collections.singleton("jdbc:fixture");
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/dataset/DataSetEnvironmentManager.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/dataset/DataSetEnvironmentManager.java
index e34307a..73bbb43 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/dataset/DataSetEnvironmentManager.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/dataset/DataSetEnvironmentManager.java
@@ -23,8 +23,6 @@ import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeRegistry;
import org.apache.shardingsphere.infra.datanode.DataNode;
import org.apache.shardingsphere.infra.executor.kernel.thread.ExecutorServiceManager;
-import org.apache.shardingsphere.infra.metadata.schema.builder.loader.dialect.DatabaseMetaDataDialectHandler;
-import org.apache.shardingsphere.infra.metadata.schema.builder.loader.dialect.DatabaseMetaDataDialectHandlerFactory;
import org.apache.shardingsphere.sharding.algorithm.sharding.inline.InlineExpressionParser;
import org.apache.shardingsphere.test.integration.cases.dataset.DataSet;
import org.apache.shardingsphere.test.integration.cases.dataset.metadata.DataSetColumn;
@@ -48,7 +46,6 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-import java.util.Optional;
import java.util.concurrent.Callable;
/**
@@ -69,14 +66,6 @@ public final class DataSetEnvironmentManager {
this.actualDataSources = actualDataSources;
}
- private static String generateTableName(final String tableName, final DatabaseType databaseType) {
- Optional<DatabaseMetaDataDialectHandler> databaseMetaDataDialectHandler = DatabaseMetaDataDialectHandlerFactory.findHandler(databaseType);
- if (databaseMetaDataDialectHandler.isPresent()) {
- return databaseMetaDataDialectHandler.get().getQuoteCharacter().wrap(tableName);
- }
- throw new UnsupportedOperationException(String.format("Cannot support database [%s].", databaseType));
- }
-
/**
* Fill data.
*
@@ -96,7 +85,8 @@ public final class DataSetEnvironmentManager {
}
String insertSQL;
try (Connection connection = actualDataSources.get(dataNode.getDataSourceName()).getConnection()) {
- insertSQL = generateInsertSQL(generateTableName(dataNode.getTableName(), DatabaseTypeRegistry.getDatabaseTypeByURL(connection.getMetaData().getURL())), dataSetMetadata.getColumns());
+ DatabaseType databaseType = DatabaseTypeRegistry.getDatabaseTypeByURL(connection.getMetaData().getURL());
+ insertSQL = generateInsertSQL(databaseType.getQuoteCharacter().wrap(dataNode.getTableName()), dataSetMetadata.getColumns());
}
fillDataTasks.add(new InsertTask(actualDataSources.get(dataNode.getDataSourceName()), insertSQL, sqlValueGroups));
}
@@ -213,8 +203,8 @@ public final class DataSetEnvironmentManager {
public Void call() throws SQLException {
try (Connection connection = dataSource.getConnection()) {
for (String each : tableNames) {
- String tableName = generateTableName(each, DatabaseTypeRegistry.getDatabaseTypeByURL(connection.getMetaData().getURL()));
- try (PreparedStatement preparedStatement = connection.prepareStatement(String.format("DELETE FROM %s", tableName))) {
+ DatabaseType databaseType = DatabaseTypeRegistry.getDatabaseTypeByURL(connection.getMetaData().getURL());
+ try (PreparedStatement preparedStatement = connection.prepareStatement(String.format("DELETE FROM %s", databaseType.getQuoteCharacter().wrap(each)))) {
preparedStatement.execute();
}
}