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 ac0f7ad0 Refactor RDL CREATE DATASOURCE to ADD RESOURCE (#8648)
ac0f7ad0 is described below
commit ac0f7ad0ef361582320430d13cb5e2f941edf45e
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Dec 16 16:47:25 2020 +0800
Refactor RDL CREATE DATASOURCE to ADD RESOURCE (#8648)
---
.../src/main/antlr4/imports/Keyword.g4 | 12 ++++++++--
.../src/main/antlr4/imports/RDLStatement.g4 | 4 ++--
.../src/main/antlr4/imports/RQLStatement.g4 | 4 ++--
.../distsql/parser/autogen/DistSQLStatement.g4 | 4 ++--
.../distsql/parser/core/DistSQLVisitor.java | 26 +++++++++++-----------
...nnectionSegment.java => DataSourceSegment.java} | 4 ++--
...esStatement.java => AddResourcesStatement.java} | 8 +++----
...sStatement.java => ShowResourcesStatement.java} | 4 ++--
...text.java => AddResourcesStatementContext.java} | 8 +++----
...ext.java => ShowResourcesStatementContext.java} | 8 +++----
.../text/distsql/DistSQLBackendHandlerFactory.java | 6 ++---
.../text/distsql/rdl/RDLBackendHandler.java | 14 ++++++------
.../rql/DataSourcesQueryBackendHandler.java | 12 +++++-----
.../text/distsql/RDLBackendHandlerTest.java | 6 ++---
...CreateDataSourcesStatementContextConverter.java | 12 +++++-----
...teDataSourcesStatementContextConverterTest.java | 16 ++++++-------
.../command/query/PostgreSQLCommand.java | 4 ++--
.../command/query/PostgreSQLCommandTest.java | 4 ++--
18 files changed, 82 insertions(+), 74 deletions(-)
diff --git
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/Keyword.g4
b/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/Keyword.g4
index 02a27e6..79e8b81 100644
---
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/Keyword.g4
+++
b/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/Keyword.g4
@@ -23,6 +23,10 @@ WS
: [ \t\r\n] + ->skip
;
+ADD
+ : A D D
+ ;
+
CREATE
: C R E A T E
;
@@ -35,8 +39,12 @@ SHOW
: S H O W
;
-DATASOURCES
- : D A T A S O U R C E S
+RESOURCE
+ : R E S O U R C E
+ ;
+
+RESOURCES
+ : R E S O U R C E S
;
RULE
diff --git
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RDLStatement.g4
b/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RDLStatement.g4
index 16361de..d2438c9 100644
---
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RDLStatement.g4
+++
b/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RDLStatement.g4
@@ -19,8 +19,8 @@ grammar RDLStatement;
import Keyword, Literals, Symbol;
-createDataSources
- : CREATE DATASOURCES LP dataSource (COMMA dataSource)* RP
+addResource
+ : ADD RESOURCE LP dataSource (COMMA dataSource)* RP
;
dataSource
diff --git
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RQLStatement.g4
b/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RQLStatement.g4
index 4bd2e37..8280e6d 100644
---
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RQLStatement.g4
+++
b/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RQLStatement.g4
@@ -19,8 +19,8 @@ grammar RQLStatement;
import Keyword, Literals, Symbol;
-showDataSources
- : SHOW DATASOURCES (FROM schemaName)?
+showResources
+ : SHOW RESOURCES (FROM schemaName)?
;
showRule
diff --git
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/DistSQLStatement.g4
b/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/DistSQLStatement.g4
index 87debf7..773d631 100644
---
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/DistSQLStatement.g4
+++
b/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/DistSQLStatement.g4
@@ -20,10 +20,10 @@ grammar DistSQLStatement;
import Symbol, RDLStatement, RQLStatement;
execute
- : (createDataSources
+ : (addResource
| createShardingRule
| dropShardingRule
- | showDataSources
+ | showResources
| showRule
) SEMI?
;
diff --git
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/java/org/apache/shardingsphere/distsql/parser/core/DistSQLVisitor.java
b/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/java/org/apache/shardingsphere/distsql/parser/core/DistSQLVisitor.java
index b332118..944cae5 100644
---
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/java/org/apache/shardingsphere/distsql/parser/core/DistSQLVisitor.java
+++
b/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/java/org/apache/shardingsphere/distsql/parser/core/DistSQLVisitor.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.distsql.parser.core;
import
org.apache.shardingsphere.distsql.parser.autogen.DistSQLStatementBaseVisitor;
-import
org.apache.shardingsphere.distsql.parser.autogen.DistSQLStatementParser.CreateDataSourcesContext;
+import
org.apache.shardingsphere.distsql.parser.autogen.DistSQLStatementParser.AddResourceContext;
import
org.apache.shardingsphere.distsql.parser.autogen.DistSQLStatementParser.CreateShardingRuleContext;
import
org.apache.shardingsphere.distsql.parser.autogen.DistSQLStatementParser.DataSourceContext;
import
org.apache.shardingsphere.distsql.parser.autogen.DistSQLStatementParser.DataSourceDefinitionContext;
@@ -27,15 +27,15 @@ import
org.apache.shardingsphere.distsql.parser.autogen.DistSQLStatementParser.S
import
org.apache.shardingsphere.distsql.parser.autogen.DistSQLStatementParser.ShardingAlgorithmPropertiesContext;
import
org.apache.shardingsphere.distsql.parser.autogen.DistSQLStatementParser.ShardingAlgorithmPropertyContext;
import
org.apache.shardingsphere.distsql.parser.autogen.DistSQLStatementParser.ShardingTableRuleDefinitionContext;
-import
org.apache.shardingsphere.distsql.parser.autogen.DistSQLStatementParser.ShowDataSourcesContext;
+import
org.apache.shardingsphere.distsql.parser.autogen.DistSQLStatementParser.ShowResourcesContext;
import
org.apache.shardingsphere.distsql.parser.autogen.DistSQLStatementParser.ShowRuleContext;
import
org.apache.shardingsphere.distsql.parser.autogen.DistSQLStatementParser.TableNameContext;
-import
org.apache.shardingsphere.distsql.parser.segment.DataSourceConnectionSegment;
+import org.apache.shardingsphere.distsql.parser.segment.DataSourceSegment;
import org.apache.shardingsphere.distsql.parser.segment.TableRuleSegment;
-import
org.apache.shardingsphere.distsql.parser.statement.rdl.create.impl.CreateDataSourcesStatement;
+import
org.apache.shardingsphere.distsql.parser.statement.rdl.create.impl.AddResourcesStatement;
import
org.apache.shardingsphere.distsql.parser.statement.rdl.create.impl.CreateShardingRuleStatement;
import
org.apache.shardingsphere.distsql.parser.statement.rdl.drop.impl.DropShardingRuleStatement;
-import
org.apache.shardingsphere.distsql.parser.statement.rql.show.ShowDataSourcesStatement;
+import
org.apache.shardingsphere.distsql.parser.statement.rql.show.ShowResourcesStatement;
import
org.apache.shardingsphere.distsql.parser.statement.rql.show.ShowRuleStatement;
import org.apache.shardingsphere.sql.parser.api.visitor.ASTNode;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.SchemaSegment;
@@ -52,24 +52,24 @@ import java.util.LinkedList;
public final class DistSQLVisitor extends DistSQLStatementBaseVisitor<ASTNode>
{
@Override
- public ASTNode visitCreateDataSources(final CreateDataSourcesContext ctx) {
- Collection<DataSourceConnectionSegment> connectionInfos = new
LinkedList<>();
+ public ASTNode visitAddResource(final AddResourceContext ctx) {
+ Collection<DataSourceSegment> connectionInfos = new LinkedList<>();
for (DataSourceContext each : ctx.dataSource()) {
- connectionInfos.add((DataSourceConnectionSegment) visit(each));
+ connectionInfos.add((DataSourceSegment) visit(each));
}
- return new CreateDataSourcesStatement(connectionInfos);
+ return new AddResourcesStatement(connectionInfos);
}
@Override
public ASTNode visitDataSource(final DataSourceContext ctx) {
- DataSourceConnectionSegment result = (DataSourceConnectionSegment)
visit(ctx.dataSourceDefinition());
+ DataSourceSegment result = (DataSourceSegment)
visit(ctx.dataSourceDefinition());
result.setName(ctx.dataSourceName().getText());
return result;
}
@Override
public ASTNode visitDataSourceDefinition(final DataSourceDefinitionContext
ctx) {
- DataSourceConnectionSegment result = new DataSourceConnectionSegment();
+ DataSourceSegment result = new DataSourceSegment();
result.setHostName(ctx.hostName().getText());
result.setPort(ctx.port().getText());
result.setDb(ctx.dbName().getText());
@@ -124,8 +124,8 @@ public final class DistSQLVisitor extends
DistSQLStatementBaseVisitor<ASTNode> {
}
@Override
- public ASTNode visitShowDataSources(final ShowDataSourcesContext ctx) {
- return new ShowDataSourcesStatement(null == ctx.schemaName() ? null :
(SchemaSegment) visit(ctx.schemaName()));
+ public ASTNode visitShowResources(final ShowResourcesContext ctx) {
+ return new ShowResourcesStatement(null == ctx.schemaName() ? null :
(SchemaSegment) visit(ctx.schemaName()));
}
@Override
diff --git
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-statement/src/main/java/org/apache/shardingsphere/distsql/parser/segment/DataSourceConnectionSegment.java
b/shardingsphere-distsql-parser/shardingsphere-distsql-parser-statement/src/main/java/org/apache/shardingsphere/distsql/parser/segment/DataSourceSegment.java
similarity index 91%
rename from
shardingsphere-distsql-parser/shardingsphere-distsql-parser-statement/src/main/java/org/apache/shardingsphere/distsql/parser/segment/DataSourceConnectionSegment.java
rename to
shardingsphere-distsql-parser/shardingsphere-distsql-parser-statement/src/main/java/org/apache/shardingsphere/distsql/parser/segment/DataSourceSegment.java
index ae6d09c..9eb9cf6 100644
---
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-statement/src/main/java/org/apache/shardingsphere/distsql/parser/segment/DataSourceConnectionSegment.java
+++
b/shardingsphere-distsql-parser/shardingsphere-distsql-parser-statement/src/main/java/org/apache/shardingsphere/distsql/parser/segment/DataSourceSegment.java
@@ -22,11 +22,11 @@ import lombok.Setter;
import org.apache.shardingsphere.sql.parser.api.visitor.ASTNode;
/**
- * Data source connection segment.
+ * Data source segment.
*/
@Getter
@Setter
-public final class DataSourceConnectionSegment implements ASTNode {
+public final class DataSourceSegment implements ASTNode {
private String name;
diff --git
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/rdl/create/impl/CreateDataSourcesStatement.java
b/shardingsphere-distsql-parser/shardingsphere-distsql-parser-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/rdl/create/impl/AddResourcesStatement.java
similarity index 85%
rename from
shardingsphere-distsql-parser/shardingsphere-distsql-parser-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/rdl/create/impl/CreateDataSourcesStatement.java
rename to
shardingsphere-distsql-parser/shardingsphere-distsql-parser-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/rdl/create/impl/AddResourcesStatement.java
index c41752a..05eaff9 100644
---
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/rdl/create/impl/CreateDataSourcesStatement.java
+++
b/shardingsphere-distsql-parser/shardingsphere-distsql-parser-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/rdl/create/impl/AddResourcesStatement.java
@@ -19,17 +19,17 @@ package
org.apache.shardingsphere.distsql.parser.statement.rdl.create.impl;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
-import
org.apache.shardingsphere.distsql.parser.segment.DataSourceConnectionSegment;
+import org.apache.shardingsphere.distsql.parser.segment.DataSourceSegment;
import
org.apache.shardingsphere.distsql.parser.statement.rdl.create.CreateRDLStatement;
import java.util.Collection;
/**
- * Create dataSource statement.
+ * Add resource statement.
*/
@RequiredArgsConstructor
@Getter
-public final class CreateDataSourcesStatement extends CreateRDLStatement {
+public final class AddResourcesStatement extends CreateRDLStatement {
- private final Collection<DataSourceConnectionSegment> connectionInfos;
+ private final Collection<DataSourceSegment> dataSources;
}
diff --git
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/rql/show/ShowDataSourcesStatement.java
b/shardingsphere-distsql-parser/shardingsphere-distsql-parser-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/rql/show/ShowResourcesStatement.java
similarity index 92%
rename from
shardingsphere-distsql-parser/shardingsphere-distsql-parser-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/rql/show/ShowDataSourcesStatement.java
rename to
shardingsphere-distsql-parser/shardingsphere-distsql-parser-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/rql/show/ShowResourcesStatement.java
index 60476a9..da015a9 100644
---
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/rql/show/ShowDataSourcesStatement.java
+++
b/shardingsphere-distsql-parser/shardingsphere-distsql-parser-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/rql/show/ShowResourcesStatement.java
@@ -23,11 +23,11 @@ import
org.apache.shardingsphere.distsql.parser.statement.rql.RQLStatement;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.SchemaSegment;
/**
- * Show data sources statement.
+ * Show resources statement.
*/
@RequiredArgsConstructor
@Getter
-public final class ShowDataSourcesStatement extends RQLStatement {
+public final class ShowResourcesStatement extends RQLStatement {
private final SchemaSegment schemaName;
}
diff --git
a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/rdl/CreateDataSourcesStatementContext.java
b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/rdl/AddResourcesStatementContext.java
similarity index 79%
rename from
shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/rdl/CreateDataSourcesStatementContext.java
rename to
shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/rdl/AddResourcesStatementContext.java
index 08a696c..439bf50 100644
---
a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/rdl/CreateDataSourcesStatementContext.java
+++
b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/rdl/AddResourcesStatementContext.java
@@ -18,19 +18,19 @@
package org.apache.shardingsphere.infra.binder.statement.rdl;
import lombok.Getter;
-import
org.apache.shardingsphere.distsql.parser.statement.rdl.create.impl.CreateDataSourcesStatement;
+import
org.apache.shardingsphere.distsql.parser.statement.rdl.create.impl.AddResourcesStatement;
import
org.apache.shardingsphere.infra.binder.statement.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
/**
- * Create dataSource statement context.
+ * Add resource statement context.
*/
@Getter
-public final class CreateDataSourcesStatementContext extends
CommonSQLStatementContext<CreateDataSourcesStatement> {
+public final class AddResourcesStatementContext extends
CommonSQLStatementContext<AddResourcesStatement> {
private final DatabaseType databaseType;
- public CreateDataSourcesStatementContext(final CreateDataSourcesStatement
sqlStatement, final DatabaseType databaseType) {
+ public AddResourcesStatementContext(final AddResourcesStatement
sqlStatement, final DatabaseType databaseType) {
super(sqlStatement);
this.databaseType = databaseType;
}
diff --git
a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/rdl/ShowDataSourcesStatementContext.java
b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/rdl/ShowResourcesStatementContext.java
similarity index 79%
rename from
shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/rdl/ShowDataSourcesStatementContext.java
rename to
shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/rdl/ShowResourcesStatementContext.java
index 8dbef02..2d0a82a 100644
---
a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/rdl/ShowDataSourcesStatementContext.java
+++
b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/rdl/ShowResourcesStatementContext.java
@@ -17,15 +17,15 @@
package org.apache.shardingsphere.infra.binder.statement.rdl;
-import
org.apache.shardingsphere.distsql.parser.statement.rql.show.ShowDataSourcesStatement;
+import
org.apache.shardingsphere.distsql.parser.statement.rql.show.ShowResourcesStatement;
import
org.apache.shardingsphere.infra.binder.statement.CommonSQLStatementContext;
/**
- * Show data sources statement context.
+ * Show resources statement context.
*/
-public final class ShowDataSourcesStatementContext extends
CommonSQLStatementContext<ShowDataSourcesStatement> {
+public final class ShowResourcesStatementContext extends
CommonSQLStatementContext<ShowResourcesStatement> {
- public ShowDataSourcesStatementContext(final ShowDataSourcesStatement
sqlStatement) {
+ public ShowResourcesStatementContext(final ShowResourcesStatement
sqlStatement) {
super(sqlStatement);
}
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/DistSQLBackendHandlerFactory.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/DistSQLBackendHandlerFactory.java
index 67a844c..a365a59 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/DistSQLBackendHandlerFactory.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/DistSQLBackendHandlerFactory.java
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.proxy.backend.text.distsql;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.distsql.parser.statement.rdl.RDLStatement;
-import
org.apache.shardingsphere.distsql.parser.statement.rql.show.ShowDataSourcesStatement;
+import
org.apache.shardingsphere.distsql.parser.statement.rql.show.ShowResourcesStatement;
import
org.apache.shardingsphere.distsql.parser.statement.rql.show.ShowRuleStatement;
import
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
import org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandler;
@@ -50,8 +50,8 @@ public final class DistSQLBackendHandlerFactory {
if (sqlStatement instanceof ShowRuleStatement) {
return Optional.of(new RuleQueryBackendHandler((ShowRuleStatement)
sqlStatement, backendConnection));
}
- if (sqlStatement instanceof ShowDataSourcesStatement) {
- return Optional.of(new
DataSourcesQueryBackendHandler((ShowDataSourcesStatement) sqlStatement,
backendConnection));
+ if (sqlStatement instanceof ShowResourcesStatement) {
+ return Optional.of(new
DataSourcesQueryBackendHandler((ShowResourcesStatement) sqlStatement,
backendConnection));
}
if (sqlStatement instanceof RDLStatement || sqlStatement instanceof
CreateDatabaseStatement || sqlStatement instanceof DropDatabaseStatement) {
return Optional.of(new RDLBackendHandler(sqlStatement,
backendConnection));
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/RDLBackendHandler.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/RDLBackendHandler.java
index 51ef3b1..6b67d90 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/RDLBackendHandler.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/RDLBackendHandler.java
@@ -19,7 +19,7 @@ package
org.apache.shardingsphere.proxy.backend.text.distsql.rdl;
import com.google.common.base.Joiner;
import lombok.RequiredArgsConstructor;
-import
org.apache.shardingsphere.distsql.parser.statement.rdl.create.impl.CreateDataSourcesStatement;
+import
org.apache.shardingsphere.distsql.parser.statement.rdl.create.impl.AddResourcesStatement;
import
org.apache.shardingsphere.distsql.parser.statement.rdl.create.impl.CreateShardingRuleStatement;
import
org.apache.shardingsphere.distsql.parser.statement.rdl.drop.impl.DropShardingRuleStatement;
import
org.apache.shardingsphere.governance.core.event.model.datasource.DataSourcePersistEvent;
@@ -28,7 +28,7 @@ import
org.apache.shardingsphere.governance.core.event.model.schema.SchemaNamePe
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import
org.apache.shardingsphere.infra.binder.statement.ddl.CreateDatabaseStatementContext;
import
org.apache.shardingsphere.infra.binder.statement.ddl.DropDatabaseStatementContext;
-import
org.apache.shardingsphere.infra.binder.statement.rdl.CreateDataSourcesStatementContext;
+import
org.apache.shardingsphere.infra.binder.statement.rdl.AddResourcesStatementContext;
import
org.apache.shardingsphere.infra.binder.statement.rdl.CreateShardingRuleStatementContext;
import
org.apache.shardingsphere.infra.binder.statement.rdl.DropShardingRuleStatementContext;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
@@ -95,7 +95,7 @@ public final class RDLBackendHandler implements
TextProtocolBackendHandler {
return new UpdateResponseHeader(context.getSqlStatement());
}
- private ResponseHeader execute(final CreateDataSourcesStatementContext
context) {
+ private ResponseHeader execute(final AddResourcesStatementContext context)
{
Map<String, YamlDataSourceParameter> parameters =
CreateDataSourcesStatementContextConverter.convert(context);
Map<String, DataSourceConfiguration> dataSources =
DataSourceParameterConverter.getDataSourceConfigurationMap(
DataSourceParameterConverter.getDataSourceParameterMapFromYamlConfiguration(parameters));
@@ -201,8 +201,8 @@ public final class RDLBackendHandler implements
TextProtocolBackendHandler {
private SQLStatementContext<?> getSQLStatementContext() {
DatabaseType databaseType =
ProxyContext.getInstance().getMetaDataContexts().getMetaData(backendConnection.getSchemaName()).getResource().getDatabaseType();
- if (sqlStatement instanceof CreateDataSourcesStatement) {
- return new
CreateDataSourcesStatementContext((CreateDataSourcesStatement) sqlStatement,
databaseType);
+ if (sqlStatement instanceof AddResourcesStatement) {
+ return new AddResourcesStatementContext((AddResourcesStatement)
sqlStatement, databaseType);
}
if (sqlStatement instanceof CreateShardingRuleStatement) {
return new
CreateShardingRuleStatementContext((CreateShardingRuleStatement) sqlStatement);
@@ -223,8 +223,8 @@ public final class RDLBackendHandler implements
TextProtocolBackendHandler {
if (context instanceof CreateDatabaseStatementContext) {
return execute((CreateDatabaseStatementContext) context);
}
- if (context instanceof CreateDataSourcesStatementContext) {
- return execute((CreateDataSourcesStatementContext) context);
+ if (context instanceof AddResourcesStatementContext) {
+ return execute((AddResourcesStatementContext) context);
}
if (context instanceof CreateShardingRuleStatementContext) {
return execute((CreateShardingRuleStatementContext) context);
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/DataSourcesQueryBackendHandler.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/DataSourcesQueryBackendHandler.java
index 7f32de4..ae1c334 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/DataSourcesQueryBackendHandler.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/DataSourcesQueryBackendHandler.java
@@ -18,8 +18,8 @@
package org.apache.shardingsphere.proxy.backend.text.distsql.rql;
import lombok.RequiredArgsConstructor;
-import
org.apache.shardingsphere.distsql.parser.statement.rql.show.ShowDataSourcesStatement;
-import
org.apache.shardingsphere.infra.binder.statement.rdl.ShowDataSourcesStatementContext;
+import
org.apache.shardingsphere.distsql.parser.statement.rql.show.ShowResourcesStatement;
+import
org.apache.shardingsphere.infra.binder.statement.rdl.ShowResourcesStatementContext;
import org.apache.shardingsphere.infra.config.datasource.DataSourceConverter;
import org.apache.shardingsphere.infra.config.datasource.DataSourceParameter;
import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
@@ -45,7 +45,7 @@ import java.util.Map;
@RequiredArgsConstructor
public final class DataSourcesQueryBackendHandler implements
TextProtocolBackendHandler {
- private final ShowDataSourcesStatement sqlStatement;
+ private final ShowResourcesStatement sqlStatement;
private final BackendConnection backendConnection;
@@ -55,10 +55,10 @@ public final class DataSourcesQueryBackendHandler
implements TextProtocolBackend
@Override
public ResponseHeader execute() {
- return execute(new ShowDataSourcesStatementContext(sqlStatement));
+ return execute(new ShowResourcesStatementContext(sqlStatement));
}
- private ResponseHeader execute(final ShowDataSourcesStatementContext
context) {
+ private ResponseHeader execute(final ShowResourcesStatementContext
context) {
String schemaName = getSchemaName(context);
QueryHeader nameQueryHeader = new QueryHeader(schemaName, "", "name",
"name", Types.CHAR, "CHAR", 255, 0, false, false, false, false);
QueryHeader contentQueryHeader = new QueryHeader(schemaName, "", "data
source", "data source", Types.CHAR, "CHAR", 255, 0, false, false, false, false);
@@ -68,7 +68,7 @@ public final class DataSourcesQueryBackendHandler implements
TextProtocolBackend
return new QueryResponseHeader(Arrays.asList(nameQueryHeader,
contentQueryHeader));
}
- private String getSchemaName(final ShowDataSourcesStatementContext
context) {
+ private String getSchemaName(final ShowResourcesStatementContext context) {
String result = null == context.getSqlStatement().getSchemaName() ?
backendConnection.getSchemaName() :
context.getSqlStatement().getSchemaName().getIdentifier().getValue();
if (null == result) {
throw new NoDatabaseSelectedException();
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/RDLBackendHandlerTest.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/RDLBackendHandlerTest.java
index 9d44b5d..12df1f6 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/RDLBackendHandlerTest.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/RDLBackendHandlerTest.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.proxy.backend.text.distsql;
import lombok.SneakyThrows;
-import
org.apache.shardingsphere.distsql.parser.statement.rdl.create.impl.CreateDataSourcesStatement;
+import
org.apache.shardingsphere.distsql.parser.statement.rdl.create.impl.AddResourcesStatement;
import
org.apache.shardingsphere.distsql.parser.statement.rdl.create.impl.CreateShardingRuleStatement;
import org.apache.shardingsphere.infra.auth.builtin.DefaultAuthentication;
import
org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
@@ -155,11 +155,11 @@ public final class RDLBackendHandlerTest {
public void assertExecuteDataSourcesContext() throws SQLException {
BackendConnection connection = mock(BackendConnection.class);
when(connection.getSchemaName()).thenReturn("schema");
- RDLBackendHandler executeEngine = new
RDLBackendHandler(mock(CreateDataSourcesStatement.class), connection);
+ RDLBackendHandler executeEngine = new
RDLBackendHandler(mock(AddResourcesStatement.class), connection);
try {
executeEngine.execute();
} catch (final SQLException ex) {
- assertThat(ex.getMessage(), is("No Registry center to execute
`CreateDataSourcesStatement` SQL"));
+ assertThat(ex.getMessage(), is("No Registry center to execute
`AddResourcesStatement` SQL"));
}
setGovernanceMetaDataContexts(true);
ResponseHeader response = executeEngine.execute();
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/converter/CreateDataSourcesStatementContextConverter.java
b/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/converter/CreateDataSourcesStatementContextConverter.java
index e3b682a..d05516e 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/converter/CreateDataSourcesStatementContextConverter.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/converter/CreateDataSourcesStatementContextConverter.java
@@ -19,8 +19,8 @@ package org.apache.shardingsphere.proxy.converter;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
-import
org.apache.shardingsphere.distsql.parser.segment.DataSourceConnectionSegment;
-import
org.apache.shardingsphere.infra.binder.statement.rdl.CreateDataSourcesStatementContext;
+import org.apache.shardingsphere.distsql.parser.segment.DataSourceSegment;
+import
org.apache.shardingsphere.infra.binder.statement.rdl.AddResourcesStatementContext;
import org.apache.shardingsphere.infra.config.datasource.DataSourceParameter;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.proxy.config.yaml.YamlDataSourceParameter;
@@ -40,9 +40,9 @@ public final class CreateDataSourcesStatementContextConverter
{
* @param sqlStatementContext create data source statement context
* @return YAML data source parameter map
*/
- public static Map<String, YamlDataSourceParameter> convert(final
CreateDataSourcesStatementContext sqlStatementContext) {
- Map<String, YamlDataSourceParameter> result = new
LinkedHashMap<>(sqlStatementContext.getSqlStatement().getConnectionInfos().size(),
1);
- for (DataSourceConnectionSegment each :
sqlStatementContext.getSqlStatement().getConnectionInfos()) {
+ public static Map<String, YamlDataSourceParameter> convert(final
AddResourcesStatementContext sqlStatementContext) {
+ Map<String, YamlDataSourceParameter> result = new
LinkedHashMap<>(sqlStatementContext.getSqlStatement().getDataSources().size(),
1);
+ for (DataSourceSegment each :
sqlStatementContext.getSqlStatement().getDataSources()) {
DataSourceParameter parameter = new DataSourceParameter();
YamlDataSourceParameter dataSource = new YamlDataSourceParameter();
dataSource.setUrl(getURL(sqlStatementContext.getDatabaseType(),
each));
@@ -58,7 +58,7 @@ public final class CreateDataSourcesStatementContextConverter
{
return result;
}
- private static String getURL(final DatabaseType databaseType, final
DataSourceConnectionSegment connectionSegment) {
+ private static String getURL(final DatabaseType databaseType, final
DataSourceSegment connectionSegment) {
return String.format("%s//%s:%s/%s",
databaseType.getJdbcUrlPrefixes().iterator().next(),
connectionSegment.getHostName(), connectionSegment.getPort(),
connectionSegment.getDb());
}
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-common/src/test/java/org/apache/shardingsphere/proxy/converter/CreateDataSourcesStatementContextConverterTest.java
b/shardingsphere-proxy/shardingsphere-proxy-common/src/test/java/org/apache/shardingsphere/proxy/converter/CreateDataSourcesStatementContextConverterTest.java
index e872f44..be38950 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-common/src/test/java/org/apache/shardingsphere/proxy/converter/CreateDataSourcesStatementContextConverterTest.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-common/src/test/java/org/apache/shardingsphere/proxy/converter/CreateDataSourcesStatementContextConverterTest.java
@@ -17,9 +17,9 @@
package org.apache.shardingsphere.proxy.converter;
-import
org.apache.shardingsphere.distsql.parser.segment.DataSourceConnectionSegment;
-import
org.apache.shardingsphere.distsql.parser.statement.rdl.create.impl.CreateDataSourcesStatement;
-import
org.apache.shardingsphere.infra.binder.statement.rdl.CreateDataSourcesStatementContext;
+import org.apache.shardingsphere.distsql.parser.segment.DataSourceSegment;
+import
org.apache.shardingsphere.distsql.parser.statement.rdl.create.impl.AddResourcesStatement;
+import
org.apache.shardingsphere.infra.binder.statement.rdl.AddResourcesStatementContext;
import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
import org.apache.shardingsphere.proxy.config.yaml.YamlDataSourceParameter;
import org.junit.Before;
@@ -36,17 +36,17 @@ import static org.junit.Assert.assertTrue;
public final class CreateDataSourcesStatementContextConverterTest {
- private CreateDataSourcesStatementContext sqlStatement;
+ private AddResourcesStatementContext sqlStatement;
@Before
public void setUp() {
- sqlStatement = new CreateDataSourcesStatementContext(new
CreateDataSourcesStatement(createDataSourceConnectionSegments()), new
MySQLDatabaseType());
+ sqlStatement = new AddResourcesStatementContext(new
AddResourcesStatement(createDataSourceConnectionSegments()), new
MySQLDatabaseType());
}
- private Collection<DataSourceConnectionSegment>
createDataSourceConnectionSegments() {
- Collection<DataSourceConnectionSegment> result = new LinkedList<>();
+ private Collection<DataSourceSegment> createDataSourceConnectionSegments()
{
+ Collection<DataSourceSegment> result = new LinkedList<>();
for (int i = 0; i < 2; i++) {
- DataSourceConnectionSegment segment = new
DataSourceConnectionSegment();
+ DataSourceSegment segment = new DataSourceSegment();
segment.setName(String.format("ds%s", i));
segment.setHostName("127.0.0.1");
segment.setPassword("3306");
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/PostgreSQLCommand.java
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/PostgreSQLCommand.java
index 4e6e270..096c3cb 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/PostgreSQLCommand.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/PostgreSQLCommand.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.proxy.frontend.postgresql.command.query;
import lombok.RequiredArgsConstructor;
-import
org.apache.shardingsphere.distsql.parser.statement.rdl.create.impl.CreateDataSourcesStatement;
+import
org.apache.shardingsphere.distsql.parser.statement.rdl.create.impl.AddResourcesStatement;
import
org.apache.shardingsphere.distsql.parser.statement.rdl.create.impl.CreateShardingRuleStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateDatabaseStatement;
@@ -50,7 +50,7 @@ public final class PostgreSQLCommand {
if (sqlStatement instanceof UpdateStatement) {
return "UPDATE";
}
- if (sqlStatement instanceof CreateDatabaseStatement || sqlStatement
instanceof CreateDataSourcesStatement || sqlStatement instanceof
CreateShardingRuleStatement) {
+ if (sqlStatement instanceof CreateDatabaseStatement || sqlStatement
instanceof AddResourcesStatement || sqlStatement instanceof
CreateShardingRuleStatement) {
return "CREATE";
}
if (sqlStatement instanceof DropDatabaseStatement) {
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/PostgreSQLCommandTest.java
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/PostgreSQLCommandTest.java
index 98bdda9..66a1507 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/PostgreSQLCommandTest.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/PostgreSQLCommandTest.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.proxy.frontend.postgresql.command.query;
-import
org.apache.shardingsphere.distsql.parser.statement.rdl.create.impl.CreateDataSourcesStatement;
+import
org.apache.shardingsphere.distsql.parser.statement.rdl.create.impl.AddResourcesStatement;
import
org.apache.shardingsphere.distsql.parser.statement.rdl.create.impl.CreateShardingRuleStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateDatabaseStatement;
@@ -65,7 +65,7 @@ public final class PostgreSQLCommandTest {
@Test
public void
assertPostgreSQLCommandWhenSQLStatementInstanceOfCreateDataSourcesStatement() {
- assertThat(new
PostgreSQLCommand(mock(CreateDataSourcesStatement.class)).getSQLCommand(),
is("CREATE"));
+ assertThat(new
PostgreSQLCommand(mock(AddResourcesStatement.class)).getSQLCommand(),
is("CREATE"));
}
@Test