Posts

Design Pattern - Builder

Image
 Builder  Definition  A builder pattern is a design pattern designed to provide a flexible solution to various object creation problems in object-oriented programming. The intent of the Builder design pattern is to separate the construction of a complex object from its representation.  Advantages  Allows you to vary a product's internal representation  Encapsulates code for construction and representation  Provides control over steps of construction process  Disadvantages  A distinct concrete builder must be created for each type of product May hamper dependency injection.  Builder with code  public class Car { private final Long id ; private final String name ; protected static class Builder { private Long id ; private String name ; public Builder id ( Long id) { this . id = id; return this ; } p

Spring Boot JPA - Pagination

Image
Pagination  Pagination is a mechanism to separate a bit result set into smaller chunks. Providing a fluent pagination navigator could increase both the value of your website for search engines and enhance user experience through minimizing the response time.  Static pagination with Spring Boot  Let's first define ExampleEntity and a repository for ExampleEntity @Entity @Table (name = "Example" ) @Getter @Builder @AllArgsConstructor @NoArgsConstructor @ToString public class ExampleEntity { @Id @GeneratedValue (strategy = GenerationType . IDENTITY ) private Long id ; @Column (length = 100 , nullable = false ) private String content ; } @Repository public interface ExampleRepository extends JpaRepository < ExampleEntity , Long > { } Now's let's insert dummy data's that will be used for pagination.  @Test public void testInsert () { LongStream . rangeClosed ( 1 , 300 ).forEach(i -> {

Spring Boot JPA - What is JPA, Entity, Repository

Image
 Database  Spring Boot uses JPA (Java Persistence API) to map Java objects to tables in the database. Mapping an object to a table in a database is called ORM(Object Relational Mapping) and JPA is one of Java's way of achieving ORM. JPA is not dependent on specified database language, so that users can associate many different databases using JPA.  JPA Data persistence is the ability to maintain data between application executions.  Persistence is vital for  applications that are developed for enterprises. JPA is a collection of classes and methods to persistently store the vast amounts of data into a database which is provided by the Oracle corporation. To reduce the burden of writing codes for relational object management, a programmer follows the JPA framework, which allows easy interaction with the database instance. JPA standardizes the task of object-relational mapping by using annotations or XML to map objects into one or more tables of a dat