1- package org .baeldung .spring_batch_intro .partitioner ;
1+ package org .baeldung .batch .partitioner ;
22
3- import java .io .IOException ;
4- import java .net .MalformedURLException ;
5- import java .text .ParseException ;
6-
7- import javax .sql .DataSource ;
8-
9- import org .baeldung .spring_batch_intro .model .Transaction ;
10- import org .baeldung .spring_batch_intro .service .RecordFieldSetMapper ;
3+ import org .baeldung .batch .model .Transaction ;
4+ import org .baeldung .batch .service .RecordFieldSetMapper ;
115import org .springframework .batch .core .Job ;
126import org .springframework .batch .core .Step ;
137import org .springframework .batch .core .configuration .annotation .EnableBatchProcessing ;
3327import org .springframework .core .io .Resource ;
3428import org .springframework .core .io .support .ResourcePatternResolver ;
3529import org .springframework .core .task .TaskExecutor ;
36- import org .springframework .jdbc .datasource .embedded .EmbeddedDatabase ;
3730import org .springframework .jdbc .datasource .embedded .EmbeddedDatabaseBuilder ;
3831import org .springframework .jdbc .datasource .embedded .EmbeddedDatabaseType ;
3932import org .springframework .oxm .Marshaller ;
4033import org .springframework .oxm .jaxb .Jaxb2Marshaller ;
4134import org .springframework .scheduling .concurrent .ThreadPoolTaskExecutor ;
4235import org .springframework .transaction .PlatformTransactionManager ;
4336
37+ import javax .sql .DataSource ;
38+ import java .io .IOException ;
39+ import java .net .MalformedURLException ;
40+ import java .text .ParseException ;
41+
4442@ Configuration
4543@ EnableBatchProcessing
4644public class SpringbatchPartitionConfig {
@@ -57,26 +55,26 @@ public class SpringbatchPartitionConfig {
5755 @ Bean (name = "partitionerJob" )
5856 public Job partitionerJob () throws UnexpectedInputException , MalformedURLException , ParseException {
5957 return jobs .get ("partitionerJob" )
60- .start (partitionStep ())
61- .build ();
58+ .start (partitionStep ())
59+ .build ();
6260 }
6361
6462 @ Bean
6563 public Step partitionStep () throws UnexpectedInputException , MalformedURLException , ParseException {
6664 return steps .get ("partitionStep" )
67- .partitioner ("slaveStep" , partitioner ())
68- .step (slaveStep ())
69- .taskExecutor (taskExecutor ())
70- .build ();
65+ .partitioner ("slaveStep" , partitioner ())
66+ .step (slaveStep ())
67+ .taskExecutor (taskExecutor ())
68+ .build ();
7169 }
7270
7371 @ Bean
7472 public Step slaveStep () throws UnexpectedInputException , MalformedURLException , ParseException {
7573 return steps .get ("slaveStep" )
76- .<Transaction , Transaction > chunk (1 )
77- .reader (itemReader (null ))
78- .writer (itemWriter (marshaller (), null ))
79- .build ();
74+ .<Transaction , Transaction >chunk (1 )
75+ .reader (itemReader (null ))
76+ .writer (itemWriter (marshaller (), null ))
77+ .build ();
8078 }
8179
8280 @ Bean
@@ -95,12 +93,12 @@ public CustomMultiResourcePartitioner partitioner() {
9593 @ Bean
9694 @ StepScope
9795 public FlatFileItemReader <Transaction > itemReader (@ Value ("#{stepExecutionContext[fileName]}" ) String filename ) throws UnexpectedInputException , ParseException {
98- FlatFileItemReader <Transaction > reader = new FlatFileItemReader <Transaction >();
96+ FlatFileItemReader <Transaction > reader = new FlatFileItemReader <>();
9997 DelimitedLineTokenizer tokenizer = new DelimitedLineTokenizer ();
100- String [] tokens = { "username" , "userid" , "transactiondate" , "amount" };
98+ String [] tokens = {"username" , "userid" , "transactiondate" , "amount" };
10199 tokenizer .setNames (tokens );
102100 reader .setResource (new ClassPathResource ("input/partitioner/" + filename ));
103- DefaultLineMapper <Transaction > lineMapper = new DefaultLineMapper <Transaction >();
101+ DefaultLineMapper <Transaction > lineMapper = new DefaultLineMapper <>();
104102 lineMapper .setLineTokenizer (tokenizer );
105103 lineMapper .setFieldSetMapper (new RecordFieldSetMapper ());
106104 reader .setLinesToSkip (1 );
@@ -121,7 +119,7 @@ public StaxEventItemWriter<Transaction> itemWriter(Marshaller marshaller, @Value
121119 @ Bean
122120 public Marshaller marshaller () {
123121 Jaxb2Marshaller marshaller = new Jaxb2Marshaller ();
124- marshaller .setClassesToBeBound (new Class [] { Transaction .class } );
122+ marshaller .setClassesToBeBound (Transaction .class );
125123 return marshaller ;
126124 }
127125
@@ -142,16 +140,15 @@ private JobRepository getJobRepository() throws Exception {
142140 // JobRepositoryFactoryBean's methods Throws Generic Exception,
143141 // it would have been better to have a specific one
144142 factory .afterPropertiesSet ();
145- return ( JobRepository ) factory .getObject ();
143+ return factory .getObject ();
146144 }
147145
148146 private DataSource dataSource () {
149147 EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder ();
150- EmbeddedDatabase db = builder .setType (EmbeddedDatabaseType .HSQL )
151- .addScript ("classpath:org/springframework/batch/core/schema-drop-h2.sql" )
152- .addScript ("classpath:org/springframework/batch/core/schema-h2.sql" )
153- .build ();
154- return db ;
148+ return builder .setType (EmbeddedDatabaseType .HSQL )
149+ .addScript ("classpath:org/springframework/batch/core/schema-drop-h2.sql" )
150+ .addScript ("classpath:org/springframework/batch/core/schema-h2.sql" )
151+ .build ();
155152 }
156153
157154 private PlatformTransactionManager getTransactionManager () {
0 commit comments