Commit dc36e721 authored by terrymanu's avatar terrymanu
Browse files

remove ShowRoutingEngine

parent bb5f14e2
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import io.shardingjdbc.core.parsing.SQLParsingEngine;
import io.shardingjdbc.core.parsing.parser.context.GeneratedKey;
import io.shardingjdbc.core.parsing.parser.dialect.mysql.statement.DescStatement;
import io.shardingjdbc.core.parsing.parser.dialect.mysql.statement.ShowStatement;
import io.shardingjdbc.core.parsing.parser.dialect.mysql.statement.ShowType;
import io.shardingjdbc.core.parsing.parser.sql.SQLStatement;
import io.shardingjdbc.core.parsing.parser.sql.ddl.DDLStatement;
import io.shardingjdbc.core.parsing.parser.sql.dml.insert.InsertStatement;
@@ -42,7 +43,6 @@ import io.shardingjdbc.core.routing.type.complex.CartesianRoutingResult;
import io.shardingjdbc.core.routing.type.complex.CartesianTableReference;
import io.shardingjdbc.core.routing.type.complex.ComplexRoutingEngine;
import io.shardingjdbc.core.routing.type.ignore.IgnoreRoutingEngine;
import io.shardingjdbc.core.routing.type.show.ShowRoutingEngine;
import io.shardingjdbc.core.routing.type.standard.StandardRoutingEngine;
import io.shardingjdbc.core.routing.type.unicast.UnicastRoutingEngine;
import io.shardingjdbc.core.rule.ShardingRule;
@@ -121,8 +121,14 @@ public final class ParsingSQLRouter implements SQLRouter {
            routingEngine = new IgnoreRoutingEngine();
        } else if (sqlStatement instanceof DDLStatement) {
            routingEngine = new TableBroadcastRoutingEngine(shardingRule, sqlStatement);
        } else if (sqlStatement instanceof ShowStatement) {
            routingEngine = new ShowRoutingEngine(shardingRule, (ShowStatement) sqlStatement);
        } else if (sqlStatement instanceof ShowStatement && ShowType.DATABASES == ((ShowStatement) sqlStatement).getShowType()) {
            routingEngine = new DatabaseBroadcastRoutingEngine(shardingRule);
        } else if (sqlStatement instanceof ShowStatement && ShowType.TABLES == ((ShowStatement) sqlStatement).getShowType()) {
            routingEngine = new DatabaseBroadcastRoutingEngine(shardingRule);
        } else if (sqlStatement instanceof ShowStatement && ShowType.COLUMNS == ((ShowStatement) sqlStatement).getShowType()) {
            routingEngine = new UnicastRoutingEngine(shardingRule, sqlStatement);
        } else if (sqlStatement instanceof ShowStatement && ShowType.OTHER == ((ShowStatement) sqlStatement).getShowType()) {
            routingEngine = new UnicastRoutingEngine(shardingRule, sqlStatement);
        } else if (sqlStatement instanceof DescStatement) {
            routingEngine = new UnicastRoutingEngine(shardingRule, sqlStatement);
        } else if (tableNames.isEmpty()) {
+0 −2
Original line number Diff line number Diff line
@@ -19,14 +19,12 @@ package io.shardingjdbc.core.routing.type.ignore;

import io.shardingjdbc.core.routing.type.RoutingEngine;
import io.shardingjdbc.core.routing.type.RoutingResult;
import lombok.RequiredArgsConstructor;

/**
 * Ignore routing engine.
 * 
 * @author zhangliang
 */
@RequiredArgsConstructor
public final class IgnoreRoutingEngine implements RoutingEngine {
    
    @Override
+0 −58
Original line number Diff line number Diff line
/*
 * 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 io.shardingjdbc.core.routing.type.show;

import io.shardingjdbc.core.parsing.parser.dialect.mysql.statement.ShowStatement;
import io.shardingjdbc.core.parsing.parser.dialect.mysql.statement.ShowType;
import io.shardingjdbc.core.routing.type.RoutingEngine;
import io.shardingjdbc.core.routing.type.RoutingResult;
import io.shardingjdbc.core.routing.type.TableUnit;
import io.shardingjdbc.core.routing.type.unicast.UnicastRoutingEngine;
import io.shardingjdbc.core.rule.ShardingRule;
import lombok.RequiredArgsConstructor;

/**
 * Show routing engine.
 * 
 * @author zhangliang
 */
@RequiredArgsConstructor
public final class ShowRoutingEngine implements RoutingEngine {
    
    private final ShardingRule shardingRule;
    
    private final ShowStatement showStatement;
    
    @Override
    public RoutingResult route() {
        RoutingResult result = new RoutingResult();
        // TODO databases don't need route
        if (ShowType.DATABASES == showStatement.getShowType() || ShowType.TABLES == showStatement.getShowType()) {
            for (String each : shardingRule.getDataSourceMap().keySet()) {
                result.getTableUnits().getTableUnits().add(new TableUnit(each, "", ""));
            }
        } else if (ShowType.COLUMNS == showStatement.getShowType()) {
            // TODO refactor to UnicastRoutingEngine
            UnicastRoutingEngine engine = new UnicastRoutingEngine(shardingRule, showStatement);
            return engine.route();
        } else {
            result.getTableUnits().getTableUnits().add(new TableUnit(shardingRule.getDataSourceMap().keySet().iterator().next(), "", ""));
        }
        return result;
    }
}