diff --git a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/parsing/parser/dialect/mysql/MySQLSelectParser.java b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/parsing/parser/dialect/mysql/MySQLSelectParser.java index e45f71403cb014f82856c0eb78f6c710ede40cc1..20f1924f2439775dfef1f4f6c1a095ee9a5a95ce 100755 --- a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/parsing/parser/dialect/mysql/MySQLSelectParser.java +++ b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/parsing/parser/dialect/mysql/MySQLSelectParser.java @@ -21,7 +21,6 @@ import com.dangdang.ddframe.rdb.sharding.api.rule.ShardingRule; import com.dangdang.ddframe.rdb.sharding.parsing.lexer.LexerEngine; import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.HavingSQLParser; import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.SelectListSQLParser; -import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.SelectRestSQLParser; import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.WhereSQLParser; import com.dangdang.ddframe.rdb.sharding.parsing.parser.statement.dql.select.AbstractSelectParser; import com.dangdang.ddframe.rdb.sharding.parsing.parser.statement.dql.select.SelectStatement; @@ -37,15 +36,12 @@ public final class MySQLSelectParser extends AbstractSelectParser { private final MySQLLimitSQLParser limitSQLParser; - private final SelectRestSQLParser selectRestSQLParser; - public MySQLSelectParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) { - super(shardingRule, lexerEngine, - new MySQLDistinctSQLParser(lexerEngine), new SelectListSQLParser(shardingRule, lexerEngine), new MySQLTableSQLParser(shardingRule, lexerEngine), - new WhereSQLParser(lexerEngine), new MySQLGroupBySQLParser(lexerEngine), new HavingSQLParser(lexerEngine), new MySQLOrderBySQLParser(lexerEngine)); + super(shardingRule, lexerEngine, new MySQLDistinctSQLParser(lexerEngine), new SelectListSQLParser(shardingRule, lexerEngine), new MySQLTableSQLParser(shardingRule, lexerEngine), + new WhereSQLParser(lexerEngine), new MySQLGroupBySQLParser(lexerEngine), new HavingSQLParser(lexerEngine), new MySQLOrderBySQLParser(lexerEngine), + new MySQLSelectRestSQLParser(lexerEngine)); selectOptionSQLParser = new MySQLSelectOptionSQLParser(lexerEngine); limitSQLParser = new MySQLLimitSQLParser(lexerEngine); - selectRestSQLParser = new MySQLSelectRestSQLParser(lexerEngine); } @Override @@ -59,7 +55,7 @@ public final class MySQLSelectParser extends AbstractSelectParser { parseHaving(); parseOrderBy(selectStatement); parseLimit(selectStatement); - selectRestSQLParser.parse(); + parseSelectRest(); } private void parseSelectOption() { diff --git a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/parsing/parser/dialect/oracle/OracleSelectParser.java b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/parsing/parser/dialect/oracle/OracleSelectParser.java index b381f1fca6f0e3a20f2bee9a2b022ac66a169d31..879333f242b0e556024628fb75daf8e8a3ffa23d 100755 --- a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/parsing/parser/dialect/oracle/OracleSelectParser.java +++ b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/parsing/parser/dialect/oracle/OracleSelectParser.java @@ -37,16 +37,13 @@ public final class OracleSelectParser extends AbstractSelectParser { private final OracleForParser forParser; - private final SelectRestSQLParser selectRestSQLParser; - public OracleSelectParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) { - super(shardingRule, lexerEngine, - new OracleDistinctSQLParser(lexerEngine), new OracleSelectListSQLParser(shardingRule, lexerEngine), new OracleTableSQLParser(shardingRule, lexerEngine), - new OracleWhereSQLParser(lexerEngine), new OracleGroupBySQLParser(lexerEngine), new HavingSQLParser(lexerEngine), new OracleOrderBySQLParser(lexerEngine)); + super(shardingRule, lexerEngine, new OracleDistinctSQLParser(lexerEngine), new OracleSelectListSQLParser(shardingRule, lexerEngine), new OracleTableSQLParser(shardingRule, lexerEngine), + new OracleWhereSQLParser(lexerEngine), new OracleGroupBySQLParser(lexerEngine), new HavingSQLParser(lexerEngine), new OracleOrderBySQLParser(lexerEngine), + new SelectRestSQLParser(lexerEngine)); hierarchicalQueryClauseParser = new OracleHierarchicalQueryClauseParser(shardingRule, lexerEngine); modelClauseParser = new OracleModelClauseParser(lexerEngine); forParser = new OracleForParser(lexerEngine); - selectRestSQLParser = new SelectRestSQLParser(lexerEngine); } @Override @@ -61,7 +58,7 @@ public final class OracleSelectParser extends AbstractSelectParser { parseModelClause(selectStatement); parseOrderBy(selectStatement); parseFor(selectStatement); - selectRestSQLParser.parse(); + parseSelectRest(); } private void parseHierarchicalQueryClause(final SelectStatement selectStatement) { diff --git a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/parsing/parser/dialect/postgresql/PostgreSQLSelectParser.java b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/parsing/parser/dialect/postgresql/PostgreSQLSelectParser.java index 98d71030340251675caad5b8e1b83bcea6b1d7e9..8efbdc17c0c161e156d5dbf6c170a341cc46a85d 100755 --- a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/parsing/parser/dialect/postgresql/PostgreSQLSelectParser.java +++ b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/parsing/parser/dialect/postgresql/PostgreSQLSelectParser.java @@ -23,7 +23,6 @@ import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.DistinctSQLParser; import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.GroupBySQLParser; import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.HavingSQLParser; import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.SelectListSQLParser; -import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.SelectRestSQLParser; import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.TableSQLParser; import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.WhereSQLParser; import com.dangdang.ddframe.rdb.sharding.parsing.parser.statement.dql.select.AbstractSelectParser; @@ -40,15 +39,12 @@ public final class PostgreSQLSelectParser extends AbstractSelectParser { private final PostgreSQLForSQLParser forSQLParser; - private final SelectRestSQLParser selectRestSQLParser; - public PostgreSQLSelectParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) { super(shardingRule, lexerEngine, new DistinctSQLParser(lexerEngine), new SelectListSQLParser(shardingRule, lexerEngine), new TableSQLParser(shardingRule, lexerEngine), new WhereSQLParser(lexerEngine), new GroupBySQLParser(lexerEngine), - new HavingSQLParser(lexerEngine), new PostgreSQLOrderBySQLParser(lexerEngine)); + new HavingSQLParser(lexerEngine), new PostgreSQLOrderBySQLParser(lexerEngine), new PostgreSQLSelectRestSQLParser(lexerEngine)); limitSQLParser = new PostgreSQLLimitSQLParser(lexerEngine); forSQLParser = new PostgreSQLForSQLParser(lexerEngine); - selectRestSQLParser = new PostgreSQLSelectRestSQLParser(lexerEngine); } @Override @@ -62,7 +58,7 @@ public final class PostgreSQLSelectParser extends AbstractSelectParser { parseOrderBy(selectStatement); parseLimit(selectStatement); parseFor(); - selectRestSQLParser.parse(); + parseSelectRest(); } private void parseLimit(final SelectStatement selectStatement) { diff --git a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/parsing/parser/dialect/sqlserver/SQLServerSelectParser.java b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/parsing/parser/dialect/sqlserver/SQLServerSelectParser.java index 805380b555498bd1fe7820c05777d27ea5fa3747..787e34352695c57d728d5960dcd7cd59635783e4 100755 --- a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/parsing/parser/dialect/sqlserver/SQLServerSelectParser.java +++ b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/parsing/parser/dialect/sqlserver/SQLServerSelectParser.java @@ -39,16 +39,13 @@ public final class SQLServerSelectParser extends AbstractSelectParser { private final SQLServerForSQLParser forSQLParser; - private final SelectRestSQLParser selectRestSQLParser; - public SQLServerSelectParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) { - super(shardingRule, lexerEngine, - new DistinctSQLParser(lexerEngine), new SQLServerSelectListSQLParser(shardingRule, lexerEngine), new SQLServerTableSQLParser(shardingRule, lexerEngine), - new SQLServerWhereSQLParser(lexerEngine), new GroupBySQLParser(lexerEngine), new HavingSQLParser(lexerEngine), new SQLServerOrderBySQLParser(lexerEngine)); + super(shardingRule, lexerEngine, new DistinctSQLParser(lexerEngine), new SQLServerSelectListSQLParser(shardingRule, lexerEngine), new SQLServerTableSQLParser(shardingRule, lexerEngine), + new SQLServerWhereSQLParser(lexerEngine), new GroupBySQLParser(lexerEngine), new HavingSQLParser(lexerEngine), new SQLServerOrderBySQLParser(lexerEngine), + new SelectRestSQLParser(lexerEngine)); sqlServerTopParser = new SQLServerTopParser(lexerEngine); offsetSQLParser = new SQLServerOffsetSQLParser(lexerEngine); forSQLParser = new SQLServerForSQLParser(lexerEngine); - selectRestSQLParser = new SelectRestSQLParser(lexerEngine); } @Override @@ -63,7 +60,7 @@ public final class SQLServerSelectParser extends AbstractSelectParser { parseOrderBy(selectStatement); parseOffset(selectStatement); parseFor(); - selectRestSQLParser.parse(); + parseSelectRest(); } private void parseTop(final SelectStatement selectStatement) { diff --git a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/parsing/parser/statement/dql/select/AbstractSelectParser.java b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/parsing/parser/statement/dql/select/AbstractSelectParser.java index f0c1c9112fa6d5062bbaefb703e99799e11e5feb..0b9fbaf9472b312e79f345a012dcab9e3fa3e669 100755 --- a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/parsing/parser/statement/dql/select/AbstractSelectParser.java +++ b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/parsing/parser/statement/dql/select/AbstractSelectParser.java @@ -32,6 +32,7 @@ import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.GroupBySQLParser; import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.HavingSQLParser; import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.OrderBySQLParser; import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.SelectListSQLParser; +import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.SelectRestSQLParser; import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.TableSQLParser; import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.WhereSQLParser; import com.dangdang.ddframe.rdb.sharding.parsing.parser.statement.SQLStatementParser; @@ -80,6 +81,8 @@ public abstract class AbstractSelectParser implements SQLStatementParser { private final OrderBySQLParser orderBySQLParser; + private final SelectRestSQLParser selectRestSQLParser; + private final List items = new LinkedList<>(); @Override @@ -147,6 +150,10 @@ public abstract class AbstractSelectParser implements SQLStatementParser { orderBySQLParser.parse(selectStatement); } + protected final void parseSelectRest() { + selectRestSQLParser.parse(); + } + private void appendDerivedColumns(final SelectStatement selectStatement) { ItemsToken itemsToken = new ItemsToken(selectStatement.getSelectListLastPosition()); appendAvgDerivedColumns(itemsToken, selectStatement);