Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Apache Shardingsphere DatabaseMetaDataManager Manage

From Leeroopedia


Knowledge Sources
Domains Mode_Management, Metadata, DDL
Last Updated 2026-02-10 00:00 GMT

Overview

Synchronized manager for database-level metadata operations including schema, table, and view lifecycle management.

Description

DatabaseMetaDataManager handles all database-level metadata operations with synchronized access. It manages database addition/removal, schema addition/removal, table and view alterations, and schema renaming. When schemas change, it triggers global rule refreshes to keep the runtime state consistent.

Usage

Invoked by change handlers in cluster mode or directly by standalone mode to apply metadata changes received from events or API calls.

Code Reference

Source Location

Signature

@RequiredArgsConstructor
public final class DatabaseMetaDataManager {

    private final MetaDataContexts metaDataContexts;

    public synchronized void addDatabase(String databaseName);
    public synchronized void dropDatabase(String databaseName);
    public synchronized void addSchema(String databaseName, String schemaName);
    public synchronized void dropSchema(String databaseName, String schemaName);
    public synchronized void alterTable(String databaseName, String schemaName, ShardingSphereTable table);
    public synchronized void dropTable(String databaseName, String schemaName, String tableName);
    public synchronized void alterView(String databaseName, String schemaName, ShardingSphereView view);
    public synchronized void dropView(String databaseName, String schemaName, String viewName);
    public synchronized void renameSchema(String databaseName, String fromSchemaName, String toSchemaName);
}

Import

import org.apache.shardingsphere.mode.metadata.manager.database.DatabaseMetaDataManager;

I/O Contract

Inputs

Name Type Required Description
databaseName String Yes Target database name
schemaName String Varies Target schema name
table ShardingSphereTable Varies Table metadata to alter
view ShardingSphereView Varies View metadata to alter

Outputs

Name Type Description
void Side effect: updates MetaDataContexts and triggers rule refresh

Usage Examples

DatabaseMetaDataManager manager = metaDataContextManager.getDatabaseMetaDataManager();

// Add a new database
manager.addDatabase("new_db");

// Add a schema
manager.addSchema("new_db", "public");

// Alter a table
manager.alterTable("new_db", "public", updatedTable);

// Drop a schema (also removes from global rules)
manager.dropSchema("new_db", "old_schema");

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment