-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor rule item changed subscriber (#26763)
* Refactor SingleTableSubscriber * Refactor EncryptTableSubscriber * Refactor EncryptTableSubscriber * Refactor RuleItemChangedSubscribeEngine * Refactor EncryptorSubscriber * Refactor CompatibleEncryptorSubscriber and CompatibleEncryptTableSubscriber * Refactor MaskAlgorithmSubscriber and MaskTableSubscriber * Refactor ReadwriteSplittingLoadBalancerSubscriber * Refactor ReadwriteSplittingDataSourceSubscriber * Refactor BroadcastTableSubscriber * Refactor DefaultStrategySubscribeEngine * Refactor DefaultShardingAuditorStrategySubscriber * Refactor DefaultShardingColumnSubscriber * Refactor KeyGeneratorSubscriber * Refactor ShardingAuditorSubscriber * Refactor ShardingAutoTableSubscriber * Refactor ShardingCacheSubscriber * Refactor ShardingTableSubscriber * Refactor ShardingTableReferenceSubscriber * Refactor ShadowTableSubscriber * Refactor ShadowDataSourceSubscriber * Refactor ShadowAlgorithmSubscriber * Refactor DefaultShadowAlgorithmNameSubscriber
- Loading branch information
Showing
54 changed files
with
1,706 additions
and
834 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
...in/java/org/apache/shardingsphere/broadcast/subscriber/BroadcastTableSubscribeEngine.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.apache.shardingsphere.broadcast.subscriber; | ||
|
||
import org.apache.shardingsphere.broadcast.api.config.BroadcastRuleConfiguration; | ||
import org.apache.shardingsphere.broadcast.rule.BroadcastRule; | ||
import org.apache.shardingsphere.broadcast.yaml.config.YamlBroadcastRuleConfiguration; | ||
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; | ||
import org.apache.shardingsphere.infra.rule.event.rule.alter.AlterRuleItemEvent; | ||
import org.apache.shardingsphere.infra.rule.event.rule.drop.DropRuleItemEvent; | ||
import org.apache.shardingsphere.infra.util.yaml.YamlEngine; | ||
import org.apache.shardingsphere.mode.manager.ContextManager; | ||
import org.apache.shardingsphere.mode.subsciber.RuleItemChangedSubscribeEngine; | ||
|
||
import java.util.LinkedList; | ||
|
||
/** | ||
* Broadcast table subscribe engine. | ||
*/ | ||
public final class BroadcastTableSubscribeEngine extends RuleItemChangedSubscribeEngine<BroadcastRuleConfiguration, BroadcastRuleConfiguration> { | ||
|
||
public BroadcastTableSubscribeEngine(final ContextManager contextManager) { | ||
super(contextManager); | ||
} | ||
|
||
@Override | ||
protected BroadcastRuleConfiguration swapRuleItemConfigurationFromEvent(final AlterRuleItemEvent event, final String yamlContent) { | ||
return new BroadcastRuleConfiguration(YamlEngine.unmarshal(yamlContent, YamlBroadcastRuleConfiguration.class).getTables()); | ||
} | ||
|
||
@Override | ||
protected BroadcastRuleConfiguration findRuleConfiguration(final ShardingSphereDatabase database) { | ||
return database.getRuleMetaData().findSingleRule(BroadcastRule.class).map(BroadcastRule::getConfiguration).orElseGet(() -> new BroadcastRuleConfiguration(new LinkedList<>())); | ||
} | ||
|
||
@Override | ||
protected void changeRuleItemConfiguration(final AlterRuleItemEvent event, final BroadcastRuleConfiguration currentRuleConfig, final BroadcastRuleConfiguration toBeChangedItemConfig) { | ||
currentRuleConfig.getTables().clear(); | ||
currentRuleConfig.getTables().addAll(toBeChangedItemConfig.getTables()); | ||
} | ||
|
||
@Override | ||
protected void dropRuleItemConfiguration(final DropRuleItemEvent event, final BroadcastRuleConfiguration currentRuleConfig) { | ||
currentRuleConfig.getTables().clear(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...e/shardingsphere/encrypt/subscriber/compatible/CompatibleEncryptTableSubscribeEngine.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.apache.shardingsphere.encrypt.subscriber.compatible; | ||
|
||
import org.apache.shardingsphere.encrypt.api.config.CompatibleEncryptRuleConfiguration; | ||
import org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration; | ||
import org.apache.shardingsphere.encrypt.rule.EncryptRule; | ||
import org.apache.shardingsphere.encrypt.yaml.config.rule.YamlEncryptTableRuleConfiguration; | ||
import org.apache.shardingsphere.encrypt.yaml.swapper.rule.YamlEncryptTableRuleConfigurationSwapper; | ||
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; | ||
import org.apache.shardingsphere.infra.rule.event.rule.alter.AlterRuleItemEvent; | ||
import org.apache.shardingsphere.infra.rule.event.rule.drop.DropNamedRuleItemEvent; | ||
import org.apache.shardingsphere.infra.rule.event.rule.drop.DropRuleItemEvent; | ||
import org.apache.shardingsphere.infra.util.yaml.YamlEngine; | ||
import org.apache.shardingsphere.mode.manager.ContextManager; | ||
import org.apache.shardingsphere.mode.subsciber.RuleItemChangedSubscribeEngine; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.LinkedList; | ||
|
||
/** | ||
* Compatible encrypt table subscribe engine. | ||
* @deprecated compatible support will remove in next version. | ||
*/ | ||
@Deprecated | ||
public final class CompatibleEncryptTableSubscribeEngine extends RuleItemChangedSubscribeEngine<CompatibleEncryptRuleConfiguration, EncryptTableRuleConfiguration> { | ||
|
||
public CompatibleEncryptTableSubscribeEngine(final ContextManager contextManager) { | ||
super(contextManager); | ||
} | ||
|
||
@Override | ||
protected EncryptTableRuleConfiguration swapRuleItemConfigurationFromEvent(final AlterRuleItemEvent event, final String yamlContent) { | ||
return new YamlEncryptTableRuleConfigurationSwapper().swapToObject(YamlEngine.unmarshal(yamlContent, YamlEncryptTableRuleConfiguration.class)); | ||
} | ||
|
||
@Override | ||
protected CompatibleEncryptRuleConfiguration findRuleConfiguration(final ShardingSphereDatabase database) { | ||
return database.getRuleMetaData().findSingleRule(EncryptRule.class) | ||
.map(optional -> getCompatibleEncryptRuleConfiguration((CompatibleEncryptRuleConfiguration) optional.getConfiguration())) | ||
.orElseGet(() -> new CompatibleEncryptRuleConfiguration(new LinkedList<>(), new LinkedHashMap<>())); | ||
} | ||
|
||
private CompatibleEncryptRuleConfiguration getCompatibleEncryptRuleConfiguration(final CompatibleEncryptRuleConfiguration config) { | ||
return null == config.getTables() ? new CompatibleEncryptRuleConfiguration(new LinkedList<>(), config.getEncryptors()) : config; | ||
} | ||
|
||
@Override | ||
protected void changeRuleItemConfiguration(final AlterRuleItemEvent event, final CompatibleEncryptRuleConfiguration currentRuleConfig, final EncryptTableRuleConfiguration toBeChangedItemConfig) { | ||
// TODO refactor DistSQL to only persist config | ||
currentRuleConfig.getTables().removeIf(each -> each.getName().equals(toBeChangedItemConfig.getName())); | ||
currentRuleConfig.getTables().add(toBeChangedItemConfig); | ||
} | ||
|
||
@Override | ||
protected void dropRuleItemConfiguration(final DropRuleItemEvent event, final CompatibleEncryptRuleConfiguration currentRuleConfig) { | ||
currentRuleConfig.getTables().removeIf(each -> each.getName().equals(((DropNamedRuleItemEvent) event).getItemName())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.