Skip to content

Commit

Permalink
Refactor ShardingSphereSchema.putView (#33817)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu authored Nov 26, 2024
1 parent 15dc388 commit 7b87b62
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,6 @@ public void putTable(final String tableName, final ShardingSphereTable table) {
tables.put(tableName.toLowerCase(), table);
}

/**
* Add view.
*
* @param viewName view name
* @param view view
*/
public void putView(final String viewName, final ShardingSphereView view) {
views.put(viewName.toLowerCase(), view);
}

/**
* Add tables.
*
Expand All @@ -113,6 +103,15 @@ public void putTables(final Map<String, ShardingSphereTable> tables) {
}
}

/**
* Add view.
*
* @param view view
*/
public void putView(final ShardingSphereView view) {
views.put(view.getName().toLowerCase(), view);
}

/**
* Remove table.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ private void alterView(final String databaseName, final String schemaName, final
if (TableRefreshUtils.isSingleTable(beBoChangedView.getName(), database)) {
database.reloadRules();
}
database.getSchema(schemaName).putView(beBoChangedView.getName(), beBoChangedView);
database.getSchema(schemaName).putView(beBoChangedView);
}

private void dropTable(final String databaseName, final String schemaName, final String toBeDeletedTableName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private ShardingSphereSchema getSchema(final ShardingSphereDatabase database, fi
Optional<ShardingSphereTable> actualViewMetaData = Optional.ofNullable(schemaMap.get(schemaName)).map(optional -> optional.getTable(viewName));
ShardingSphereSchema result = new ShardingSphereSchema(schemaName);
actualViewMetaData.ifPresent(optional -> result.putTable(viewName, optional));
result.putView(viewName, new ShardingSphereView(viewName, viewDefinition));
result.putView(new ShardingSphereView(viewName, viewDefinition));
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private void addViewsToDataNode(final ShardingSphereDatabase database, final Str
database.getRuleMetaData().getAttributes(MutableDataNodeRuleAttribute.class).forEach(each -> each.put(logicDataSourceName, schemaName, entry.getKey()));
}
Optional.ofNullable(toBeAddedTables.get(entry.getKey().toLowerCase())).ifPresent(optional -> database.getSchema(schemaName).putTable(entry.getKey(), optional));
database.getSchema(schemaName).putView(entry.getKey(), entry.getValue());
database.getSchema(schemaName).putView(entry.getValue());
}
}

Expand Down

0 comments on commit 7b87b62

Please sign in to comment.