java.lang.Object
com.darkcollective.relix.connectors.std.internal.JdbcCatalogProvider
All Implemented Interfaces:
CatalogProvider

public final class JdbcCatalogProvider extends Object implements CatalogProvider
A CatalogProvider that introspects table schemas from a live database over JDBC, used when a connection.table reference declares no schema.

Columns are read from DatabaseMetaData.getColumns(java.lang.String, java.lang.String, java.lang.String, java.lang.String), mapping SQL types to relix ScalarTypes. Because identifier case-folding varies by dialect (H2 folds to upper-case, PostgreSQL to lower-case), the table name is tried as-given and then upper- and lower-cased. Any failure (unreachable database, unknown table) yields Optional.empty() rather than throwing, so analysis degrades to a clear "schema unavailable" diagnostic.

Statistics (tableStatistics(com.darkcollective.relix.lang.ast.ConnectionDeclaration, java.lang.String)) supply a COUNT(*) row count, the primary-key columns, and per-column distinct/null counts (gathered in one aggregate query), all read on demand. Each lookup opens a fresh connection and performs no caching; connection reuse arrives in a later phase.

Connections come from a ConnectionProvider, so a connection whose coordinates are not a URL can still be introspected. One analyzer holds one catalog provider for every connection a script declares, including non-JDBC ones; a declaration this provider cannot open is reported as Optional.empty() — schema unavailable — rather than raised, which is the same degradation an unreachable database already gets.

  • Constructor Details

    • JdbcCatalogProvider

      public JdbcCatalogProvider()
      Creates a provider opening connections from ConnectionProvider.FROM_URL.
    • JdbcCatalogProvider

      public JdbcCatalogProvider(ConnectionProvider connections)
      Creates a provider opening connections from connections.
      Parameters:
      connections - the source of introspection connections; must not be null
  • Method Details

    • tableSchema

      public Optional<Schema> tableSchema(ConnectionDeclaration connection, String table)
      Description copied from interface: CatalogProvider
      Returns the output schema of table within connection, or Optional.empty() if it cannot be determined.
      Specified by:
      tableSchema in interface CatalogProvider
      Parameters:
      connection - the declared connection the table belongs to
      table - the (possibly schema-qualified) remote table name
      Returns:
      the table's schema, or empty if unavailable
    • tableStatistics

      public Optional<RelationStatistics> tableStatistics(ConnectionDeclaration connection, String table)
      Description copied from interface: CatalogProvider
      Returns optimizer statistics (row count, keys) for table within connection, or Optional.empty() if none are available.

      The default returns empty; introspecting providers override this to query the live catalog. Statistics are advisory: a missing or partial value never affects correctness, only the quality of cost-based decisions.

      Specified by:
      tableStatistics in interface CatalogProvider
      Parameters:
      connection - the declared connection the table belongs to
      table - the (possibly schema-qualified) remote table name
      Returns:
      the table's statistics, or empty if unavailable