Skip to content

Instantly share code, notes, and snippets.

Last active September 29, 2022 19:45
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
public abstract class DataExtractor implements RowMapper<DataEventMessage> {
protected ObjectMapper objectMapper;
private String sql;
private String schema;
private JdbcTemplate jdbcTemplate;
public DataEventMessage extract(final long uniqueId) {
return jdbcTemplate.query(sql, this, uniqueId);
public abstract String getPrimaryTable();
public abstract String getSql();
public void postConstruct() {
this.objectMapper = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);
this.sql = getSql().replace("<schema>", schema);
public DataExtractor setJdbcTemplate(final JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
return this;
public DataExtractor setSchema(@Value("${database.schema}") final String schema) {
this.schema = schema;
return this;
public boolean shouldExport() {
return true;
public class FooExtractor extends DataExtractor {
private static final String SQL = ""
+ " SELECT bar.baz AS baz,"
+ " foo.qux AS qux,"
+ " foo.quux AS quux"
+ " FROM <schema>.foo foo"
+ " JOIN <schema>.bar bar ON = bar.foo_id"
+ " WHERE = ?";
public String getPrimaryTable() {
return "foo";
public String getSql() {
return SQL;
public DataEventMessage mapRow(final ResultSet rs, final int rowNum) throws SQLException {
var message = new DataEventMessage();
return message;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment