Package com.ecom.winners.configurations
Class UserTransaction
java.lang.Object
com.ecom.winners.configurations.UserTransaction
Configuration for the User transactions job.
In this step, user's transactions are streamed from a CSV file from resources as TransactionDTO,
transformed into a Transaction entity, and persisted into the database.
- See Also:
-
Configuration
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.batch.core.Step
insertUserTransactions
(org.springframework.batch.core.repository.JobRepository jobRepository, TransactionProcessor transactionProcessor, org.springframework.transaction.PlatformTransactionManager transactionManager, org.springframework.batch.item.database.JpaItemWriter<Transaction> transactionWriter, org.springframework.batch.item.file.FlatFileItemReader<TransactionDTO> transactionReader, int chunkSize) The User's transaction Step.processor
(UserRepository userRepository) The Transaction processor checks the user_id from TransactionDTO with the help of UserRepository and finds the equivalent user in the database.org.springframework.batch.item.file.FlatFileItemReader<TransactionDTO>
Reader starts with streaming the rows from the CSV file from the resource path, selects headers, and converts rows into TransactionDTOorg.springframework.batch.item.database.JpaItemWriter<Transaction>
writer
(jakarta.persistence.EntityManagerFactory entityManagerFactory) The Transaction writer takes a Transaction entity from the processor, persists into the database where it also manages the required relation between user and it's transactions.
-
Constructor Details
-
UserTransaction
public UserTransaction()
-
-
Method Details
-
reader
@Bean(name="transactionReader") public org.springframework.batch.item.file.FlatFileItemReader<TransactionDTO> reader(@Value("${transaction.reader.resource.path}") String resourcePath, @Value("${transaction.reader.resource.headers}") String names) Reader starts with streaming the rows from the CSV file from the resource path, selects headers, and converts rows into TransactionDTO- Parameters:
resourcePath
- path to CSV filenames
- headers of the CSV file- Returns:
- FlatFileItemReader of type TransactionDTO
-
processor
@Bean(name="transactionProcessor") public TransactionProcessor processor(UserRepository userRepository) The Transaction processor checks the user_id from TransactionDTO with the help of UserRepository and finds the equivalent user in the database. It creates the Transaction entity based on the user entity and amount. Transaction entity generates a creation date for each Transaction.- Parameters:
userRepository
- repository for managing interactions for User resource in the database- Returns:
- TransactionProcessor that is an implementation of ItemProcessor
- See Also:
-
ItemProcessor
UserRepository
-
writer
@Bean(name="transactionWriter") public org.springframework.batch.item.database.JpaItemWriter<Transaction> writer(jakarta.persistence.EntityManagerFactory entityManagerFactory) The Transaction writer takes a Transaction entity from the processor, persists into the database where it also manages the required relation between user and it's transactions.- Parameters:
entityManagerFactory
- EntityManagerFactory- Returns:
- JpaItemWriter of type Transaction entity
- See Also:
-
ItemWriter
EntityManagerFactory
-
insertUserTransactions
@Bean(name="insertUserTransactions") public org.springframework.batch.core.Step insertUserTransactions(org.springframework.batch.core.repository.JobRepository jobRepository, TransactionProcessor transactionProcessor, org.springframework.transaction.PlatformTransactionManager transactionManager, org.springframework.batch.item.database.JpaItemWriter<Transaction> transactionWriter, org.springframework.batch.item.file.FlatFileItemReader<TransactionDTO> transactionReader, @Value("${transaction.reader.chunk.size}") int chunkSize) The User's transaction Step. A step that manages the insertion of the user's transactions from a CSV file into the database- Parameters:
jobRepository
- JobRepositorytransactionProcessor
- TransactionProcessortransactionManager
- PlatformTransactionManagertransactionWriter
- JpaItemWriter for TransactionstransactionReader
- FlatFileItemReader for TransactionDTOchunkSize
- size of the batch- Returns:
- Step
- See Also:
-
JobRepository
TransactionProcessor
PlatformTransactionManager
JpaItemWriter
FlatFileItemReader
Value
-