提交 21816e5b 编写于 作者: T terrymanu

fix #386

上级 79d3d55d
## 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) 当函数+列名中存在'`'防止关键字时处理出错
......
......@@ -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
......
/*
* 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;
}
}
<?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" />
......
<dataset>
<t_order a="1" />
<t_order a="1" />
<t_order a="1" />
<t_order a="1" />
<t_order a="1" />
<t_order a="1" />
<t_order a="1" />
<t_order a="1" />
<t_order a="1" />
<t_order a="1" />
</dataset>
<dataset>
<t_order a="1" />
<t_order a="1" />
<t_order a="1" />
<t_order a="1" />
<t_order a="1" />
<t_order a="1" />
<t_order a="1" />
<t_order a="1" />
<t_order a="1" />
<t_order a="1" />
</dataset>
<dataset>
<t_order a="1" />
<t_order a="1" />
<t_order a="1" />
<t_order a="1" />
<t_order a="1" />
<t_order a="1" />
<t_order a="1" />
<t_order a="1" />
<t_order a="1" />
<t_order a="1" />
</dataset>
<?xml version="1.0" encoding="UTF-8"?>
<asserts>
<assert id="assertSelectOne">
</assert>
<assert id="assertSelectNotEqualsWithSingleTable" parameters="1">
<tables>
<table name="t_order_item" />
......
<?xml version="1.0" encoding="UTF-8"?>
<sqls>
<sql id="assertSelectOne" value="SELECT 1 as a" />
<sql id="assertSelectNotEqualsWithSingleTable" value="SELECT * FROM t_order_item WHERE item_id &lt;&gt; %s ORDER BY item_id" />
<sql id="assertSelectNotEqualsWithSingleTableForExclamationEqual" value="SELECT * FROM t_order_item WHERE item_id != %s ORDER BY item_id" />
<sql id="assertSelectNotEqualsWithSingleTableForNotIn" value="SELECT * FROM t_order_item WHERE item_id NOT IN (%s) ORDER BY item_id" />
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册