PostgreSQLSelectParser.java 3.4 KB
Newer Older
T
terrymanu 已提交
1
/*
2 3
 * Copyright 1999-2015 dangdang.com.
 * <p>
T
terrymanu 已提交
4 5 6 7 8 9 10 11 12 13 14
 * 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.
15
 * </p>
T
terrymanu 已提交
16 17
 */

T
terrymanu 已提交
18
package com.dangdang.ddframe.rdb.sharding.parsing.parser.dialect.postgresql;
T
terrymanu 已提交
19

20
import com.dangdang.ddframe.rdb.sharding.api.rule.ShardingRule;
T
terrymanu 已提交
21
import com.dangdang.ddframe.rdb.sharding.parsing.lexer.LexerEngine;
22
import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.OrderBySQLParser;
T
terrymanu 已提交
23
import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.DistinctSQLParser;
24
import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.GroupBySQLParser;
T
terrymanu 已提交
25
import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.HavingSQLParser;
26
import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.SelectListSQLParser;
T
terrymanu 已提交
27
import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.SelectRestSQLParser;
T
terrymanu 已提交
28
import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.TableSQLParser;
T
terrymanu 已提交
29
import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.WhereSQLParser;
T
terrymanu 已提交
30
import com.dangdang.ddframe.rdb.sharding.parsing.parser.statement.dql.select.AbstractSelectParser;
31
import com.dangdang.ddframe.rdb.sharding.parsing.parser.statement.dql.select.SelectStatement;
32

T
terrymanu 已提交
33 34 35 36 37 38
/**
 * PostgreSQL Select语句解析器.
 *
 * @author zhangliang
 */
public final class PostgreSQLSelectParser extends AbstractSelectParser {
T
terrymanu 已提交
39
    
T
terrymanu 已提交
40 41
    private final HavingSQLParser havingSQLParser;
    
42
    private final OrderBySQLParser orderBySQLParser;
43
    
T
terrymanu 已提交
44 45
    private  final PostgreSQLLimitSQLParser limitSQLParser;
    
T
terrymanu 已提交
46 47
    private  final PostgreSQLForSQLParser forSQLParser;
    
T
terrymanu 已提交
48 49
    private final SelectRestSQLParser selectRestSQLParser;
    
50
    public PostgreSQLSelectParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
T
terrymanu 已提交
51
        super(shardingRule, lexerEngine, new DistinctSQLParser(lexerEngine), 
T
terrymanu 已提交
52
                new SelectListSQLParser(shardingRule, lexerEngine), new TableSQLParser(shardingRule, lexerEngine), new WhereSQLParser(lexerEngine), new GroupBySQLParser(lexerEngine));
T
terrymanu 已提交
53
        havingSQLParser = new HavingSQLParser(lexerEngine);
54
        orderBySQLParser = new PostgreSQLOrderBySQLParser(lexerEngine);
T
terrymanu 已提交
55
        limitSQLParser = new PostgreSQLLimitSQLParser(lexerEngine);
T
terrymanu 已提交
56
        forSQLParser = new PostgreSQLForSQLParser(lexerEngine);
T
terrymanu 已提交
57
        selectRestSQLParser = new PostgreSQLSelectRestSQLParser(lexerEngine);
T
terrymanu 已提交
58 59
    }
    
T
terrymanu 已提交
60
    @Override
61
    protected void parseInternal(final SelectStatement selectStatement) {
T
terrymanu 已提交
62
        parseDistinct();
T
terrymanu 已提交
63
        parseSelectList(selectStatement, getItems());
64
        parseFrom(selectStatement);
T
terrymanu 已提交
65
        parseWhere(getShardingRule(), selectStatement, getItems());
T
terrymanu 已提交
66
        parseGroupBy(selectStatement);
T
terrymanu 已提交
67
        havingSQLParser.parse();
68
        orderBySQLParser.parse(selectStatement);
T
terrymanu 已提交
69 70 71 72 73 74
        parseLimit(selectStatement);
        parseFor();
        selectRestSQLParser.parse();
    }
    
    private void parseLimit(final SelectStatement selectStatement) {
T
terrymanu 已提交
75
        limitSQLParser.parse(selectStatement);
T
terrymanu 已提交
76 77 78
    }
    
    private void parseFor() {
T
terrymanu 已提交
79
        forSQLParser.parse();
T
terrymanu 已提交
80
    }
T
terrymanu 已提交
81
}