PostgreSQLSelectParser.java 3.0 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 22
import com.dangdang.ddframe.rdb.sharding.parsing.lexer.LexerEngine;
import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.DistinctSQLParser;
23
import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.GroupBySQLParser;
T
terrymanu 已提交
24
import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.HavingSQLParser;
25
import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.SelectListSQLParser;
T
terrymanu 已提交
26
import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.TableSQLParser;
T
terrymanu 已提交
27
import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.WhereSQLParser;
T
terrymanu 已提交
28
import com.dangdang.ddframe.rdb.sharding.parsing.parser.statement.dql.select.AbstractSelectParser;
29
import com.dangdang.ddframe.rdb.sharding.parsing.parser.statement.dql.select.SelectStatement;
30

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