Skip to content
This repository has been archived by the owner on Dec 8, 2023. It is now read-only.

Latest commit

 

History

History
128 lines (99 loc) · 6.19 KB

README.md

File metadata and controls

128 lines (99 loc) · 6.19 KB

Drowsy

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.

alt text
Drowsy, the bear

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

Drowsy Modules

Database access can quickly become a complex problem that in many cases cannot be solved with a one-size-fits-all solution. With this in mind, Drowsy is built upon 4 independent and strictly separated modules, each tackling a different concern. If you only want query building, there is no reason to include configuration, database migration, connection pooling or any other unnecessary dependencies in your project.
Additionally and for convenience there is a 5th module that groups the other four and exposes an unified API.

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

Transaction


Models database operations at the connection and transaction level. Ensures resource deallocation, transaction commit and rollback on error.
Transaction's module wiki

Query


Query builder classes that help you build prepared statements.
Query's module wiki

Mapper


Simple ResultSet to bean mapping.
Mapper's module wiki

Drowsy


The full bundle. Glues all the modules together in a simplified, easy to use API.

Usage

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);

Configuration

DataSource configuration is as in HikariCP plus two Flyway specific configurations, all prefixed with jdbc by default.

jdbc.jdbcUrl=jdbc:postgresql://localhost:5432/MyDB
jdbc.username=me
jdbc.password=hunter2
...

# Whether or not to use Flyway, defaults to false
jdbc.flyway.bypass=false

# From Flyway's Javadoc:
#  "Whether to automatically call baseline when migrate is executed
#   against a non-empty schema with no metadata table
#   This schema will then be baselined with the baselineVersion
#   before executing the migrations.
#   Only migrations above baselineVersion will then be applied.", defaults to false
jdbc.flyway.baselineOnMigrate=true

# 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>3.0.2</version>
</dependency>