提交 f301fdc9 编写于 作者: G gaohongtao

Fix #212 prompts for missing data source rule

上级 fe69b296
......@@ -98,6 +98,7 @@ public final class ShardingConnection extends AbstractConnectionAdapter {
}
Context metricsContext = MetricsContext.start(Joiner.on("-").join("ShardingConnection-getConnection", dataSourceName));
DataSource dataSource = shardingContext.getShardingRule().getDataSourceRule().getDataSource(dataSourceName);
Preconditions.checkState(null != dataSource, "Missing the rule of %s in DataSourceRule", dataSourceName);
String realDataSourceName = dataSourceName;
if (dataSource instanceof MasterSlaveDataSource) {
dataSource = ((MasterSlaveDataSource) dataSource).getDataSource(sqlStatementType);
......
......@@ -82,4 +82,16 @@ public final class StaticShardingBothForStatementWithSelectTest extends Abstract
String sql = "SELECT * FROM t_global";
assertDataSet("integrate/dataset/dbtbl/expect/select/SelectGlobalTableOnly.xml", getShardingDataSource().getConnection(), "t_global", sql);
}
@Test
public void assertSelectGlobalTableWithDatabaseName() throws SQLException, DatabaseUnitException {
String sql = "SELECT * FROM dataSource_dbtbl_0.t_global";
assertDataSet("integrate/dataset/dbtbl/expect/select/SelectGlobalTableOnly.xml", getShardingDataSource().getConnection(), "t_global", sql);
}
@Test(expected = IllegalStateException.class)
public void assertSelectGlobalTableLacking() throws SQLException, DatabaseUnitException {
String sql = "SELECT * FROM dbtbl_0.t_global";
assertDataSet("integrate/dataset/dbtbl/expect/select/SelectGlobalTableOnly.xml", getShardingDataSource().getConnection(), "t_global", sql);
}
}
......@@ -8,6 +8,15 @@
<condition-context />
</condition-contexts>
</assert>
<assert id="assertSelectWithDatabaseName" sql="select * from db.order" expected-sql="SELECT * FROM [Token(db.order)]">
<tables>
<table name="db.order" />
</tables>
<condition-contexts>
<condition-context />
</condition-contexts>
</assert>
<assert id="assertSelectWithTableNameAsAlias" sql="select * from order where order.order_id = 1" expected-sql="SELECT * FROM [Token(order)] WHERE [Token(order)].order_id = 1">
<tables>
......
......@@ -7,6 +7,14 @@ prev = "/03-community/architecture"
next = "/03-community/directory-structure"
+++
## 1.4.2
### 功能提升
### 缺陷修正
1. [ISSUE #212](https://github.com/dangdangdotcom/sharding-jdbc/issues/212) 对去缺少数据源规则给出更有意义的提示
1. [ISSUE #214](https://github.com/dangdangdotcom/sharding-jdbc/issues/214) where中 table_name.column_name in (?,?)无法解析表达式
## 1.4.2
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册