Click here to Skip to main content
15,886,199 members
Articles / Programming Languages / SQL

Functional, Fluent JDBC - FluentJdbc

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
19 Jan 2015CPOL1 min read 7.5K   1  
FluentJdbc is a functional, fluent API to execute most common SQL operations an application needs as a single statement.

Some projects relying on a relational database do just fine using a high-level ORM, some have need for more low-level control over the queries. Using JDBC directly for application development can be really cumbersome. Not because it's a bad API, the problem is it's so low-level it's really more suitable for tool- than application development.

There are many abstraction layer libraries over JDBC that add the much needed syntax sugar. Even so, sometimes I find it difficult to find a suitable one for the applications I work on. Either because they constrain in some way or have other unwanted properties (like transitive dependencies).

In some cases, I implemented abstractions of my own and a pattern has started to emerge. I decided to collect those ideas and make it a library for easier reuse. A library that makes the most common SQL querying operations as simple, declarative as possible, is light-weight, has no dependencies. Most similar libraries don't make use of a fluent API which makes way for some interesting possibilities in terms of both readability and flexibility. Also I wanted to put some emphasis on easy integration to popular persistence / transaction management tools since the goal is to complement them, not necessarily replace them. As a result, it blends quite well with JPA, Spring, Guice, JEE, etc.

Some of FluentJdbc's features are listed below:

  • Easy integration to a project (DataSource and other alternatives)
  • Execution of select/insert/update/delete/alter/... statements as one-liners
  • Parameter mapping (named, positional, supporting java.time, extension with custom types)
  • Accessing generated keys of insert/update queries
  • Automatic result -> pojo mapping
  • Transaction handling

Check out FluentJdbc's github page for more details. The artifact is up in maven central, if someone wants to give it a shot:

XML
<dependency>
    <groupid>org.codejargon</groupid>
    <artifactid>fluentjdbc</artifactid>
    <version>0.9.9</version>
</dependency>

Note: Java 8 only

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Norway Norway
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --