This is an automated email from the ASF dual-hosted git repository.
panjuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 194fa402069 Avoid to use mySQL for variable names (#28268)
194fa402069 is described below
commit 194fa402069ac2224c9a67c818ed4144855b8bfd
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Aug 27 13:50:19 2023 +0800
Avoid to use mySQL for variable names (#28268)
---
.../rewrite/token/OrderByTokenGeneratorTest.java | 6 +-
.../dal/ShowColumnsStatementContextTest.java | 10 +--
.../dal/ShowCreateTableStatementContextTest.java | 8 +-
.../dal/ShowIndexStatementContextTest.java | 8 +-
.../ddl/AlterViewStatementContextTest.java | 8 +-
.../mysql/ingest/MySQLPositionInitializerTest.java | 4 +-
.../sql/common/extractor/TableExtractorTest.java | 8 +-
.../sql/common/util/WhereExtractUtilsTest.java | 8 +-
.../handler/dal/FlushStatementHandlerTest.java | 8 +-
.../admin/MySQLAdminExecutorCreatorTest.java | 96 +++++++++++-----------
10 files changed, 83 insertions(+), 81 deletions(-)
diff --git
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/OrderByTokenGeneratorTest.java
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/OrderByTokenGeneratorTest.java
index f10883033a7..3adc32877bf 100644
---
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/OrderByTokenGeneratorTest.java
+++
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/OrderByTokenGeneratorTest.java
@@ -72,10 +72,10 @@ class OrderByTokenGeneratorTest {
void assertGenerateSQLToken() {
WindowSegment windowSegment = mock(WindowSegment.class);
when(windowSegment.getStopIndex()).thenReturn(2);
- MySQLSelectStatement mySQLSelectStatement =
mock(MySQLSelectStatement.class);
-
when(mySQLSelectStatement.getWindow()).thenReturn(Optional.of(windowSegment));
+ MySQLSelectStatement selectStatement =
mock(MySQLSelectStatement.class);
+
when(selectStatement.getWindow()).thenReturn(Optional.of(windowSegment));
SelectStatementContext selectStatementContext =
mock(SelectStatementContext.class, RETURNS_DEEP_STUBS);
-
when(selectStatementContext.getSqlStatement()).thenReturn(mySQLSelectStatement);
+
when(selectStatementContext.getSqlStatement()).thenReturn(selectStatement);
Collection<OrderByItem> orderByItems = getOrderByItems();
when(selectStatementContext.getOrderByContext().getItems()).thenReturn(orderByItems);
OrderByTokenGenerator generator = new OrderByTokenGenerator();
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 e86c5a7546a..78d60e511e2 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
@@ -40,16 +40,16 @@ class ShowColumnsStatementContextTest {
@Test
void assertNewInstance() {
- MySQLShowColumnsStatement mySQLShowColumnsStatement =
mock(MySQLShowColumnsStatement.class);
+ MySQLShowColumnsStatement showColumnsStatement =
mock(MySQLShowColumnsStatement.class);
String tableName = "tbl_1";
String databaseName = "sharding_db";
SimpleTableSegment table = new SimpleTableSegment(new
TableNameSegment(0, 0, new IdentifierValue(tableName)));
FromSchemaSegment fromSchema = new FromSchemaSegment(0, 0, new
DatabaseSegment(0, 0, new IdentifierValue(databaseName)));
- when(mySQLShowColumnsStatement.getTable()).thenReturn(table);
-
when(mySQLShowColumnsStatement.getFromSchema()).thenReturn(Optional.of(fromSchema));
- ShowColumnsStatementContext actual = new
ShowColumnsStatementContext(mySQLShowColumnsStatement);
+ when(showColumnsStatement.getTable()).thenReturn(table);
+
when(showColumnsStatement.getFromSchema()).thenReturn(Optional.of(fromSchema));
+ ShowColumnsStatementContext actual = new
ShowColumnsStatementContext(showColumnsStatement);
assertThat(actual, instanceOf(CommonSQLStatementContext.class));
- assertThat(actual.getSqlStatement(), is(mySQLShowColumnsStatement));
+ assertThat(actual.getSqlStatement(), is(showColumnsStatement));
assertThat(actual.getAllTables().stream().map(each ->
each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()),
is(Collections.singletonList(tableName)));
assertThat(actual.getRemoveSegments(),
is(Collections.singletonList(fromSchema)));
}
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 1895764666b..29e57435f7e 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
@@ -37,12 +37,12 @@ class ShowCreateTableStatementContextTest {
@Test
void assertNewInstance() {
- MySQLShowCreateTableStatement mySQLShowCreateTableStatement =
mock(MySQLShowCreateTableStatement.class);
+ MySQLShowCreateTableStatement showCreateTableStatement =
mock(MySQLShowCreateTableStatement.class);
SimpleTableSegment table = new SimpleTableSegment(new
TableNameSegment(0, 0, new IdentifierValue("tbl_1")));
- when(mySQLShowCreateTableStatement.getTable()).thenReturn(table);
- ShowCreateTableStatementContext actual = new
ShowCreateTableStatementContext(mySQLShowCreateTableStatement);
+ when(showCreateTableStatement.getTable()).thenReturn(table);
+ ShowCreateTableStatementContext actual = new
ShowCreateTableStatementContext(showCreateTableStatement);
assertThat(actual, instanceOf(CommonSQLStatementContext.class));
- assertThat(actual.getSqlStatement(),
is(mySQLShowCreateTableStatement));
+ assertThat(actual.getSqlStatement(), is(showCreateTableStatement));
assertThat(actual.getAllTables().stream().map(each ->
each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()),
is(Collections.singletonList("tbl_1")));
}
}
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 00a0062257b..c8a259ab79b 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
@@ -37,12 +37,12 @@ class ShowIndexStatementContextTest {
@Test
void assertNewInstance() {
- MySQLShowIndexStatement mySQLShowIndexStatement =
mock(MySQLShowIndexStatement.class);
+ MySQLShowIndexStatement showIndexStatement =
mock(MySQLShowIndexStatement.class);
SimpleTableSegment table = new SimpleTableSegment(new
TableNameSegment(0, 0, new IdentifierValue("tbl_1")));
- when(mySQLShowIndexStatement.getTable()).thenReturn(table);
- ShowIndexStatementContext actual = new
ShowIndexStatementContext(mySQLShowIndexStatement);
+ when(showIndexStatement.getTable()).thenReturn(table);
+ ShowIndexStatementContext actual = new
ShowIndexStatementContext(showIndexStatement);
assertThat(actual, instanceOf(CommonSQLStatementContext.class));
- assertThat(actual.getSqlStatement(), is(mySQLShowIndexStatement));
+ assertThat(actual.getSqlStatement(), is(showIndexStatement));
assertThat(actual.getAllTables().stream().map(each ->
each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()),
is(Collections.singletonList("tbl_1")));
}
}
diff --git
a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterViewStatementContextTest.java
b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterViewStatementContextTest.java
index 415c304fa7c..eab23029a68 100644
---
a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterViewStatementContextTest.java
+++
b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterViewStatementContextTest.java
@@ -50,10 +50,10 @@ class AlterViewStatementContextTest {
void assertMySQLNewInstance() {
SelectStatement select = mock(MySQLSelectStatement.class);
when(select.getFrom()).thenReturn(view);
- MySQLAlterViewStatement mySQLAlterViewStatement =
mock(MySQLAlterViewStatement.class);
- when(mySQLAlterViewStatement.getView()).thenReturn(view);
- when(mySQLAlterViewStatement.getSelect()).thenReturn(select);
- assertNewInstance(mySQLAlterViewStatement);
+ MySQLAlterViewStatement alterViewStatement =
mock(MySQLAlterViewStatement.class);
+ when(alterViewStatement.getView()).thenReturn(view);
+ when(alterViewStatement.getSelect()).thenReturn(select);
+ assertNewInstance(alterViewStatement);
}
@Test
diff --git
a/kernel/data-pipeline/dialect/mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/MySQLPositionInitializerTest.java
b/kernel/data-pipeline/dialect/mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/MySQLPositionInitializerTest.java
index 6b9d5c6e434..10b7976f759 100644
---
a/kernel/data-pipeline/dialect/mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/MySQLPositionInitializerTest.java
+++
b/kernel/data-pipeline/dialect/mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/MySQLPositionInitializerTest.java
@@ -61,8 +61,8 @@ class MySQLPositionInitializerTest {
@Test
void assertGetCurrentPosition() throws SQLException {
- MySQLPositionInitializer mySQLPositionInitializer = new
MySQLPositionInitializer();
- BinlogPosition actual = mySQLPositionInitializer.init(dataSource, "");
+ MySQLPositionInitializer positionInitializer = new
MySQLPositionInitializer();
+ BinlogPosition actual = positionInitializer.init(dataSource, "");
assertThat(actual.getServerId(), is(SERVER_ID));
assertThat(actual.getFilename(), is(LOG_FILE_NAME));
assertThat(actual.getPosition(), is(LOG_POSITION));
diff --git
a/parser/sql/statement/src/test/java/org/apache/shardingsphere/sql/parser/sql/common/extractor/TableExtractorTest.java
b/parser/sql/statement/src/test/java/org/apache/shardingsphere/sql/parser/sql/common/extractor/TableExtractorTest.java
index 63180cb7c7c..97888a11ee6 100644
---
a/parser/sql/statement/src/test/java/org/apache/shardingsphere/sql/parser/sql/common/extractor/TableExtractorTest.java
+++
b/parser/sql/statement/src/test/java/org/apache/shardingsphere/sql/parser/sql/common/extractor/TableExtractorTest.java
@@ -92,14 +92,14 @@ class TableExtractorTest {
@Test
void assertExtractTablesFromInsert() {
- MySQLInsertStatement mySQLInsertStatement = new MySQLInsertStatement();
- mySQLInsertStatement.setTable(new SimpleTableSegment(new
TableNameSegment(122, 128, new IdentifierValue("t_order"))));
+ MySQLInsertStatement insertStatement = new MySQLInsertStatement();
+ insertStatement.setTable(new SimpleTableSegment(new
TableNameSegment(122, 128, new IdentifierValue("t_order"))));
Collection<AssignmentSegment> assignmentSegments = new LinkedList<>();
ColumnSegment columnSegment = new ColumnSegment(133, 136, new
IdentifierValue("id"));
columnSegment.setOwner(new OwnerSegment(130, 132, new
IdentifierValue("t_order")));
assignmentSegments.add(new ColumnAssignmentSegment(130, 140,
Collections.singletonList(columnSegment), new LiteralExpressionSegment(141,
142, 1)));
- mySQLInsertStatement.setOnDuplicateKeyColumns(new
OnDuplicateKeyColumnsSegment(130, 140, assignmentSegments));
- tableExtractor.extractTablesFromInsert(mySQLInsertStatement);
+ insertStatement.setOnDuplicateKeyColumns(new
OnDuplicateKeyColumnsSegment(130, 140, assignmentSegments));
+ tableExtractor.extractTablesFromInsert(insertStatement);
assertThat(tableExtractor.getRewriteTables().size(), is(2));
Iterator<SimpleTableSegment> tableSegmentIterator =
tableExtractor.getRewriteTables().iterator();
assertTableSegment(tableSegmentIterator.next(), 122, 128, "t_order");
diff --git
a/parser/sql/statement/src/test/java/org/apache/shardingsphere/sql/parser/sql/common/util/WhereExtractUtilsTest.java
b/parser/sql/statement/src/test/java/org/apache/shardingsphere/sql/parser/sql/common/util/WhereExtractUtilsTest.java
index c0dbc3f25fd..1b33759e24d 100644
---
a/parser/sql/statement/src/test/java/org/apache/shardingsphere/sql/parser/sql/common/util/WhereExtractUtilsTest.java
+++
b/parser/sql/statement/src/test/java/org/apache/shardingsphere/sql/parser/sql/common/util/WhereExtractUtilsTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.sql.parser.sql.common.util;
+import com.google.common.base.Preconditions;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.BinaryOperationExpression;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.subquery.SubquerySegment;
@@ -72,6 +73,7 @@ class WhereExtractUtilsTest {
selectStatement.setProjections(projections);
Collection<WhereSegment> subqueryWhereSegments =
WhereExtractUtils.getSubqueryWhereSegments(selectStatement);
WhereSegment actual = subqueryWhereSegments.iterator().next();
+
Preconditions.checkState(subQuerySelectStatement.getWhere().isPresent());
assertThat(actual.getExpr(),
is(subQuerySelectStatement.getWhere().get().getExpr()));
}
@@ -85,9 +87,9 @@ class WhereExtractUtilsTest {
new ColumnSegment(75, 83, new IdentifierValue("order_id")),
"=", "oi.order_id = o.order_id"));
MySQLSelectStatement subQuerySelectStatement = new
MySQLSelectStatement();
subQuerySelectStatement.setFrom(joinTableSegment);
- MySQLSelectStatement mySQLSelectStatement = new MySQLSelectStatement();
- mySQLSelectStatement.setFrom(new SubqueryTableSegment(new
SubquerySegment(20, 84, subQuerySelectStatement)));
- Collection<WhereSegment> subqueryWhereSegments =
WhereExtractUtils.getSubqueryWhereSegments(mySQLSelectStatement);
+ MySQLSelectStatement selectStatement = new MySQLSelectStatement();
+ selectStatement.setFrom(new SubqueryTableSegment(new
SubquerySegment(20, 84, subQuerySelectStatement)));
+ Collection<WhereSegment> subqueryWhereSegments =
WhereExtractUtils.getSubqueryWhereSegments(selectStatement);
WhereSegment actual = subqueryWhereSegments.iterator().next();
assertThat(actual.getExpr(), is(((JoinTableSegment)
subQuerySelectStatement.getFrom()).getCondition()));
}
diff --git
a/parser/sql/statement/src/test/java/org/apache/shardingsphere/sql/parser/sql/dialect/handler/dal/FlushStatementHandlerTest.java
b/parser/sql/statement/src/test/java/org/apache/shardingsphere/sql/parser/sql/dialect/handler/dal/FlushStatementHandlerTest.java
index ee46391a486..fff672c40e6 100644
---
a/parser/sql/statement/src/test/java/org/apache/shardingsphere/sql/parser/sql/dialect/handler/dal/FlushStatementHandlerTest.java
+++
b/parser/sql/statement/src/test/java/org/apache/shardingsphere/sql/parser/sql/dialect/handler/dal/FlushStatementHandlerTest.java
@@ -31,10 +31,10 @@ class FlushStatementHandlerTest {
@Test
void assertGetSimpleTableSegmentForMySQL() {
- MySQLFlushStatement mySQLFlushStatement = new MySQLFlushStatement();
-
assertTrue(FlushStatementHandler.getSimpleTableSegment(mySQLFlushStatement).isEmpty());
- mySQLFlushStatement.getTables().add(new SimpleTableSegment(new
TableNameSegment(0, 2, new IdentifierValue("foo_table"))));
-
assertThat(FlushStatementHandler.getSimpleTableSegment(mySQLFlushStatement),
is(mySQLFlushStatement.getTables()));
+ MySQLFlushStatement flushStatement = new MySQLFlushStatement();
+
assertTrue(FlushStatementHandler.getSimpleTableSegment(flushStatement).isEmpty());
+ flushStatement.getTables().add(new SimpleTableSegment(new
TableNameSegment(0, 2, new IdentifierValue("foo_table"))));
+
assertThat(FlushStatementHandler.getSimpleTableSegment(flushStatement),
is(flushStatement.getTables()));
}
@Test
diff --git
a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLAdminExecutorCreatorTest.java
b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLAdminExecutorCreatorTest.java
index bbbc8fe19b7..a482f350689 100644
---
a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLAdminExecutorCreatorTest.java
+++
b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLAdminExecutorCreatorTest.java
@@ -165,12 +165,12 @@ class MySQLAdminExecutorCreatorTest {
@Test
void assertCreateWithSelectStatementForShowConnectionId() {
- MySQLSelectStatement mySQLSelectStatement =
mock(MySQLSelectStatement.class);
- when(mySQLSelectStatement.getFrom()).thenReturn(null);
+ MySQLSelectStatement selectStatement =
mock(MySQLSelectStatement.class);
+ when(selectStatement.getFrom()).thenReturn(null);
ProjectionsSegment projectionsSegment = mock(ProjectionsSegment.class);
when(projectionsSegment.getProjections()).thenReturn(Collections.singletonList(new
ExpressionProjectionSegment(0, 10, "CONNECTION_ID()")));
-
when(mySQLSelectStatement.getProjections()).thenReturn(projectionsSegment);
-
when(sqlStatementContext.getSqlStatement()).thenReturn(mySQLSelectStatement);
+ when(selectStatement.getProjections()).thenReturn(projectionsSegment);
+
when(sqlStatementContext.getSqlStatement()).thenReturn(selectStatement);
Optional<DatabaseAdminExecutor> actual = new
MySQLAdminExecutorCreator().create(sqlStatementContext, "select
CONNECTION_ID()", "", Collections.emptyList());
assertTrue(actual.isPresent());
assertThat(actual.get(), instanceOf(ShowConnectionIdExecutor.class));
@@ -178,12 +178,12 @@ class MySQLAdminExecutorCreatorTest {
@Test
void assertCreateWithSelectStatementForShowVersion() {
- MySQLSelectStatement mySQLSelectStatement =
mock(MySQLSelectStatement.class);
- when(mySQLSelectStatement.getFrom()).thenReturn(null);
+ MySQLSelectStatement selectStatement =
mock(MySQLSelectStatement.class);
+ when(selectStatement.getFrom()).thenReturn(null);
ProjectionsSegment projectionsSegment = mock(ProjectionsSegment.class);
when(projectionsSegment.getProjections()).thenReturn(Collections.singletonList(new
ExpressionProjectionSegment(0, 10, "version()")));
-
when(mySQLSelectStatement.getProjections()).thenReturn(projectionsSegment);
-
when(sqlStatementContext.getSqlStatement()).thenReturn(mySQLSelectStatement);
+ when(selectStatement.getProjections()).thenReturn(projectionsSegment);
+
when(sqlStatementContext.getSqlStatement()).thenReturn(selectStatement);
Optional<DatabaseAdminExecutor> actual = new
MySQLAdminExecutorCreator().create(sqlStatementContext, "select version()", "",
Collections.emptyList());
assertTrue(actual.isPresent());
assertThat(actual.get(), instanceOf(ShowVersionExecutor.class));
@@ -191,12 +191,12 @@ class MySQLAdminExecutorCreatorTest {
@Test
void assertCreateWithSelectStatementForCurrentUser() {
- MySQLSelectStatement mySQLSelectStatement =
mock(MySQLSelectStatement.class);
- when(mySQLSelectStatement.getFrom()).thenReturn(null);
+ MySQLSelectStatement selectStatement =
mock(MySQLSelectStatement.class);
+ when(selectStatement.getFrom()).thenReturn(null);
ProjectionsSegment projectionsSegment = mock(ProjectionsSegment.class);
when(projectionsSegment.getProjections()).thenReturn(Collections.singletonList(new
ExpressionProjectionSegment(0, 10, "CURRENT_USER()")));
-
when(mySQLSelectStatement.getProjections()).thenReturn(projectionsSegment);
-
when(sqlStatementContext.getSqlStatement()).thenReturn(mySQLSelectStatement);
+ when(selectStatement.getProjections()).thenReturn(projectionsSegment);
+
when(sqlStatementContext.getSqlStatement()).thenReturn(selectStatement);
Optional<DatabaseAdminExecutor> actual = new
MySQLAdminExecutorCreator().create(sqlStatementContext, "select
CURRENT_USER()", "", Collections.emptyList());
assertTrue(actual.isPresent());
assertThat(actual.get(), instanceOf(ShowCurrentUserExecutor.class));
@@ -205,14 +205,14 @@ class MySQLAdminExecutorCreatorTest {
@Test
void assertCreateWithSelectStatementForTransactionReadOnly() {
initProxyContext(Collections.emptyMap());
- MySQLSelectStatement mySQLSelectStatement =
mock(MySQLSelectStatement.class);
- when(mySQLSelectStatement.getFrom()).thenReturn(null);
+ MySQLSelectStatement selectStatement =
mock(MySQLSelectStatement.class);
+ when(selectStatement.getFrom()).thenReturn(null);
ProjectionsSegment projectionsSegment = mock(ProjectionsSegment.class);
VariableSegment variableSegment = new VariableSegment(0, 0,
"transaction_read_only");
variableSegment.setScope("SESSION");
when(projectionsSegment.getProjections()).thenReturn(Collections.singletonList(new
ExpressionProjectionSegment(0, 10, "@@session.transaction_read_only",
variableSegment)));
-
when(mySQLSelectStatement.getProjections()).thenReturn(projectionsSegment);
-
when(sqlStatementContext.getSqlStatement()).thenReturn(mySQLSelectStatement);
+ when(selectStatement.getProjections()).thenReturn(projectionsSegment);
+
when(sqlStatementContext.getSqlStatement()).thenReturn(selectStatement);
Optional<DatabaseAdminExecutor> actual = new
MySQLAdminExecutorCreator().create(sqlStatementContext, "select
@@session.transaction_read_only", "", Collections.emptyList());
assertTrue(actual.isPresent());
assertThat(actual.get(),
instanceOf(MySQLSystemVariableQueryExecutor.class));
@@ -221,14 +221,14 @@ class MySQLAdminExecutorCreatorTest {
@Test
void assertCreateWithSelectStatementForTransactionIsolation() {
initProxyContext(Collections.emptyMap());
- MySQLSelectStatement mySQLSelectStatement =
mock(MySQLSelectStatement.class);
- when(mySQLSelectStatement.getFrom()).thenReturn(null);
+ MySQLSelectStatement selectStatement =
mock(MySQLSelectStatement.class);
+ when(selectStatement.getFrom()).thenReturn(null);
ProjectionsSegment projectionsSegment = mock(ProjectionsSegment.class);
VariableSegment variableSegment = new VariableSegment(0, 0,
"transaction_isolation");
variableSegment.setScope("SESSION");
when(projectionsSegment.getProjections()).thenReturn(Collections.singletonList(new
ExpressionProjectionSegment(0, 10, "@@session.transaction_isolation",
variableSegment)));
-
when(mySQLSelectStatement.getProjections()).thenReturn(projectionsSegment);
-
when(sqlStatementContext.getSqlStatement()).thenReturn(mySQLSelectStatement);
+ when(selectStatement.getProjections()).thenReturn(projectionsSegment);
+
when(sqlStatementContext.getSqlStatement()).thenReturn(selectStatement);
Optional<DatabaseAdminExecutor> actual = new
MySQLAdminExecutorCreator().create(sqlStatementContext, "select
@@session.transaction_isolation", "", Collections.emptyList());
assertTrue(actual.isPresent());
assertThat(actual.get(),
instanceOf(MySQLSystemVariableQueryExecutor.class));
@@ -237,12 +237,12 @@ class MySQLAdminExecutorCreatorTest {
@Test
void assertCreateWithSelectStatementForShowDatabase() {
initProxyContext(Collections.emptyMap());
- MySQLSelectStatement mySQLSelectStatement =
mock(MySQLSelectStatement.class);
- when(mySQLSelectStatement.getFrom()).thenReturn(null);
+ MySQLSelectStatement selectStatement =
mock(MySQLSelectStatement.class);
+ when(selectStatement.getFrom()).thenReturn(null);
ProjectionsSegment projectionsSegment = mock(ProjectionsSegment.class);
when(projectionsSegment.getProjections()).thenReturn(Collections.singletonList(new
ExpressionProjectionSegment(0, 10, "DATABASE()")));
-
when(mySQLSelectStatement.getProjections()).thenReturn(projectionsSegment);
-
when(sqlStatementContext.getSqlStatement()).thenReturn(mySQLSelectStatement);
+ when(selectStatement.getProjections()).thenReturn(projectionsSegment);
+
when(sqlStatementContext.getSqlStatement()).thenReturn(selectStatement);
Optional<DatabaseAdminExecutor> actual = new
MySQLAdminExecutorCreator().create(sqlStatementContext, "select DATABASE()",
"", Collections.emptyList());
assertTrue(actual.isPresent());
assertThat(actual.get(),
instanceOf(ShowCurrentDatabaseExecutor.class));
@@ -251,12 +251,12 @@ class MySQLAdminExecutorCreatorTest {
@Test
void assertCreateWithOtherSelectStatementForNoResource() {
initProxyContext(Collections.emptyMap());
- MySQLSelectStatement mySQLSelectStatement =
mock(MySQLSelectStatement.class);
- when(mySQLSelectStatement.getFrom()).thenReturn(null);
+ MySQLSelectStatement selectStatement =
mock(MySQLSelectStatement.class);
+ when(selectStatement.getFrom()).thenReturn(null);
ProjectionsSegment projectionsSegment = mock(ProjectionsSegment.class);
when(projectionsSegment.getProjections()).thenReturn(Collections.singletonList(new
ExpressionProjectionSegment(0, 10, "CURRENT_DATE()")));
-
when(mySQLSelectStatement.getProjections()).thenReturn(projectionsSegment);
-
when(sqlStatementContext.getSqlStatement()).thenReturn(mySQLSelectStatement);
+ when(selectStatement.getProjections()).thenReturn(projectionsSegment);
+
when(sqlStatementContext.getSqlStatement()).thenReturn(selectStatement);
Optional<DatabaseAdminExecutor> actual = new
MySQLAdminExecutorCreator().create(sqlStatementContext, "select
CURRENT_DATE()", null, Collections.emptyList());
assertTrue(actual.isPresent());
assertThat(actual.get(), instanceOf(NoResourceShowExecutor.class));
@@ -270,12 +270,12 @@ class MySQLAdminExecutorCreatorTest {
initProxyContext(result);
when(ProxyContext.getInstance().getAllDatabaseNames()).thenReturn(Collections.singleton("db_0"));
when(ProxyContext.getInstance().getDatabase("db_0")).thenReturn(database);
- MySQLSelectStatement mySQLSelectStatement =
mock(MySQLSelectStatement.class);
- when(mySQLSelectStatement.getFrom()).thenReturn(null);
+ MySQLSelectStatement selectStatement =
mock(MySQLSelectStatement.class);
+ when(selectStatement.getFrom()).thenReturn(null);
ProjectionsSegment projectionsSegment = mock(ProjectionsSegment.class);
when(projectionsSegment.getProjections()).thenReturn(Collections.singletonList(new
ExpressionProjectionSegment(0, 10, "CURRENT_DATE()")));
-
when(mySQLSelectStatement.getProjections()).thenReturn(projectionsSegment);
-
when(sqlStatementContext.getSqlStatement()).thenReturn(mySQLSelectStatement);
+ when(selectStatement.getProjections()).thenReturn(projectionsSegment);
+
when(sqlStatementContext.getSqlStatement()).thenReturn(selectStatement);
Optional<DatabaseAdminExecutor> actual = new
MySQLAdminExecutorCreator().create(sqlStatementContext, "select
CURRENT_DATE()", "test_db", Collections.emptyList());
assertThat(actual, is(Optional.empty()));
}
@@ -288,12 +288,12 @@ class MySQLAdminExecutorCreatorTest {
initProxyContext(result);
when(ProxyContext.getInstance().getAllDatabaseNames()).thenReturn(Collections.singleton("db_0"));
when(ProxyContext.getInstance().getDatabase("db_0")).thenReturn(database);
- MySQLSelectStatement mySQLSelectStatement =
mock(MySQLSelectStatement.class);
- when(mySQLSelectStatement.getFrom()).thenReturn(null);
+ MySQLSelectStatement selectStatement =
mock(MySQLSelectStatement.class);
+ when(selectStatement.getFrom()).thenReturn(null);
ProjectionsSegment projectionsSegment = mock(ProjectionsSegment.class);
when(projectionsSegment.getProjections()).thenReturn(Collections.singletonList(new
ExpressionProjectionSegment(0, 10, "CURRENT_DATE()")));
-
when(mySQLSelectStatement.getProjections()).thenReturn(projectionsSegment);
-
when(sqlStatementContext.getSqlStatement()).thenReturn(mySQLSelectStatement);
+ when(selectStatement.getProjections()).thenReturn(projectionsSegment);
+
when(sqlStatementContext.getSqlStatement()).thenReturn(selectStatement);
Optional<DatabaseAdminExecutor> actual = new
MySQLAdminExecutorCreator().create(sqlStatementContext, "select
CURRENT_DATE()", null, Collections.emptyList());
assertTrue(actual.isPresent());
assertThat(actual.get(),
instanceOf(UnicastResourceShowExecutor.class));
@@ -304,9 +304,9 @@ class MySQLAdminExecutorCreatorTest {
initProxyContext(Collections.emptyMap());
SimpleTableSegment tableSegment = new SimpleTableSegment(new
TableNameSegment(10, 13, new IdentifierValue("ENGINES")));
tableSegment.setOwner(new OwnerSegment(7, 8, new
IdentifierValue("information_schema")));
- MySQLSelectStatement mySQLSelectStatement =
mock(MySQLSelectStatement.class);
- when(mySQLSelectStatement.getFrom()).thenReturn(tableSegment);
-
when(sqlStatementContext.getSqlStatement()).thenReturn(mySQLSelectStatement);
+ MySQLSelectStatement selectStatement =
mock(MySQLSelectStatement.class);
+ when(selectStatement.getFrom()).thenReturn(tableSegment);
+
when(sqlStatementContext.getSqlStatement()).thenReturn(selectStatement);
Optional<DatabaseAdminExecutor> actual = new
MySQLAdminExecutorCreator().create(sqlStatementContext, "select ENGINE from
ENGINES", "information_schema", Collections.emptyList());
assertTrue(actual.isPresent());
assertThat(actual.get(),
instanceOf(DefaultDatabaseMetaDataExecutor.class));
@@ -317,9 +317,9 @@ class MySQLAdminExecutorCreatorTest {
initProxyContext(Collections.emptyMap());
SimpleTableSegment tableSegment = new SimpleTableSegment(new
TableNameSegment(10, 13, new IdentifierValue("SCHEMATA")));
tableSegment.setOwner(new OwnerSegment(7, 8, new
IdentifierValue("information_schema")));
- MySQLSelectStatement mySQLSelectStatement =
mock(MySQLSelectStatement.class);
- when(mySQLSelectStatement.getFrom()).thenReturn(tableSegment);
-
when(sqlStatementContext.getSqlStatement()).thenReturn(mySQLSelectStatement);
+ MySQLSelectStatement selectStatement =
mock(MySQLSelectStatement.class);
+ when(selectStatement.getFrom()).thenReturn(tableSegment);
+
when(sqlStatementContext.getSqlStatement()).thenReturn(selectStatement);
Optional<DatabaseAdminExecutor> actual = new
MySQLAdminExecutorCreator().create(sqlStatementContext, "select SCHEMA_NAME
from SCHEMATA", "information_schema", Collections.emptyList());
assertTrue(actual.isPresent());
assertThat(actual.get(),
instanceOf(SelectInformationSchemataExecutor.class));
@@ -333,9 +333,9 @@ class MySQLAdminExecutorCreatorTest {
initProxyContext(Collections.emptyMap());
SimpleTableSegment tableSegment = new SimpleTableSegment(new
TableNameSegment(10, 13, new IdentifierValue("CHARACTER_SETS")));
tableSegment.setOwner(new OwnerSegment(7, 8, new
IdentifierValue("information_schema")));
- MySQLSelectStatement mySQLSelectStatement =
mock(MySQLSelectStatement.class);
- when(mySQLSelectStatement.getFrom()).thenReturn(tableSegment);
-
when(sqlStatementContext.getSqlStatement()).thenReturn(mySQLSelectStatement);
+ MySQLSelectStatement selectStatement =
mock(MySQLSelectStatement.class);
+ when(selectStatement.getFrom()).thenReturn(tableSegment);
+
when(sqlStatementContext.getSqlStatement()).thenReturn(selectStatement);
Optional<DatabaseAdminExecutor> actual = new
MySQLAdminExecutorCreator().create(sqlStatementContext, "select
CHARACTER_SET_NAME from CHARACTER_SETS", "", Collections.emptyList());
assertFalse(actual.isPresent());
}
@@ -345,9 +345,9 @@ class MySQLAdminExecutorCreatorTest {
initProxyContext(Collections.emptyMap());
SimpleTableSegment tableSegment = new SimpleTableSegment(new
TableNameSegment(10, 13, new IdentifierValue("accounts")));
tableSegment.setOwner(new OwnerSegment(7, 8, new
IdentifierValue("performance_schema")));
- MySQLSelectStatement mySQLSelectStatement =
mock(MySQLSelectStatement.class);
- when(mySQLSelectStatement.getFrom()).thenReturn(tableSegment);
-
when(sqlStatementContext.getSqlStatement()).thenReturn(mySQLSelectStatement);
+ MySQLSelectStatement selectStatement =
mock(MySQLSelectStatement.class);
+ when(selectStatement.getFrom()).thenReturn(tableSegment);
+
when(sqlStatementContext.getSqlStatement()).thenReturn(selectStatement);
Optional<DatabaseAdminExecutor> actual = new
MySQLAdminExecutorCreator().create(sqlStatementContext, "select * from
accounts", "", Collections.emptyList());
assertFalse(actual.isPresent());
}