From b6e035d1238550fe111b7cd0d701b6b086764397 Mon Sep 17 00:00:00 2001 From: Zhengqiang Duan Date: Wed, 9 Oct 2024 16:57:52 +0800 Subject: [PATCH] Minor refactor for EncryptRule build RuleAttributes (#33184) --- .../shardingsphere/encrypt/rule/EncryptRule.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptRule.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptRule.java index fa9c08181c2f2..a60a399481e2e 100644 --- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptRule.java +++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptRule.java @@ -68,7 +68,11 @@ public EncryptRule(final String databaseName, final EncryptRuleConfiguration rul each.getColumns().forEach(this::checkEncryptorType); tables.put(each.getName(), new EncryptTable(each, encryptors)); } - attributes.set(new RuleAttributes(new EncryptTableMapperRuleAttribute(tables.keySet()))); + attributes.set(buildRuleAttributes()); + } + + private RuleAttributes buildRuleAttributes() { + return new RuleAttributes(new EncryptTableMapperRuleAttribute(tables.keySet())); } private Map createEncryptors(final EncryptRuleConfiguration ruleConfig) { @@ -156,13 +160,13 @@ public boolean partialUpdate(final EncryptRuleConfiguration toBeUpdatedRuleConfi Collection toBeAddedTableNames = toBeUpdatedTablesNames.stream().filter(each -> !tables.containsKey(each)).collect(Collectors.toList()); if (!toBeAddedTableNames.isEmpty()) { toBeAddedTableNames.forEach(each -> addTableRule(each, toBeUpdatedRuleConfig)); - attributes.set(new RuleAttributes(new EncryptTableMapperRuleAttribute(tables.keySet()))); + attributes.set(buildRuleAttributes()); return true; } Collection toBeRemovedTableNames = tables.keySet().stream().filter(each -> !toBeUpdatedTablesNames.contains(each)).collect(Collectors.toList()); if (!toBeRemovedTableNames.isEmpty()) { toBeRemovedTableNames.forEach(tables::remove); - attributes.set(new RuleAttributes(new EncryptTableMapperRuleAttribute(tables.keySet()))); + attributes.set(buildRuleAttributes()); // TODO check and remove unused INLINE encryptors return true; }