Commit 21816e5b authored by terrymanu's avatar terrymanu
Browse files

fix #386

parent 79d3d55d
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
## 2.0.0.M1

### 功能提升

1. [ISSUE #386](https://github.com/shardingjdbc/sharding-jdbc/issues/386) 支持SELECT 1这种不包含表名称的SQL

### 缺陷修正

1. [ISSUE #387](https://github.com/shardingjdbc/sharding-jdbc/issues/387) 当函数+列名中存在'`'防止关键字时处理出错
+4 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@

package io.shardingjdbc.core.routing.router;

import io.shardingjdbc.core.routing.type.all.DatabaseAllRoutingEngine;
import io.shardingjdbc.core.rule.ShardingRule;
import io.shardingjdbc.core.constant.DatabaseType;
import io.shardingjdbc.core.jdbc.core.ShardingContext;
@@ -108,7 +109,9 @@ public final class ParsingSQLRouter implements SQLRouter {
    private RoutingResult route(final List<Object> parameters, final SQLStatement sqlStatement) {
        Collection<String> tableNames = sqlStatement.getTables().getTableNames();
        RoutingEngine routingEngine;
        if (1 == tableNames.size() || shardingRule.isAllBindingTables(tableNames) || shardingRule.isAllInDefaultDataSource(tableNames)) {
        if (tableNames.isEmpty()) {
            routingEngine = new DatabaseAllRoutingEngine(shardingRule.getDataSourceMap());
        } else if (1 == tableNames.size() || shardingRule.isAllBindingTables(tableNames) || shardingRule.isAllInDefaultDataSource(tableNames)) {
            routingEngine = new SimpleRoutingEngine(shardingRule, parameters, tableNames.iterator().next(), sqlStatement);
        } else {
            // TODO config for cartesian set
+48 −0
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.all;

import io.shardingjdbc.core.routing.type.RoutingEngine;
import io.shardingjdbc.core.routing.type.RoutingResult;
import io.shardingjdbc.core.routing.type.TableUnit;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import javax.sql.DataSource;
import java.util.Map;

/**
 * Database all routing engine.
 * 
 * @author zhangliang
 */
@RequiredArgsConstructor
@Slf4j
public final class DatabaseAllRoutingEngine implements RoutingEngine {
    
    private final Map<String, DataSource> dataSourceMap;
    
    @Override
    public RoutingResult route() {
        RoutingResult result = new RoutingResult();
        for (String each : dataSourceMap.keySet()) {
            result.getTableUnits().getTableUnits().add(new TableUnit(each, "", ""));
        }
        return result;
    }
}
+5 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>
<sqls>
    <sql id="assertSelectOne">
        <sharding-rule>
            <data expected="select/SelectOne.xml" />
        </sharding-rule>
    </sql>
    <sql id="assertSelectNotEqualsWithSingleTable">
        <sharding-rule value="tbl">
            <data parameter="100000" expected="select/SelectNotEqualsWithSingleTable.xml" />
+3 −0
Original line number Diff line number Diff line
<dataset>
    <t_order a="1" />
</dataset>
Loading