Giter Club home page Giter Club logo

roach-data's Introduction

Roach Data

Collection of small Spring Boot demos using CockroachDB with common data access frameworks and ORMs.

The purpose is to showcase how CockroachDB can be used with a mainstream Enterprise Java framework stack composed by Spring Boot, Spring Data and Spring HATEOAS.

Data access variants include the following. All are based on Spring Boot 2.x unless marked with 3.x:

  • JDBC - using plain Spring Data JDBC
  • JDBC (plain) - using plain JDBC (not spring data)
  • Relational (3.x) - using Spring Data JDBC / Relational (spring boot 3.x)
  • JPA - using Spring Data JPA with Hibernate as ORM provider
  • JPA (orders) - using Spring Data JPA to model a simple order system
  • jOOQ - using Spring Boot with jOOQ (not officially supported by spring-data)
  • MyBatis - using Spring Data MyBatis/JDBC
  • JSON - using Spring Data JPA and JSONB types with inverted indexes
  • Reactive - using Spring Data r2dbc with the reactive PSQL driver (spring boot 3.x)
  • Reactive (2.x) - using Spring Data r2dbc with the reactive PSQL driver
  • JDBI - using JDBI with the PSQL driver

The demos are independent and use a similar schema and test workload.

Common Spring Boot features demonstrated:

  • Liquibase Schema versioning
  • Hikari Connection Pool
  • Executable jar with embedded Jetty container
  • Pagination, both manual and via Spring Data JPA
  • Transaction retries with exponential backoff using AspectJ
  • Hypermedia API via Spring HATEOAS and HAL media type
  • Simple HTTP client invoking commands

Prerequisites

  • JDK17+ LTS (OpenJDK compatible)
  • Maven 3+ (wrapper provided)
  • CockroachDB with a database named roach_data

Building

./mvnw clean install

See each respective module for more details.

Running

All demos do the same thing, which is to run through a series of concurrent account transfer requests. The requests are being intentionally submitted in a way that will cause lock contention in the database and trigger aborts and retry's.

By default, the contention level is zero (serial execution) so you won't see any errors. To observe these errors, pass a number (>1) to the command line representing the thread count. Then you will see transaction conflicts and retries on the server side until the demo settles with an end message:

"All client workers finished but server keeps running. Have a nice day!"

The service remains running after the test is complete and can be access via:

You could use something like Postman to send requests to the API on your own.

JDBC demo

(Using custom JDBC URL)

java -jar roach-data-jdbc/target/roach-data-jdbc.jar --spring.datasource.url=jdbc:postgresql://localhost:26257/roach_data?sslmode=disable

Run with contention/retries:

java -jar roach-data-jdbc/target/roach-data-jdbc.jar --concurrency=8

JPA demo

java -jar roach-data-jpa/target/roach-data-jpa.jar

JPA orders demo

java -jar roach-data-jpa-orders/target/roach-data-jpa-orders.jar

jOOQ demo

java -jar roach-data-jooq/target/roach-data-jooq.jar

MyBatis demo

java -jar roach-data-mybatis/target/roach-data-mybatis.jar

Reactive demo

java -jar roach-data-reactive/target/roach-data-reactive.jar

roach-data's People

Contributors

ericharmeling avatar kai-niemi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

roach-data's Issues

Dead code in io.roach.data.jpa.RetryableTransactionAspect

Hi guys,

Any reason why the following block of code exists at line 67 of io.roach.data.jpa.RetryableTransactionAspect?

Throwable t = ex.getUndeclaredThrowable();
while (t instanceof UndeclaredThrowableException) {
    t = ((UndeclaredThrowableException) t).getUndeclaredThrowable();
}

Looks like code that was written before Throwable.getCause() was introduced.

Link to line:
https://github.com/cockroachlabs/roach-data/blob/7a0c18bde7996fb8a556109b733629caacdd6267/roach-data-jpa/src/main/java/io/roach/data/jpa/RetryableTransactionAspect.java#L67C17-L67C17

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.