提交 585d8c0c 编写于 作者: T terrymanu

refactor parseWhere

上级 d47bdbc3
...@@ -37,8 +37,6 @@ public final class MySQLSelectParser extends AbstractSelectParser { ...@@ -37,8 +37,6 @@ public final class MySQLSelectParser extends AbstractSelectParser {
private final MySQLSelectOptionSQLParser selectOptionSQLParser; private final MySQLSelectOptionSQLParser selectOptionSQLParser;
private final WhereSQLParser whereSQLParser;
private final GroupBySQLParser groupBySQLParser; private final GroupBySQLParser groupBySQLParser;
private final HavingSQLParser havingSQLParser; private final HavingSQLParser havingSQLParser;
...@@ -50,9 +48,9 @@ public final class MySQLSelectParser extends AbstractSelectParser { ...@@ -50,9 +48,9 @@ public final class MySQLSelectParser extends AbstractSelectParser {
private final SelectRestSQLParser selectRestSQLParser; private final SelectRestSQLParser selectRestSQLParser;
public MySQLSelectParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) { public MySQLSelectParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
super(shardingRule, lexerEngine, new MySQLDistinctSQLParser(lexerEngine), new SelectListSQLParser(shardingRule, lexerEngine), new MySQLTableSQLParser(shardingRule, lexerEngine)); super(shardingRule, lexerEngine,
new MySQLDistinctSQLParser(lexerEngine), new SelectListSQLParser(shardingRule, lexerEngine), new MySQLTableSQLParser(shardingRule, lexerEngine), new WhereSQLParser(lexerEngine));
selectOptionSQLParser = new MySQLSelectOptionSQLParser(lexerEngine); selectOptionSQLParser = new MySQLSelectOptionSQLParser(lexerEngine);
whereSQLParser = new WhereSQLParser(lexerEngine);
groupBySQLParser = new MySQLGroupBySQLParser(lexerEngine); groupBySQLParser = new MySQLGroupBySQLParser(lexerEngine);
havingSQLParser = new HavingSQLParser(lexerEngine); havingSQLParser = new HavingSQLParser(lexerEngine);
orderBySQLParser = new MySQLOrderBySQLParser(lexerEngine); orderBySQLParser = new MySQLOrderBySQLParser(lexerEngine);
...@@ -66,7 +64,7 @@ public final class MySQLSelectParser extends AbstractSelectParser { ...@@ -66,7 +64,7 @@ public final class MySQLSelectParser extends AbstractSelectParser {
selectOptionSQLParser.parse(); selectOptionSQLParser.parse();
parseSelectList(selectStatement, getItems()); parseSelectList(selectStatement, getItems());
parseFrom(selectStatement); parseFrom(selectStatement);
whereSQLParser.parse(getShardingRule(), selectStatement, getItems()); parseWhere(getShardingRule(), selectStatement, getItems());
groupBySQLParser.parse(selectStatement); groupBySQLParser.parse(selectStatement);
havingSQLParser.parse(); havingSQLParser.parse();
orderBySQLParser.parse(selectStatement); orderBySQLParser.parse(selectStatement);
......
...@@ -23,7 +23,6 @@ import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.GroupBySQLParser; ...@@ -23,7 +23,6 @@ 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.HavingSQLParser;
import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.OrderBySQLParser; import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.OrderBySQLParser;
import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.SelectRestSQLParser; 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.AbstractSelectParser;
import com.dangdang.ddframe.rdb.sharding.parsing.parser.statement.dql.select.SelectStatement; import com.dangdang.ddframe.rdb.sharding.parsing.parser.statement.dql.select.SelectStatement;
...@@ -34,8 +33,6 @@ import com.dangdang.ddframe.rdb.sharding.parsing.parser.statement.dql.select.Sel ...@@ -34,8 +33,6 @@ import com.dangdang.ddframe.rdb.sharding.parsing.parser.statement.dql.select.Sel
*/ */
public final class OracleSelectParser extends AbstractSelectParser { public final class OracleSelectParser extends AbstractSelectParser {
private final WhereSQLParser whereSQLParser;
private final OracleHierarchicalQueryClauseParser hierarchicalQueryClauseParser; private final OracleHierarchicalQueryClauseParser hierarchicalQueryClauseParser;
private final GroupBySQLParser groupBySQLParser; private final GroupBySQLParser groupBySQLParser;
...@@ -51,8 +48,9 @@ public final class OracleSelectParser extends AbstractSelectParser { ...@@ -51,8 +48,9 @@ public final class OracleSelectParser extends AbstractSelectParser {
private final SelectRestSQLParser selectRestSQLParser; private final SelectRestSQLParser selectRestSQLParser;
public OracleSelectParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) { public OracleSelectParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
super(shardingRule, lexerEngine, new OracleDistinctSQLParser(lexerEngine), new OracleSelectListSQLParser(shardingRule, lexerEngine), new OracleTableSQLParser(shardingRule, lexerEngine)); super(shardingRule, lexerEngine,
whereSQLParser = new OracleWhereSQLParser(lexerEngine); new OracleDistinctSQLParser(lexerEngine), new OracleSelectListSQLParser(shardingRule, lexerEngine),
new OracleTableSQLParser(shardingRule, lexerEngine), new OracleWhereSQLParser(lexerEngine));
hierarchicalQueryClauseParser = new OracleHierarchicalQueryClauseParser(shardingRule, lexerEngine); hierarchicalQueryClauseParser = new OracleHierarchicalQueryClauseParser(shardingRule, lexerEngine);
groupBySQLParser = new OracleGroupBySQLParser(lexerEngine); groupBySQLParser = new OracleGroupBySQLParser(lexerEngine);
havingSQLParser = new HavingSQLParser(lexerEngine); havingSQLParser = new HavingSQLParser(lexerEngine);
...@@ -67,7 +65,7 @@ public final class OracleSelectParser extends AbstractSelectParser { ...@@ -67,7 +65,7 @@ public final class OracleSelectParser extends AbstractSelectParser {
parseDistinct(); parseDistinct();
parseSelectList(selectStatement, getItems()); parseSelectList(selectStatement, getItems());
parseFrom(selectStatement); parseFrom(selectStatement);
whereSQLParser.parse(getShardingRule(), selectStatement, getItems()); parseWhere(getShardingRule(), selectStatement, getItems());
hierarchicalQueryClauseParser.parse(selectStatement); hierarchicalQueryClauseParser.parse(selectStatement);
groupBySQLParser.parse(selectStatement); groupBySQLParser.parse(selectStatement);
havingSQLParser.parse(); havingSQLParser.parse();
......
...@@ -37,8 +37,6 @@ import com.dangdang.ddframe.rdb.sharding.parsing.parser.statement.dql.select.Sel ...@@ -37,8 +37,6 @@ import com.dangdang.ddframe.rdb.sharding.parsing.parser.statement.dql.select.Sel
*/ */
public final class PostgreSQLSelectParser extends AbstractSelectParser { public final class PostgreSQLSelectParser extends AbstractSelectParser {
private final WhereSQLParser whereSQLParser;
private final GroupBySQLParser groupBySQLParser; private final GroupBySQLParser groupBySQLParser;
private final HavingSQLParser havingSQLParser; private final HavingSQLParser havingSQLParser;
...@@ -52,8 +50,8 @@ public final class PostgreSQLSelectParser extends AbstractSelectParser { ...@@ -52,8 +50,8 @@ public final class PostgreSQLSelectParser extends AbstractSelectParser {
private final SelectRestSQLParser selectRestSQLParser; private final SelectRestSQLParser selectRestSQLParser;
public PostgreSQLSelectParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) { public PostgreSQLSelectParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
super(shardingRule, lexerEngine, new DistinctSQLParser(lexerEngine), new SelectListSQLParser(shardingRule, lexerEngine), new TableSQLParser(shardingRule, lexerEngine)); super(shardingRule, lexerEngine, new DistinctSQLParser(lexerEngine),
whereSQLParser = new WhereSQLParser(lexerEngine); new SelectListSQLParser(shardingRule, lexerEngine), new TableSQLParser(shardingRule, lexerEngine), new WhereSQLParser(lexerEngine));
groupBySQLParser = new GroupBySQLParser(lexerEngine); groupBySQLParser = new GroupBySQLParser(lexerEngine);
havingSQLParser = new HavingSQLParser(lexerEngine); havingSQLParser = new HavingSQLParser(lexerEngine);
orderBySQLParser = new PostgreSQLOrderBySQLParser(lexerEngine); orderBySQLParser = new PostgreSQLOrderBySQLParser(lexerEngine);
...@@ -67,7 +65,7 @@ public final class PostgreSQLSelectParser extends AbstractSelectParser { ...@@ -67,7 +65,7 @@ public final class PostgreSQLSelectParser extends AbstractSelectParser {
parseDistinct(); parseDistinct();
parseSelectList(selectStatement, getItems()); parseSelectList(selectStatement, getItems());
parseFrom(selectStatement); parseFrom(selectStatement);
whereSQLParser.parse(getShardingRule(), selectStatement, getItems()); parseWhere(getShardingRule(), selectStatement, getItems());
groupBySQLParser.parse(selectStatement); groupBySQLParser.parse(selectStatement);
havingSQLParser.parse(); havingSQLParser.parse();
orderBySQLParser.parse(selectStatement); orderBySQLParser.parse(selectStatement);
......
...@@ -25,7 +25,6 @@ import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.GroupBySQLParser; ...@@ -25,7 +25,6 @@ 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.HavingSQLParser;
import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.OrderBySQLParser; import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.OrderBySQLParser;
import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.SelectRestSQLParser; 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.AbstractSelectParser;
import com.dangdang.ddframe.rdb.sharding.parsing.parser.statement.dql.select.SelectStatement; import com.dangdang.ddframe.rdb.sharding.parsing.parser.statement.dql.select.SelectStatement;
...@@ -38,8 +37,6 @@ public final class SQLServerSelectParser extends AbstractSelectParser { ...@@ -38,8 +37,6 @@ public final class SQLServerSelectParser extends AbstractSelectParser {
private final SQLServerTopParser sqlServerTopParser; private final SQLServerTopParser sqlServerTopParser;
private final WhereSQLParser whereSQLParser;
private final GroupBySQLParser groupBySQLParser; private final GroupBySQLParser groupBySQLParser;
private final HavingSQLParser havingSQLParser; private final HavingSQLParser havingSQLParser;
...@@ -53,9 +50,10 @@ public final class SQLServerSelectParser extends AbstractSelectParser { ...@@ -53,9 +50,10 @@ public final class SQLServerSelectParser extends AbstractSelectParser {
private final SelectRestSQLParser selectRestSQLParser; private final SelectRestSQLParser selectRestSQLParser;
public SQLServerSelectParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) { public SQLServerSelectParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
super(shardingRule, lexerEngine, new DistinctSQLParser(lexerEngine), new SQLServerSelectListSQLParser(shardingRule, lexerEngine), new SQLServerTableSQLParser(shardingRule, lexerEngine)); super(shardingRule, lexerEngine,
new DistinctSQLParser(lexerEngine), new SQLServerSelectListSQLParser(shardingRule, lexerEngine), new SQLServerTableSQLParser(shardingRule, lexerEngine),
new SQLServerWhereSQLParser(lexerEngine));
sqlServerTopParser = new SQLServerTopParser(lexerEngine); sqlServerTopParser = new SQLServerTopParser(lexerEngine);
whereSQLParser = new SQLServerWhereSQLParser(lexerEngine);
groupBySQLParser = new GroupBySQLParser(lexerEngine); groupBySQLParser = new GroupBySQLParser(lexerEngine);
havingSQLParser = new HavingSQLParser(lexerEngine); havingSQLParser = new HavingSQLParser(lexerEngine);
orderBySQLParser = new MySQLOrderBySQLParser(lexerEngine); orderBySQLParser = new MySQLOrderBySQLParser(lexerEngine);
...@@ -70,7 +68,7 @@ public final class SQLServerSelectParser extends AbstractSelectParser { ...@@ -70,7 +68,7 @@ public final class SQLServerSelectParser extends AbstractSelectParser {
parseTop(selectStatement); parseTop(selectStatement);
parseSelectList(selectStatement, getItems()); parseSelectList(selectStatement, getItems());
parseFrom(selectStatement); parseFrom(selectStatement);
whereSQLParser.parse(getShardingRule(), selectStatement, getItems()); parseWhere(getShardingRule(), selectStatement, getItems());
groupBySQLParser.parse(selectStatement); groupBySQLParser.parse(selectStatement);
havingSQLParser.parse(); havingSQLParser.parse();
orderBySQLParser.parse(selectStatement); orderBySQLParser.parse(selectStatement);
......
...@@ -30,6 +30,7 @@ import com.dangdang.ddframe.rdb.sharding.parsing.parser.exception.SQLParsingUnsu ...@@ -30,6 +30,7 @@ import com.dangdang.ddframe.rdb.sharding.parsing.parser.exception.SQLParsingUnsu
import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.DistinctSQLParser; import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.DistinctSQLParser;
import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.SelectListSQLParser; import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.SelectListSQLParser;
import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.TableSQLParser; 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; import com.dangdang.ddframe.rdb.sharding.parsing.parser.statement.SQLStatementParser;
import com.dangdang.ddframe.rdb.sharding.parsing.parser.token.ItemsToken; import com.dangdang.ddframe.rdb.sharding.parsing.parser.token.ItemsToken;
import com.dangdang.ddframe.rdb.sharding.parsing.parser.token.OrderByToken; import com.dangdang.ddframe.rdb.sharding.parsing.parser.token.OrderByToken;
...@@ -68,6 +69,8 @@ public abstract class AbstractSelectParser implements SQLStatementParser { ...@@ -68,6 +69,8 @@ public abstract class AbstractSelectParser implements SQLStatementParser {
private final TableSQLParser tableSQLParser; private final TableSQLParser tableSQLParser;
private final WhereSQLParser whereSQLParser;
private final List<SelectItem> items = new LinkedList<>(); private final List<SelectItem> items = new LinkedList<>();
@Override @Override
...@@ -91,6 +94,14 @@ public abstract class AbstractSelectParser implements SQLStatementParser { ...@@ -91,6 +94,14 @@ public abstract class AbstractSelectParser implements SQLStatementParser {
protected abstract void parseInternal(final SelectStatement selectStatement); protected abstract void parseInternal(final SelectStatement selectStatement);
protected final void parseDistinct() {
distinctSQLParser.parse();
}
protected final void parseSelectList(final SelectStatement selectStatement, final List<SelectItem> items) {
selectListSQLParser.parse(selectStatement, items);
}
protected final void parseFrom(final SelectStatement selectStatement) { protected final void parseFrom(final SelectStatement selectStatement) {
if (lexerEngine.equalAny(DefaultKeyword.INTO)) { if (lexerEngine.equalAny(DefaultKeyword.INTO)) {
throw new SQLParsingUnsupportedException(DefaultKeyword.INTO); throw new SQLParsingUnsupportedException(DefaultKeyword.INTO);
...@@ -111,12 +122,8 @@ public abstract class AbstractSelectParser implements SQLStatementParser { ...@@ -111,12 +122,8 @@ public abstract class AbstractSelectParser implements SQLStatementParser {
tableSQLParser.parseJoinTable(selectStatement); tableSQLParser.parseJoinTable(selectStatement);
} }
protected final void parseDistinct() { protected final void parseWhere(final ShardingRule shardingRule, final SelectStatement selectStatement, final List<SelectItem> items) {
distinctSQLParser.parse(); whereSQLParser.parse(shardingRule, selectStatement, items);
}
protected final void parseSelectList(final SelectStatement selectStatement, final List<SelectItem> items) {
selectListSQLParser.parse(selectStatement, items);
} }
private void appendDerivedColumns(final SelectStatement selectStatement) { private void appendDerivedColumns(final SelectStatement selectStatement) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册