JDBC Extension

The JDBC extension enables reading from and writing to databases with a JDBC interface in Grainite applications.

Setup

In order to be able to use the JDBC extension, first include it as a dependency in your application's pom.xml file.

...
<dependency>
  <groupId>ext.grainite</groupId>
  <artifactId>grainite-jdbc</artifactId>
  <version>{GRAINITE-VERSION}</version>
</dependency>
...

Replace {GRAINITE-VERSION} with the version of Grainite you are also using for libgrainite (the Grainite Client library for Java).

Contents

The JDBC Extension includes:

  • JDBCReaderTask: Task to continuously call a stored procedure on a given database, with a timestamp parameter, to get incremental changes.

  • JDBCWriterHandler: Handler that will write its payload to a given table in the database

JDBCReaderTask

The reader assumes that there is a stored procedure it can invoke with a timestamp parameter, that will return changed rows along with their timestamp. It can then invoke this continuously to establish a "poor-man’s change data capture (CDC)."

Also, it is expected that the returned resultset should have a column recordId that represents the ID of the record, when found, it is expected that the row is being updated and inserted when recordId is not found in the record. Similarly, there is an expected entityName on the returned row, this is then used as the key for the topic or grain message.

The JDBCReaderTask also backs-off when it does not get any results - this backoff is exponential with a max of 60 seconds.

Usage

To include this task in your application, you must specify the taskClass ext.grainite.tasks.jdbcreader.JDBCReaderTask and taskInstanceClass ext.grainite.tasks.jdbcreader.JDBCReaderInstance in your application's configuration YAML file.

app.yaml
...
tasks:
  - task_name: my_jdbc_reader_task
    taskClass: ext.grainite.tasks.jdbcreader.JDBCReaderTask
    taskInstanceClass: ext.grainite.tasks.jdbcreader.JDBCReaderInstance
    config:
...

Below are the configuration options that can be passed in under config:

JDBCWriterHandler

changeType is expected in each record with a value of ‘CREATE’, ‘UPDATE’ or ‘DELETE’.

Usage

To include this handler in your application, you must specify the class_name ext.grainite.handlers.jdbcwriter.JDBCWriterHandler in your application's configuration YAML file.

app.yaml
...
tables:
  - table_name: my_jdbc_writer
    key_type: string
    action_handlers:
      - name: my_jdbc_writer
        type: java
        class_name: ext.grainite.handlers.jdbcwriter.JDBCWriterHandler
        config:
...

Below are the configuration options that can be passed in under config:

JDBC is a trademark of ORACLE AMERICA, INC.

Last updated