https://github.com/youssefgamalmohamed/spring-boot-database
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
https://github.com/youssefgamalmohamed/spring-boot-database
java jooq mongodb mysql spring-boot spring-data-jdbc spring-data-jpa spring-jdbc-template
Last synced: about 2 months ago
JSON representation
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
- Host: GitHub
- URL: https://github.com/youssefgamalmohamed/spring-boot-database
- Owner: youssefGamalMohamed
- Created: 2023-12-20T09:56:13.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-05-12T15:09:00.000Z (about 2 years ago)
- Last Synced: 2024-05-13T10:23:14.568Z (about 2 years ago)
- Topics: java, jooq, mongodb, mysql, spring-boot, spring-data-jdbc, spring-data-jpa, spring-jdbc-template
- Language: Java
- Homepage:
- Size: 156 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Spring Boot With Database (SQL, NoSQL)
This project implements a simple CRUD e-commerce API with an extendable data layer that supports both SQL (MySQL) and NoSQL (MongoDB) databases.
## Problem
The problem we face is that when the service layer is tightly coupled with the data layer, it becomes difficult to maintain and develop the code. If you need to switch from an SQL to a NoSQL database (or vice versa), the code is not easily extendable to accommodate such changes.
## Solution
To address this issue, we refactor the code to isolate the data layer from the service layer. This allows for the addition or change of databases by sending objects between layers that each knows how to handle, with the data layer converting these objects to the appropriate format for storage in SQL or NoSQL databases.
## Architecture
The architecture allows for easy extension of the data layer by adding any database.

## Features
Implementing multi-database support (SQL, NoSQL) in the data layer with different approaches:
- **JOOQ With MySQL**
- **Spring Jdbc Template With MySQL**
- **Spring Data Jdbc With MySQL**
- **Spring Data JPA With**
- **MySQL**
- **MongoDB**
## Code
In the service layer, to specify which database to use, you need to change the bean name to the corresponding data layer implementation. For example:
- **ProductServiceImpl.java**
Change the qualifier name to the appropriate database repository implementation:
```java
@Autowired
@Qualifier("mongoProductRepoImpl") <--------------
private ProductRepoInterface productRepo;
```
- **CategoryServiceImpl.java**
Follow the same step for the category repository:
```java
@Autowired
@Qualifier("mongoCategoryRepoImpl") <--------------
private CategoryRepoInterface categoryRepo;
```
## Installation Prerequisites
- **Programming Languages**
- Java 17
- **Databases**
- MySQL 8
- MongoDB
- **Build Tool**
- Maven
## Docker Compose
To run the application using Docker Compose, follow these steps:
1. **Ensure Docker and Docker Compose are installed** on your system. You can download Docker Desktop from [Docker's official website](https://www.docker.com/products/docker-desktop).
2. **Clone the repository** if you haven't already:
```bash
git clone https://github.com/youssefGamalMohamed/spring-boot-database.git
cd spring-boot-database
```
3. **Build and run the Docker containers** using Docker Compose:
```bash
docker-compose up --build
```
This command will build the Docker images and start the containers defined in the `docker-compose.yml` file.
4. **Access the application**:
- The Spring Boot application should be available at `http://localhost:8080` by default.
5. **Stop the Docker containers**:
To stop the running containers, use:
```bash
docker-compose down
```
## Postman Collection
- Download the Postman Collection from [here](https://github.com/youssefGamalMohamed/Spring-With-Database/blob/0a7f08ea1c8ee4bc88e2437f85e990599afc1d55/Ecommerce.postman_collection.json)