JDBC

JDBC Source Configuration

The JDBC Source allows you to load files from within a JDBC database

Maven Dependency

We first must ensure we are importing the correct dependency. Your pom should have:

    <!-- For JDBC Source -->
    <dependency>
        <groupId>com.activeviam.io</groupId>
        <artifactId>data-connectors-jdbc</artifactId>
        <version>${dataconnectors.version}</version>
    </dependency>

Source Configuration

We build an instance of JdbcScopedFetchSource that collects all the JDBC topics. It can load data from a Database into ActivePivot, based on SQL statements (defined via source topics) and fetch business scopes, which are defined at fetch time to derive the SQL input parameters required for injection into those statements.

Below is an example:

@Bean(destroyMethod = "close")
public IJdbcScopedFetchSource jdbcSource() {

    final IJdbcScopedFetchSource source = new JdbcScopedFetchSource(dbConnectionConfig.dbConnectionFactory(), null);

    final String productTopicSql = String.join(" ",
            "SELECT ProductId AS ",
            DatastoreNames.PRODUCT_ID,
            ", Name AS ",
            DatastoreNames.PRODUCT_NAME,
            ", Color AS ",
            DatastoreNames.PRODUCT_COLOR,
            ", Price AS ",
            DatastoreNames.PRODUCT_PRICE,
            ", CobDate AS ",
            DatastoreNames.PRODUCT_COB_DATE,
            " FROM ", PRODUCT_TABLE_NAME
            ," WHERE  CobDate = ?"
            );

    source.addTopic(
            new JdbcStatementTopic(
                    JDBC_TOPIC__PRODUCT,
                    productTopicSql,
                    new CobDateScopeToSqlParametersConverter(),
                    null,
                    JdbcPreparedStatementTask.PLUGIN_KEY,
                    null));

    return source;
}

private static class CobDateScopeToSqlParametersConverter extends JdbcStatementTopic.ScopeToSqlParametersConverter {

    public CobDateScopeToSqlParametersConverter() {
        super(DataLoadControllerRestService.SCOPE_KEY__COB_DATE);
    }

    @Override
    protected Object formatValue(
            final String key,
            final Object value) {

        if (DataLoadControllerRestService.SCOPE_KEY__COB_DATE.equals(key)) {
            return java.sql.Date.valueOf(LocalDate.parse((String) value));
        }
        return super.formatValue(key, value);
    }    
}