Skip to content

Commit

Permalink
Fix #212 prompts for missing data source rule
Browse files Browse the repository at this point in the history
  • Loading branch information
gaohongtao committed Jan 10, 2017
1 parent 3842365 commit 5d599c4
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ private Connection getConnectionInternal(final String dataSourceName, final SQLS
}
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,16 @@ public void assertSelectGlobalTableOnly() throws SQLException, DatabaseUnitExcep
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
8 changes: 8 additions & 0 deletions sharding-jdbc-doc/content/03-community/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.1

Expand Down

0 comments on commit 5d599c4

Please sign in to comment.