提交 75d28f9d 编写于 作者: T terrymanu

IllegalStateException => ShardingRuleException for rule package

上级 560a8e00
......@@ -18,7 +18,6 @@
package io.shardingjdbc.core.rule;
import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
......@@ -70,7 +69,9 @@ public final class BindingTableRule {
break;
}
}
Preconditions.checkState(-1 != index, String.format("Actual table [%s].[%s] is not in table config", dataSource, otherActualTable));
if (-1 == index) {
throw new ShardingRuleException("Actual table [%s].[%s] is not in table config", dataSource, otherActualTable);
}
for (TableRule each : tableRules) {
if (each.getLogicTable().equals(logicTable.toLowerCase())) {
return each.getActualDataNodes().get(index).getTableName().toLowerCase();
......
......@@ -17,7 +17,6 @@
package io.shardingjdbc.core.rule;
import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
import lombok.EqualsAndHashCode;
import lombok.Getter;
......@@ -49,7 +48,9 @@ public class DataNode {
* @param dataNode string of data node. use {@code .} to split data source name and table name.
*/
public DataNode(final String dataNode) {
Preconditions.checkArgument(DataNode.isValidDataNode(dataNode), String.format("Invalid format for actual data nodes: '%s'", dataNode));
if (!isValidDataNode(dataNode)) {
throw new ShardingRuleException("Invalid format for actual data nodes: '%s'", dataNode);
}
List<String> segments = Splitter.on(DELIMITER).splitToList(dataNode);
dataSourceName = segments.get(0);
tableName = segments.get(1);
......
......@@ -18,6 +18,7 @@
package io.shardingjdbc.core.rule;
import com.google.common.base.Preconditions;
import io.shardingjdbc.core.exception.ShardingJdbcException;
import io.shardingjdbc.core.keygen.KeyGenerator;
import io.shardingjdbc.core.routing.strategy.ShardingStrategy;
import lombok.Getter;
......@@ -77,7 +78,9 @@ public final class TableRule {
List<DataNode> result = new LinkedList<>();
for (String each : actualDataNodes) {
DataNode dataNode = new DataNode(each);
Preconditions.checkArgument(dataSourceMap.containsKey(dataNode.getDataSourceName()), String.format("Cannot find data source in sharding rule, invalid actual data node is: '%s'", each));
if (!dataSourceMap.containsKey(dataNode.getDataSourceName())) {
throw new ShardingJdbcException("Cannot find data source in sharding rule, invalid actual data node is: '%s'", each);
}
result.add(dataNode);
}
return result;
......
......@@ -48,7 +48,7 @@ public final class BindingTableRuleTest {
assertThat(createBindingTableRule().getBindingActualTable("ds1", "Sub_Logic_Table", "table_1"), is("sub_table_1"));
}
@Test(expected = IllegalStateException.class)
@Test(expected = ShardingRuleException.class)
public void assertGetBindingActualTablesFailureWhenNotFound() {
createBindingTableRule().getBindingActualTable("no_ds", "Sub_Logic_Table", "table_1");
}
......
......@@ -31,12 +31,12 @@ public class DataNodeTest {
assertThat(dataNode.getTableName(), is("tbl_0"));
}
@Test(expected = IllegalArgumentException.class)
@Test(expected = ShardingRuleException.class)
public void assertNewInValidDataNodeWithoutDelimiter() {
new DataNode("ds_0tbl_0");
}
@Test(expected = IllegalArgumentException.class)
@Test(expected = ShardingRuleException.class)
public void assertNewInValidDataNodeWithTwoDelimiters() {
new DataNode("ds_0.tbl_0.tbl_1");
}
......
......@@ -23,6 +23,7 @@ import io.shardingjdbc.core.jdbc.core.ShardingContext;
import io.shardingjdbc.core.jdbc.core.datasource.ShardingDataSource;
import io.shardingjdbc.core.rule.BindingTableRule;
import io.shardingjdbc.core.rule.ShardingRule;
import io.shardingjdbc.core.rule.ShardingRuleException;
import org.apache.commons.dbcp.BasicDataSource;
import org.h2.Driver;
import org.junit.Test;
......@@ -65,7 +66,7 @@ public class YamlShardingDataSourceTest {
getShardingRule("/yaml/config/config-classNotFound.yaml");
}
@Test(expected = IllegalStateException.class)
@Test(expected = ShardingRuleException.class)
public void assertBindingError() throws SQLException, IOException, URISyntaxException, ReflectiveOperationException {
Map<String, DataSource> dataSourceMap = new HashMap<>(1);
dataSourceMap.put("ds", createDataSource());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册