Class DataSourceService

java.lang.Object
io.micronaut.controlpanel.panels.datasource.DataSourceService

@EachBean(DataSource.class) public class DataSourceService extends Object
Service for a specific DataSource, providing metadata about tables, columns, keys, etc.
  • Constructor Details

    • DataSourceService

      @Inject public DataSourceService(@Parameter DataSource dataSource, List<io.micronaut.controlpanel.panels.datasource.ConnectionPoolInspector> connectionPoolInspectors)
    • DataSourceService

      public DataSourceService(@Parameter DataSource dataSource)
  • Method Details

    • getJdbcInfo

      public JdbcInfo getJdbcInfo()
      Retrieves JDBC product and driver metadata for the datasource.
      Returns:
      JDBC metadata, or an empty metadata object if it cannot be read
    • getPoolInfo

      public Optional<PoolInfo> getPoolInfo()
      Retrieves connection pool metadata when the datasource uses a supported pool provider.
      Returns:
      pool metadata for supported datasources, otherwise empty
    • getTables

      public final List<Table> getTables()
      Retrieves a list of tables from the database, including schema, columns, primary keys, and foreign keys.
      Returns:
      List of Table metadata objects
    • generateMermaidER

      public String generateMermaidER(List<Table> tables)
      Generate a Mermaid ER diagram for the current datasource based on the provided tables metadata. It includes entities with attributes (type, size, NOT NULL) and relationships based on foreign keys.
      Parameters:
      tables - Tables discovered by getTables()
      Returns:
      Mermaid ER diagram code
    • executeQuery

      public DataSourceService.QueryResult executeQuery(String sql, int start, int length)
      Sanitize, execute and paginate a SQL query.
      Parameters:
      sql - The SQL to execute
      start - Offset of the first row
      length - Maximum number of rows to return
      Returns:
      QueryResult with column labels, rows and total row count