From f301fdc9ff1e22ecb8507ee81eda4be91c17bc82 Mon Sep 17 00:00:00 2001 From: gaohongtao Date: Tue, 10 Jan 2017 19:45:34 +0800 Subject: [PATCH] Fix #212 prompts for missing data source rule --- .../rdb/sharding/jdbc/ShardingConnection.java | 1 + ...StaticShardingBothForStatementWithSelectTest.java | 12 ++++++++++++ .../parser/mysql/statement/simple_select.xml | 9 +++++++++ .../content/03-community/release-notes.md | 8 ++++++++ 4 files changed, 30 insertions(+) diff --git a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/jdbc/ShardingConnection.java b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/jdbc/ShardingConnection.java index d337405077825..80ccdd6184d25 100644 --- a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/jdbc/ShardingConnection.java +++ b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/jdbc/ShardingConnection.java @@ -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); diff --git a/sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/integrate/dbtbl/statically/statement/StaticShardingBothForStatementWithSelectTest.java b/sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/integrate/dbtbl/statically/statement/StaticShardingBothForStatementWithSelectTest.java index 7568a61863b6d..49157f5ff2f1c 100644 --- a/sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/integrate/dbtbl/statically/statement/StaticShardingBothForStatementWithSelectTest.java +++ b/sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/integrate/dbtbl/statically/statement/StaticShardingBothForStatementWithSelectTest.java @@ -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); + } } diff --git a/sharding-jdbc-core/src/test/resources/com/dangdang/ddframe/rdb/sharding/parser/mysql/statement/simple_select.xml b/sharding-jdbc-core/src/test/resources/com/dangdang/ddframe/rdb/sharding/parser/mysql/statement/simple_select.xml index f2094ebdd1893..34871f508bc3a 100644 --- a/sharding-jdbc-core/src/test/resources/com/dangdang/ddframe/rdb/sharding/parser/mysql/statement/simple_select.xml +++ b/sharding-jdbc-core/src/test/resources/com/dangdang/ddframe/rdb/sharding/parser/mysql/statement/simple_select.xml @@ -8,6 +8,15 @@ + + + + + + + + + diff --git a/sharding-jdbc-doc/content/03-community/release-notes.md b/sharding-jdbc-doc/content/03-community/release-notes.md index 5d88ad38c68f9..7d9f8d90d55f9 100644 --- a/sharding-jdbc-doc/content/03-community/release-notes.md +++ b/sharding-jdbc-doc/content/03-community/release-notes.md @@ -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