Skip to content

Commit

Permalink
Refactor alterRuleConfiguration and removeRuleConfigurationItem inter…
Browse files Browse the repository at this point in the history
…face in StandaloneModeContextManager
  • Loading branch information
zhaojinchao95 committed May 22, 2024
1 parent 9e58dbc commit 7ea04f2
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -269,28 +269,29 @@ public Collection<MetaDataVersion> alterRuleConfiguration(final String databaseN
Collection<MetaDataVersion> metaDataVersions = contextManager.getMetaDataContexts().getPersistService().getDatabaseRulePersistService()
.persistConfigurations(contextManager.getMetaDataContexts().getMetaData().getDatabase(databaseName).getName(), Collections.singletonList(toBeAlteredRuleConfig));
contextManager.getMetaDataContexts().getPersistService().getMetaDataVersionPersistService().switchActiveVersion(metaDataVersions);
sendDatabaseRuleChangedEvent(databaseName, metaDataVersions);
sendDatabaseRuleChangedEvent(databaseName, metaDataVersions, Type.UPDATED);
clearServiceCache();
}
return Collections.emptyList();
}

private void sendDatabaseRuleChangedEvent(final String databaseName, final Collection<MetaDataVersion> metaDataVersions) {
private void sendDatabaseRuleChangedEvent(final String databaseName, final Collection<MetaDataVersion> metaDataVersions, final Type type) {
for (MetaDataVersion each : metaDataVersions) {
sendDatabaseRuleChangedEvent(databaseName, each);
sendDatabaseRuleChangedEvent(databaseName, each, type);
}
}

private void sendDatabaseRuleChangedEvent(final String databaseName, final MetaDataVersion metaDataVersion) {
ruleConfigurationEventBuilder.build(databaseName, new DataChangedEvent(metaDataVersion.getActiveVersionNodePath(), metaDataVersion.getNextActiveVersion(), Type.UPDATED))
private void sendDatabaseRuleChangedEvent(final String databaseName, final MetaDataVersion metaDataVersion, final Type type) {
ruleConfigurationEventBuilder.build(databaseName, new DataChangedEvent(metaDataVersion.getActiveVersionNodePath(), metaDataVersion.getNextActiveVersion(), type))
.ifPresent(optional -> contextManager.getComputeNodeInstanceContext().getEventBusContext().post(optional));
}

@Override
public void removeRuleConfigurationItem(final String databaseName, final RuleConfiguration toBeRemovedRuleConfig) {
if (null != toBeRemovedRuleConfig) {
sendDatabaseRuleChangedEvent(databaseName,
contextManager.getMetaDataContexts().getPersistService().getDatabaseRulePersistService().deleteConfigurations(databaseName, Collections.singleton(toBeRemovedRuleConfig)));
contextManager.getMetaDataContexts().getPersistService().getDatabaseRulePersistService().deleteConfigurations(databaseName,
Collections.singleton(toBeRemovedRuleConfig)), Type.DELETED);
clearServiceCache();
}
}
Expand Down

0 comments on commit 7ea04f2

Please sign in to comment.