/*
 * Copyright 1999-2015 dangdang.com.
 * <p>
 * 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.
 * </p>
 */

package com.dangdang.ddframe.rdb.sharding.parsing.parser.dialect.mysql;

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.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.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;

/**
 * MySQL Select语句解析器.
 *
 * @author zhangliang
 */
public final class MySQLSelectParser extends AbstractSelectParser {
    
    private final MySQLSelectOptionSQLParser selectOptionSQLParser;
    
    private final HavingSQLParser havingSQLParser;
    
    private final OrderBySQLParser orderBySQLParser;
    
    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));
        selectOptionSQLParser = new MySQLSelectOptionSQLParser(lexerEngine);
        havingSQLParser = new HavingSQLParser(lexerEngine);
        orderBySQLParser = new MySQLOrderBySQLParser(lexerEngine);
        limitSQLParser = new MySQLLimitSQLParser(lexerEngine);
        selectRestSQLParser = new MySQLSelectRestSQLParser(lexerEngine);
    }
    
    @Override
    protected void parseInternal(final SelectStatement selectStatement) {
        parseDistinct();
        selectOptionSQLParser.parse();
        parseSelectList(selectStatement, getItems());
        parseFrom(selectStatement);
        parseWhere(getShardingRule(), selectStatement, getItems());
        parseGroupBy(selectStatement);
        havingSQLParser.parse();
        orderBySQLParser.parse(selectStatement);
        limitSQLParser.parse(selectStatement);
        selectRestSQLParser.parse();
    }
}

@@ -2692,33 +2692,38 @@
 inct();%0A        
-s
+parseS
 electOptionSQLPa
@@ -2717,31 +2717,16 @@
 ctOption
-SQLParser.parse
 ();%0A    
@@ -2992,32 +2992,275 @@
 lectStatement);%0A
+        parseLimit(selectStatement);%0A        selectRestSQLParser.parse();%0A    %7D%0A    %0A    private void parseSelectOption() %7B%0A        selectOptionSQLParser.parse();%0A    %7D%0A    %0A    private void parseLimit(final SelectStatement selectStatement) %7B%0A
         limitSQL
@@ -3294,45 +3294,8 @@
 t);%0A
-        selectRestSQLParser.parse();%0A
     

refactor MySQL parser