Skip to content

Commit

Permalink
Simplify MetaDataContextsFactory (#34321)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu authored Jan 12, 2025
1 parent 91724d0 commit 0f36656
Showing 1 changed file with 6 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,28 +72,20 @@ public final class MetaDataContextsFactory {
* @return meta data contexts
* @throws SQLException SQL exception
*/
public static MetaDataContexts create(final MetaDataPersistService persistService, final ContextManagerBuilderParameter param,
final ComputeNodeInstanceContext instanceContext) throws SQLException {
public static MetaDataContexts create(final MetaDataPersistService persistService,
final ContextManagerBuilderParameter param, final ComputeNodeInstanceContext instanceContext) throws SQLException {
return isCreateByLocal(persistService) ? createByLocal(persistService, param, instanceContext) : createByRepository(persistService, param, instanceContext);
}

private static boolean isCreateByLocal(final MetaDataPersistService persistService) {
return persistService.getDatabaseMetaDataFacade().getDatabase().loadAllDatabaseNames().isEmpty();
}

private static MetaDataContexts createByLocal(final MetaDataPersistService persistService, final ContextManagerBuilderParameter param,
final ComputeNodeInstanceContext instanceContext) throws SQLException {
Map<String, DatabaseConfiguration> effectiveDatabaseConfigs = param.getDatabaseConfigs();
Collection<RuleConfiguration> globalRuleConfigs;
if (instanceContext.getModeConfiguration().isCluster()) {
globalRuleConfigs = new RuleConfigurationPersistDecorateEngine(instanceContext).tryRestore(param.getGlobalRuleConfigs());
param.getGlobalRuleConfigs().clear();
param.getGlobalRuleConfigs().addAll(globalRuleConfigs);
} else {
globalRuleConfigs = param.getGlobalRuleConfigs();
}
private static MetaDataContexts createByLocal(final MetaDataPersistService persistService,
final ContextManagerBuilderParameter param, final ComputeNodeInstanceContext instanceContext) throws SQLException {
Collection<RuleConfiguration> globalRuleConfigs = param.getGlobalRuleConfigs();
ConfigurationProperties props = new ConfigurationProperties(param.getProps());
Map<String, ShardingSphereDatabase> databases = ExternalMetaDataFactory.create(effectiveDatabaseConfigs, props, instanceContext);
Map<String, ShardingSphereDatabase> databases = ExternalMetaDataFactory.create(param.getDatabaseConfigs(), props, instanceContext);
MetaDataContexts result = newMetaDataContexts(persistService, param, globalRuleConfigs, databases, props);
persistDatabaseConfigurations(result, param, persistService, instanceContext);
persistMetaData(result, persistService);
Expand Down

0 comments on commit 0f36656

Please sign in to comment.