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 f2fa992507e9e..5dcc5439ebdcd 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.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 @@ void assertInsertRoute() { 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 8fac0725822c5..9c123497b2260 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.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 @@ private SelectStatementContext mockSelectStatementContext(final String tableName 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 0504b9a939d65..e5387f7573171 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.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 @@ void assertCheckWithDifferentEncryptorsInJoinCondition() { 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 @@ void assertCheckWithNotMatchedLikeQueryEncryptor() { 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 @@ void assertCheckSuccess() { 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 0e625eb5e8332..527a8a709952f 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 @@ 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.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 @@ class EncryptMetaDataReviseEngineTest { - private static final String TABLE_NAME = "t_encrypt"; - @Test void assertRevise() { - Map 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 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 columns = actual.getColumns().iterator(); - assertThat(columns.next().getName(), is("id")); - assertThat(columns.next().getName(), is("pwd")); + List 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 @@ private TableMetaData createTableMetaData() { Collection 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 3fd62697982d7..37bde3327b6da 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.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 actual = new ArrayList<>(new EncryptParameterRewritersRegistry(mock(EncryptRule.class), DefaultDatabase.LOGIC_NAME, Collections.emptyList()).getParameterRewriters()); + List 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 43a4e689780f7..7b2d575a21896 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.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 static EncryptRule createEncryptRule() { */ public static InsertStatementContext createInsertStatementContext(final List 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 @@ private static InsertStatement createInsertSelectStatement(final boolean contain 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 insertColumns = Arrays.asList(userIdColumn, userNameColumn); if (containsInsertColumns) { @@ -147,7 +146,7 @@ private static InsertStatement createInsertSelectStatement(final boolean contain 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 static UpdateStatementContext createUpdateStatementContext() { 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 @@ private static List createValueExpressions() { */ public static InsertStatementContext createInsertSelectStatementContext(final List 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 9c076acf788f0..3e9e3d648bc75 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.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 @@ void setup() { @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 @@ void assertIsGenerateSQLToken() { 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 sqlTokens = generator.generateSQLTokens(updateStatementContext); @@ -67,8 +66,8 @@ void assertGenerateSQLTokenFromGenerateNewSQLToken() { private Collection 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 ec1e3619ed117..18b3e0c84ffa5 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.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 @@ void assertGenerateSQLTokensWhenOwnerMatchTableAlias() { 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 @@ void assertGenerateSQLTokensWhenOwnerMatchTableAlias() { 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 actual = generator.generateSQLTokens(sqlStatementContext); assertThat(actual.size(), is(1)); @@ -103,7 +102,7 @@ void assertGenerateSQLTokensWhenOwnerMatchTableAliasForSameTable() { 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 @@ void assertGenerateSQLTokensWhenOwnerMatchTableAliasForSameTable() { 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 actual = generator.generateSQLTokens(sqlStatementContext); assertThat(actual.size(), is(1)); @@ -133,7 +132,7 @@ void assertGenerateSQLTokensWhenOwnerMatchTableName() { 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 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 fa76a3f31cb49..c503669a7be06 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.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 @@ 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 @@ private SelectStatementContext buildSelectStatementContext() { 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 4ecee6d7705bc..27a6a73a3c192 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 @@ 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 @@ void assertCreateGenerateKeyContextWhenCreateWithGenerateKeyColumnConfigurationF @Test void assertCreateGenerateKeyContextWhenCreateWithGenerateUpperCaseKeyColumnConfigurationForMySQL2() { - assertCreateGenerateKeyContextWhenCreateWithGenerateKeyColumnConfiguration(new MySQLInsertStatement(), "tbl2"); + assertCreateGenerateKeyContextWhenCreateWithGenerateKeyColumnConfiguration(new MySQLInsertStatement(), "bar_tbl"); } @Test @@ -132,7 +131,7 @@ void assertCreateGenerateKeyContextWhenCreateWithGenerateKeyColumnConfigurationF } 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 @@ void assertCreateGenerateKeyContextWhenFindForSQLServer() { } 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 5d991ae48c578..76c30b4ac62ba 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 @@ 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 @@ void assertGetRevisedRowCountForSQLServer() { 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 @@ private void getRevisedRowCountWithMax(final SelectStatement selectStatement) { 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 7cc16b3e2ecb7..4b43dabf43d18 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.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 @@ private void assertCreateProjectionsContextWithoutIndexOrderByItemSegment(final 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 @@ private void assertCreateProjectionsContextWhenColumnOrderByItemSegmentOwnerPres 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 d9106ed54d24a..f33525cb05c91 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 @@ void assertGetTableNames() { 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 @@ void assertInstanceCreatedWhenNoExceptionThrown() { void assertFindTableNameWhenSingleTable() { SimpleTableSegment tableSegment = createTableSegment("table_1", "tbl_1"); ColumnSegment columnSegment = createColumnSegment(null, "col"); - Map actual = new TablesContext(Collections.singletonList(tableSegment), databaseType, DefaultDatabase.LOGIC_NAME) + Map 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 @@ void assertFindTableNameWhenColumnSegmentOwnerPresent() { SimpleTableSegment tableSegment1 = createTableSegment("table_1", "tbl_1"); SimpleTableSegment tableSegment2 = createTableSegment("table_2", "tbl_2"); ColumnSegment columnSegment = createColumnSegment("table_1", "col"); - Map actual = new TablesContext(Arrays.asList(tableSegment1, tableSegment2), databaseType, DefaultDatabase.LOGIC_NAME) + Map 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 @@ void assertFindTableNameWhenColumnSegmentOwnerAbsent() { SimpleTableSegment tableSegment1 = createTableSegment("table_1", "tbl_1"); SimpleTableSegment tableSegment2 = createTableSegment("table_2", "tbl_2"); ColumnSegment columnSegment = createColumnSegment(null, "col"); - Map actual = new TablesContext(Arrays.asList(tableSegment1, tableSegment2), databaseType, DefaultDatabase.LOGIC_NAME) + Map actual = new TablesContext(Arrays.asList(tableSegment1, tableSegment2), databaseType, "foo_db") .findTableNames(Collections.singletonList(columnSegment), mock(ShardingSphereSchema.class)); assertTrue(actual.isEmpty()); } @@ -116,7 +115,7 @@ void assertFindTableNameWhenColumnSegmentOwnerAbsentAndSchemaMetaDataContainsCol when(schema.getAllColumnNames("table_1")).thenReturn(Collections.singletonList("col")); ColumnSegment columnSegment = createColumnSegment(null, "col"); Map 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 @@ void assertFindTableNameWhenColumnSegmentOwnerAbsentAndSchemaMetaDataContainsCol 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 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 @@ void assertGetSchemaNameWithSameSchemaAndSameTable() { 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 @@ void assertGetSchemaNameWithSameSchemaAndDifferentTable() { 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 @@ void assertGetSchemaNameWithDifferentSchemaAndSameTable() { 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 @@ void assertGetSchemaNameWithDifferentSchemaAndDifferentTable() { 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 @@ void assertGetSchemaName() { 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 c1baeebe36ec8..ef5876b805aca 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.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 @@ void assertSQLStatementContextCreatedWhenSQLStatementInstanceOfSelectStatement() 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 @@ void assertSQLStatementContextCreatedWhenSQLStatementInstanceOfSQLServerInsertSt 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 @@ void assertNewInstanceForCursorStatement() { 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 7c3927b59ada0..b7a3b7c303273 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 @@ private void assertNewInstance(final AnalyzeTableStatement analyzeTableStatement 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 ea332418441c5..fda4d10df6e39 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 @@ void assertPostgreSQLNewInstance() { 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 7394d053fbab2..8fb44f8d550c9 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 8937ccdcc08c5..35bbd289fdc55 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 a0770817469d0..8495b3f077878 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 e37cfeb88e949..602ebb2c4e9e1 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 70afe700fb799..ad7f4fabda468 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 17fc380431b2f..08f0b286caea2 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 @@ void assertSQL92NewInstance() { } 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 b338c19d2455e..af3f91c127f48 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 @@ void assertSQL92NewInstance() { } 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 aff2de6805f38..29ca585ac857c 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 @@ public final class DefaultDatabase { /** - * Schema name. + * Database name. */ public static final String LOGIC_NAME = "logic_db"; }