Skip to content

alejandro-du/mongodb-vaadin-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vaadin + Spring Boot + MongoDB + MariaDB MaxScale demo

License

This example shows how to connect a Vaadin application to MongoDB databases. This file also shows how to use MaxScale to connect the same application to a MariaDB backend using the NoSQL protocol without modifying the app.

Preparing the database

You need MongoDB listening on port 27017 or a MariaDB database and a MaxScale instance with a Listener using the nosqlprotocol protocol.

Setting up the database cluster using Docker

Clone this repository:

git clone https://github.com/alejandro-du/mongodb-vaadin-demo.git

Spin up a MariaDB database and a database proxy (MaxScale):

cd mongodb-vaadin-demo
docker compose up -d

WARNING! These Docker images are not suitable for production!

Run the web application

Build the Java web application using Maven:

mvn package

Run the application:

java -jar target/mongodb-vaadin-demo.jar

Access the application in your browser at http://localhost:9090. Insert some data.

Access the MaxScale GUI at http://localhost:8989/ using the following credentials:

  • Username: admin
  • Password: mariadb

In the menu, go to the query editor and connect to the database using:

  • Listener name: query_router_listener
  • Username: user
  • Password: password

Inspect the database and query the student table:

select * from student

Or use MariaDB's JSON functions:

select
	json_value(doc, '$.firstName') as firstName,
	json_value(doc, '$.lastName') as lastName,
	id as regNumber
from student

Or if you want to join data with other tables in the database:

select s.*, st.id regNumber
from student st,
    json_table(st.doc, '$'
        columns(
            firstName varchar(255) path '$.firstName',
            lastName varchar(255) path '$.lastName'
        )
    ) as s

To shutdown the database cluster run:

docker compose down

Add -v to the above command if you want to remove the related Docker volumes as well (you'll lose all the configuration and data).

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published