From aff01a2300ff6f3963a448b5db60d82d092d2b5c Mon Sep 17 00:00:00 2001 From: Raja Kolli Date: Tue, 20 Aug 2024 02:31:01 +0000 Subject: [PATCH] feat : removes lombok --- batch-boot-jpa-sample/pom.xml | 6 +-- .../config/ApplicationProperties.java | 51 ++++++++++++++++-- .../bootbatchjpa/config/BatchConfig.java | 21 ++++---- .../bootbatchjpa/config/Initializer.java | 11 ++-- .../bootbatchjpa/entities/Customer.java | 53 ++++++++++++++++--- .../services/CustomerService.java | 12 +++-- .../bootbatchjpa/utils/AppConstants.java | 8 +-- 7 files changed, 123 insertions(+), 39 deletions(-) diff --git a/batch-boot-jpa-sample/pom.xml b/batch-boot-jpa-sample/pom.xml index c208b0943..8cd42a883 100644 --- a/batch-boot-jpa-sample/pom.xml +++ b/batch-boot-jpa-sample/pom.xml @@ -67,11 +67,7 @@ spring-boot-configuration-processor true - - org.projectlombok - lombok - true - + org.springframework.boot spring-boot-starter-data-jpa diff --git a/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/config/ApplicationProperties.java b/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/config/ApplicationProperties.java index d4e207692..67845c9e9 100644 --- a/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/config/ApplicationProperties.java +++ b/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/config/ApplicationProperties.java @@ -1,21 +1,66 @@ package com.example.bootbatchjpa.config; -import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.NestedConfigurationProperty; -@Data @ConfigurationProperties("application") public class ApplicationProperties { @NestedConfigurationProperty private Cors cors = new Cors(); - @Data + public Cors getCors() { + return cors; + } + + public void setCors(Cors cors) { + this.cors = cors; + } + public static class Cors { private String pathPattern = "/api/**"; private String allowedMethods = "*"; private String allowedHeaders = "*"; private String allowedOriginPatterns = "*"; private boolean allowCredentials = true; + + public String getPathPattern() { + return pathPattern; + } + + public void setPathPattern(String pathPattern) { + this.pathPattern = pathPattern; + } + + public String getAllowedMethods() { + return allowedMethods; + } + + public void setAllowedMethods(String allowedMethods) { + this.allowedMethods = allowedMethods; + } + + public String getAllowedHeaders() { + return allowedHeaders; + } + + public void setAllowedHeaders(String allowedHeaders) { + this.allowedHeaders = allowedHeaders; + } + + public String getAllowedOriginPatterns() { + return allowedOriginPatterns; + } + + public void setAllowedOriginPatterns(String allowedOriginPatterns) { + this.allowedOriginPatterns = allowedOriginPatterns; + } + + public boolean isAllowCredentials() { + return allowCredentials; + } + + public void setAllowCredentials(boolean allowCredentials) { + this.allowCredentials = allowCredentials; + } } } diff --git a/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/config/BatchConfig.java b/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/config/BatchConfig.java index e5dab9b94..b954454da 100644 --- a/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/config/BatchConfig.java +++ b/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/config/BatchConfig.java @@ -7,14 +7,9 @@ import java.time.LocalDateTime; import java.util.HashMap; import java.util.Map; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.batch.core.BatchStatus; -import org.springframework.batch.core.Job; -import org.springframework.batch.core.JobExecution; -import org.springframework.batch.core.JobExecutionListener; -import org.springframework.batch.core.JobParameters; -import org.springframework.batch.core.Step; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.batch.core.*; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; import org.springframework.batch.core.configuration.annotation.StepScope; import org.springframework.batch.core.job.builder.JobBuilder; @@ -32,12 +27,16 @@ @Configuration(proxyBeanMethods = false) @EnableBatchProcessing -@Slf4j -@RequiredArgsConstructor -public class BatchConfig implements JobExecutionListener { +class BatchConfig implements JobExecutionListener { + + private static final Logger log = LoggerFactory.getLogger(BatchConfig.class); private final EntityManagerFactory entityManagerFactory; + BatchConfig(EntityManagerFactory entityManagerFactory) { + this.entityManagerFactory = entityManagerFactory; + } + @Bean Job allCustomersJob( JpaPagingItemReader jpaPagingItemReader, diff --git a/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/config/Initializer.java b/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/config/Initializer.java index 528dfb399..3479a7832 100644 --- a/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/config/Initializer.java +++ b/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/config/Initializer.java @@ -5,19 +5,22 @@ import com.example.bootbatchjpa.entities.Customer; import com.example.bootbatchjpa.repositories.CustomerRepository; import java.util.List; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; import org.instancio.Instancio; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.boot.CommandLineRunner; import org.springframework.stereotype.Component; @Component -@RequiredArgsConstructor -@Slf4j class Initializer implements CommandLineRunner { + private static final Logger log = LoggerFactory.getLogger(Initializer.class); private final CustomerRepository customerRepository; + Initializer(CustomerRepository customerRepository) { + this.customerRepository = customerRepository; + } + @Override public void run(String... args) { log.info("Running Initializer....."); diff --git a/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/entities/Customer.java b/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/entities/Customer.java index d9fb9043a..3e8f32750 100644 --- a/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/entities/Customer.java +++ b/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/entities/Customer.java @@ -8,18 +8,10 @@ import jakarta.persistence.Table; import jakarta.validation.constraints.NotEmpty; import java.util.Objects; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; import org.hibernate.Hibernate; @Entity @Table(name = "customers") -@Getter -@Setter -@NoArgsConstructor -@AllArgsConstructor public class Customer { @Id @@ -34,6 +26,51 @@ public class Customer { private String gender; + public Customer(Long id, String name, String address, String gender) { + this.id = id; + this.name = name; + this.address = address; + this.gender = gender; + } + + public Customer() {} + + public Long getId() { + return id; + } + + public Customer setId(Long id) { + this.id = id; + return this; + } + + public @NotEmpty(message = "Name cannot be empty") String getName() { + return name; + } + + public Customer setName(@NotEmpty(message = "Name cannot be empty") String name) { + this.name = name; + return this; + } + + public String getAddress() { + return address; + } + + public Customer setAddress(String address) { + this.address = address; + return this; + } + + public String getGender() { + return gender; + } + + public Customer setGender(String gender) { + this.gender = gender; + return this; + } + @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/services/CustomerService.java b/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/services/CustomerService.java index bb4e067ad..bae14cf18 100644 --- a/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/services/CustomerService.java +++ b/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/services/CustomerService.java @@ -5,7 +5,6 @@ import com.example.bootbatchjpa.model.response.PagedResult; import com.example.bootbatchjpa.repositories.CustomerRepository; import java.util.Optional; -import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; @@ -14,14 +13,16 @@ import org.springframework.transaction.annotation.Transactional; @Service -@Transactional +@Transactional(readOnly = true) @Loggable -@RequiredArgsConstructor public class CustomerService { private final CustomerRepository customerRepository; - @Transactional(readOnly = true) + public CustomerService(CustomerRepository customerRepository) { + this.customerRepository = customerRepository; + } + public PagedResult findAllCustomers( int pageNo, int pageSize, String sortBy, String sortDir) { Sort sort = @@ -36,15 +37,16 @@ public PagedResult findAllCustomers( return new PagedResult<>(customersPage); } - @Transactional(readOnly = true) public Optional findCustomerById(Long id) { return customerRepository.findById(id); } + @Transactional public Customer saveCustomer(Customer customer) { return customerRepository.save(customer); } + @Transactional public void deleteCustomerById(Long id) { customerRepository.deleteById(id); } diff --git a/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/utils/AppConstants.java b/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/utils/AppConstants.java index 6d0dfc563..69b28b12d 100644 --- a/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/utils/AppConstants.java +++ b/batch-boot-jpa-sample/src/main/java/com/example/bootbatchjpa/utils/AppConstants.java @@ -1,8 +1,5 @@ package com.example.bootbatchjpa.utils; -import lombok.experimental.UtilityClass; - -@UtilityClass public final class AppConstants { public static final String PROFILE_PROD = "prod"; public static final String PROFILE_NOT_PROD = "!" + PROFILE_PROD; @@ -12,4 +9,9 @@ public final class AppConstants { public static final String DEFAULT_PAGE_SIZE = "10"; public static final String DEFAULT_SORT_BY = "id"; public static final String DEFAULT_SORT_DIRECTION = "asc"; + + private AppConstants() { + throw new UnsupportedOperationException( + "This is a utility class and cannot be instantiated"); + } }