java.lang.Object
com.darkcollective.relix.connectors.std.internal.JdbcDataSourceConnector
All Implemented Interfaces:
DataSourceConnector, AutoCloseable

public final class JdbcDataSourceConnector extends Object implements DataSourceConnector
A DataSourceConnector that reads connection-backed tables over JDBC.

For a relation declared as source T from conn { … } or referenced as conn.table, this connector resolves the relation's ConnectionTableSourceConfig (from SemanticModel.sources()) and the matching ConnectionDeclaration (from SemanticModel.connections()), opens a JDBC connection, runs SELECT * FROM <table>, and maps each ResultSet row to a relix Row using the requested schema.

Rows are streamed lazily: the returned Stream pulls from the live ResultSet and, when the stream is closed, closes the ResultSet and Statement and releases the Connection back to a ConnectionPool for reuse. The executor closes every source stream (materialising operators via try-with-resources, the terminal stream in QueryExecutor), so connections are released deterministically. A driver fetch-size hint is set so drivers that honour it stream from a server-side cursor rather than buffering the whole result. Credentials are taken from the (placeholders already resolved) connection configuration.

close() closes the pool — but only when the connector created it (the JdbcDataSourceConnector(SemanticModel) constructor); a pool passed in is owned by the caller.

  • Constructor Details

    • JdbcDataSourceConnector

      public JdbcDataSourceConnector(SemanticModel model)
      Creates a connector with its own ConnectionPool, closed by close().
      Parameters:
      model - the semantic model whose sources and connections describe each JDBC-backed relation; must not be null
    • JdbcDataSourceConnector

      public JdbcDataSourceConnector(SemanticModel model, ConnectionPool pool)
      Creates a connector backed by a shared ConnectionPool; the pool is owned by the caller and is not closed by close().
      Parameters:
      model - the semantic model; must not be null
      pool - the shared connection pool; must not be null
    • JdbcDataSourceConnector

      public JdbcDataSourceConnector(SemanticModel model, DriverProvisioner provisioner)
      Creates a connector (with its own pool) that provisions a missing JDBC driver on demand via provisioner before failing.
      Parameters:
      model - the semantic model; must not be null
      provisioner - the driver provisioner consulted when no driver is registered for a connection URL; must not be null
    • JdbcDataSourceConnector

      public JdbcDataSourceConnector(SemanticModel model, ConnectionPool pool, DriverProvisioner provisioner)
      Creates a connector over a shared ConnectionPool that also provisions a missing JDBC driver on demand — the two halves of the other constructors at once.

      This is the shape a long-lived host wants: the pool outlives any one query, so it is the caller's and is not closed by close(), while a pool built over a ConnectionProvider that serves live handles is how a bound DataSource reaches execution.

      Parameters:
      model - the semantic model; must not be null
      pool - the shared connection pool; must not be null
      provisioner - the driver provisioner consulted when no driver is registered for a connection URL; must not be null
  • Method Details

    • close

      public void close()
      Description copied from interface: DataSourceConnector
      Releases any resources the connector holds (e.g. a pool of database connections). The default does nothing, so simple lambda connectors need not implement it; resource-backed connectors override it. Overrides do not throw checked exceptions, so try-with-resources needs no extra catch.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface DataSourceConnector
    • open

      public Stream<Row> open(String relationName, Schema schema)
      Description copied from interface: DataSourceConnector
      Opens a stream of rows for the named relation.
      Specified by:
      open in interface DataSourceConnector
      Parameters:
      relationName - the canonical (lower-cased) relation name
      schema - the expected schema; may be used to map source columns to the correct positions and types
      Returns:
      a stream of rows; the caller is responsible for closing it
    • openQuery

      public Stream<Row> openQuery(String connectionName, String nativeQuery, Schema schema)
      Description copied from interface: DataSourceConnector
      Runs a pushed-down native query on a named connection and streams the result.

      Columns are read positionally, in schema order, so the query's result column order must match schema. The default implementation rejects pushdown; connectors that support native-query execution override it.

      Specified by:
      openQuery in interface DataSourceConnector
      Parameters:
      connectionName - the canonical name of the connection to run the query on
      nativeQuery - the backend-native query text (SQL for JDBC, etc.)
      schema - the expected output schema; columns are read by position
      Returns:
      a stream of rows; the caller is responsible for closing it