Chapter III SpringBoot - Part 2 - Data Access
Chapter III SpringBoot - Part 2 - Data Access
Service Layer
Data Access
Spring Data
DataBase
Client HTTP
Layer
JDBC
Mobile app View
§ Entities
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.
§ It aims to simplify data access within the Java application development framework.
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
§ 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:
§ 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.
§ 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
14