diff --git a/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/rule/ShardingRule.java b/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/rule/ShardingRule.java index 6b0eaf1e7b7a1a5e8046d11b4ce8c65f34a1fb24..890dc32bc491ff9cb53a0ecc5194f15189ef073d 100644 --- a/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/rule/ShardingRule.java +++ b/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/rule/ShardingRule.java @@ -19,7 +19,6 @@ package io.shardingjdbc.core.rule; import com.google.common.base.Optional; import com.google.common.base.Strings; -import io.shardingjdbc.core.exception.ShardingJdbcException; import io.shardingjdbc.core.keygen.KeyGenerator; import io.shardingjdbc.core.parsing.parser.context.condition.Column; import io.shardingjdbc.core.routing.strategy.ShardingStrategy; @@ -130,7 +129,7 @@ public final class ShardingRule { if (null != defaultDataSourceName) { return createTableRuleWithDefaultDataSource(logicTableName.toLowerCase()); } - throw new ShardingJdbcException("Cannot find table rule and default data source with logic table: '%s'", logicTableName); + throw new ShardingRuleException("Cannot find table rule and default data source with logic table: '%s'", logicTableName); } private TableRule createTableRuleWithDefaultDataSource(final String logicTableName) { @@ -274,7 +273,7 @@ public final class ShardingRule { public Number generateKey(final String logicTableName) { Optional tableRule = tryFindTableRuleByLogicTable(logicTableName); if (!tableRule.isPresent()) { - throw new ShardingJdbcException("Cannot find strategy for generate keys."); + throw new ShardingRuleException("Cannot find strategy for generate keys."); } if (null != tableRule.get().getKeyGenerator()) { return tableRule.get().getKeyGenerator().generateKey(); @@ -294,7 +293,7 @@ public final class ShardingRule { return each.getLogicTable(); } } - throw new ShardingJdbcException("Cannot find logic table name with logic index name: '%s'", logicIndexName); + throw new ShardingRuleException("Cannot find logic table name with logic index name: '%s'", logicIndexName); } /** @@ -310,6 +309,6 @@ public final class ShardingRule { return each; } } - throw new ShardingJdbcException("Cannot find actual data node for logic table name: '%s'", tableRule.getLogicTable()); + throw new ShardingRuleException("Cannot find actual data node for logic table name: '%s'", tableRule.getLogicTable()); } } diff --git a/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/rule/ShardingRuleException.java b/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/rule/ShardingRuleException.java new file mode 100644 index 0000000000000000000000000000000000000000..3668380a51d4acc7ca591ea60949b053b6c2b4ea --- /dev/null +++ b/sharding-jdbc-core/src/main/java/io/shardingjdbc/core/rule/ShardingRuleException.java @@ -0,0 +1,38 @@ +/* + * Copyright 1999-2015 dangdang.com. + *

+ * 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. + *

+ */ + +package io.shardingjdbc.core.rule; + +/** + * Sharding rule exception. + * + * @author zhangliang + */ +public final class ShardingRuleException extends RuntimeException { + + private static final long serialVersionUID = -1360264079938958332L; + + /** + * Constructs an exception with formatted error message and arguments. + * + * @param errorMessage formatted error message + * @param args arguments of error message + */ + public ShardingRuleException(final String errorMessage, final Object... args) { + super(String.format(errorMessage, args)); + } +}