Giter Site home page Giter Site logo

binakot / java-inheritance-into-postgresql-jsonb-mapping Goto Github PK

View Code? Open in Web Editor NEW
4.0 0.0 1.0 71 KB

The demo project with mapping of Java objects inheritance into PostgreSQL JSONB columns via Jackson and MyBatis.

License: MIT License

Java 99.13% Dockerfile 0.87%
java spring mybatis jackson postgresql jsonb orm hacktoberfest

java-inheritance-into-postgresql-jsonb-mapping's Introduction

Java inheritance into PostgreSQL JSONB mapping

The demo project with mapping of Java objects inheritance into PostgreSQL JSONB columns via Jackson and MyBatis.

Development

To build & test:

$ ./gradlew build test

Running on localhost

To run application on localhost:

$ ./gradlew bootRun

Required PostgreSQL running on port 5432 with database schema. It can be done with Docker container:

$ docker run \
    --name postgres \
    -e POSTGRES_DB="postgres" \
    -e POSTGRES_USER="postgres" \
    -e POSTGRES_PASSWORD="postgres" \
    -v postgres_data:/var/lib/postgresql \
    -v ${PWD}/src/main/resources/sql/init.sql:/docker-entrypoint-initdb.d/1.init.sql \
    -v ${PWD}/src/main/resources/sql/data.sql:/docker-entrypoint-initdb.d/2.data.sql \
    -p 5432:5432 \
    -d postgres:latest

Running in Docker (the easiest start)

To package the application into jar file:

$ ./gradlew bootJar

To build the application docker image:

$ docker-compose build

To run in Docker with PostgreSQL database:

$ docker-compose up -d

To stop the application and PostgreSQL database:

$ docker-compose down --volumes

Examples

Vehicle

SQL:

id         | 1
type       | VEHICLE
latitude   | 45.047579
longitude  | 38.963983
course     | 10
speed      | 15
attributes | {"model": "Toyota Camry", "regNumber": "A 123 BC 777"}

JSON:

{
    "id": 1,
    "type": "VEHICLE",
    "latitude": 45.047579,
    "longitude": 38.963983,
    "course": 10,
    "speed": 15,
    "model": "Toyota Camry",
    "regNumber": "A 123 BC 777"
}

Employee

SQL:

id         | 3
type       | EMPLOYEE
latitude   | 45.026158
longitude  | 38.927763
course     | 30
speed      | 35
attributes | {"name": "John Doe", "phoneNumber": "8-800 2000 600"}

JSON:

{
    "id": 3,
    "type": "EMPLOYEE",
    "latitude": 45.026158,
    "longitude": 38.927763,
    "course": 30,
    "speed": 35,
    "name": "John Doe",
    "phoneNumber": "8-800 2000 600"
}

P.S.

Thanks to @0ffer, it was his idea and initial implementation.

java-inheritance-into-postgresql-jsonb-mapping's People

Contributors

binakot avatar

Stargazers

 avatar  avatar  avatar  avatar

Forkers

liyingben

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.