This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang 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 f52a8521a7a Replace stream with loop in ShardingAuditChecker (#19601)
f52a8521a7a is described below
commit f52a8521a7a0b8cbf5cb5690f6dab588f673da55
Author: 吴伟杰 <[email protected]>
AuthorDate: Wed Jul 27 17:02:40 2022 +0800
Replace stream with loop in ShardingAuditChecker (#19601)
* Replace stream with loop in ShardingAuditChecker
* Fix checkstyle in ShardingAuditChecker
---
.../sharding/checker/audit/ShardingAuditChecker.java | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/checker/audit/ShardingAuditChecker.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/checker/audit/ShardingAuditChecker.java
index f04c71076b3..9452a117a4f 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/checker/audit/ShardingAuditChecker.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/checker/audit/ShardingAuditChecker.java
@@ -27,12 +27,12 @@ import
org.apache.shardingsphere.sharding.api.config.strategy.audit.ShardingAudi
import org.apache.shardingsphere.sharding.constant.ShardingOrder;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.BiPredicate;
-import java.util.stream.Collectors;
/**
* Sharding audit checker.
@@ -50,8 +50,7 @@ public final class ShardingAuditChecker implements
SQLChecker<ShardingRule> {
Collection<String> disableAuditNames = sqlStatementContext instanceof
CommonSQLStatementContext
? ((CommonSQLStatementContext<?>)
sqlStatementContext).getSqlHintExtractor().findDisableAuditNames()
: Collections.emptyList();
- Collection<ShardingAuditStrategyConfiguration> auditStrategies =
sqlStatementContext.getTablesContext().getTableNames().stream().filter(rule::isShardingTable)
- .map(each ->
rule.getAuditStrategyConfiguration(rule.getTableRule(each))).collect(Collectors.toList());
+ Collection<ShardingAuditStrategyConfiguration> auditStrategies =
getShardingAuditStrategies(sqlStatementContext, rule);
for (ShardingAuditStrategyConfiguration auditStrategy :
auditStrategies) {
for (String auditorName : auditStrategy.getAuditorNames()) {
if (auditStrategy.isAllowHintDisable() &&
disableAuditNames.contains(auditorName.toLowerCase())) {
@@ -76,6 +75,17 @@ public final class ShardingAuditChecker implements
SQLChecker<ShardingRule> {
return true;
}
+ private Collection<ShardingAuditStrategyConfiguration>
getShardingAuditStrategies(final SQLStatementContext<?> sqlStatementContext,
final ShardingRule rule) {
+ Collection<String> tableNames =
sqlStatementContext.getTablesContext().getTableNames();
+ Collection<ShardingAuditStrategyConfiguration> result = new
ArrayList<>(tableNames.size());
+ for (String each : tableNames) {
+ if (rule.isShardingTable(each)) {
+
result.add(rule.getAuditStrategyConfiguration(rule.getTableRule(each)));
+ }
+ }
+ return result;
+ }
+
@Override
public int getOrder() {
return ShardingOrder.ORDER;