1
DATA ACCESS LAYER
CLIENTS WEB APPLICATION
Web Layer Model Layer
Client HTTP
SGBD
Navigateur Controller
Service Layer
Data Access
Spring Data
DataBase
Client HTTP
Layer
JDBC
Mobile app View
Client SOAP Web Service
JAVA, PHP, .NET
2
MVC : MODEL
§ The Model layer in Spring Boot is the part of the application responsible for
managing data and business logic.
§ Data access layer
§ Entities
§ Data Access Objects DAOs
§ Business logic Layer
3
MVC : MODEL
§ Data access layer
- Entities: are Java classes that represent the core data structure of your application. They
encapsulate the state and behaviour of the data.
- Data Access Object (DAO): is a design pattern used in software development to abstract
and encapsulate the access to a data source, such as a database. The DAO pattern provides
a way to separate the business logic or application code from the low-level details of
accessing the database.
4
SPRING DATA
Data access layer of a spring boot application is developed using Spring Data.
What is spring Data?
Spring Data is a framework, part of the Spring framework ecosystem.
§ It aims to simplify data access within the Java application development framework.
§ It provides a consistent, high-level approach for interacting with data sources.
5
SPRING DATA
§ Spring Data provides a set of abstractions, templates, and helper classes that reduce
the amount of boilerplate code needed to perform common data access operations.
§ It also supports a wide range of data stores, making it easy to switch between
different databases including Relational databases, NoSQL databases, and other data
stores, without major code changes.
6
SPRING DATA COMPONENTS
Spring Data
Relational database NoSQL database Search Engines Spring Data REST
Spring Data JPA Spring Data MongoDB Spring Data for
Apache Solr
Spring Data JDBC Spring Data Redis
Spring Data for
Elasticsearch
Spring Data for Apache
Cassandra
7
SPRING DATA COMPONENTS
§ Spring Data JPA: This module which is based on object-relational mapping (ORM),
simplifies the implementation of data access using the Java Persistence API (JPA) for
relational databases.
§ Spring Data JDBC: Spring Data JDBC provides a simpler, more direct approach to working
with relational databases using Java objects. It's particularly well-suited for scenarios
where you want more control over SQL queries.
8
SPRING DATA COMPONENTS
§ Spring Data MongoDB: This module provides support for working with MongoDB, a
popular NoSQL database. It includes abstractions for performing CRUD (Create, Read,
Update, Delete) operations on MongoDB documents.
§ Spring Data Redis: This module offers support for working with Redis, an in-memory
data structure store. It includes abstractions for common Redis operations, such as
caching and distributed data structures.
9
SPRING DATA / OBJECT-RELATIONAL MAPPING
§ ORM stands for Object-Relational Mapping. It's a programming technique used to
interact with databases in an object-oriented way.
§ In traditional database systems, data is stored in tables, and interactions with the
database are typically done using SQL (Structured Query Language).
§ Using ORM, instead of writing raw SQL queries, developers can use a programming
language (such as Python, Java, or C#) to interact with the database using objects.
§ Objects represent the data in the database, and the ORM library takes care of
translating between the objects and the underlying database tables.
10
SPRING DATA / OBJECT-RELATIONAL MAPPING
§ Entities: These are the objects that represent data in the database. Each entity
typically corresponds to a table in the database.
§ Attributes: These are the properties of an entity, which correspond to the columns in
a database table.
§ Relationships: ORM allows you to define relationships between entities, such as one-
to-one, one-to-many, or many-to-many relationships.
11
SPRING DATA / OBJECT-RELATIONAL MAPPING
Popular ORM frameworks in different programming languages include:
§ Hibernate (Java): A widely-used ORM framework for Java applications.
§ Django ORM (Python): Part of the Django web framework, it provides a powerful and
easy-to-use ORM for Python developers.
§ Entity Framework (C#): Developed by Microsoft, it's the ORM framework for .NET
applications.
§ Sequelize (JavaScript/Node.js): An ORM for Node.js applications, compatible with
multiple database systems.
12
SPRING DATA / OBJECT-RELATIONAL MAPPING
§ CRUD Operations: ORM libraries provide methods for performing the basic CRUD
operations (Create, Read, Update, Delete) on entities.
§ Database Agnosticism: ORM libraries are designed to work with various database
systems, so you can switch between different databases (e.g., MySQL, PostgreSQL,
SQLite) without changing your code significantly.
13
SPRING DATA JPA Java Application
Spring Data JPA: is a part of the larger Spring
Data project, which aims to simplify data access Spring Data
in Java applications. Specifically, Spring Data JPA JPA
provides a high-level abstraction over Java
Hibernate
Persistence API (JPA) which is a Java
specification for object-relational mapping JPA
(ORM).
JDBC
JPA (Java Persistence API): JPA is a standard
Java specification for ORM that allows Java
objects to be mapped to database tables and
vice versa. Database
14