Skip to content

This Repo Contains All Applied Examples About Spring with Connection to Database with ( JOOQ , Spring JDBC Template , Spring Data JDBC , Spring Data JPA ) and any one of them are applied in different branches

Notifications You must be signed in to change notification settings

youssefGamalMohamed/spring-boot-database

Repository files navigation

Spring Boot With Database ( SQL, NoSQL )

This project applied simple CRUD e-commerce API with an extendable Data Layer and allowed code extendability for connecting to either SQL as MySQL or NoSQL as MongoDB

Problem

The problem that we face is that when we make the service layer tightly coupled with the data layer, it makes the code hard to maintain and develop. If you write the code for Service Layer Tight Coupled with Data Layer and for some reason you have a new change that says "We need to Switch from SQL to NoSQL DB" or vice versa, then that is the problem; the code is not able to be extendable for adding or changing the Data Layer to another Database

Solution

To solve this problem, we need to refactor our code to be able to change or add any database by isolating the data layer from the service layer by sending only the objects that each of them (data layer, service layer) knows and the data layer converts the object to new object that he can store in the database (SQL, NoSQL)

Architecture

As we see here can extend our Data Layer by adding any Database Spring-With-Database drawio (1)

Features

Implementing Multi-Database ( SQL , NoSQL ) in Data Layer with different ways:

  • JOOQ With MySQL
  • Spring Jdbc Template With MySQL
  • Spring Data Jdbc With MySQL
  • Spring Data Jpa With
    • MySQL
    • MongoDb

Code

In the Service Layer when we need to tell the Data Layer which Database we need to use then we need to change only the Bean name to the Bean of the required Data Layer implementation as an example

  • ProductServiceImpl.java here we need to change the qualifier name for the implementation of the database repository
    @Autowired
    @Qualifier("mongoProductRepoImpl") <--------------
    private ProductRepoInterface productRepo;
    
  • CategoryServiceImpl.java and also here we will follow the same step
    @Autowired
    @Qualifier("mongoCategoryRepoImpl") <--------------
    private CategoryRepoInterface categoryRepo;
    

Installation Prerequisites

  • Programming Languages

    • Java 17

  • Databases

    • MySQL 8

    • MongoDB

  • Build Tool

    • Maven

Postman Collection

  • Download Postman Collection From here

About

This Repo Contains All Applied Examples About Spring with Connection to Database with ( JOOQ , Spring JDBC Template , Spring Data JDBC , Spring Data JPA ) and any one of them are applied in different branches

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages