You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2020/10/27 11:03:05 UTC
[shardingsphere] branch master updated: Add
SQLVisitorFacadeRegistry for spi (#7934)
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 a46dc52 Add SQLVisitorFacadeRegistry for spi (#7934)
a46dc52 is described below
commit a46dc5272273c752488274d0ebe0acbc6b0844fe
Author: Liang Zhang <te...@163.com>
AuthorDate: Tue Oct 27 19:02:47 2020 +0800
Add SQLVisitorFacadeRegistry for spi (#7934)
* Move SQLVisitorFacade to spi package
* Add SQLVisitorFacadeRegistry for spi
* Remove useless SQLParserConfiguration.getSQLVisitorFacadeClasses
---
.../sql/parser/mysql/MySQLParserConfiguration.java | 14 -----
.../format/facade/MySQLFormatSQLVisitorFacade.java | 9 ++-
.../facade/MySQLStatementSQLVisitorFacade.java | 9 ++-
....shardingsphere.sql.parser.spi.SQLVisitorFacade | 19 ++++++
.../parser/oracle/OracleParserConfiguration.java | 14 -----
.../facade/OracleFormatSQLVisitorFacade.java | 11 +++-
.../facade/OracleStatementSQLVisitorFacade.java | 9 ++-
....shardingsphere.sql.parser.spi.SQLVisitorFacade | 19 ++++++
.../postgresql/PostgreSQLParserConfiguration.java | 14 -----
.../facade/PostgreSQLFormatSQLVisitorFacade.java | 11 +++-
.../PostgreSQLStatementSQLVisitorFacade.java | 9 ++-
....shardingsphere.sql.parser.spi.SQLVisitorFacade | 19 ++++++
.../sql/parser/sql92/SQL92ParserConfiguration.java | 14 -----
.../format/facade/SQL92FormatSQLVisitorFacade.java | 11 +++-
.../facade/SQL92StatementSQLVisitorFacade.java | 9 ++-
....shardingsphere.sql.parser.spi.SQLVisitorFacade | 19 ++++++
.../sqlserver/SQLServerParserConfiguration.java | 14 -----
.../facade/SQLServerFormatSQLVisitorFacade.java | 11 +++-
.../facade/SQLServerStatementSQLVisitorFacade.java | 9 ++-
....shardingsphere.sql.parser.spi.SQLVisitorFacade | 19 ++++++
.../core/visitor/SQLFormatVisitorFactory.java | 11 +---
.../core/visitor/SQLStatementVisitorFactory.java | 11 +---
.../core/visitor/SQLVisitorFacadeRegistry.java | 69 ++++++++++++++++++++++
.../sql/parser/spi/SQLParserConfiguration.java | 10 ----
.../{api/visitor => spi}/SQLVisitorFacade.java | 25 +++++---
25 files changed, 261 insertions(+), 128 deletions(-)
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/MySQLParserConfiguration.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/MySQLParserConfiguration.java
index ed14844..d049bdb 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/MySQLParserConfiguration.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/MySQLParserConfiguration.java
@@ -19,16 +19,10 @@ package org.apache.shardingsphere.sql.parser.mysql;
import org.apache.shardingsphere.sql.parser.api.lexer.SQLLexer;
import org.apache.shardingsphere.sql.parser.api.parser.SQLParser;
-import org.apache.shardingsphere.sql.parser.api.visitor.SQLVisitorFacade;
import org.apache.shardingsphere.sql.parser.mysql.lexer.MySQLLexer;
import org.apache.shardingsphere.sql.parser.mysql.parser.MySQLParser;
-import org.apache.shardingsphere.sql.parser.mysql.visitor.format.facade.MySQLFormatSQLVisitorFacade;
-import org.apache.shardingsphere.sql.parser.mysql.visitor.statement.facade.MySQLStatementSQLVisitorFacade;
import org.apache.shardingsphere.sql.parser.spi.SQLParserConfiguration;
-import java.util.HashMap;
-import java.util.Map;
-
/**
* SQL parser configuration for MySQL.
*/
@@ -48,12 +42,4 @@ public final class MySQLParserConfiguration implements SQLParserConfiguration {
public Class<? extends SQLParser> getParserClass() {
return MySQLParser.class;
}
-
- @Override
- public Map<String, Class<? extends SQLVisitorFacade>> getSQLVisitorFacadeClasses() {
- Map<String, Class<? extends SQLVisitorFacade>> result = new HashMap<>(2, 1);
- result.put("STATEMENT", MySQLStatementSQLVisitorFacade.class);
- result.put("FORMAT", MySQLFormatSQLVisitorFacade.class);
- return result;
- }
}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/format/facade/MySQLFormatSQLVisitorFacade.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/format/facade/MySQLFormatSQLVisitorFacade.java
index ba65f69..f89551d 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/format/facade/MySQLFormatSQLVisitorFacade.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/format/facade/MySQLFormatSQLVisitorFacade.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.sql.parser.mysql.visitor.format.facade;
-import org.apache.shardingsphere.sql.parser.api.visitor.SQLVisitorFacade;
+import org.apache.shardingsphere.sql.parser.spi.SQLVisitorFacade;
import org.apache.shardingsphere.sql.parser.api.visitor.type.DALSQLVisitor;
import org.apache.shardingsphere.sql.parser.api.visitor.type.DCLSQLVisitor;
import org.apache.shardingsphere.sql.parser.api.visitor.type.DDLSQLVisitor;
@@ -67,7 +67,12 @@ public final class MySQLFormatSQLVisitorFacade implements SQLVisitorFacade {
}
@Override
- public String getType() {
+ public String getDatabaseType() {
+ return "MySQL";
+ }
+
+ @Override
+ public String getVisitorType() {
return "FORMAT";
}
}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/facade/MySQLStatementSQLVisitorFacade.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/facade/MySQLStatementSQLVisitorFacade.java
index 0adbae6..70f11a9 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/facade/MySQLStatementSQLVisitorFacade.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/facade/MySQLStatementSQLVisitorFacade.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.sql.parser.mysql.visitor.statement.facade;
-import org.apache.shardingsphere.sql.parser.api.visitor.SQLVisitorFacade;
+import org.apache.shardingsphere.sql.parser.spi.SQLVisitorFacade;
import org.apache.shardingsphere.sql.parser.api.visitor.type.DALSQLVisitor;
import org.apache.shardingsphere.sql.parser.api.visitor.type.DCLSQLVisitor;
import org.apache.shardingsphere.sql.parser.api.visitor.type.DDLSQLVisitor;
@@ -67,7 +67,12 @@ public final class MySQLStatementSQLVisitorFacade implements SQLVisitorFacade {
}
@Override
- public String getType() {
+ public String getDatabaseType() {
+ return "MySQL";
+ }
+
+ @Override
+ public String getVisitorType() {
return "STATEMENT";
}
}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/resources/META-INF/services/org.apache.shardingsphere.sql.parser.spi.SQLVisitorFacade b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/resources/META-INF/services/org.apache.shardingsphere.sql.parser.spi.SQLVisitorFacade
new file mode 100644
index 0000000..6b31cc1
--- /dev/null
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/resources/META-INF/services/org.apache.shardingsphere.sql.parser.spi.SQLVisitorFacade
@@ -0,0 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+org.apache.shardingsphere.sql.parser.mysql.visitor.statement.facade.MySQLStatementSQLVisitorFacade
+org.apache.shardingsphere.sql.parser.mysql.visitor.format.facade.MySQLFormatSQLVisitorFacade
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/OracleParserConfiguration.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/OracleParserConfiguration.java
index 621c45d..156722c 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/OracleParserConfiguration.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/OracleParserConfiguration.java
@@ -19,16 +19,10 @@ package org.apache.shardingsphere.sql.parser.oracle;
import org.apache.shardingsphere.sql.parser.api.lexer.SQLLexer;
import org.apache.shardingsphere.sql.parser.api.parser.SQLParser;
-import org.apache.shardingsphere.sql.parser.api.visitor.SQLVisitorFacade;
import org.apache.shardingsphere.sql.parser.oracle.lexer.OracleLexer;
import org.apache.shardingsphere.sql.parser.oracle.parser.OracleParser;
-import org.apache.shardingsphere.sql.parser.oracle.visitor.format.facade.OracleFormatSQLVisitorFacade;
-import org.apache.shardingsphere.sql.parser.oracle.visitor.statement.facade.OracleStatementSQLVisitorFacade;
import org.apache.shardingsphere.sql.parser.spi.SQLParserConfiguration;
-import java.util.HashMap;
-import java.util.Map;
-
/**
* SQL parser configuration for Oracle.
*/
@@ -48,12 +42,4 @@ public final class OracleParserConfiguration implements SQLParserConfiguration {
public Class<? extends SQLParser> getParserClass() {
return OracleParser.class;
}
-
- @Override
- public Map<String, Class<? extends SQLVisitorFacade>> getSQLVisitorFacadeClasses() {
- Map<String, Class<? extends SQLVisitorFacade>> result = new HashMap<>(2, 1);
- result.put("STATEMENT", OracleStatementSQLVisitorFacade.class);
- result.put("FORMAT", OracleFormatSQLVisitorFacade.class);
- return result;
- }
}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/format/facade/OracleFormatSQLVisitorFacade.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/format/facade/OracleFormatSQLVisitorFacade.java
index cd3f687..5783edb 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/format/facade/OracleFormatSQLVisitorFacade.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/format/facade/OracleFormatSQLVisitorFacade.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.sql.parser.oracle.visitor.format.facade;
-import org.apache.shardingsphere.sql.parser.api.visitor.SQLVisitorFacade;
+import org.apache.shardingsphere.sql.parser.spi.SQLVisitorFacade;
import org.apache.shardingsphere.sql.parser.api.visitor.type.DALSQLVisitor;
import org.apache.shardingsphere.sql.parser.api.visitor.type.DCLSQLVisitor;
import org.apache.shardingsphere.sql.parser.api.visitor.type.DDLSQLVisitor;
@@ -26,7 +26,7 @@ import org.apache.shardingsphere.sql.parser.api.visitor.type.RLSQLVisitor;
import org.apache.shardingsphere.sql.parser.api.visitor.type.TCLSQLVisitor;
/**
- * Format SQL Visitor facade for MySQL.
+ * Format SQL Visitor facade for Oracle.
*/
public final class OracleFormatSQLVisitorFacade implements SQLVisitorFacade {
@@ -61,7 +61,12 @@ public final class OracleFormatSQLVisitorFacade implements SQLVisitorFacade {
}
@Override
- public String getType() {
+ public String getDatabaseType() {
+ return "Oracle";
+ }
+
+ @Override
+ public String getVisitorType() {
return "FORMAT";
}
}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/facade/OracleStatementSQLVisitorFacade.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/facade/OracleStatementSQLVisitorFacade.java
index 0eb2be4..7dc1e0d 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/facade/OracleStatementSQLVisitorFacade.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/java/org/apache/shardingsphere/sql/parser/oracle/visitor/statement/facade/OracleStatementSQLVisitorFacade.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.sql.parser.oracle.visitor.statement.facade;
-import org.apache.shardingsphere.sql.parser.api.visitor.SQLVisitorFacade;
+import org.apache.shardingsphere.sql.parser.spi.SQLVisitorFacade;
import org.apache.shardingsphere.sql.parser.api.visitor.type.DALSQLVisitor;
import org.apache.shardingsphere.sql.parser.api.visitor.type.DCLSQLVisitor;
import org.apache.shardingsphere.sql.parser.api.visitor.type.DDLSQLVisitor;
@@ -66,7 +66,12 @@ public final class OracleStatementSQLVisitorFacade implements SQLVisitorFacade {
}
@Override
- public String getType() {
+ public String getDatabaseType() {
+ return "Oracle";
+ }
+
+ @Override
+ public String getVisitorType() {
return "STATEMENT";
}
}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/resources/META-INF/services/org.apache.shardingsphere.sql.parser.spi.SQLVisitorFacade b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/resources/META-INF/services/org.apache.shardingsphere.sql.parser.spi.SQLVisitorFacade
new file mode 100644
index 0000000..1035612
--- /dev/null
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-oracle/src/main/resources/META-INF/services/org.apache.shardingsphere.sql.parser.spi.SQLVisitorFacade
@@ -0,0 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+org.apache.shardingsphere.sql.parser.oracle.visitor.statement.facade.OracleStatementSQLVisitorFacade
+org.apache.shardingsphere.sql.parser.oracle.visitor.format.facade.OracleFormatSQLVisitorFacade
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/PostgreSQLParserConfiguration.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/PostgreSQLParserConfiguration.java
index db482d3..beb8927 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/PostgreSQLParserConfiguration.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/PostgreSQLParserConfiguration.java
@@ -19,16 +19,10 @@ package org.apache.shardingsphere.sql.parser.postgresql;
import org.apache.shardingsphere.sql.parser.api.lexer.SQLLexer;
import org.apache.shardingsphere.sql.parser.api.parser.SQLParser;
-import org.apache.shardingsphere.sql.parser.api.visitor.SQLVisitorFacade;
import org.apache.shardingsphere.sql.parser.postgresql.lexer.PostgreSQLLexer;
import org.apache.shardingsphere.sql.parser.postgresql.parser.PostgreSQLParser;
-import org.apache.shardingsphere.sql.parser.postgresql.visitor.format.facade.PostgreSQLFormatSQLVisitorFacade;
-import org.apache.shardingsphere.sql.parser.postgresql.visitor.statement.facade.PostgreSQLStatementSQLVisitorFacade;
import org.apache.shardingsphere.sql.parser.spi.SQLParserConfiguration;
-import java.util.HashMap;
-import java.util.Map;
-
/**
* SQL parser configuration for PostgreSQL.
*/
@@ -48,12 +42,4 @@ public final class PostgreSQLParserConfiguration implements SQLParserConfigurati
public Class<? extends SQLParser> getParserClass() {
return PostgreSQLParser.class;
}
-
- @Override
- public Map<String, Class<? extends SQLVisitorFacade>> getSQLVisitorFacadeClasses() {
- Map<String, Class<? extends SQLVisitorFacade>> result = new HashMap<>(2, 1);
- result.put("STATEMENT", PostgreSQLStatementSQLVisitorFacade.class);
- result.put("FORMAT", PostgreSQLFormatSQLVisitorFacade.class);
- return result;
- }
}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/format/facade/PostgreSQLFormatSQLVisitorFacade.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/format/facade/PostgreSQLFormatSQLVisitorFacade.java
index eb3324d..74dc4c6 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/format/facade/PostgreSQLFormatSQLVisitorFacade.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/format/facade/PostgreSQLFormatSQLVisitorFacade.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.sql.parser.postgresql.visitor.format.facade;
-import org.apache.shardingsphere.sql.parser.api.visitor.SQLVisitorFacade;
+import org.apache.shardingsphere.sql.parser.spi.SQLVisitorFacade;
import org.apache.shardingsphere.sql.parser.api.visitor.type.DALSQLVisitor;
import org.apache.shardingsphere.sql.parser.api.visitor.type.DCLSQLVisitor;
import org.apache.shardingsphere.sql.parser.api.visitor.type.DDLSQLVisitor;
@@ -26,7 +26,7 @@ import org.apache.shardingsphere.sql.parser.api.visitor.type.RLSQLVisitor;
import org.apache.shardingsphere.sql.parser.api.visitor.type.TCLSQLVisitor;
/**
- * Format SQL Visitor facade for MySQL.
+ * Format SQL Visitor facade for PostgreSQL.
*/
public final class PostgreSQLFormatSQLVisitorFacade implements SQLVisitorFacade {
@@ -61,7 +61,12 @@ public final class PostgreSQLFormatSQLVisitorFacade implements SQLVisitorFacade
}
@Override
- public String getType() {
+ public String getDatabaseType() {
+ return "PostgreSQL";
+ }
+
+ @Override
+ public String getVisitorType() {
return "FORMAT";
}
}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/facade/PostgreSQLStatementSQLVisitorFacade.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/facade/PostgreSQLStatementSQLVisitorFacade.java
index 9532c3e..6b0e622 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/facade/PostgreSQLStatementSQLVisitorFacade.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/facade/PostgreSQLStatementSQLVisitorFacade.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.sql.parser.postgresql.visitor.statement.facade;
-import org.apache.shardingsphere.sql.parser.api.visitor.SQLVisitorFacade;
+import org.apache.shardingsphere.sql.parser.spi.SQLVisitorFacade;
import org.apache.shardingsphere.sql.parser.api.visitor.type.DALSQLVisitor;
import org.apache.shardingsphere.sql.parser.api.visitor.type.DCLSQLVisitor;
import org.apache.shardingsphere.sql.parser.api.visitor.type.DDLSQLVisitor;
@@ -66,7 +66,12 @@ public final class PostgreSQLStatementSQLVisitorFacade implements SQLVisitorFaca
}
@Override
- public String getType() {
+ public String getDatabaseType() {
+ return "PostgreSQL";
+ }
+
+ @Override
+ public String getVisitorType() {
return "STATEMENT";
}
}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/resources/META-INF/services/org.apache.shardingsphere.sql.parser.spi.SQLVisitorFacade b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/resources/META-INF/services/org.apache.shardingsphere.sql.parser.spi.SQLVisitorFacade
new file mode 100644
index 0000000..b1fc497
--- /dev/null
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/resources/META-INF/services/org.apache.shardingsphere.sql.parser.spi.SQLVisitorFacade
@@ -0,0 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+org.apache.shardingsphere.sql.parser.postgresql.visitor.statement.facade.PostgreSQLStatementSQLVisitorFacade
+org.apache.shardingsphere.sql.parser.postgresql.visitor.format.facade.PostgreSQLFormatSQLVisitorFacade
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sql92/src/main/java/org/apache/shardingsphere/sql/parser/sql92/SQL92ParserConfiguration.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sql92/src/main/java/org/apache/shardingsphere/sql/parser/sql92/SQL92ParserConfiguration.java
index be8d31f..9404528 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sql92/src/main/java/org/apache/shardingsphere/sql/parser/sql92/SQL92ParserConfiguration.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sql92/src/main/java/org/apache/shardingsphere/sql/parser/sql92/SQL92ParserConfiguration.java
@@ -19,15 +19,9 @@ package org.apache.shardingsphere.sql.parser.sql92;
import org.apache.shardingsphere.sql.parser.api.lexer.SQLLexer;
import org.apache.shardingsphere.sql.parser.api.parser.SQLParser;
-import org.apache.shardingsphere.sql.parser.api.visitor.SQLVisitorFacade;
import org.apache.shardingsphere.sql.parser.spi.SQLParserConfiguration;
import org.apache.shardingsphere.sql.parser.sql92.lexer.SQL92Lexer;
import org.apache.shardingsphere.sql.parser.sql92.parser.SQL92Parser;
-import org.apache.shardingsphere.sql.parser.sql92.visitor.format.facade.SQL92FormatSQLVisitorFacade;
-import org.apache.shardingsphere.sql.parser.sql92.visitor.statement.facade.SQL92StatementSQLVisitorFacade;
-
-import java.util.HashMap;
-import java.util.Map;
/**
* SQL parser configuration for SQL92.
@@ -48,12 +42,4 @@ public final class SQL92ParserConfiguration implements SQLParserConfiguration {
public Class<? extends SQLParser> getParserClass() {
return SQL92Parser.class;
}
-
- @Override
- public Map<String, Class<? extends SQLVisitorFacade>> getSQLVisitorFacadeClasses() {
- Map<String, Class<? extends SQLVisitorFacade>> result = new HashMap<>(2, 1);
- result.put("STATEMENT", SQL92StatementSQLVisitorFacade.class);
- result.put("FORMAT", SQL92FormatSQLVisitorFacade.class);
- return result;
- }
}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sql92/src/main/java/org/apache/shardingsphere/sql/parser/sql92/visitor/format/facade/SQL92FormatSQLVisitorFacade.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sql92/src/main/java/org/apache/shardingsphere/sql/parser/sql92/visitor/format/facade/SQL92FormatSQLVisitorFacade.java
index 046b19f..a761656 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sql92/src/main/java/org/apache/shardingsphere/sql/parser/sql92/visitor/format/facade/SQL92FormatSQLVisitorFacade.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sql92/src/main/java/org/apache/shardingsphere/sql/parser/sql92/visitor/format/facade/SQL92FormatSQLVisitorFacade.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.sql.parser.sql92.visitor.format.facade;
-import org.apache.shardingsphere.sql.parser.api.visitor.SQLVisitorFacade;
+import org.apache.shardingsphere.sql.parser.spi.SQLVisitorFacade;
import org.apache.shardingsphere.sql.parser.api.visitor.type.DALSQLVisitor;
import org.apache.shardingsphere.sql.parser.api.visitor.type.DCLSQLVisitor;
import org.apache.shardingsphere.sql.parser.api.visitor.type.DDLSQLVisitor;
@@ -26,7 +26,7 @@ import org.apache.shardingsphere.sql.parser.api.visitor.type.RLSQLVisitor;
import org.apache.shardingsphere.sql.parser.api.visitor.type.TCLSQLVisitor;
/**
- * Format SQL Visitor facade for MySQL.
+ * Format SQL Visitor facade for SQL92.
*/
public final class SQL92FormatSQLVisitorFacade implements SQLVisitorFacade {
@@ -61,7 +61,12 @@ public final class SQL92FormatSQLVisitorFacade implements SQLVisitorFacade {
}
@Override
- public String getType() {
+ public String getDatabaseType() {
+ return "SQL92";
+ }
+
+ @Override
+ public String getVisitorType() {
return "FORMAT";
}
}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sql92/src/main/java/org/apache/shardingsphere/sql/parser/sql92/visitor/statement/facade/SQL92StatementSQLVisitorFacade.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sql92/src/main/java/org/apache/shardingsphere/sql/parser/sql92/visitor/statement/facade/SQL92StatementSQLVisitorFacade.java
index 1cf6efd..0ff0202 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sql92/src/main/java/org/apache/shardingsphere/sql/parser/sql92/visitor/statement/facade/SQL92StatementSQLVisitorFacade.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sql92/src/main/java/org/apache/shardingsphere/sql/parser/sql92/visitor/statement/facade/SQL92StatementSQLVisitorFacade.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.sql.parser.sql92.visitor.statement.facade;
-import org.apache.shardingsphere.sql.parser.api.visitor.SQLVisitorFacade;
+import org.apache.shardingsphere.sql.parser.spi.SQLVisitorFacade;
import org.apache.shardingsphere.sql.parser.api.visitor.type.DALSQLVisitor;
import org.apache.shardingsphere.sql.parser.api.visitor.type.DCLSQLVisitor;
import org.apache.shardingsphere.sql.parser.api.visitor.type.DDLSQLVisitor;
@@ -66,7 +66,12 @@ public final class SQL92StatementSQLVisitorFacade implements SQLVisitorFacade {
}
@Override
- public String getType() {
+ public String getDatabaseType() {
+ return "SQL92";
+ }
+
+ @Override
+ public String getVisitorType() {
return "STATEMENT";
}
}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sql92/src/main/resources/META-INF/services/org.apache.shardingsphere.sql.parser.spi.SQLVisitorFacade b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sql92/src/main/resources/META-INF/services/org.apache.shardingsphere.sql.parser.spi.SQLVisitorFacade
new file mode 100644
index 0000000..5260c57
--- /dev/null
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sql92/src/main/resources/META-INF/services/org.apache.shardingsphere.sql.parser.spi.SQLVisitorFacade
@@ -0,0 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+org.apache.shardingsphere.sql.parser.sql92.visitor.statement.facade.SQL92StatementSQLVisitorFacade
+org.apache.shardingsphere.sql.parser.sql92.visitor.format.facade.SQL92FormatSQLVisitorFacade
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/SQLServerParserConfiguration.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/SQLServerParserConfiguration.java
index b64e0db..e8b6945 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/SQLServerParserConfiguration.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/SQLServerParserConfiguration.java
@@ -19,15 +19,9 @@ package org.apache.shardingsphere.sql.parser.sqlserver;
import org.apache.shardingsphere.sql.parser.api.lexer.SQLLexer;
import org.apache.shardingsphere.sql.parser.api.parser.SQLParser;
-import org.apache.shardingsphere.sql.parser.api.visitor.SQLVisitorFacade;
import org.apache.shardingsphere.sql.parser.spi.SQLParserConfiguration;
import org.apache.shardingsphere.sql.parser.sqlserver.lexer.SQLServerLexer;
import org.apache.shardingsphere.sql.parser.sqlserver.parser.SQLServerParser;
-import org.apache.shardingsphere.sql.parser.sqlserver.visitor.format.facade.SQLServerFormatSQLVisitorFacade;
-import org.apache.shardingsphere.sql.parser.sqlserver.visitor.statement.facade.SQLServerStatementSQLVisitorFacade;
-
-import java.util.HashMap;
-import java.util.Map;
/**
* SQL parser configuration for SQLServer.
@@ -48,12 +42,4 @@ public final class SQLServerParserConfiguration implements SQLParserConfiguratio
public Class<? extends SQLParser> getParserClass() {
return SQLServerParser.class;
}
-
- @Override
- public Map<String, Class<? extends SQLVisitorFacade>> getSQLVisitorFacadeClasses() {
- Map<String, Class<? extends SQLVisitorFacade>> result = new HashMap<>(2, 1);
- result.put("STATEMENT", SQLServerStatementSQLVisitorFacade.class);
- result.put("FORMAT", SQLServerFormatSQLVisitorFacade.class);
- return result;
- }
}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/format/facade/SQLServerFormatSQLVisitorFacade.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/format/facade/SQLServerFormatSQLVisitorFacade.java
index 5524c09..3ccf4aa 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/format/facade/SQLServerFormatSQLVisitorFacade.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/format/facade/SQLServerFormatSQLVisitorFacade.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.sql.parser.sqlserver.visitor.format.facade;
-import org.apache.shardingsphere.sql.parser.api.visitor.SQLVisitorFacade;
+import org.apache.shardingsphere.sql.parser.spi.SQLVisitorFacade;
import org.apache.shardingsphere.sql.parser.api.visitor.type.DALSQLVisitor;
import org.apache.shardingsphere.sql.parser.api.visitor.type.DCLSQLVisitor;
import org.apache.shardingsphere.sql.parser.api.visitor.type.DDLSQLVisitor;
@@ -26,7 +26,7 @@ import org.apache.shardingsphere.sql.parser.api.visitor.type.RLSQLVisitor;
import org.apache.shardingsphere.sql.parser.api.visitor.type.TCLSQLVisitor;
/**
- * Format SQL Visitor facade for MySQL.
+ * Format SQL Visitor facade for SQLServer.
*/
public final class SQLServerFormatSQLVisitorFacade implements SQLVisitorFacade {
@@ -61,7 +61,12 @@ public final class SQLServerFormatSQLVisitorFacade implements SQLVisitorFacade {
}
@Override
- public String getType() {
+ public String getDatabaseType() {
+ return "SQLServer";
+ }
+
+ @Override
+ public String getVisitorType() {
return "FORMAT";
}
}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/facade/SQLServerStatementSQLVisitorFacade.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/facade/SQLServerStatementSQLVisitorFacade.java
index d869576..03d9226 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/facade/SQLServerStatementSQLVisitorFacade.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/facade/SQLServerStatementSQLVisitorFacade.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.sql.parser.sqlserver.visitor.statement.facade;
-import org.apache.shardingsphere.sql.parser.api.visitor.SQLVisitorFacade;
+import org.apache.shardingsphere.sql.parser.spi.SQLVisitorFacade;
import org.apache.shardingsphere.sql.parser.api.visitor.type.DALSQLVisitor;
import org.apache.shardingsphere.sql.parser.api.visitor.type.DCLSQLVisitor;
import org.apache.shardingsphere.sql.parser.api.visitor.type.DDLSQLVisitor;
@@ -66,7 +66,12 @@ public final class SQLServerStatementSQLVisitorFacade implements SQLVisitorFacad
}
@Override
- public String getType() {
+ public String getDatabaseType() {
+ return "SQLServer";
+ }
+
+ @Override
+ public String getVisitorType() {
return "STATEMENT";
}
}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/resources/META-INF/services/org.apache.shardingsphere.sql.parser.spi.SQLVisitorFacade b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/resources/META-INF/services/org.apache.shardingsphere.sql.parser.spi.SQLVisitorFacade
new file mode 100644
index 0000000..eacb1d5
--- /dev/null
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/resources/META-INF/services/org.apache.shardingsphere.sql.parser.spi.SQLVisitorFacade
@@ -0,0 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+org.apache.shardingsphere.sql.parser.sqlserver.visitor.statement.facade.SQLServerStatementSQLVisitorFacade
+org.apache.shardingsphere.sql.parser.sqlserver.visitor.format.facade.SQLServerFormatSQLVisitorFacade
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/visitor/SQLFormatVisitorFactory.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/visitor/SQLFormatVisitorFactory.java
index 20aac50..5abcec8 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/visitor/SQLFormatVisitorFactory.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/visitor/SQLFormatVisitorFactory.java
@@ -21,9 +21,8 @@ import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.SneakyThrows;
import org.antlr.v4.runtime.tree.ParseTreeVisitor;
-import org.apache.shardingsphere.sql.parser.api.visitor.SQLVisitorFacade;
-import org.apache.shardingsphere.sql.parser.core.SQLParserConfigurationRegistry;
import org.apache.shardingsphere.sql.parser.exception.SQLParsingException;
+import org.apache.shardingsphere.sql.parser.spi.SQLVisitorFacade;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatementType;
/**
@@ -40,12 +39,8 @@ public final class SQLFormatVisitorFactory {
* @return parse tree visitor
*/
public static ParseTreeVisitor newInstance(final String databaseTypeName, final SQLVisitorRule sqlVisitorRule) {
- return createParseTreeVisitor(getSQLVisitorFacadeEngine(databaseTypeName), sqlVisitorRule.getType());
- }
-
- @SneakyThrows(ReflectiveOperationException.class)
- private static SQLVisitorFacade getSQLVisitorFacadeEngine(final String databaseTypeName) {
- return SQLParserConfigurationRegistry.getInstance().getSQLParserConfiguration(databaseTypeName).getSQLVisitorFacadeClasses().get("FORMAT").getConstructor().newInstance();
+ SQLVisitorFacade facade = SQLVisitorFacadeRegistry.getInstance().getSQLVisitorFacade(databaseTypeName, "FORMAT");
+ return createParseTreeVisitor(facade, sqlVisitorRule.getType());
}
@SneakyThrows(ReflectiveOperationException.class)
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/visitor/SQLStatementVisitorFactory.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/visitor/SQLStatementVisitorFactory.java
index 0055d90..5e53c58 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/visitor/SQLStatementVisitorFactory.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/visitor/SQLStatementVisitorFactory.java
@@ -21,9 +21,8 @@ import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.SneakyThrows;
import org.antlr.v4.runtime.tree.ParseTreeVisitor;
-import org.apache.shardingsphere.sql.parser.api.visitor.SQLVisitorFacade;
-import org.apache.shardingsphere.sql.parser.core.SQLParserConfigurationRegistry;
import org.apache.shardingsphere.sql.parser.exception.SQLParsingException;
+import org.apache.shardingsphere.sql.parser.spi.SQLVisitorFacade;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatementType;
/**
@@ -40,12 +39,8 @@ public final class SQLStatementVisitorFactory {
* @return parse tree visitor
*/
public static ParseTreeVisitor newInstance(final String databaseTypeName, final SQLVisitorRule sqlVisitorRule) {
- return createParseTreeVisitor(getSQLVisitorFacadeEngine(databaseTypeName), sqlVisitorRule.getType());
- }
-
- @SneakyThrows(ReflectiveOperationException.class)
- private static SQLVisitorFacade getSQLVisitorFacadeEngine(final String databaseTypeName) {
- return SQLParserConfigurationRegistry.getInstance().getSQLParserConfiguration(databaseTypeName).getSQLVisitorFacadeClasses().get("STATEMENT").getConstructor().newInstance();
+ SQLVisitorFacade facade = SQLVisitorFacadeRegistry.getInstance().getSQLVisitorFacade(databaseTypeName, "STATEMENT");
+ return createParseTreeVisitor(facade, sqlVisitorRule.getType());
}
@SneakyThrows(ReflectiveOperationException.class)
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/visitor/SQLVisitorFacadeRegistry.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/visitor/SQLVisitorFacadeRegistry.java
new file mode 100644
index 0000000..dc003fb
--- /dev/null
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/core/visitor/SQLVisitorFacadeRegistry.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.sql.parser.core.visitor;
+
+import org.apache.shardingsphere.sql.parser.spi.SQLVisitorFacade;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.ServiceLoader;
+
+/**
+ * SQL visitor facade registry.
+ */
+public final class SQLVisitorFacadeRegistry {
+
+ private static final SQLVisitorFacadeRegistry INSTANCE = new SQLVisitorFacadeRegistry();
+
+ private final Map<String, SQLVisitorFacade> facades;
+
+ private SQLVisitorFacadeRegistry() {
+ facades = new HashMap<>();
+ for (SQLVisitorFacade each : ServiceLoader.load(SQLVisitorFacade.class)) {
+ facades.put(getQualifiedType(each.getDatabaseType(), each.getVisitorType()), each);
+ }
+ }
+
+ /**
+ * Get instance.
+ *
+ * @return instance
+ */
+ public static SQLVisitorFacadeRegistry getInstance() {
+ return INSTANCE;
+ }
+
+ /**
+ * Get SQL visitor facade.
+ *
+ * @param databaseType database type
+ * @param visitorType visitor type
+ * @return SQL visitor facade
+ */
+ public SQLVisitorFacade getSQLVisitorFacade(final String databaseType, final String visitorType) {
+ String qualifiedType = getQualifiedType(databaseType, visitorType);
+ if (facades.containsKey(qualifiedType)) {
+ return facades.get(qualifiedType);
+ }
+ throw new UnsupportedOperationException(String.format("Cannot support '%s' visitor with database '%s'", visitorType, databaseType));
+ }
+
+ private String getQualifiedType(final String databaseType, final String visitorType) {
+ return String.join(".", databaseType, visitorType);
+ }
+}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-spi/src/main/java/org/apache/shardingsphere/sql/parser/spi/SQLParserConfiguration.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-spi/src/main/java/org/apache/shardingsphere/sql/parser/spi/SQLParserConfiguration.java
index cb439ba..550a544 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-spi/src/main/java/org/apache/shardingsphere/sql/parser/spi/SQLParserConfiguration.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-spi/src/main/java/org/apache/shardingsphere/sql/parser/spi/SQLParserConfiguration.java
@@ -19,9 +19,6 @@ package org.apache.shardingsphere.sql.parser.spi;
import org.apache.shardingsphere.sql.parser.api.lexer.SQLLexer;
import org.apache.shardingsphere.sql.parser.api.parser.SQLParser;
-import org.apache.shardingsphere.sql.parser.api.visitor.SQLVisitorFacade;
-
-import java.util.Map;
/**
* SQL parser configuration.
@@ -48,11 +45,4 @@ public interface SQLParserConfiguration {
* @return SQL parser class type
*/
Class<? extends SQLParser> getParserClass();
-
- /**
- * Get SQL visitor facade classes.
- *
- * @return SQL visitor facade classes
- */
- Map<String, Class<? extends SQLVisitorFacade>> getSQLVisitorFacadeClasses();
}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-spi/src/main/java/org/apache/shardingsphere/sql/parser/api/visitor/SQLVisitorFacade.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-spi/src/main/java/org/apache/shardingsphere/sql/parser/spi/SQLVisitorFacade.java
similarity index 83%
rename from shardingsphere-sql-parser/shardingsphere-sql-parser-spi/src/main/java/org/apache/shardingsphere/sql/parser/api/visitor/SQLVisitorFacade.java
rename to shardingsphere-sql-parser/shardingsphere-sql-parser-spi/src/main/java/org/apache/shardingsphere/sql/parser/spi/SQLVisitorFacade.java
index d339d7c..4c60d18 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-spi/src/main/java/org/apache/shardingsphere/sql/parser/api/visitor/SQLVisitorFacade.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-spi/src/main/java/org/apache/shardingsphere/sql/parser/spi/SQLVisitorFacade.java
@@ -15,7 +15,9 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.sql.parser.api.visitor;
+package org.apache.shardingsphere.sql.parser.spi;
+
+import org.apache.shardingsphere.sql.parser.api.visitor.SQLVisitor;
/**
* SQL visitor facade.
@@ -23,6 +25,20 @@ package org.apache.shardingsphere.sql.parser.api.visitor;
public interface SQLVisitorFacade {
/**
+ * Get name of database type.
+ *
+ * @return name of database type
+ */
+ String getDatabaseType();
+
+ /**
+ * Get SQL visitor type.
+ *
+ * @return SQL visitor type
+ */
+ String getVisitorType();
+
+ /**
* Get DML visitor class.
*
* @return DML visitor class
@@ -63,11 +79,4 @@ public interface SQLVisitorFacade {
* @return RL visitor class
*/
Class<? extends SQLVisitor> getRLVisitorClass();
-
- /**
- * Get SQL visitor facade type.
- *
- * @return SQL visitor facade type
- */
- String getType();
}