Easy to use, lightweight java framework, built on top of JDBC that allows you to build high performance DB access for your Java applications, without the typical productivity and reliability penalties of not using an ORM.
Things you can do with Drowsy
- Prevent resource leaks caused by developer oopsies, such as unclosed connections, result sets or statements
- Build SQL queries with little boilerplate and good legibility, without sacrificing the ability to do weird stuff
- Trivial ResultSet to Java objects mapping
- Truly modular framework, allowing the developer to pick and choose what features of Drowsy to use, even in a multiple framework context
Things you cannot expect from Drowsy
- Hiding the relational model from your application
- Non-JDBC data sources support
As of now, Drowsy is still a single project.
<dependency>
<groupId>org.irenical.drowsy</groupId>
<artifactId>drowsy</artifactId>
<version>0.0.11</version>
</dependency>
In it you can find the following modules:
[org.irenical.drowsy.datasource]
A DataSource implementation with built-in dynamic configuration, allowing you to change any property at runtime. It's built upon HikariCP, Flyway and Jindy.
DataSource's module wiki
[org.irenical.drowsy.transaction]
Models database operations at the connection and transaction level. Ensures resource deallocation, transaction commit and rollback on error.
Transaction's module wiki
[org.irenical.drowsy.query]
Query builder classes that help you build prepared statements.
Query's module wiki
[org.irenical.drowsy.mapper]
Simple ResultSet to bean mapping.
Mapper's module wiki
[org.irenical.drowsy]
The full bundle. Glues all the modules together in a simplified, easy to use API.
Note: You can use the modules separately, the examples bellow assume you are using the entire Drowsy bundle.
Life cycle
Drowsy drowsy = new Drowsy();
drowsy.start();
... your app doing stuff ...
drowsy.stop();
Simple select
Query query = SelectBuilder.create("select * from people").build();
List<LegitPerson> got = drowsy.read(query, LegitPerson.class);
DataSource configuration is as in HikariCP, prefixed with jdbc. Plus two Flyway specific configurations.
jdbc.url=jdbc:postgresql://localhost:5432/MyDB
jdbc.username=me
jdbc.password=hunter2
...
# Whether or not to use Flyway, defaults to false
jdbc.flyway.bypass=false
#If set and Flyway is active, only updates greater that this will be applied, defaults to null
jdbc.flyway.baselineVersion=3
Drowsy uses Jindy for configuration, so a Jindy binding is required. The easiest way to do this is probably by adding the following dependency to your application. You can then use System.setProperty() or a config.properties file in your resources to set Drowsy's configuration.
<dependency>
<groupId>org.irenical.jindy</groupId>
<artifactId>jindy-apacheconfig-impl</artifactId>
<version>2.1.0</version>
</dependency>