Awesome
JDBI-ORM demo using Vaadin
A demo project showing the CRUD capabilities of the JDBI-ORM ORM library. Requires Java 17+. Uses jdbi-orm-vaadin.
The Person
entity is mapped to the database tables; inheriting from Entity and Dao
will make it inherit a bunch of useful methods such as findAll()
and save()
. It will also gain means of
providing all of its instances via a DataProvider
. See the MainView
Grid configuration for details.
See the live demo.
Documentation
Please see the Vaadin Boot documentation on how you run, develop and package this Vaadin-Boot-based app.
To run the app, simply run the Main.main()
method from your IDE.
Database
To make things easy we'll use in-memory H2 database. We'll use the jdbi-orm-vaadin library to create Grid filters easily.
We will use Flyway for database migration. Check out Bootstrap on how the migration scripts are ran when the app is initialized.
PostgreSQL
You can also use the PostgreSQL database - simply set the JDBC_URL
, JDBC_USERNAME
and JDBC_PASSWORD
env variables
accordingly. To test out, you can start PostgreSQL in docker:
docker run --rm -ti -e POSTGRES_PASSWORD=mysecretpassword -p 127.0.0.1:5432:5432 postgres:15.2
That will create a database named postgres
, username postgres
and password mysecretpassword
.
Then set the env variables as follows:
export JDBC_URL="jdbc:postgresql://localhost:5432/postgres"
export JDBC_USERNAME="postgres"
export JDBC_PASSWORD="mysecretpassword"
To run tests on PostgreSQL, run Maven as follows:
$ mvn -C test -DargLine="-Dtest.postgresql"
The tests will start PostgreSQL in Docker using TestContainers automatically.
Docker
The easiest way to run the app in Docker is to run the app with the embedded H2 database. See the Dockerfile for more documentation on how to build the docker image and run it.
To run the app with PostgreSQL, the easiest way is to run PostgreSQL in a separate docker image,
then connect the images. That's exactly what docker-compose.yaml
is doing: it's starting the app in one Docker container, PostgreSQL in another, and
connects them in a private network. It then configures the app via env variables
to connect to the postgres
machine running PostgreSQL. To run this setup,
run
$ docker-compose up
This command will build this project in production mode, then create a Docker image out of that, and will run the app with Postgres.
Kubernetes
Please see the Vaadin app with persistent PostgreSQL in Kubernetes article for an explanation how this works. In short, make sure that the necessary plugins are enabled:
$ microk8s enable dns hostpath-storage registry
Then, build the Docker image and push it to the Microk8s internal registry:
$ docker build --no-cache -t localhost:32000/test/jdbi-orm-vaadin-crud-demo:latest .
$ docker push localhost:32000/test/jdbi-orm-vaadin-crud-demo
Then, apply the Kubernetes config file:
$ mkctl apply -f kubernetes-app.yaml
You should be able to browse to localhost and see the app up-and-running.