HubSpot/jdbi-javadoc-queries

Name: jdbi-javadoc-queries

Owner: HubSpot

Description: null

Created: 2017-09-08 16:28:58.0

Updated: 2017-09-19 05:57:05.0

Pushed: 2017-09-12 17:11:03.0

Homepage: null

Size: 9

Language: null

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

jdbi-javadoc-queries

When using the JDBI SQL object API, it can be convenient and straight-forward to write your queries inline. For long queries, however, it can be hard to format them nicely due to Java's lack of multiline string literals. And because annotation values need to be constants, most multiline string workarounds aren't usable (since they usually rely on some form of method call). This also affects more than just readability, I've often written code such as:

qlQuery("" + 
      "SELECT * " +
      "FROM table" +
      "WHERE id = :id")
dget getById(@Bind("id") long id);        

Which is invalid due to the lack of whitespace between table and WHERE.

The goal of this library is to allow inline queries to be expressed using one of the few multiline string constructs that Java does support: comments! For ease of initial implementation, only Javadoc comments are supported. The previous example could be written as:

*
 SELECT *
 FROM table
 WHERE id = :id
/
qlQuery
dget getById(@Bind("id") long id);        

At build time, there is an annotation processor that captures these Javadoc comments and generates a helper class. At runtime, there is a org.skife.jdbi.v2.tweak.StatementLocator that looks up the SQL based on the SQL object class + method.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.