From 5a9d899b094eff8c057b084c0bfe2d0c391cc454 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Thu, 15 Feb 2018 16:06:08 +0800 Subject: [PATCH] fix #600 --- .../shardingjdbc/core/constant/SQLType.java | 9 +++- .../statement/ShardingPreparedStatement.java | 6 ++- .../core/statement/ShardingStatement.java | 6 ++- .../lexer/dialect/mysql/MySQLKeyword.java | 1 - .../lexer/dialect/oracle/OracleKeyword.java | 3 -- .../dialect/sqlserver/SQLServerKeyword.java | 1 - .../parsing/lexer/token/DefaultKeyword.java | 8 ++++ .../MySQLAliasExpressionParser.java | 9 ++-- .../OracleAliasExpressionParser.java | 13 +++--- .../parsing/parser/sql/SQLParserFactory.java | 7 +++ .../parsing/parser/sql/ddl/DDLStatement.java | 4 -- .../parsing/parser/sql/dml/DMLStatement.java | 4 -- .../parsing/parser/sql/dql/DQLStatement.java | 4 -- .../parsing/parser/sql/tcl/TCLParser.java | 33 ++++++++++++++ .../parser/sql/tcl/TCLParserFactory.java | 45 +++++++++++++++++++ .../parsing/parser/sql/tcl/TCLStatement.java | 35 +++++++++++++++ .../src/test/resources/parser/tcl.xml | 8 ++++ .../src/test/resources/sql/tcl/tcl.xml | 8 ++++ 18 files changed, 174 insertions(+), 30 deletions(-) create mode 100644 sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/sql/tcl/TCLParser.java create mode 100644 sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/sql/tcl/TCLParserFactory.java create mode 100644 sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/sql/tcl/TCLStatement.java create mode 100644 sharding-jdbc-core/src/test/resources/parser/tcl.xml create mode 100644 sharding-jdbc-core/src/test/resources/sql/tcl/tcl.xml diff --git a/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/constant/SQLType.java b/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/constant/SQLType.java index a20d598eca643..f6381326a8330 100644 --- a/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/constant/SQLType.java +++ b/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/constant/SQLType.java @@ -43,5 +43,12 @@ public enum SQLType { * *

Such as {@code CREATE}, {@code ALTER}, {@code DROP}, {@code TRUNCATE}.

*/ - DDL + DDL, + + /** + * Transaction Control Language. + * + *

Such as {@code SET}, {@code COMMIT}, {@code ROLLBACK}, {@code SAVEPOIINT}, {@code BEGIN}.

+ */ + TCL } diff --git a/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/jdbc/core/statement/ShardingPreparedStatement.java b/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/jdbc/core/statement/ShardingPreparedStatement.java index c62db96c0bdc1..ae37ec5b9878a 100644 --- a/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/jdbc/core/statement/ShardingPreparedStatement.java +++ b/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/jdbc/core/statement/ShardingPreparedStatement.java @@ -271,7 +271,11 @@ public ResultSet getResultSet() throws SQLException { for (PreparedStatement each : routedStatements) { resultSets.add(each.getResultSet()); } - currentResultSet = new ShardingResultSet(resultSets, new MergeEngine(resultSets, (SelectStatement) routeResult.getSqlStatement()).merge(), this); + if (routeResult.getSqlStatement() instanceof SelectStatement) { + currentResultSet = new ShardingResultSet(resultSets, new MergeEngine(resultSets, (SelectStatement) routeResult.getSqlStatement()).merge(), this); + } else { + currentResultSet = resultSets.get(0); + } return currentResultSet; } } diff --git a/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/jdbc/core/statement/ShardingStatement.java b/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/jdbc/core/statement/ShardingStatement.java index 5a0f3bdfa4e02..71b862693322b 100644 --- a/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/jdbc/core/statement/ShardingStatement.java +++ b/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/jdbc/core/statement/ShardingStatement.java @@ -247,7 +247,11 @@ public ResultSet getResultSet() throws SQLException { for (Statement each : routedStatements) { resultSets.add(each.getResultSet()); } - currentResultSet = new ShardingResultSet(resultSets, new MergeEngine(resultSets, (SelectStatement) routeResult.getSqlStatement()).merge(), this); + if (routeResult.getSqlStatement() instanceof SelectStatement) { + currentResultSet = new ShardingResultSet(resultSets, new MergeEngine(resultSets, (SelectStatement) routeResult.getSqlStatement()).merge(), this); + } else { + currentResultSet = resultSets.get(0); + } return currentResultSet; } } diff --git a/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/lexer/dialect/mysql/MySQLKeyword.java b/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/lexer/dialect/mysql/MySQLKeyword.java index d66726bd94342..b5d5243c7b4b7 100755 --- a/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/lexer/dialect/mysql/MySQLKeyword.java +++ b/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/lexer/dialect/mysql/MySQLKeyword.java @@ -31,7 +31,6 @@ public enum MySQLKeyword implements Keyword { LIMIT, OFFSET, VALUE, - BEGIN, FORCE, PARTITION, DISTINCTROW, diff --git a/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/lexer/dialect/oracle/OracleKeyword.java b/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/lexer/dialect/oracle/OracleKeyword.java index 99c85288909fa..c79d49749dbbb 100755 --- a/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/lexer/dialect/oracle/OracleKeyword.java +++ b/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/lexer/dialect/oracle/OracleKeyword.java @@ -27,7 +27,6 @@ public enum OracleKeyword implements Keyword { LOCKED, - COMMIT, CREATION, UPDATED, UPSERT, @@ -75,8 +74,6 @@ public enum OracleKeyword implements Keyword { MAXTRANS, MINEXTENTS, MAXEXTENTS, - BEGIN, - SAVEPOINT, MATCHED, LOB, DIMENSION, diff --git a/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/lexer/dialect/sqlserver/SQLServerKeyword.java b/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/lexer/dialect/sqlserver/SQLServerKeyword.java index ff5dc78a42a4c..67614a460e00d 100755 --- a/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/lexer/dialect/sqlserver/SQLServerKeyword.java +++ b/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/lexer/dialect/sqlserver/SQLServerKeyword.java @@ -35,7 +35,6 @@ public enum SQLServerKeyword implements Keyword { ONLY, OUTPUT, AUTO, - BEGIN, IDENTITY, BROWSE, TYPE, diff --git a/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/lexer/token/DefaultKeyword.java b/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/lexer/token/DefaultKeyword.java index 15147d6019753..80db1d1dad32b 100755 --- a/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/lexer/token/DefaultKeyword.java +++ b/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/lexer/token/DefaultKeyword.java @@ -146,6 +146,14 @@ public enum DefaultKeyword implements Keyword { HAVING, UNION, + /* + TCL + */ + COMMIT, + ROLLBACK, + SAVEPOINT, + BEGIN, + /* Other Command */ diff --git a/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/dialect/mysql/clause/expression/MySQLAliasExpressionParser.java b/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/dialect/mysql/clause/expression/MySQLAliasExpressionParser.java index 8222491d33155..2ed563a5bf734 100644 --- a/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/dialect/mysql/clause/expression/MySQLAliasExpressionParser.java +++ b/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/dialect/mysql/clause/expression/MySQLAliasExpressionParser.java @@ -26,8 +26,8 @@ protected TokenType[] getCustomizedAvailableKeywordsForSelectItemAlias() { DefaultKeyword.TRUNCATE, DefaultKeyword.END, DefaultKeyword.FULL, DefaultKeyword.CLOSE, DefaultKeyword.CAST, DefaultKeyword.ESCAPE, DefaultKeyword.SOME, DefaultKeyword.UNTIL, DefaultKeyword.OPEN, DefaultKeyword.OVER, DefaultKeyword.PASSWORD, DefaultKeyword.LOCAL, DefaultKeyword.GLOBAL, DefaultKeyword.STORAGE, DefaultKeyword.DATA, DefaultKeyword.COALESCE, DefaultKeyword.VARCHAR2, DefaultKeyword.DATE, DefaultKeyword.TIME, DefaultKeyword.BOOLEAN, DefaultKeyword.ANY, DefaultKeyword.GREATEST, - DefaultKeyword.LEAST, DefaultKeyword.POSITION, DefaultKeyword.SUBSTRING, DefaultKeyword.TRIM, - MySQLKeyword.OFFSET, MySQLKeyword.VALUE, MySQLKeyword.BEGIN, MySQLKeyword.QUICK, MySQLKeyword.CACHE, MySQLKeyword.SQL_CACHE, MySQLKeyword.SQL_NO_CACHE, MySQLKeyword.SQL_BUFFER_RESULT, + DefaultKeyword.LEAST, DefaultKeyword.POSITION, DefaultKeyword.SUBSTRING, DefaultKeyword.TRIM, DefaultKeyword.BEGIN, + MySQLKeyword.OFFSET, MySQLKeyword.VALUE, MySQLKeyword.QUICK, MySQLKeyword.CACHE, MySQLKeyword.SQL_CACHE, MySQLKeyword.SQL_NO_CACHE, MySQLKeyword.SQL_BUFFER_RESULT, MySQLKeyword.FIRST, MySQLKeyword.ALGORITHM, MySQLKeyword.DISCARD, MySQLKeyword.IMPORT, MySQLKeyword.VALIDATION, MySQLKeyword.REORGANIZE, MySQLKeyword.EXCHANGE, MySQLKeyword.REBUILD, MySQLKeyword.REPAIR, MySQLKeyword.REMOVE, MySQLKeyword.UPGRADE, MySQLKeyword.KEY_BLOCK_SIZE, MySQLKeyword.AUTO_INCREMENT, MySQLKeyword.AVG_ROW_LENGTH, MySQLKeyword.CHECKSUM, MySQLKeyword.COMPRESSION, MySQLKeyword.CONNECTION, MySQLKeyword.DIRECTORY, MySQLKeyword.DELAY_KEY_WRITE, MySQLKeyword.ENCRYPTION, MySQLKeyword.ENGINE, MySQLKeyword.INSERT_METHOD, @@ -41,8 +41,9 @@ protected TokenType[] getCustomizedAvailableKeywordsForTableAlias() { return new TokenType[]{ DefaultKeyword.FUNCTION, DefaultKeyword.COMMENT, DefaultKeyword.ROW, DefaultKeyword.EXECUTE, DefaultKeyword.MODIFY, DefaultKeyword.VALIDATE, DefaultKeyword.USER, DefaultKeyword.IDENTIFIED, DefaultKeyword.END, DefaultKeyword.CLOSE, DefaultKeyword.CAST, - DefaultKeyword.ESCAPE, DefaultKeyword.SOME, DefaultKeyword.OPEN, DefaultKeyword.OVER, DefaultKeyword.COALESCE, DefaultKeyword.VARCHAR2, DefaultKeyword.DATE, DefaultKeyword.ANY, - MySQLKeyword.OFFSET, MySQLKeyword.BEGIN, MySQLKeyword.QUICK, MySQLKeyword.CACHE, MySQLKeyword.SQL_CACHE, MySQLKeyword.SQL_NO_CACHE, MySQLKeyword.SQL_BUFFER_RESULT, + DefaultKeyword.ESCAPE, DefaultKeyword.SOME, DefaultKeyword.OPEN, DefaultKeyword.OVER, DefaultKeyword.COALESCE, DefaultKeyword.VARCHAR2, + DefaultKeyword.DATE, DefaultKeyword.ANY, DefaultKeyword.BEGIN, + MySQLKeyword.OFFSET, MySQLKeyword.QUICK, MySQLKeyword.CACHE, MySQLKeyword.SQL_CACHE, MySQLKeyword.SQL_NO_CACHE, MySQLKeyword.SQL_BUFFER_RESULT, MySQLKeyword.FIRST, MySQLKeyword.ALGORITHM, MySQLKeyword.DISCARD, MySQLKeyword.IMPORT, MySQLKeyword.VALIDATION, MySQLKeyword.REORGANIZE, MySQLKeyword.EXCHANGE, MySQLKeyword.REBUILD, MySQLKeyword.REPAIR, MySQLKeyword.KEY_BLOCK_SIZE, MySQLKeyword.AUTO_INCREMENT, MySQLKeyword.AVG_ROW_LENGTH, MySQLKeyword.CHECKSUM, MySQLKeyword.COMPRESSION, MySQLKeyword.CONNECTION, MySQLKeyword.DIRECTORY, MySQLKeyword.DELAY_KEY_WRITE, MySQLKeyword.ENCRYPTION, MySQLKeyword.ENGINE, MySQLKeyword.INSERT_METHOD, diff --git a/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/dialect/oracle/clause/expression/OracleAliasExpressionParser.java b/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/dialect/oracle/clause/expression/OracleAliasExpressionParser.java index e629ce54fa08b..28d1525e6c2c8 100644 --- a/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/dialect/oracle/clause/expression/OracleAliasExpressionParser.java +++ b/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/dialect/oracle/clause/expression/OracleAliasExpressionParser.java @@ -31,15 +31,16 @@ protected TokenType[] getCustomizedAvailableKeywordsForSelectItemAlias() { DefaultKeyword.STORAGE, DefaultKeyword.DATA, DefaultKeyword.COALESCE, DefaultKeyword.CHARACTER, DefaultKeyword.VARYING, DefaultKeyword.INT, DefaultKeyword.DEC, DefaultKeyword.NUMERIC, DefaultKeyword.REAL, DefaultKeyword.DOUBLE, DefaultKeyword.PRECISION, DefaultKeyword.TIME, DefaultKeyword.INTERVAL, DefaultKeyword.BOOLEAN, DefaultKeyword.BLOB, DefaultKeyword.XOR, DefaultKeyword.GREATEST, DefaultKeyword.LEAST, DefaultKeyword.POSITION, DefaultKeyword.SUBSTRING, DefaultKeyword.TRIM, DefaultKeyword.BOTH, DefaultKeyword.LEADING, - DefaultKeyword.TRAILING, DefaultKeyword.CONVERT, DefaultKeyword.CONSTRAINT, DefaultKeyword.PRIMARY, DefaultKeyword.FOREIGN, DefaultKeyword.KEY, DefaultKeyword.REFERENCES, - OracleKeyword.LOCKED, OracleKeyword.COMMIT, OracleKeyword.CREATION, OracleKeyword.UPDATED, OracleKeyword.UPSERT, OracleKeyword.CONNECT_BY_ROOT, + DefaultKeyword.TRAILING, DefaultKeyword.CONVERT, DefaultKeyword.CONSTRAINT, DefaultKeyword.PRIMARY, DefaultKeyword.FOREIGN, DefaultKeyword.KEY, + DefaultKeyword.REFERENCES, DefaultKeyword.COMMIT, DefaultKeyword.BEGIN, DefaultKeyword.SAVEPOINT, + OracleKeyword.LOCKED, OracleKeyword.CREATION, OracleKeyword.UPDATED, OracleKeyword.UPSERT, OracleKeyword.CONNECT_BY_ROOT, OracleKeyword.STORE, OracleKeyword.MERGE, OracleKeyword.PURGE, OracleKeyword.GOTO, OracleKeyword.ONLY, OracleKeyword.AUTOMATIC, OracleKeyword.MAIN, OracleKeyword.PCTINCREASE, OracleKeyword.CHUNK, OracleKeyword.LIMIT, OracleKeyword.GROUPING, OracleKeyword.ROLLUP, OracleKeyword.CUBE, OracleKeyword.UNLIMITED, OracleKeyword.SIBLINGS, OracleKeyword.INCLUDE, OracleKeyword.EXCLUDE, OracleKeyword.PIVOT, OracleKeyword.UNPIVOT, OracleKeyword.EXCEPTION, OracleKeyword.EXCEPTIONS, OracleKeyword.ERRORS, OracleKeyword.DEFERRED, OracleKeyword.NAV, OracleKeyword.VERSIONS, OracleKeyword.WAIT, OracleKeyword.SAMPLE, OracleKeyword.CONTINUE, OracleKeyword.TIMESTAMP, OracleKeyword.SEGMENT, OracleKeyword.PARTITION, OracleKeyword.SUBPARTITION, OracleKeyword.RETURN, OracleKeyword.RETURNING, OracleKeyword.REJECT, OracleKeyword.MAXTRANS, OracleKeyword.MINEXTENTS, - OracleKeyword.BEGIN, OracleKeyword.SAVEPOINT, OracleKeyword.MATCHED, OracleKeyword.LOB, OracleKeyword.DIMENSION, OracleKeyword.FORCE, OracleKeyword.FIRST, + OracleKeyword.MATCHED, OracleKeyword.LOB, OracleKeyword.DIMENSION, OracleKeyword.FORCE, OracleKeyword.FIRST, OracleKeyword.NEXT, OracleKeyword.LAST, OracleKeyword.EXTRACT, OracleKeyword.RULES, OracleKeyword.INITIALLY, OracleKeyword.KEEP, OracleKeyword.KEEP_DUPLICATES, OracleKeyword.REFERENCE, OracleKeyword.SEED, OracleKeyword.IGNORE, OracleKeyword.MEASURES, OracleKeyword.LOGGING, OracleKeyword.MAXSIZE, OracleKeyword.FLASH_CACHE, OracleKeyword.CELL_FLASH_CACHE, OracleKeyword.SKIP, OracleKeyword.NONE, OracleKeyword.NULLS, OracleKeyword.SINGLE, OracleKeyword.SCN, OracleKeyword.INITRANS, @@ -58,13 +59,13 @@ protected TokenType[] getCustomizedAvailableKeywordsForTableAlias() { DefaultKeyword.OVER, DefaultKeyword.LOOP, DefaultKeyword.EXPLAIN, DefaultKeyword.COALESCE, DefaultKeyword.CHARACTER, DefaultKeyword.VARYING, DefaultKeyword.INT, DefaultKeyword.DEC, DefaultKeyword.NUMERIC, DefaultKeyword.REAL, DefaultKeyword.DOUBLE, DefaultKeyword.PRECISION, DefaultKeyword.INTERVAL, DefaultKeyword.BLOB, DefaultKeyword.XOR, DefaultKeyword.BOTH, DefaultKeyword.LEADING, DefaultKeyword.TRAILING, DefaultKeyword.CONVERT, DefaultKeyword.CONSTRAINT, DefaultKeyword.PRIMARY, - DefaultKeyword.FOREIGN, DefaultKeyword.KEY, DefaultKeyword.REFERENCES, - OracleKeyword.LOCKED, OracleKeyword.COMMIT, OracleKeyword.CREATION, OracleKeyword.UPDATED, OracleKeyword.UPSERT, OracleKeyword.STORE, OracleKeyword.MERGE, + DefaultKeyword.FOREIGN, DefaultKeyword.KEY, DefaultKeyword.REFERENCES, DefaultKeyword.BEGIN, DefaultKeyword.SAVEPOINT, DefaultKeyword.COMMIT, + OracleKeyword.LOCKED, OracleKeyword.CREATION, OracleKeyword.UPDATED, OracleKeyword.UPSERT, OracleKeyword.STORE, OracleKeyword.MERGE, OracleKeyword.PURGE, OracleKeyword.GOTO, OracleKeyword.ONLY, OracleKeyword.AUTOMATIC, OracleKeyword.MAIN, OracleKeyword.PCTINCREASE, OracleKeyword.CHUNK, OracleKeyword.LIMIT, OracleKeyword.GROUPING, OracleKeyword.ROLLUP, OracleKeyword.CUBE, OracleKeyword.UNLIMITED, OracleKeyword.SIBLINGS, OracleKeyword.INCLUDE, OracleKeyword.EXCLUDE, OracleKeyword.PIVOT, OracleKeyword.UNPIVOT, OracleKeyword.EXCEPTION, OracleKeyword.EXCEPTIONS, OracleKeyword.ERRORS, OracleKeyword.DEFERRED, OracleKeyword.NAV, OracleKeyword.VERSIONS, OracleKeyword.WAIT, OracleKeyword.CONTINUE, OracleKeyword.TIMESTAMP, OracleKeyword.SEGMENT, OracleKeyword.RETURN, - OracleKeyword.RETURNING, OracleKeyword.REJECT, OracleKeyword.MAXTRANS, OracleKeyword.MINEXTENTS, OracleKeyword.BEGIN, OracleKeyword.SAVEPOINT, OracleKeyword.MATCHED, + OracleKeyword.RETURNING, OracleKeyword.REJECT, OracleKeyword.MAXTRANS, OracleKeyword.MINEXTENTS, OracleKeyword.MATCHED, OracleKeyword.LOB, OracleKeyword.DIMENSION, OracleKeyword.FORCE, OracleKeyword.FIRST, OracleKeyword.NEXT, OracleKeyword.LAST, OracleKeyword.EXTRACT, OracleKeyword.RULES, OracleKeyword.INITIALLY, OracleKeyword.KEEP, OracleKeyword.KEEP_DUPLICATES, OracleKeyword.REFERENCE, OracleKeyword.SEED, OracleKeyword.IGNORE, OracleKeyword.MEASURES, OracleKeyword.LOGGING, OracleKeyword.MAXSIZE, OracleKeyword.FLASH_CACHE, OracleKeyword.CELL_FLASH_CACHE, OracleKeyword.SKIP, OracleKeyword.NONE, OracleKeyword.NULLS, diff --git a/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/sql/SQLParserFactory.java b/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/sql/SQLParserFactory.java index 89f81dca18880..a3db0a2721fbf 100644 --- a/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/sql/SQLParserFactory.java +++ b/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/sql/SQLParserFactory.java @@ -17,6 +17,7 @@ package io.shardingjdbc.core.parsing.parser.sql; +import io.shardingjdbc.core.parsing.parser.sql.tcl.TCLParserFactory; import io.shardingjdbc.core.rule.ShardingRule; import io.shardingjdbc.core.constant.DatabaseType; import io.shardingjdbc.core.parsing.lexer.LexerEngine; @@ -72,6 +73,12 @@ public static SQLParser newInstance(final DatabaseType dbType, final TokenType t return DropParserFactory.newInstance(dbType, shardingRule, lexerEngine); case TRUNCATE: return TruncateParserFactory.newInstance(dbType, shardingRule, lexerEngine); + case SET: + case COMMIT: + case ROLLBACK: + case SAVEPOINT: + case BEGIN: + return TCLParserFactory.newInstance(dbType, shardingRule, lexerEngine); default: throw new SQLParsingUnsupportedException(lexerEngine.getCurrentToken().getType()); } diff --git a/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/sql/ddl/DDLStatement.java b/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/sql/ddl/DDLStatement.java index b4b06cafa838e..352b76c30e753 100644 --- a/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/sql/ddl/DDLStatement.java +++ b/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/sql/ddl/DDLStatement.java @@ -19,8 +19,6 @@ import io.shardingjdbc.core.constant.SQLType; import io.shardingjdbc.core.parsing.parser.sql.AbstractSQLStatement; -import lombok.Getter; -import lombok.Setter; import lombok.ToString; /** @@ -28,8 +26,6 @@ * * @author zhangliang */ -@Getter -@Setter @ToString(callSuper = true) public final class DDLStatement extends AbstractSQLStatement { diff --git a/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/sql/dml/DMLStatement.java b/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/sql/dml/DMLStatement.java index 081e90de0cb8a..dd180fd86949c 100644 --- a/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/sql/dml/DMLStatement.java +++ b/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/sql/dml/DMLStatement.java @@ -19,8 +19,6 @@ import io.shardingjdbc.core.constant.SQLType; import io.shardingjdbc.core.parsing.parser.sql.AbstractSQLStatement; -import lombok.Getter; -import lombok.Setter; import lombok.ToString; /** @@ -28,8 +26,6 @@ * * @author zhangliang */ -@Getter -@Setter @ToString(callSuper = true) public class DMLStatement extends AbstractSQLStatement { diff --git a/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/sql/dql/DQLStatement.java b/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/sql/dql/DQLStatement.java index 1e50d187bb99d..ad7e073d09e61 100644 --- a/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/sql/dql/DQLStatement.java +++ b/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/sql/dql/DQLStatement.java @@ -19,8 +19,6 @@ import io.shardingjdbc.core.constant.SQLType; import io.shardingjdbc.core.parsing.parser.sql.AbstractSQLStatement; -import lombok.Getter; -import lombok.Setter; import lombok.ToString; /** @@ -28,8 +26,6 @@ * * @author zhangliang */ -@Getter -@Setter @ToString(callSuper = true) public class DQLStatement extends AbstractSQLStatement { diff --git a/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/sql/tcl/TCLParser.java b/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/sql/tcl/TCLParser.java new file mode 100644 index 0000000000000..62f254ef85c1a --- /dev/null +++ b/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/sql/tcl/TCLParser.java @@ -0,0 +1,33 @@ +/* + * Copyright 1999-2015 dangdang.com. + *

+ * Licensed 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 io.shardingjdbc.core.parsing.parser.sql.tcl; + +import io.shardingjdbc.core.parsing.parser.sql.SQLParser; + +/** + * TCL parser. + * + * @author zhangliang + */ +public final class TCLParser implements SQLParser { + + @Override + public TCLStatement parse() { + return new TCLStatement(); + } +} diff --git a/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/sql/tcl/TCLParserFactory.java b/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/sql/tcl/TCLParserFactory.java new file mode 100644 index 0000000000000..ffee84b26cc03 --- /dev/null +++ b/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/sql/tcl/TCLParserFactory.java @@ -0,0 +1,45 @@ +/* + * Copyright 1999-2015 dangdang.com. + *

+ * Licensed 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 io.shardingjdbc.core.parsing.parser.sql.tcl; + +import io.shardingjdbc.core.constant.DatabaseType; +import io.shardingjdbc.core.parsing.lexer.LexerEngine; +import io.shardingjdbc.core.rule.ShardingRule; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +/** + * Transaction Control Language parser factory. + * + * @author zhangliang + */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class TCLParserFactory { + + /** + * Create TCL parser instance. + * + * @param dbType database type + * @param shardingRule databases and tables sharding rule + * @param lexerEngine lexical analysis engine. + * @return create parser instance + */ + public static TCLParser newInstance(final DatabaseType dbType, final ShardingRule shardingRule, final LexerEngine lexerEngine) { + return new TCLParser(); + } +} diff --git a/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/sql/tcl/TCLStatement.java b/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/sql/tcl/TCLStatement.java new file mode 100644 index 0000000000000..a8ab5f09bca48 --- /dev/null +++ b/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/parsing/parser/sql/tcl/TCLStatement.java @@ -0,0 +1,35 @@ +/* + * Copyright 1999-2015 dangdang.com. + *

+ * Licensed 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 io.shardingjdbc.core.parsing.parser.sql.tcl; + +import io.shardingjdbc.core.constant.SQLType; +import io.shardingjdbc.core.parsing.parser.sql.AbstractSQLStatement; +import lombok.ToString; + +/** + * Transaction Control Language statement. + * + * @author zhangliang + */ +@ToString(callSuper = true) +public final class TCLStatement extends AbstractSQLStatement { + + public TCLStatement() { + super(SQLType.TCL); + } +} diff --git a/sharding-jdbc-core/src/test/resources/parser/tcl.xml b/sharding-jdbc-core/src/test/resources/parser/tcl.xml new file mode 100644 index 0000000000000..335a68b850355 --- /dev/null +++ b/sharding-jdbc-core/src/test/resources/parser/tcl.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/sharding-jdbc-core/src/test/resources/sql/tcl/tcl.xml b/sharding-jdbc-core/src/test/resources/sql/tcl/tcl.xml new file mode 100644 index 0000000000000..e1153f8e1d2f2 --- /dev/null +++ b/sharding-jdbc-core/src/test/resources/sql/tcl/tcl.xml @@ -0,0 +1,8 @@ + + + + + + + +