PostgreSQLSelectParser.java 3.5 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;
T
terrymanu 已提交
22
import com.dangdang.ddframe.rdb.sharding.parsing.lexer.dialect.postgresql.PostgreSQLKeyword;
T
terrymanu 已提交
23
import com.dangdang.ddframe.rdb.sharding.parsing.lexer.token.DefaultKeyword;
T
terrymanu 已提交
24
import com.dangdang.ddframe.rdb.sharding.parsing.lexer.token.Keyword;
25
import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.AbstractOrderBySQLParser;
T
terrymanu 已提交
26
import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.DistinctSQLParser;
27
import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.GroupBySQLParser;
T
terrymanu 已提交
28
import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.HavingSQLParser;
29
import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.SelectListSQLParser;
T
terrymanu 已提交
30
import com.dangdang.ddframe.rdb.sharding.parsing.parser.sql.WhereSQLParser;
T
terrymanu 已提交
31
import com.dangdang.ddframe.rdb.sharding.parsing.parser.statement.dql.select.AbstractSelectParser;
32
import com.dangdang.ddframe.rdb.sharding.parsing.parser.statement.dql.select.SelectStatement;
33

T
terrymanu 已提交
34 35 36 37 38 39
/**
 * PostgreSQL Select语句解析器.
 *
 * @author zhangliang
 */
public final class PostgreSQLSelectParser extends AbstractSelectParser {
T
terrymanu 已提交
40
    
T
terrymanu 已提交
41 42
    private final DistinctSQLParser distinctSQLParser;
    
43 44 45 46
    private final SelectListSQLParser selectListSQLParser;
    
    private final GroupBySQLParser groupBySQLParser;
    
T
terrymanu 已提交
47 48
    private final HavingSQLParser havingSQLParser;
    
49 50
    private final AbstractOrderBySQLParser orderBySQLParser;
    
T
terrymanu 已提交
51 52
    private  final PostgreSQLLimitSQLParser limitSQLParser;
    
T
terrymanu 已提交
53 54
    private  final PostgreSQLForSQLParser forSQLParser;
    
55 56
    public PostgreSQLSelectParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
        super(shardingRule, lexerEngine, new WhereSQLParser(lexerEngine));
T
terrymanu 已提交
57
        distinctSQLParser = new DistinctSQLParser(lexerEngine);
58 59
        selectListSQLParser = new SelectListSQLParser(shardingRule, lexerEngine);
        groupBySQLParser = new GroupBySQLParser(lexerEngine);
T
terrymanu 已提交
60
        havingSQLParser = new HavingSQLParser(lexerEngine);
61
        orderBySQLParser = new PostgreSQLOrderBySQLParser(lexerEngine);
T
terrymanu 已提交
62
        limitSQLParser = new PostgreSQLLimitSQLParser(lexerEngine);
T
terrymanu 已提交
63
        forSQLParser = new PostgreSQLForSQLParser(lexerEngine);
T
terrymanu 已提交
64 65
    }
    
T
terrymanu 已提交
66
    @Override
67
    protected void parseInternal(final SelectStatement selectStatement) {
T
terrymanu 已提交
68
        distinctSQLParser.parse();
69
        selectListSQLParser.parse(selectStatement, getItems());
70 71
        parseFrom(selectStatement);
        parseWhere(selectStatement);
72
        groupBySQLParser.parse(selectStatement);
T
terrymanu 已提交
73
        havingSQLParser.parse();
74
        orderBySQLParser.parse(selectStatement);
T
terrymanu 已提交
75
        limitSQLParser.parse(selectStatement);
T
terrymanu 已提交
76
        forSQLParser.parse();
T
terrymanu 已提交
77
        parseRest();
T
terrymanu 已提交
78 79
    }
    
T
terrymanu 已提交
80 81 82 83
    @Override
    protected Keyword[] getUnsupportedKeywordsRest() {
        return new Keyword[] {PostgreSQLKeyword.WINDOW, DefaultKeyword.FETCH};
    }
T
terrymanu 已提交
84
}