No description, website, or topics provided.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.travis
src
.gitignore
.travis.sh
.travis.yml
.travis_after_success.sh
LICENSE
README.md
pom.xml
release

README.md

JDBJ is a small jdbc fluent interface for capturing query intent before query execution.

Primary Features

  • Named Parameters (No Positional Parameters, ever)
  • Collections bindable (not during batch execution)
  • Null-Safe fetching of (Boolean|Byte|Double|Float|Integer|Long|Short)
  • Lambda interface for bindings, transactions
  • Fetch-forward read-only cursors, always
  • Script Execution, with parameters
  • Comprehensive test suites for latest postgres, h2, derby, SQLite, MySql

Sample Code

Insert inside a transaction:

//INSERT some students
final List<NewStudent> newStudents = Arrays.asList(
        new NewStudent("Ada", "Lovelace", new BigDecimal("4.00")),
        new NewStudent("Haskell", "Curry", new BigDecimal("4.00"))
);

//NewStudent.INSERT is the resource which contains our sql statement
final ExecuteInsert<Long> insert = JDBJ.resource("student_insert.sql")
        .insert(rs->rs.getLong(1));

//db is a javax.sql.DataSource
List<Long> generatedKeys = JDBJ.transaction(connection -> {
    final List<Long> keys = new ArrayList<>();
    for (NewStudent newStudent : newStudents) {
        keys.addAll(insert.bindValues(newStudent::bindings).execute(connection));
    }
    return keys;
}).execute(db);

Select to list:

//setup query object
final MapQuery<Student> studentsByIds = JDBJ.resource("student_by_ids_limit.sql")
        .query()
        .bindLong(":limit", 10L)
        .bindLongs(":ids", generatedKeys)
        .map(Student::from);

//get as list
final ExecuteQuery<List<Student>> listQuery = studentsByIds
        .toList();
System.out.println(listQuery.execute(db));

Select to stream:

//get as stream
final StreamQuery<Student> streamQuery = studentsByIds
        .toStream();
try (Stream<Student> stream = streamQuery.execute(db)) {
    stream.forEach(System.out::println);
}

Examples

A full set of examples is being developed in the examples-branch, but here are some quick examples maintained in the test directory: