You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ji...@apache.org on 2021/10/26 07:18:02 UTC
[shardingsphere] branch master updated: Reduce Properties
invocation in InlineShardingAlgorithm (#13282)
This is an automated email from the ASF dual-hosted git repository.
jianglongtao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 5ded926 Reduce Properties invocation in InlineShardingAlgorithm (#13282)
5ded926 is described below
commit 5ded926cd46b9aefa4d5abb8e6e5dbb8e8f4d664
Author: 吴伟杰 <wu...@apache.org>
AuthorDate: Tue Oct 26 15:17:19 2021 +0800
Reduce Properties invocation in InlineShardingAlgorithm (#13282)
* Reduce Properties invocation in InlineShardingAlgorithm
* Refactor for code style
* Fix checkstyle
---
.../sharding/inline/InlineShardingAlgorithm.java | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/inline/InlineShardingAlgorithm.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/inline/InlineShardingAlgorithm.java
index ffeb8e3b..28d7172 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/inline/InlineShardingAlgorithm.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/inline/InlineShardingAlgorithm.java
@@ -39,6 +39,8 @@ public final class InlineShardingAlgorithm implements StandardShardingAlgorithm<
private static final String ALLOW_RANGE_QUERY_KEY = "allow-range-query-with-inline-sharding";
+ private String algorithmExpression;
+
private boolean allowRangeQuery;
@Getter
@@ -47,16 +49,14 @@ public final class InlineShardingAlgorithm implements StandardShardingAlgorithm<
@Override
public void init() {
+ algorithmExpression = getAlgorithmExpression();
allowRangeQuery = isAllowRangeQuery();
}
- private Closure<?> createClosure() {
+ private String getAlgorithmExpression() {
String expression = props.getProperty(ALGORITHM_EXPRESSION_KEY);
Preconditions.checkNotNull(expression, "Inline sharding algorithm expression cannot be null.");
- String algorithmExpression = InlineExpressionParser.handlePlaceHolder(expression.trim());
- Closure<?> result = new InlineExpressionParser(algorithmExpression).evaluateClosure().rehydrate(new Expando(), null, null);
- result.setResolveStrategy(Closure.DELEGATE_ONLY);
- return result;
+ return InlineExpressionParser.handlePlaceHolder(expression.trim());
}
private boolean isAllowRangeQuery() {
@@ -78,6 +78,12 @@ public final class InlineShardingAlgorithm implements StandardShardingAlgorithm<
throw new UnsupportedOperationException("Since the property of `" + ALLOW_RANGE_QUERY_KEY + "` is false, inline sharding algorithm can not tackle with range query.");
}
+ private Closure<?> createClosure() {
+ Closure<?> result = new InlineExpressionParser(algorithmExpression).evaluateClosure().rehydrate(new Expando(), null, null);
+ result.setResolveStrategy(Closure.DELEGATE_ONLY);
+ return result;
+ }
+
@Override
public String getType() {
return "INLINE";