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 2024/12/04 02:05:45 UTC
(shardingsphere) branch master updated: Decouple DefaultDatabase.LOGIC_NAME and test cases (#33907)
This is an automated email from the ASF dual-hosted git repository.
zhangliang 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 87f2b59c90a Decouple DefaultDatabase.LOGIC_NAME and test cases (#33907)
87f2b59c90a is described below
commit 87f2b59c90aff2665db4b351d50228df6a3f8f00
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Wed Dec 4 10:05:38 2024 +0800
Decouple DefaultDatabase.LOGIC_NAME and test cases (#33907)
* Decouple DefaultDatabase.LOGIC_NAME and test cases
* Decouple DefaultDatabase.LOGIC_NAME and test cases
---
.../core/advice/SQLRouteCountAdviceTest.java | 3 +--
.../EncryptOrderByItemSupportedCheckerTest.java | 3 +--
...EncryptPredicateColumnSupportedCheckerTest.java | 15 +++++------
.../metadata/EncryptMetaDataReviseEngineTest.java | 23 +++++++---------
.../EncryptParameterRewritersRegistryTest.java | 3 +--
.../fixture/EncryptGeneratorFixtureBuilder.java | 23 ++++++++--------
...cryptPredicateRightValueTokenGeneratorTest.java | 9 +++----
.../EncryptProjectionTokenGeneratorTest.java | 11 ++++----
.../EncryptGroupByItemTokenGeneratorTest.java | 7 +++--
.../engine/GeneratedKeyContextEngineTest.java | 17 ++++++------
.../select/pagination/PaginationContextTest.java | 9 +++----
.../engine/ProjectionsContextEngineTest.java | 7 +++--
.../context/segment/table/TablesContextTest.java | 31 +++++++++++-----------
.../statement/SQLStatementContextFactoryTest.java | 22 +++++++--------
.../dal/AnalyzeTableStatementContextTest.java | 3 +--
.../statement/dal/ExplainStatementContextTest.java | 3 +--
.../dal/OptimizeTableStatementContextTest.java | 3 +--
.../dal/ShowColumnsStatementContextTest.java | 12 +++------
.../dal/ShowCreateTableStatementContextTest.java | 7 +++--
.../dal/ShowIndexStatementContextTest.java | 7 +++--
.../dcl/DenyUserStatementContextTest.java | 7 +++--
.../statement/dcl/GrantStatementContextTest.java | 10 +++----
.../statement/dcl/RevokeStatementContextTest.java | 10 +++----
.../infra/database/core/DefaultDatabase.java | 2 +-
24 files changed, 109 insertions(+), 138 deletions(-)
diff --git a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLRouteCountAdviceTest.java b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLRouteCountAdviceTest.java
index f2fa992507e..5dcc5439ebd 100644
--- a/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLRouteCountAdviceTest.java
+++ b/agent/plugins/metrics/core/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/core/advice/SQLRouteCountAdviceTest.java
@@ -24,7 +24,6 @@ import org.apache.shardingsphere.agent.plugin.metrics.core.config.MetricConfigur
import org.apache.shardingsphere.agent.plugin.metrics.core.fixture.TargetAdviceObjectFixture;
import org.apache.shardingsphere.agent.plugin.metrics.core.fixture.collector.MetricsCollectorFixture;
import org.apache.shardingsphere.infra.binder.context.statement.UnknownSQLStatementContext;
-import org.apache.shardingsphere.infra.database.core.DefaultDatabase;
import org.apache.shardingsphere.infra.hint.HintValueContext;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.session.connection.ConnectionContext;
@@ -64,7 +63,7 @@ class SQLRouteCountAdviceTest {
private ConnectionContext mockConnectionContext() {
ConnectionContext result = mock(ConnectionContext.class);
- when(result.getCurrentDatabaseName()).thenReturn(Optional.of(DefaultDatabase.LOGIC_NAME));
+ when(result.getCurrentDatabaseName()).thenReturn(Optional.of("foo_db"));
return result;
}
diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/orderby/EncryptOrderByItemSupportedCheckerTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/orderby/EncryptOrderByItemSupportedCheckerTest.java
index 8fac0725822..9c123497b22 100644
--- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/orderby/EncryptOrderByItemSupportedCheckerTest.java
+++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/orderby/EncryptOrderByItemSupportedCheckerTest.java
@@ -25,7 +25,6 @@ import org.apache.shardingsphere.infra.binder.context.segment.select.orderby.Ord
import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContext;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext;
-import org.apache.shardingsphere.infra.database.core.DefaultDatabase;
import org.apache.shardingsphere.infra.database.core.metadata.database.enums.NullsOrderType;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
@@ -128,7 +127,7 @@ class EncryptOrderByItemSupportedCheckerTest {
when(result.getOrderByContext().getItems()).thenReturn(Collections.singleton(orderByItem));
when(result.getGroupByContext().getItems()).thenReturn(Collections.emptyList());
when(result.getSubqueryContexts().values()).thenReturn(Collections.emptyList());
- when(result.getTablesContext()).thenReturn(new TablesContext(Collections.singleton(simpleTableSegment), databaseType, DefaultDatabase.LOGIC_NAME));
+ when(result.getTablesContext()).thenReturn(new TablesContext(Collections.singleton(simpleTableSegment), databaseType, "foo_db"));
return result;
}
}
diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/predicate/EncryptPredicateColumnSupportedCheckerTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/predicate/EncryptPredicateColumnSupportedCheckerTest.java
index 0504b9a939d..e5387f75731 100644
--- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/predicate/EncryptPredicateColumnSupportedCheckerTest.java
+++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/predicate/EncryptPredicateColumnSupportedCheckerTest.java
@@ -21,7 +21,6 @@ import org.apache.shardingsphere.encrypt.exception.metadata.MissingMatchedEncryp
import org.apache.shardingsphere.encrypt.rewrite.token.generator.fixture.EncryptGeneratorFixtureBuilder;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext;
-import org.apache.shardingsphere.infra.database.core.DefaultDatabase;
import org.apache.shardingsphere.infra.exception.generic.UnsupportedSQLOperationException;
import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.BinaryOperationExpression;
@@ -67,11 +66,9 @@ class EncryptPredicateColumnSupportedCheckerTest {
private SQLStatementContext mockSelectStatementContextWithDifferentEncryptorsInJoinCondition() {
ColumnSegment leftColumn = new ColumnSegment(0, 0, new IdentifierValue("user_name"));
- leftColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(
- new IdentifierValue(DefaultDatabase.LOGIC_NAME), new IdentifierValue(DefaultDatabase.LOGIC_NAME), new IdentifierValue("t_user"), new IdentifierValue("user_name")));
+ leftColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"), new IdentifierValue("t_user"), new IdentifierValue("user_name")));
ColumnSegment rightColumn = new ColumnSegment(0, 0, new IdentifierValue("user_id"));
- rightColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(
- new IdentifierValue(DefaultDatabase.LOGIC_NAME), new IdentifierValue(DefaultDatabase.LOGIC_NAME), new IdentifierValue("t_user"), new IdentifierValue("user_id")));
+ rightColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"), new IdentifierValue("t_user"), new IdentifierValue("user_id")));
SelectStatementContext result = mock(SelectStatementContext.class);
when(result.getJoinConditions()).thenReturn(Collections.singleton(new BinaryOperationExpression(0, 0, leftColumn, rightColumn, "=", "")));
return result;
@@ -85,8 +82,8 @@ class EncryptPredicateColumnSupportedCheckerTest {
private SQLStatementContext mockSelectStatementContextWithLike() {
ColumnSegment columnSegment = new ColumnSegment(0, 0, new IdentifierValue("user_name"));
- columnSegment.setColumnBoundInfo(new ColumnSegmentBoundInfo(
- new IdentifierValue(DefaultDatabase.LOGIC_NAME), new IdentifierValue(DefaultDatabase.LOGIC_NAME), new IdentifierValue("t_user"), new IdentifierValue("user_name")));
+ columnSegment.setColumnBoundInfo(
+ new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"), new IdentifierValue("t_user"), new IdentifierValue("user_name")));
SelectStatementContext result = mock(SelectStatementContext.class, RETURNS_DEEP_STUBS);
when(result.getTablesContext().findTableNames(Collections.singleton(columnSegment), null)).thenReturn(Collections.singletonMap("user_name", "t_user"));
when(result.getColumnSegments()).thenReturn(Collections.singleton(columnSegment));
@@ -103,8 +100,8 @@ class EncryptPredicateColumnSupportedCheckerTest {
private SQLStatementContext mockSelectStatementContextWithEqual() {
ColumnSegment columnSegment = new ColumnSegment(0, 0, new IdentifierValue("user_name"));
- columnSegment.setColumnBoundInfo(new ColumnSegmentBoundInfo(
- new IdentifierValue(DefaultDatabase.LOGIC_NAME), new IdentifierValue(DefaultDatabase.LOGIC_NAME), new IdentifierValue("t_user"), new IdentifierValue("user_name")));
+ columnSegment.setColumnBoundInfo(
+ new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"), new IdentifierValue("t_user"), new IdentifierValue("user_name")));
SelectStatementContext result = mock(SelectStatementContext.class, RETURNS_DEEP_STUBS);
when(result.getTablesContext().findTableNames(Collections.singleton(columnSegment), null)).thenReturn(Collections.singletonMap("user_name", "t_user"));
when(result.getColumnSegments()).thenReturn(Collections.singleton(columnSegment));
diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/metadata/EncryptMetaDataReviseEngineTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/metadata/EncryptMetaDataReviseEngineTest.java
index 0e625eb5e83..527a8a70995 100644
--- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/metadata/EncryptMetaDataReviseEngineTest.java
+++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/metadata/EncryptMetaDataReviseEngineTest.java
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.encrypt.metadata;
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import org.apache.shardingsphere.encrypt.rule.table.EncryptTable;
-import org.apache.shardingsphere.infra.database.core.DefaultDatabase;
import org.apache.shardingsphere.infra.database.core.metadata.data.model.ColumnMetaData;
import org.apache.shardingsphere.infra.database.core.metadata.data.model.SchemaMetaData;
import org.apache.shardingsphere.infra.database.core.metadata.data.model.TableMetaData;
@@ -28,10 +27,11 @@ import org.apache.shardingsphere.infra.metadata.database.schema.reviser.MetaData
import org.junit.jupiter.api.Test;
import java.sql.Types;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
-import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -43,24 +43,21 @@ import static org.mockito.Mockito.when;
class EncryptMetaDataReviseEngineTest {
- private static final String TABLE_NAME = "t_encrypt";
-
@Test
void assertRevise() {
- Map<String, SchemaMetaData> schemaMetaData = Collections.singletonMap(
- DefaultDatabase.LOGIC_NAME, new SchemaMetaData(DefaultDatabase.LOGIC_NAME, Collections.singleton(createTableMetaData())));
- TableMetaData actual = new MetaDataReviseEngine(Collections.singleton(mockEncryptRule())).revise(
- schemaMetaData, mock(GenericSchemaBuilderMaterial.class)).get(DefaultDatabase.LOGIC_NAME).getTables().iterator().next();
+ Map<String, SchemaMetaData> schemaMetaData = Collections.singletonMap("foo_db", new SchemaMetaData("foo_db", Collections.singleton(createTableMetaData())));
+ TableMetaData actual = new MetaDataReviseEngine(
+ Collections.singleton(mockEncryptRule())).revise(schemaMetaData, mock(GenericSchemaBuilderMaterial.class)).get("foo_db").getTables().iterator().next();
assertThat(actual.getColumns().size(), is(2));
- Iterator<ColumnMetaData> columns = actual.getColumns().iterator();
- assertThat(columns.next().getName(), is("id"));
- assertThat(columns.next().getName(), is("pwd"));
+ List<ColumnMetaData> columns = new ArrayList<>(actual.getColumns());
+ assertThat(columns.get(0).getName(), is("id"));
+ assertThat(columns.get(1).getName(), is("pwd"));
}
private EncryptRule mockEncryptRule() {
EncryptRule result = mock(EncryptRule.class, RETURNS_DEEP_STUBS);
EncryptTable encryptTable = mock(EncryptTable.class);
- when(result.findEncryptTable(TABLE_NAME)).thenReturn(Optional.of(encryptTable));
+ when(result.findEncryptTable("foo_tbl")).thenReturn(Optional.of(encryptTable));
when(encryptTable.isCipherColumn("pwd_cipher")).thenReturn(true);
when(encryptTable.isLikeQueryColumn("pwd_like")).thenReturn(true);
when(encryptTable.getLogicColumnByCipherColumn("pwd_cipher")).thenReturn("pwd");
@@ -71,6 +68,6 @@ class EncryptMetaDataReviseEngineTest {
Collection<ColumnMetaData> columns = Arrays.asList(new ColumnMetaData("id", Types.INTEGER, true, true, true, true, false, false),
new ColumnMetaData("pwd_cipher", Types.VARCHAR, false, false, true, true, false, false),
new ColumnMetaData("pwd_like", Types.VARCHAR, false, false, true, true, false, false));
- return new TableMetaData(TABLE_NAME, columns, Collections.emptyList(), Collections.emptyList());
+ return new TableMetaData("foo_tbl", columns, Collections.emptyList(), Collections.emptyList());
}
}
diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/parameter/EncryptParameterRewritersRegistryTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/parameter/EncryptParameterRewritersRegistryTest.java
index 3fd62697982..37bde3327b6 100644
--- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/parameter/EncryptParameterRewritersRegistryTest.java
+++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/parameter/EncryptParameterRewritersRegistryTest.java
@@ -23,7 +23,6 @@ import org.apache.shardingsphere.encrypt.rewrite.parameter.rewriter.EncryptInser
import org.apache.shardingsphere.encrypt.rewrite.parameter.rewriter.EncryptInsertValueParameterRewriter;
import org.apache.shardingsphere.encrypt.rewrite.parameter.rewriter.EncryptPredicateParameterRewriter;
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
-import org.apache.shardingsphere.infra.database.core.DefaultDatabase;
import org.apache.shardingsphere.infra.rewrite.parameter.rewriter.ParameterRewriter;
import org.junit.jupiter.api.Test;
@@ -40,7 +39,7 @@ class EncryptParameterRewritersRegistryTest {
@Test
void assertGetParameterRewriters() {
- List<ParameterRewriter> actual = new ArrayList<>(new EncryptParameterRewritersRegistry(mock(EncryptRule.class), DefaultDatabase.LOGIC_NAME, Collections.emptyList()).getParameterRewriters());
+ List<ParameterRewriter> actual = new ArrayList<>(new EncryptParameterRewritersRegistry(mock(EncryptRule.class), "foo_db", Collections.emptyList()).getParameterRewriters());
assertThat(actual.size(), is(5));
assertThat(actual.get(0), instanceOf(EncryptAssignmentParameterRewriter.class));
assertThat(actual.get(1), instanceOf(EncryptPredicateParameterRewriter.class));
diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/fixture/EncryptGeneratorFixtureBuilder.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/fixture/EncryptGeneratorFixtureBuilder.java
index 43a4e689780..7b2d575a218 100644
--- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/fixture/EncryptGeneratorFixtureBuilder.java
+++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/fixture/EncryptGeneratorFixtureBuilder.java
@@ -29,7 +29,6 @@ import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfigurat
import org.apache.shardingsphere.infra.binder.context.statement.dml.InsertStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.dml.UpdateStatementContext;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
-import org.apache.shardingsphere.infra.database.core.DefaultDatabase;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData;
@@ -107,12 +106,12 @@ public final class EncryptGeneratorFixtureBuilder {
*/
public static InsertStatementContext createInsertStatementContext(final List<Object> params) {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
- when(database.getName()).thenReturn(DefaultDatabase.LOGIC_NAME);
+ when(database.getName()).thenReturn("foo_db");
ShardingSphereSchema schema = mock(ShardingSphereSchema.class);
- when(schema.getAllColumnNames("tbl")).thenReturn(Arrays.asList("id", "name", "status", "pwd"));
- when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(schema);
+ when(schema.getAllColumnNames("foo_tbl")).thenReturn(Arrays.asList("id", "name", "status", "pwd"));
+ when(database.getSchema("foo_db")).thenReturn(schema);
ShardingSphereMetaData metaData = new ShardingSphereMetaData(Collections.singleton(database), mock(ResourceMetaData.class), mock(RuleMetaData.class), mock(ConfigurationProperties.class));
- return new InsertStatementContext(metaData, params, createInsertStatement(), DefaultDatabase.LOGIC_NAME);
+ return new InsertStatementContext(metaData, params, createInsertStatement(), "foo_db");
}
private static InsertStatement createInsertStatement() {
@@ -130,10 +129,10 @@ public final class EncryptGeneratorFixtureBuilder {
InsertStatement result = new MySQLInsertStatement();
result.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_user"))));
ColumnSegment userIdColumn = new ColumnSegment(0, 0, new IdentifierValue("user_id"));
- userIdColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new IdentifierValue(DefaultDatabase.LOGIC_NAME), new IdentifierValue(DefaultDatabase.LOGIC_NAME), new IdentifierValue("t_user"),
+ userIdColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_db"), new IdentifierValue("t_user"),
new IdentifierValue("user_id")));
ColumnSegment userNameColumn = new ColumnSegment(0, 0, new IdentifierValue("user_name"));
- userNameColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new IdentifierValue(DefaultDatabase.LOGIC_NAME), new IdentifierValue(DefaultDatabase.LOGIC_NAME),
+ userNameColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_db"),
new IdentifierValue("t_user"), new IdentifierValue("user_name")));
List<ColumnSegment> insertColumns = Arrays.asList(userIdColumn, userNameColumn);
if (containsInsertColumns) {
@@ -147,7 +146,7 @@ public final class EncryptGeneratorFixtureBuilder {
ProjectionsSegment projections = new ProjectionsSegment(0, 0);
projections.getProjections().add(new ColumnProjectionSegment(userIdColumn));
ColumnSegment statusColumn = new ColumnSegment(0, 0, new IdentifierValue("status"));
- statusColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new IdentifierValue(DefaultDatabase.LOGIC_NAME), new IdentifierValue(DefaultDatabase.LOGIC_NAME), new IdentifierValue("t_user"),
+ statusColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_db"), new IdentifierValue("t_user"),
new IdentifierValue("status")));
projections.getProjections().add(new ColumnProjectionSegment(statusColumn));
selectStatement.setProjections(projections);
@@ -165,7 +164,7 @@ public final class EncryptGeneratorFixtureBuilder {
updateStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_user"))));
updateStatement.setWhere(createWhereSegment());
updateStatement.setSetAssignment(createSetAssignmentSegment());
- return new UpdateStatementContext(updateStatement, DefaultDatabase.LOGIC_NAME);
+ return new UpdateStatementContext(updateStatement, "foo_db");
}
private static WhereSegment createWhereSegment() {
@@ -210,11 +209,11 @@ public final class EncryptGeneratorFixtureBuilder {
*/
public static InsertStatementContext createInsertSelectStatementContext(final List<Object> params, final boolean containsInsertColumns) {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
- when(database.getName()).thenReturn(DefaultDatabase.LOGIC_NAME);
+ when(database.getName()).thenReturn("foo_db");
ShardingSphereSchema schema = mock(ShardingSphereSchema.class);
when(schema.getAllColumnNames("t_user")).thenReturn(Arrays.asList("user_id", "user_name", "pwd"));
- when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(schema);
+ when(database.getSchema("foo_db")).thenReturn(schema);
ShardingSphereMetaData metaData = new ShardingSphereMetaData(Collections.singleton(database), mock(ResourceMetaData.class), mock(RuleMetaData.class), mock(ConfigurationProperties.class));
- return new InsertStatementContext(metaData, params, createInsertSelectStatement(containsInsertColumns), DefaultDatabase.LOGIC_NAME);
+ return new InsertStatementContext(metaData, params, createInsertSelectStatement(containsInsertColumns), "foo_db");
}
}
diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/predicate/EncryptPredicateRightValueTokenGeneratorTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/predicate/EncryptPredicateRightValueTokenGeneratorTest.java
index 9c076acf788..3e9e3d648bc 100644
--- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/predicate/EncryptPredicateRightValueTokenGeneratorTest.java
+++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/predicate/EncryptPredicateRightValueTokenGeneratorTest.java
@@ -21,7 +21,6 @@ import org.apache.shardingsphere.encrypt.rewrite.condition.EncryptCondition;
import org.apache.shardingsphere.encrypt.rewrite.condition.EncryptConditionEngine;
import org.apache.shardingsphere.encrypt.rewrite.token.generator.fixture.EncryptGeneratorFixtureBuilder;
import org.apache.shardingsphere.infra.binder.context.statement.dml.UpdateStatementContext;
-import org.apache.shardingsphere.infra.database.core.DefaultDatabase;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
import org.apache.shardingsphere.infra.rewrite.sql.token.common.pojo.SQLToken;
@@ -48,7 +47,7 @@ class EncryptPredicateRightValueTokenGeneratorTest {
@Test
void assertIsGenerateSQLToken() {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class);
- when(database.getName()).thenReturn(DefaultDatabase.LOGIC_NAME);
+ when(database.getName()).thenReturn("foo_db");
generator.setDatabase(database);
assertTrue(generator.isGenerateSQLToken(EncryptGeneratorFixtureBuilder.createUpdateStatementContext()));
}
@@ -57,7 +56,7 @@ class EncryptPredicateRightValueTokenGeneratorTest {
void assertGenerateSQLTokenFromGenerateNewSQLToken() {
UpdateStatementContext updateStatementContext = EncryptGeneratorFixtureBuilder.createUpdateStatementContext();
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class);
- when(database.getName()).thenReturn(DefaultDatabase.LOGIC_NAME);
+ when(database.getName()).thenReturn("foo_db");
generator.setDatabase(database);
generator.setEncryptConditions(getEncryptConditions(updateStatementContext));
Collection<SQLToken> sqlTokens = generator.generateSQLTokens(updateStatementContext);
@@ -67,8 +66,8 @@ class EncryptPredicateRightValueTokenGeneratorTest {
private Collection<EncryptCondition> getEncryptConditions(final UpdateStatementContext updateStatementContext) {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class);
- when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class));
+ when(database.getSchema("foo_db")).thenReturn(mock(ShardingSphereSchema.class));
return new EncryptConditionEngine(EncryptGeneratorFixtureBuilder.createEncryptRule(), database)
- .createEncryptConditions(updateStatementContext.getWhereSegments(), updateStatementContext.getColumnSegments(), updateStatementContext, DefaultDatabase.LOGIC_NAME);
+ .createEncryptConditions(updateStatementContext.getWhereSegments(), updateStatementContext.getColumnSegments(), updateStatementContext, "foo_db");
}
}
diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/projection/EncryptProjectionTokenGeneratorTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/projection/EncryptProjectionTokenGeneratorTest.java
index ec1e3619ed1..18b3e0c84ff 100644
--- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/projection/EncryptProjectionTokenGeneratorTest.java
+++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/projection/EncryptProjectionTokenGeneratorTest.java
@@ -23,7 +23,6 @@ import org.apache.shardingsphere.encrypt.rule.table.EncryptTable;
import org.apache.shardingsphere.infra.binder.context.segment.select.projection.impl.ColumnProjection;
import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContext;
import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext;
-import org.apache.shardingsphere.infra.database.core.DefaultDatabase;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.rewrite.sql.token.common.pojo.SQLToken;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
@@ -81,7 +80,7 @@ class EncryptProjectionTokenGeneratorTest {
SimpleTableSegment doctorTable = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("doctor")));
doctorTable.setAlias(new AliasSegment(0, 0, new IdentifierValue("a")));
ColumnSegment column = new ColumnSegment(0, 0, new IdentifierValue("mobile"));
- column.setColumnBoundInfo(new ColumnSegmentBoundInfo(new IdentifierValue(DefaultDatabase.LOGIC_NAME), new IdentifierValue(DefaultDatabase.LOGIC_NAME), new IdentifierValue("doctor"),
+ column.setColumnBoundInfo(new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_db"), new IdentifierValue("doctor"),
new IdentifierValue("mobile")));
column.setOwner(new OwnerSegment(0, 0, new IdentifierValue("a")));
ProjectionsSegment projections = mock(ProjectionsSegment.class);
@@ -92,7 +91,7 @@ class EncryptProjectionTokenGeneratorTest {
when(sqlStatementContext.getSqlStatement().getProjections()).thenReturn(projections);
when(sqlStatementContext.getSubqueryContexts().values()).thenReturn(Collections.emptyList());
SimpleTableSegment doctorOneTable = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("doctor1")));
- when(sqlStatementContext.getTablesContext()).thenReturn(new TablesContext(Arrays.asList(doctorTable, doctorOneTable), databaseType, DefaultDatabase.LOGIC_NAME));
+ when(sqlStatementContext.getTablesContext()).thenReturn(new TablesContext(Arrays.asList(doctorTable, doctorOneTable), databaseType, "foo_db"));
when(sqlStatementContext.getProjectionsContext().getProjections()).thenReturn(Collections.singleton(new ColumnProjection("a", "mobile", null, databaseType)));
Collection<SQLToken> actual = generator.generateSQLTokens(sqlStatementContext);
assertThat(actual.size(), is(1));
@@ -103,7 +102,7 @@ class EncryptProjectionTokenGeneratorTest {
SimpleTableSegment doctorTable = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("doctor")));
doctorTable.setAlias(new AliasSegment(0, 0, new IdentifierValue("a")));
ColumnSegment column = new ColumnSegment(0, 0, new IdentifierValue("mobile"));
- column.setColumnBoundInfo(new ColumnSegmentBoundInfo(new IdentifierValue(DefaultDatabase.LOGIC_NAME), new IdentifierValue(DefaultDatabase.LOGIC_NAME), new IdentifierValue("doctor"),
+ column.setColumnBoundInfo(new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_db"), new IdentifierValue("doctor"),
new IdentifierValue("mobile")));
column.setOwner(new OwnerSegment(0, 0, new IdentifierValue("a")));
ProjectionsSegment projections = mock(ProjectionsSegment.class);
@@ -114,7 +113,7 @@ class EncryptProjectionTokenGeneratorTest {
when(sqlStatementContext.getSqlStatement().getProjections()).thenReturn(projections);
when(sqlStatementContext.getSubqueryContexts().values()).thenReturn(Collections.emptyList());
SimpleTableSegment sameDoctorTable = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("doctor")));
- when(sqlStatementContext.getTablesContext()).thenReturn(new TablesContext(Arrays.asList(doctorTable, sameDoctorTable), databaseType, DefaultDatabase.LOGIC_NAME));
+ when(sqlStatementContext.getTablesContext()).thenReturn(new TablesContext(Arrays.asList(doctorTable, sameDoctorTable), databaseType, "foo_db"));
when(sqlStatementContext.getProjectionsContext().getProjections()).thenReturn(Collections.singleton(new ColumnProjection("a", "mobile", null, databaseType)));
Collection<SQLToken> actual = generator.generateSQLTokens(sqlStatementContext);
assertThat(actual.size(), is(1));
@@ -133,7 +132,7 @@ class EncryptProjectionTokenGeneratorTest {
when(sqlStatementContext.getSubqueryContexts().values()).thenReturn(Collections.emptyList());
SimpleTableSegment doctorTable = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("doctor")));
SimpleTableSegment doctorOneTable = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("doctor1")));
- when(sqlStatementContext.getTablesContext()).thenReturn(new TablesContext(Arrays.asList(doctorTable, doctorOneTable), databaseType, DefaultDatabase.LOGIC_NAME));
+ when(sqlStatementContext.getTablesContext()).thenReturn(new TablesContext(Arrays.asList(doctorTable, doctorOneTable), databaseType, "foo_db"));
when(sqlStatementContext.getProjectionsContext().getProjections()).thenReturn(Collections.singleton(new ColumnProjection("doctor", "mobile", null, databaseType)));
Collection<SQLToken> actual = generator.generateSQLTokens(sqlStatementContext);
assertThat(actual.size(), is(1));
diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/select/EncryptGroupByItemTokenGeneratorTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/select/EncryptGroupByItemTokenGeneratorTest.java
index fa76a3f31cb..c503669a7be 100644
--- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/select/EncryptGroupByItemTokenGeneratorTest.java
+++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/select/EncryptGroupByItemTokenGeneratorTest.java
@@ -23,7 +23,6 @@ import org.apache.shardingsphere.encrypt.rule.table.EncryptTable;
import org.apache.shardingsphere.infra.binder.context.segment.select.orderby.OrderByItem;
import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContext;
import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext;
-import org.apache.shardingsphere.infra.database.core.DefaultDatabase;
import org.apache.shardingsphere.infra.database.core.metadata.database.enums.NullsOrderType;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
@@ -50,10 +49,10 @@ import static org.mockito.Mockito.when;
class EncryptGroupByItemTokenGeneratorTest {
- private EncryptGroupByItemTokenGenerator generator;
-
private final DatabaseType databaseType = TypedSPILoader.getService(DatabaseType.class, "FIXTURE");
+ private EncryptGroupByItemTokenGenerator generator;
+
@BeforeEach
void setup() {
generator = new EncryptGroupByItemTokenGenerator(mockEncryptRule());
@@ -87,7 +86,7 @@ class EncryptGroupByItemTokenGeneratorTest {
OrderByItem orderByItem = new OrderByItem(columnOrderByItemSegment);
when(result.getGroupByContext().getItems()).thenReturn(Collections.singleton(orderByItem));
when(result.getSubqueryContexts().values()).thenReturn(Collections.emptyList());
- when(result.getTablesContext()).thenReturn(new TablesContext(Collections.singleton(simpleTableSegment), databaseType, DefaultDatabase.LOGIC_NAME));
+ when(result.getTablesContext()).thenReturn(new TablesContext(Collections.singleton(simpleTableSegment), databaseType, "foo_db"));
return result;
}
}
diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/insert/keygen/engine/GeneratedKeyContextEngineTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/insert/keygen/engine/GeneratedKeyContextEngineTest.java
index 4ecee6d7705..27a6a73a3c1 100644
--- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/insert/keygen/engine/GeneratedKeyContextEngineTest.java
+++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/insert/keygen/engine/GeneratedKeyContextEngineTest.java
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.infra.binder.context.segment.insert.keygen.eng
import com.cedarsoftware.util.CaseInsensitiveMap;
import org.apache.shardingsphere.infra.binder.context.segment.insert.keygen.GeneratedKeyContext;
import org.apache.shardingsphere.infra.binder.context.segment.insert.values.InsertValueContext;
-import org.apache.shardingsphere.infra.database.core.DefaultDatabase;
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn;
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable;
@@ -62,11 +61,11 @@ class GeneratedKeyContextEngineTest {
@BeforeEach
void setUp() {
- ShardingSphereTable table = new ShardingSphereTable(
- "tbl", Collections.singletonList(new ShardingSphereColumn("id", Types.INTEGER, true, true, false, true, false, false)), Collections.emptyList(), Collections.emptyList());
- ShardingSphereTable table2 = new ShardingSphereTable(
- "tbl2", Collections.singletonList(new ShardingSphereColumn("ID", Types.INTEGER, true, true, false, true, false, false)), Collections.emptyList(), Collections.emptyList());
- schema = new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME, Arrays.asList(table, table2), Collections.emptyList());
+ ShardingSphereTable fooTable = new ShardingSphereTable(
+ "foo_tbl", Collections.singletonList(new ShardingSphereColumn("id", Types.INTEGER, true, true, false, true, false, false)), Collections.emptyList(), Collections.emptyList());
+ ShardingSphereTable barTable = new ShardingSphereTable(
+ "bar_tbl", Collections.singletonList(new ShardingSphereColumn("ID", Types.INTEGER, true, true, false, true, false, false)), Collections.emptyList(), Collections.emptyList());
+ schema = new ShardingSphereSchema("foo_db", Arrays.asList(fooTable, barTable), Collections.emptyList());
}
@Test
@@ -108,7 +107,7 @@ class GeneratedKeyContextEngineTest {
@Test
void assertCreateGenerateKeyContextWhenCreateWithGenerateUpperCaseKeyColumnConfigurationForMySQL2() {
- assertCreateGenerateKeyContextWhenCreateWithGenerateKeyColumnConfiguration(new MySQLInsertStatement(), "tbl2");
+ assertCreateGenerateKeyContextWhenCreateWithGenerateKeyColumnConfiguration(new MySQLInsertStatement(), "bar_tbl");
}
@Test
@@ -132,7 +131,7 @@ class GeneratedKeyContextEngineTest {
}
private void assertCreateGenerateKeyContextWhenCreateWithGenerateKeyColumnConfiguration(final InsertStatement insertStatement) {
- assertCreateGenerateKeyContextWhenCreateWithGenerateKeyColumnConfiguration(insertStatement, "tbl");
+ assertCreateGenerateKeyContextWhenCreateWithGenerateKeyColumnConfiguration(insertStatement, "foo_tbl");
}
private void assertCreateGenerateKeyContextWhenCreateWithGenerateKeyColumnConfiguration(final InsertStatement insertStatement, final String tableName) {
@@ -173,7 +172,7 @@ class GeneratedKeyContextEngineTest {
}
private void assertCreateGenerateKeyContextWhenFind(final InsertStatement insertStatement) {
- insertStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl"))));
+ insertStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("foo_tbl"))));
insertStatement.setInsertColumns(new InsertColumnsSegment(0, 0, Collections.singletonList(new ColumnSegment(0, 0, new IdentifierValue("id")))));
insertStatement.getValues().add(new InsertValuesSegment(0, 0, Collections.singletonList(new ParameterMarkerExpressionSegment(1, 2, 0))));
insertStatement.getValues().add(new InsertValuesSegment(0, 0, Collections.singletonList(new LiteralExpressionSegment(1, 2, 100))));
diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/pagination/PaginationContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/pagination/PaginationContextTest.java
index 5d991ae48c5..76c30b4ac62 100644
--- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/pagination/PaginationContextTest.java
+++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/pagination/PaginationContextTest.java
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.infra.binder.context.segment.select.pagination
import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
-import org.apache.shardingsphere.infra.database.core.DefaultDatabase;
import org.apache.shardingsphere.infra.database.core.metadata.database.enums.NullsOrderType;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
@@ -168,9 +167,9 @@ class PaginationContextTest {
private void getRevisedRowCount(final SelectStatement selectStatement) {
selectStatement.setProjections(new ProjectionsSegment(0, 0));
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
- when(database.getName()).thenReturn(DefaultDatabase.LOGIC_NAME);
+ when(database.getName()).thenReturn("foo_db");
ShardingSphereMetaData metaData = new ShardingSphereMetaData(Collections.singleton(database), mock(ResourceMetaData.class), mock(RuleMetaData.class), mock(ConfigurationProperties.class));
- SelectStatementContext selectStatementContext = new SelectStatementContext(metaData, Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME, Collections.emptyList());
+ SelectStatementContext selectStatementContext = new SelectStatementContext(metaData, Collections.emptyList(), selectStatement, "foo_db", Collections.emptyList());
assertThat(new PaginationContext(getOffsetSegment(), getRowCountSegment(), getParameters()).getRevisedRowCount(selectStatementContext), is(50L));
}
@@ -204,9 +203,9 @@ class PaginationContextTest {
selectStatement.setGroupBy(new GroupBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.ASC, NullsOrderType.LAST))));
selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(new IndexOrderByItemSegment(0, 0, 1, OrderDirection.DESC, NullsOrderType.LAST))));
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
- when(database.getName()).thenReturn(DefaultDatabase.LOGIC_NAME);
+ when(database.getName()).thenReturn("foo_db");
ShardingSphereMetaData metaData = new ShardingSphereMetaData(Collections.singleton(database), mock(ResourceMetaData.class), mock(RuleMetaData.class), mock(ConfigurationProperties.class));
- SelectStatementContext selectStatementContext = new SelectStatementContext(metaData, Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME, Collections.emptyList());
+ SelectStatementContext selectStatementContext = new SelectStatementContext(metaData, Collections.emptyList(), selectStatement, "foo_db", Collections.emptyList());
assertThat(new PaginationContext(getOffsetSegment(), getRowCountSegment(), getParameters()).getRevisedRowCount(selectStatementContext), is((long) Integer.MAX_VALUE));
}
}
diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/engine/ProjectionsContextEngineTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/engine/ProjectionsContextEngineTest.java
index 7cc16b3e2ec..4b43dabf43d 100644
--- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/engine/ProjectionsContextEngineTest.java
+++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/engine/ProjectionsContextEngineTest.java
@@ -23,7 +23,6 @@ import org.apache.shardingsphere.infra.binder.context.segment.select.orderby.Ord
import org.apache.shardingsphere.infra.binder.context.segment.select.projection.ProjectionsContext;
import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
-import org.apache.shardingsphere.infra.database.core.DefaultDatabase;
import org.apache.shardingsphere.infra.database.core.metadata.database.enums.NullsOrderType;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
@@ -222,9 +221,9 @@ class ProjectionsContextEngineTest {
private SelectStatementContext createSelectStatementContext(final SelectStatement selectStatement) {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
- when(database.getName()).thenReturn(DefaultDatabase.LOGIC_NAME);
+ when(database.getName()).thenReturn("foo_db");
ShardingSphereMetaData metaData = new ShardingSphereMetaData(Collections.singleton(database), mock(ResourceMetaData.class), mock(RuleMetaData.class), mock(ConfigurationProperties.class));
- return new SelectStatementContext(metaData, Collections.emptyList(), selectStatement, DefaultDatabase.LOGIC_NAME, Collections.emptyList());
+ return new SelectStatementContext(metaData, Collections.emptyList(), selectStatement, "foo_db", Collections.emptyList());
}
@Test
@@ -338,7 +337,7 @@ class ProjectionsContextEngineTest {
SimpleTableSegment tableSegment = new SimpleTableSegment(new TableNameSegment(0, 10, new IdentifierValue("name")));
ProjectionsSegment projectionsSegment = new ProjectionsSegment(0, 0);
selectStatement.setProjections(projectionsSegment);
- tableSegment.setOwner(new OwnerSegment(0, 0, new IdentifierValue(DefaultDatabase.LOGIC_NAME)));
+ tableSegment.setOwner(new OwnerSegment(0, 0, new IdentifierValue("foo_db")));
selectStatement.setFrom(tableSegment);
ShorthandProjectionSegment shorthandProjectionSegment = new ShorthandProjectionSegment(0, 10);
SimpleTableSegment table = new SimpleTableSegment(new TableNameSegment(0, 10, new IdentifierValue("name")));
diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/table/TablesContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/table/TablesContextTest.java
index d9106ed54d2..f33525cb05c 100644
--- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/table/TablesContextTest.java
+++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/table/TablesContextTest.java
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.infra.binder.context.segment.table;
-import org.apache.shardingsphere.infra.database.core.DefaultDatabase;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn;
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
@@ -52,18 +51,18 @@ class TablesContextTest {
@Test
void assertGetTableNamesWithoutTableSegments() {
- assertTrue(new TablesContext(Collections.emptyList(), Collections.emptyMap(), databaseType, DefaultDatabase.LOGIC_NAME).getTableNames().isEmpty());
+ assertTrue(new TablesContext(Collections.emptyList(), Collections.emptyMap(), databaseType, "foo_db").getTableNames().isEmpty());
}
@Test
void assertGetTableNamesWithoutSimpleTableSegments() {
- assertTrue(new TablesContext(Collections.singleton(mock(TableSegment.class)), Collections.emptyMap(), databaseType, DefaultDatabase.LOGIC_NAME).getTableNames().isEmpty());
+ assertTrue(new TablesContext(Collections.singleton(mock(TableSegment.class)), Collections.emptyMap(), databaseType, "foo_db").getTableNames().isEmpty());
}
@Test
void assertGetTableNames() {
TablesContext tablesContext = new TablesContext(
- Arrays.asList(createTableSegment("table_1", "tbl_1"), createTableSegment("table_2", "tbl_2"), createTableSegment("DUAL", "dual")), databaseType, DefaultDatabase.LOGIC_NAME);
+ Arrays.asList(createTableSegment("table_1", "tbl_1"), createTableSegment("table_2", "tbl_2"), createTableSegment("DUAL", "dual")), databaseType, "foo_db");
assertThat(tablesContext.getTableNames(), is(new HashSet<>(Arrays.asList("table_1", "table_2"))));
}
@@ -71,7 +70,7 @@ class TablesContextTest {
void assertInstanceCreatedWhenNoExceptionThrown() {
SimpleTableSegment tableSegment = new SimpleTableSegment(new TableNameSegment(0, 10, new IdentifierValue("tbl")));
tableSegment.setOwner(new OwnerSegment(0, 0, new IdentifierValue("schema")));
- TablesContext tablesContext = new TablesContext(Collections.singleton(tableSegment), databaseType, DefaultDatabase.LOGIC_NAME);
+ TablesContext tablesContext = new TablesContext(Collections.singleton(tableSegment), databaseType, "foo_db");
assertThat(tablesContext.getDatabaseName(), is(Optional.of("schema")));
assertThat(tablesContext.getSchemaName(), is(Optional.of("schema")));
assertThat(tablesContext.getTableNames(), is(Collections.singleton("tbl")));
@@ -81,7 +80,7 @@ class TablesContextTest {
void assertFindTableNameWhenSingleTable() {
SimpleTableSegment tableSegment = createTableSegment("table_1", "tbl_1");
ColumnSegment columnSegment = createColumnSegment(null, "col");
- Map<String, String> actual = new TablesContext(Collections.singletonList(tableSegment), databaseType, DefaultDatabase.LOGIC_NAME)
+ Map<String, String> actual = new TablesContext(Collections.singletonList(tableSegment), databaseType, "foo_db")
.findTableNames(Collections.singletonList(columnSegment), mock(ShardingSphereSchema.class));
assertFalse(actual.isEmpty());
assertThat(actual.get("col"), is("table_1"));
@@ -92,7 +91,7 @@ class TablesContextTest {
SimpleTableSegment tableSegment1 = createTableSegment("table_1", "tbl_1");
SimpleTableSegment tableSegment2 = createTableSegment("table_2", "tbl_2");
ColumnSegment columnSegment = createColumnSegment("table_1", "col");
- Map<String, String> actual = new TablesContext(Arrays.asList(tableSegment1, tableSegment2), databaseType, DefaultDatabase.LOGIC_NAME)
+ Map<String, String> actual = new TablesContext(Arrays.asList(tableSegment1, tableSegment2), databaseType, "foo_db")
.findTableNames(Collections.singletonList(columnSegment), mock(ShardingSphereSchema.class));
assertFalse(actual.isEmpty());
assertThat(actual.get("table_1.col"), is("table_1"));
@@ -103,7 +102,7 @@ class TablesContextTest {
SimpleTableSegment tableSegment1 = createTableSegment("table_1", "tbl_1");
SimpleTableSegment tableSegment2 = createTableSegment("table_2", "tbl_2");
ColumnSegment columnSegment = createColumnSegment(null, "col");
- Map<String, String> actual = new TablesContext(Arrays.asList(tableSegment1, tableSegment2), databaseType, DefaultDatabase.LOGIC_NAME)
+ Map<String, String> actual = new TablesContext(Arrays.asList(tableSegment1, tableSegment2), databaseType, "foo_db")
.findTableNames(Collections.singletonList(columnSegment), mock(ShardingSphereSchema.class));
assertTrue(actual.isEmpty());
}
@@ -116,7 +115,7 @@ class TablesContextTest {
when(schema.getAllColumnNames("table_1")).thenReturn(Collections.singletonList("col"));
ColumnSegment columnSegment = createColumnSegment(null, "col");
Map<String, String> actual = new TablesContext(Arrays.asList(tableSegment1, tableSegment2),
- databaseType, DefaultDatabase.LOGIC_NAME).findTableNames(Collections.singletonList(columnSegment), schema);
+ databaseType, "foo_db").findTableNames(Collections.singletonList(columnSegment), schema);
assertFalse(actual.isEmpty());
assertThat(actual.get("col"), is("table_1"));
}
@@ -127,10 +126,10 @@ class TablesContextTest {
SimpleTableSegment tableSegment2 = createTableSegment("TABLE_2", "TBL_2");
ShardingSphereTable table = new ShardingSphereTable("TABLE_1",
Collections.singletonList(new ShardingSphereColumn("COL", 0, false, false, true, true, false, false)), Collections.emptyList(), Collections.emptyList());
- ShardingSphereSchema schema = new ShardingSphereSchema(DefaultDatabase.LOGIC_NAME, Collections.singleton(table), Collections.emptyList());
+ ShardingSphereSchema schema = new ShardingSphereSchema("foo_db", Collections.singleton(table), Collections.emptyList());
ColumnSegment columnSegment = createColumnSegment(null, "COL");
Map<String, String> actual = new TablesContext(Arrays.asList(tableSegment1, tableSegment2),
- databaseType, DefaultDatabase.LOGIC_NAME).findTableNames(Collections.singletonList(columnSegment), schema);
+ databaseType, "foo_db").findTableNames(Collections.singletonList(columnSegment), schema);
assertFalse(actual.isEmpty());
assertThat(actual.get("col"), is("TABLE_1"));
}
@@ -156,7 +155,7 @@ class TablesContextTest {
tableSegment1.setOwner(new OwnerSegment(0, 0, new IdentifierValue("sharding_db_1")));
SimpleTableSegment tableSegment2 = createTableSegment("table_1", "tbl_1");
tableSegment2.setOwner(new OwnerSegment(0, 0, new IdentifierValue("sharding_db_1")));
- TablesContext tablesContext = new TablesContext(Arrays.asList(tableSegment1, tableSegment2), databaseType, DefaultDatabase.LOGIC_NAME);
+ TablesContext tablesContext = new TablesContext(Arrays.asList(tableSegment1, tableSegment2), databaseType, "foo_db");
assertTrue(tablesContext.getDatabaseName().isPresent());
assertThat(tablesContext.getDatabaseName().get(), is("sharding_db_1"));
}
@@ -167,7 +166,7 @@ class TablesContextTest {
tableSegment1.setOwner(new OwnerSegment(0, 0, new IdentifierValue("sharding_db_1")));
SimpleTableSegment tableSegment2 = createTableSegment("table_2", "tbl_2");
tableSegment2.setOwner(new OwnerSegment(0, 0, new IdentifierValue("sharding_db_1")));
- TablesContext tablesContext = new TablesContext(Arrays.asList(tableSegment1, tableSegment2), databaseType, DefaultDatabase.LOGIC_NAME);
+ TablesContext tablesContext = new TablesContext(Arrays.asList(tableSegment1, tableSegment2), databaseType, "foo_db");
assertTrue(tablesContext.getDatabaseName().isPresent());
assertThat(tablesContext.getDatabaseName().get(), is("sharding_db_1"));
}
@@ -179,7 +178,7 @@ class TablesContextTest {
SimpleTableSegment tableSegment2 = createTableSegment("table_1", "tbl_1");
tableSegment2.setOwner(new OwnerSegment(0, 0, new IdentifierValue("sharding_db_2")));
assertThrows(IllegalStateException.class,
- () -> new TablesContext(Arrays.asList(tableSegment1, tableSegment2), databaseType, DefaultDatabase.LOGIC_NAME).getDatabaseName());
+ () -> new TablesContext(Arrays.asList(tableSegment1, tableSegment2), databaseType, "foo_db").getDatabaseName());
}
@Test
@@ -189,7 +188,7 @@ class TablesContextTest {
SimpleTableSegment tableSegment2 = createTableSegment("table_2", "tbl_2");
tableSegment2.setOwner(new OwnerSegment(0, 0, new IdentifierValue("sharding_db_2")));
assertThrows(IllegalStateException.class,
- () -> new TablesContext(Arrays.asList(tableSegment1, tableSegment2), databaseType, DefaultDatabase.LOGIC_NAME).getDatabaseName());
+ () -> new TablesContext(Arrays.asList(tableSegment1, tableSegment2), databaseType, "foo_db").getDatabaseName());
}
@Test
@@ -198,7 +197,7 @@ class TablesContextTest {
tableSegment1.setOwner(new OwnerSegment(0, 0, new IdentifierValue("sharding_db_1")));
SimpleTableSegment tableSegment2 = createTableSegment("table_2", "tbl_2");
tableSegment2.setOwner(new OwnerSegment(0, 0, new IdentifierValue("sharding_db_1")));
- TablesContext tablesContext = new TablesContext(Arrays.asList(tableSegment1, tableSegment2), databaseType, DefaultDatabase.LOGIC_NAME);
+ TablesContext tablesContext = new TablesContext(Arrays.asList(tableSegment1, tableSegment2), databaseType, "foo_db");
assertTrue(tablesContext.getSchemaName().isPresent());
assertThat(tablesContext.getSchemaName().get(), is("sharding_db_1"));
}
diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/SQLStatementContextFactoryTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/SQLStatementContextFactoryTest.java
index c1baeebe36e..ef5876b805a 100644
--- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/SQLStatementContextFactoryTest.java
+++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/SQLStatementContextFactoryTest.java
@@ -25,7 +25,6 @@ import org.apache.shardingsphere.infra.binder.context.statement.dml.InsertStatem
import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext;
import org.apache.shardingsphere.infra.binder.engine.SQLBindEngine;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
-import org.apache.shardingsphere.infra.database.core.DefaultDatabase;
import org.apache.shardingsphere.infra.hint.HintValueContext;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
@@ -71,7 +70,7 @@ class SQLStatementContextFactoryTest {
MySQLSelectStatement selectStatement = new MySQLSelectStatement();
selectStatement.setLimit(new LimitSegment(0, 10, null, null));
selectStatement.setProjections(projectionsSegment);
- SQLStatementContext sqlStatementContext = new SQLBindEngine(mockMetaData(), DefaultDatabase.LOGIC_NAME, new HintValueContext()).bind(selectStatement, Collections.emptyList());
+ SQLStatementContext sqlStatementContext = new SQLBindEngine(mockMetaData(), "foo_db", new HintValueContext()).bind(selectStatement, Collections.emptyList());
assertThat(sqlStatementContext, instanceOf(SelectStatementContext.class));
}
@@ -107,14 +106,13 @@ class SQLStatementContextFactoryTest {
private void assertSQLStatementContextCreatedWhenSQLStatementInstanceOfInsertStatement(final InsertStatement insertStatement) {
insertStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl"))));
- SQLStatementContext sqlStatementContext = new SQLBindEngine(mockMetaData(), DefaultDatabase.LOGIC_NAME, new HintValueContext()).bind(insertStatement, Collections.emptyList());
+ SQLStatementContext sqlStatementContext = new SQLBindEngine(mockMetaData(), "foo_db", new HintValueContext()).bind(insertStatement, Collections.emptyList());
assertThat(sqlStatementContext, instanceOf(InsertStatementContext.class));
}
@Test
void assertSQLStatementContextCreatedWhenSQLStatementNotInstanceOfSelectStatementAndInsertStatement() {
- SQLStatementContext sqlStatementContext = new SQLBindEngine(
- mockMetaData(), DefaultDatabase.LOGIC_NAME, new HintValueContext()).bind(new MySQLAlterDatabaseStatement(), Collections.emptyList());
+ SQLStatementContext sqlStatementContext = new SQLBindEngine(mockMetaData(), "foo_db", new HintValueContext()).bind(new MySQLAlterDatabaseStatement(), Collections.emptyList());
assertThat(sqlStatementContext, instanceOf(CommonSQLStatementContext.class));
}
@@ -127,34 +125,34 @@ class SQLStatementContextFactoryTest {
when(selectStatement.getCommentSegments()).thenReturn(Collections.emptyList());
when(cursorStatement.getSelect()).thenReturn(selectStatement);
when(cursorStatement.getCommentSegments()).thenReturn(Collections.emptyList());
- SQLStatementContext actual = new SQLBindEngine(mockMetaData(), DefaultDatabase.LOGIC_NAME, new HintValueContext()).bind(cursorStatement, Collections.emptyList());
+ SQLStatementContext actual = new SQLBindEngine(mockMetaData(), "foo_db", new HintValueContext()).bind(cursorStatement, Collections.emptyList());
assertThat(actual, instanceOf(CursorStatementContext.class));
}
@Test
void assertNewInstanceForCloseStatement() {
- SQLStatementContext actual = new SQLBindEngine(mockMetaData(), DefaultDatabase.LOGIC_NAME, new HintValueContext()).bind(new OpenGaussCloseStatement(), Collections.emptyList());
+ SQLStatementContext actual = new SQLBindEngine(mockMetaData(), "foo_db", new HintValueContext()).bind(new OpenGaussCloseStatement(), Collections.emptyList());
assertThat(actual, instanceOf(CloseStatementContext.class));
}
@Test
void assertNewInstanceForMoveStatement() {
- SQLStatementContext actual = new SQLBindEngine(mockMetaData(), DefaultDatabase.LOGIC_NAME, new HintValueContext()).bind(new OpenGaussMoveStatement(), Collections.emptyList());
+ SQLStatementContext actual = new SQLBindEngine(mockMetaData(), "foo_db", new HintValueContext()).bind(new OpenGaussMoveStatement(), Collections.emptyList());
assertThat(actual, instanceOf(MoveStatementContext.class));
}
@Test
void assertNewInstanceForFetchStatement() {
- SQLStatementContext actual = new SQLBindEngine(mockMetaData(), DefaultDatabase.LOGIC_NAME, new HintValueContext()).bind(new OpenGaussFetchStatement(), Collections.emptyList());
+ SQLStatementContext actual = new SQLBindEngine(mockMetaData(), "foo_db", new HintValueContext()).bind(new OpenGaussFetchStatement(), Collections.emptyList());
assertThat(actual, instanceOf(FetchStatementContext.class));
}
private ShardingSphereMetaData mockMetaData() {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
- when(database.getName()).thenReturn(DefaultDatabase.LOGIC_NAME);
- when(database.containsSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(true);
+ when(database.getName()).thenReturn("foo_db");
+ when(database.containsSchema("foo_db")).thenReturn(true);
when(database.containsSchema("public")).thenReturn(true);
- when(database.getSchema(DefaultDatabase.LOGIC_NAME).containsTable("tbl")).thenReturn(true);
+ when(database.getSchema("foo_db").containsTable("tbl")).thenReturn(true);
when(database.getSchema("public").containsTable("tbl")).thenReturn(true);
when(database.containsSchema("dbo")).thenReturn(true);
when(database.getSchema("dbo").containsTable("tbl")).thenReturn(true);
diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/AnalyzeTableStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/AnalyzeTableStatementContextTest.java
index 7c3927b59ad..b7a3b7c3032 100644
--- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/AnalyzeTableStatementContextTest.java
+++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/AnalyzeTableStatementContextTest.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.infra.binder.context.statement.dal;
import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
-import org.apache.shardingsphere.infra.database.core.DefaultDatabase;
import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment;
import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.AnalyzeTableStatement;
@@ -50,7 +49,7 @@ class AnalyzeTableStatementContextTest {
SimpleTableSegment table1 = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl_1")));
SimpleTableSegment table2 = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl_2")));
analyzeTableStatement.getTables().addAll(Arrays.asList(table1, table2));
- AnalyzeTableStatementContext actual = new AnalyzeTableStatementContext(analyzeTableStatement, DefaultDatabase.LOGIC_NAME);
+ AnalyzeTableStatementContext actual = new AnalyzeTableStatementContext(analyzeTableStatement, "foo_db");
assertThat(actual, instanceOf(CommonSQLStatementContext.class));
assertThat(actual.getSqlStatement(), is(analyzeTableStatement));
assertThat(actual.getTablesContext().getSimpleTables().stream().map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()), is(Arrays.asList("tbl_1", "tbl_2")));
diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ExplainStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ExplainStatementContextTest.java
index ea332418441..fda4d10df6e 100644
--- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ExplainStatementContextTest.java
+++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ExplainStatementContextTest.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.infra.binder.context.statement.dal;
import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
-import org.apache.shardingsphere.infra.database.core.DefaultDatabase;
import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement;
import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ExplainStatement;
import org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLExplainStatement;
@@ -49,7 +48,7 @@ class ExplainStatementContextTest {
private void assertNewInstance(final ExplainStatement explainStatement) {
SQLStatement statement = mock(SQLStatement.class);
when(explainStatement.getSqlStatement()).thenReturn(Optional.of(statement));
- ExplainStatementContext actual = new ExplainStatementContext(explainStatement, DefaultDatabase.LOGIC_NAME);
+ ExplainStatementContext actual = new ExplainStatementContext(explainStatement, "foo_db");
assertThat(actual, instanceOf(CommonSQLStatementContext.class));
assertThat(actual.getSqlStatement(), is(explainStatement));
assertThat(actual.getSqlStatement().getSqlStatement().orElse(null), is(statement));
diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/OptimizeTableStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/OptimizeTableStatementContextTest.java
index 7394d053fba..8fb44f8d550 100644
--- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/OptimizeTableStatementContextTest.java
+++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/OptimizeTableStatementContextTest.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.infra.binder.context.statement.dal;
import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
-import org.apache.shardingsphere.infra.database.core.DefaultDatabase;
import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment;
import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
@@ -38,7 +37,7 @@ class OptimizeTableStatementContextTest {
void assertNewInstance() {
MySQLOptimizeTableStatement sqlStatement = new MySQLOptimizeTableStatement();
sqlStatement.getTables().add(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl_1"))));
- OptimizeTableStatementContext actual = new OptimizeTableStatementContext(sqlStatement, DefaultDatabase.LOGIC_NAME);
+ OptimizeTableStatementContext actual = new OptimizeTableStatementContext(sqlStatement, "foo_db");
assertThat(actual, instanceOf(CommonSQLStatementContext.class));
assertThat(actual.getSqlStatement(), is(sqlStatement));
assertThat(actual.getTablesContext().getSimpleTables().stream().map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()),
diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowColumnsStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowColumnsStatementContextTest.java
index 8937ccdcc08..35bbd289fdc 100644
--- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowColumnsStatementContextTest.java
+++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowColumnsStatementContextTest.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.infra.binder.context.statement.dal;
import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
-import org.apache.shardingsphere.infra.database.core.DefaultDatabase;
import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.FromDatabaseSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.DatabaseSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
@@ -39,17 +38,14 @@ class ShowColumnsStatementContextTest {
@Test
void assertNewInstance() {
MySQLShowColumnsStatement sqlStatement = new MySQLShowColumnsStatement();
- String tableName = "tbl_1";
- String databaseName = "sharding_db";
- SimpleTableSegment table = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue(tableName)));
- FromDatabaseSegment fromDatabase = new FromDatabaseSegment(0, 0, new DatabaseSegment(0, 0, new IdentifierValue(databaseName)));
- sqlStatement.setTable(table);
+ sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("foo_tbl"))));
+ FromDatabaseSegment fromDatabase = new FromDatabaseSegment(0, 0, new DatabaseSegment(0, 0, new IdentifierValue("foo_db")));
sqlStatement.setFromDatabase(fromDatabase);
- ShowColumnsStatementContext actual = new ShowColumnsStatementContext(sqlStatement, DefaultDatabase.LOGIC_NAME);
+ ShowColumnsStatementContext actual = new ShowColumnsStatementContext(sqlStatement, "foo_db");
assertThat(actual, instanceOf(CommonSQLStatementContext.class));
assertThat(actual.getSqlStatement(), is(sqlStatement));
assertThat(actual.getTablesContext().getSimpleTables().stream().map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()),
- is(Collections.singletonList(tableName)));
+ is(Collections.singletonList("foo_tbl")));
assertThat(actual.getRemoveSegments(), is(Collections.singletonList(fromDatabase)));
}
}
diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowCreateTableStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowCreateTableStatementContextTest.java
index a0770817469..8495b3f0778 100644
--- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowCreateTableStatementContextTest.java
+++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowCreateTableStatementContextTest.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.infra.binder.context.statement.dal;
import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
-import org.apache.shardingsphere.infra.database.core.DefaultDatabase;
import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment;
import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
@@ -37,11 +36,11 @@ class ShowCreateTableStatementContextTest {
@Test
void assertNewInstance() {
MySQLShowCreateTableStatement sqlStatement = new MySQLShowCreateTableStatement();
- sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl_1"))));
- ShowCreateTableStatementContext actual = new ShowCreateTableStatementContext(sqlStatement, DefaultDatabase.LOGIC_NAME);
+ sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("foo_tbl"))));
+ ShowCreateTableStatementContext actual = new ShowCreateTableStatementContext(sqlStatement, "foo_db");
assertThat(actual, instanceOf(CommonSQLStatementContext.class));
assertThat(actual.getSqlStatement(), is(sqlStatement));
assertThat(actual.getTablesContext().getSimpleTables().stream().map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()),
- is(Collections.singletonList("tbl_1")));
+ is(Collections.singletonList("foo_tbl")));
}
}
diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowIndexStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowIndexStatementContextTest.java
index e37cfeb88e9..602ebb2c4e9 100644
--- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowIndexStatementContextTest.java
+++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowIndexStatementContextTest.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.infra.binder.context.statement.dal;
import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
-import org.apache.shardingsphere.infra.database.core.DefaultDatabase;
import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment;
import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
@@ -37,11 +36,11 @@ class ShowIndexStatementContextTest {
@Test
void assertNewInstance() {
MySQLShowIndexStatement sqlStatement = new MySQLShowIndexStatement();
- sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl_1"))));
- ShowIndexStatementContext actual = new ShowIndexStatementContext(sqlStatement, DefaultDatabase.LOGIC_NAME);
+ sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("foo_tbl"))));
+ ShowIndexStatementContext actual = new ShowIndexStatementContext(sqlStatement, "foo_db");
assertThat(actual, instanceOf(CommonSQLStatementContext.class));
assertThat(actual.getSqlStatement(), is(sqlStatement));
assertThat(actual.getTablesContext().getSimpleTables().stream().map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()),
- is(Collections.singletonList("tbl_1")));
+ is(Collections.singletonList("foo_tbl")));
}
}
diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/DenyUserStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/DenyUserStatementContextTest.java
index 70afe700fb7..ad7f4fabda4 100644
--- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/DenyUserStatementContextTest.java
+++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/DenyUserStatementContextTest.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.infra.binder.context.statement.dcl;
import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
-import org.apache.shardingsphere.infra.database.core.DefaultDatabase;
import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment;
import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
@@ -37,12 +36,12 @@ class DenyUserStatementContextTest {
@Test
void assertNewInstance() {
SQLServerDenyUserStatement sqlStatement = new SQLServerDenyUserStatement();
- SimpleTableSegment table = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl_1")));
+ SimpleTableSegment table = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("foo_tbl")));
sqlStatement.setTable(table);
- DenyUserStatementContext actual = new DenyUserStatementContext(sqlStatement, DefaultDatabase.LOGIC_NAME);
+ DenyUserStatementContext actual = new DenyUserStatementContext(sqlStatement, "foo_db");
assertThat(actual, instanceOf(CommonSQLStatementContext.class));
assertThat(actual.getSqlStatement(), is(sqlStatement));
assertThat(actual.getTablesContext().getSimpleTables().stream().map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()),
- is(Collections.singletonList("tbl_1")));
+ is(Collections.singletonList("foo_tbl")));
}
}
diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/GrantStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/GrantStatementContextTest.java
index 17fc380431b..08f0b286cae 100644
--- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/GrantStatementContextTest.java
+++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/GrantStatementContextTest.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.infra.binder.context.statement.dcl;
import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
-import org.apache.shardingsphere.infra.database.core.DefaultDatabase;
import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment;
import org.apache.shardingsphere.sql.parser.statement.core.statement.dcl.GrantStatement;
@@ -65,12 +64,13 @@ class GrantStatementContextTest {
}
private void assertNewInstance(final GrantStatement grantStatement) {
- SimpleTableSegment table1 = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl_1")));
- SimpleTableSegment table2 = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl_2")));
+ SimpleTableSegment table1 = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("foo_tbl")));
+ SimpleTableSegment table2 = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("bar_tbl")));
grantStatement.getTables().addAll(Arrays.asList(table1, table2));
- GrantStatementContext actual = new GrantStatementContext(grantStatement, DefaultDatabase.LOGIC_NAME);
+ GrantStatementContext actual = new GrantStatementContext(grantStatement, "foo_db");
assertThat(actual, instanceOf(CommonSQLStatementContext.class));
assertThat(actual.getSqlStatement(), is(grantStatement));
- assertThat(actual.getTablesContext().getSimpleTables().stream().map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()), is(Arrays.asList("tbl_1", "tbl_2")));
+ assertThat(actual.getTablesContext().getSimpleTables().stream().map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()),
+ is(Arrays.asList("foo_tbl", "bar_tbl")));
}
}
diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/RevokeStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/RevokeStatementContextTest.java
index b338c19d245..af3f91c127f 100644
--- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/RevokeStatementContextTest.java
+++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/RevokeStatementContextTest.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.infra.binder.context.statement.dcl;
import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
-import org.apache.shardingsphere.infra.database.core.DefaultDatabase;
import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment;
import org.apache.shardingsphere.sql.parser.statement.core.statement.dcl.RevokeStatement;
@@ -65,12 +64,13 @@ class RevokeStatementContextTest {
}
private void assertNewInstance(final RevokeStatement revokeStatement) {
- SimpleTableSegment table1 = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl_1")));
- SimpleTableSegment table2 = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl_2")));
+ SimpleTableSegment table1 = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("foo_tbl")));
+ SimpleTableSegment table2 = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("bar_tbl")));
revokeStatement.getTables().addAll(Arrays.asList(table1, table2));
- RevokeStatementContext actual = new RevokeStatementContext(revokeStatement, DefaultDatabase.LOGIC_NAME);
+ RevokeStatementContext actual = new RevokeStatementContext(revokeStatement, "foo_db");
assertThat(actual, instanceOf(CommonSQLStatementContext.class));
assertThat(actual.getSqlStatement(), is(revokeStatement));
- assertThat(actual.getTablesContext().getSimpleTables().stream().map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()), is(Arrays.asList("tbl_1", "tbl_2")));
+ assertThat(actual.getTablesContext().getSimpleTables().stream().map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()),
+ is(Arrays.asList("foo_tbl", "bar_tbl")));
}
}
diff --git a/infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/DefaultDatabase.java b/infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/DefaultDatabase.java
index aff2de6805f..29ca585ac85 100644
--- a/infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/DefaultDatabase.java
+++ b/infra/database/core/src/main/java/org/apache/shardingsphere/infra/database/core/DefaultDatabase.java
@@ -27,7 +27,7 @@ import lombok.NoArgsConstructor;
public final class DefaultDatabase {
/**
- * Schema name.
+ * Database name.
*/
public static final String LOGIC_NAME = "logic_db";
}