Dropwizard Jdbi Unit Of Work

Provides support for Unit Of Work annotations with a Jdbi Backend

License

License

Categories

Categories

IDE Development Tools DropWizard Container Microservices JDBI Data Databases
GroupId

GroupId

com.github.isopropylcyanide
ArtifactId

ArtifactId

dropwizard-jdbi-unitofwork
Last Version

Last Version

1.1
Release Date

Release Date

Type

Type

jar
Description

Description

Dropwizard Jdbi Unit Of Work
Provides support for Unit Of Work annotations with a Jdbi Backend
Project URL

Project URL

https://github.com/isopropylcyanide/dropwizard-jdbi-unitofwork
Source Code Management

Source Code Management

https://github.com/isopropylcyanide/dropwizard-jdbi-unitofwork/tree/master

Download dropwizard-jdbi-unitofwork

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.isopropylcyanide/dropwizard-jdbi-unitofwork/ -->
<dependency>
    <groupId>com.github.isopropylcyanide</groupId>
    <artifactId>dropwizard-jdbi-unitofwork</artifactId>
    <version>1.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.isopropylcyanide/dropwizard-jdbi-unitofwork/
implementation 'com.github.isopropylcyanide:dropwizard-jdbi-unitofwork:1.1'
// https://jarcasting.com/artifacts/com.github.isopropylcyanide/dropwizard-jdbi-unitofwork/
implementation ("com.github.isopropylcyanide:dropwizard-jdbi-unitofwork:1.1")
'com.github.isopropylcyanide:dropwizard-jdbi-unitofwork:jar:1.1'
<dependency org="com.github.isopropylcyanide" name="dropwizard-jdbi-unitofwork" rev="1.1">
  <artifact name="dropwizard-jdbi-unitofwork" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.isopropylcyanide', module='dropwizard-jdbi-unitofwork', version='1.1')
)
libraryDependencies += "com.github.isopropylcyanide" % "dropwizard-jdbi-unitofwork" % "1.1"
[com.github.isopropylcyanide/dropwizard-jdbi-unitofwork "1.1"]

Dependencies

compile (3)

Group / Artifact Type Version
io.dropwizard : dropwizard-jdbi jar 1.3.29
org.reflections : reflections jar 0.9.12
org.slf4j : slf4j-api jar 1.7.30

test (2)

Group / Artifact Type Version
org.mockito : mockito-core jar 3.8.0
junit : junit jar 4.13.1

Project Modules

There are no modules declared in this project.

Dropwizard Jdbi - Unit of Work Support

Travis (.org) Codecov GitHub Maven Central

Provides @JdbiUnitOfWork annotation for a Jdbi backed Dropwizard backend for wrapping resource methods in a transaction context

  • Dropwizard provides a very slick @UnitOfWork annotation that wraps a transaction context around resource methods annotated with this annotation. This is very useful for wrapping multiple calls in a single database transaction all of which will succeed or roll back atomically.

  • However this support is only available for Hibernate. For all the goodness Jdbi brings, we had to bring the transactionality on our own. This module provides support for JdbiUnitOfWork with a Jdbi backend

Maven Artifacts

This project is available on Maven Central. To add it to your project you can add the following dependency to your pom.xml:

<dependency>
    <groupId>com.github.isopropylcyanide</groupId>
    <artifactId>dropwizard-jdbi-unitofwork</artifactId>
    <version>1.0</version>
 </dependency>

Features

  • transactionality across multiple datasources when called from a request thread
  • transactionality across multiple datasources across multiple threads
  • excluding, selectively, certain set of URI's from transaction contexts, such as ELB, Health Checks etc
  • Http GET methods are excluded from transaction by default.
  • Http POST methods are wrapped around in a transaction only when annotated with @JdbiUnitOfWork

Usage

  • Add the dependency to your pom.xml

  • Decide which implementation of JdbiHandleManager is suitable for your use case.

    //bind(JdbiHandleManager.class).toInstance(new RequestScopedJdbiHandleManager(dbi)); 
    bind(JdbiHandleManager.class).toInstance(new LinkedRequestScopedJdbiHandleManager(dbi)); 
  • Provide the list of package where the SQL Objects (to be attached) are located. Classes with Jdbi annotations @SqlQuery or @SqlUpdate will be picked automatically

    Set<String> daoPackages = Sets.newHashSet("<fq-package-name>", "fq-package-name", ...);
  • Install the module in your main application module.

    install(new JdbiUnitOfWorkModule(handleManager, daoPackages));
  • Start annotating resource methods with @JdbiUnitOfWork and you're good to go.

    @POST
    @Path("/")
    @JdbiUnitOfWork
    public RequestResponse createRequest() {
          ..do stateful work (across multiple Dao's)
          return response 
    }

Design

  • This library relies on Jersey Monitoring Events to bind request lifecycle with a transaction aspect
  • At the backend, all Jdbi objects such as Dao or SqlObjects are proxied behind a JdbiHandleManager
  • JdbiHandleManager contract specifies the get and clear of the actual handles to the calling thread.

image

Support

Please file bug reports and feature requests in GitHub issues.

License

Copyright (c) 2012-2020 Aman Garg

This library is licensed under the Apache License, Version 2.0.

See http://www.apache.org/licenses/LICENSE-2.0.html or the LICENSE file in this repository for the full license text.

Versions

Version
1.1
1.0