Skip to content

Commit

Permalink
feat : removes lombok
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadilipkolli committed Aug 20, 2024
1 parent be49cb4 commit aff01a2
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 39 deletions.
6 changes: 1 addition & 5 deletions batch-boot-jpa-sample/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,7 @@
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Customer> jpaPagingItemReader,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.....");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Customer> findAllCustomers(
int pageNo, int pageSize, String sortBy, String sortDir) {
Sort sort =
Expand All @@ -36,15 +37,16 @@ public PagedResult<Customer> findAllCustomers(
return new PagedResult<>(customersPage);
}

@Transactional(readOnly = true)
public Optional<Customer> 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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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");
}
}

0 comments on commit aff01a2

Please sign in to comment.