updated header to csv

This commit is contained in:
Devendra Desale 2015-12-23 14:17:31 +05:30 committed by David Morley
parent 6dcd2ff8e5
commit 17d5f4a920
5 changed files with 16 additions and 21 deletions

View File

@ -27,7 +27,7 @@ public class App {
try { try {
JobExecution execution = jobLauncher.run(job, new JobParameters()); JobExecution execution = jobLauncher.run(job, new JobParameters());
System.out.println("Job Status : " + execution.getStatus()); System.out.println("Job Status : " + execution.getStatus());
System.out.println("Job completed"); System.out.println("Job succeeded");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
System.out.println("Job failed"); System.out.println("Job failed");

View File

@ -50,6 +50,7 @@ public class SpringBatchConfig {
DefaultLineMapper<Transaction> lineMapper = new DefaultLineMapper<Transaction>(); DefaultLineMapper<Transaction> lineMapper = new DefaultLineMapper<Transaction>();
lineMapper.setLineTokenizer(tokenizer); lineMapper.setLineTokenizer(tokenizer);
lineMapper.setFieldSetMapper(new RecordFieldSetMapper()); lineMapper.setFieldSetMapper(new RecordFieldSetMapper());
reader.setLinesToSkip(1);
reader.setLineMapper(lineMapper); reader.setLineMapper(lineMapper);
return reader; return reader;
} }

View File

@ -1,3 +1,4 @@
username, user_id, transaction_date, transaction_amount
devendra, 1234, 31/10/2015, 10000 devendra, 1234, 31/10/2015, 10000
john, 2134, 3/12/2015, 12321 john, 2134, 3/12/2015, 12321
robin, 2134, 2/02/2015, 23411 robin, 2134, 2/02/2015, 23411
1 devendra username 1234 user_id 31/10/2015 transaction_date 10000 transaction_amount
1 username user_id transaction_date transaction_amount
2 devendra devendra 1234 1234 31/10/2015 31/10/2015 10000 10000
3 john john 2134 2134 3/12/2015 3/12/2015 12321 12321
4 robin robin 2134 2134 2/02/2015 2/02/2015 23411 23411

View File

@ -1,18 +1,15 @@
<beans xmlns="http://www.springframework.org/schema/beans" <beans xmlns="http://www.springframework.org/schema/beans" xmlns:batch="http://www.springframework.org/schema/batch"
xmlns:batch="http://www.springframework.org/schema/batch" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/batch xsi:schemaLocation="http://www.springframework.org/schema/batch
http://www.springframework.org/schema/batch/spring-batch-3.0.xsd http://www.springframework.org/schema/batch/spring-batch-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
"> ">
<import resource="spring.xml" /> <import resource="spring.xml" />
<bean id="itemReader" <bean id="itemReader" class="org.springframework.batch.item.file.FlatFileItemReader">
class="org.springframework.batch.item.file.FlatFileItemReader">
<property name="resource" value="input/record.csv" /> <property name="resource" value="input/record.csv" />
<property name="lineMapper"> <property name="lineMapper">
<bean <bean
class="org.springframework.batch.item.file.mapping.DefaultLineMapper"> class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
@ -20,23 +17,21 @@
<bean <bean
class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer"> class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
<property name="names" <property name="names"
value="username,userid,transactiondate,amount" /> value="username,userid,transaction_date,transaction_amount" />
</bean> </bean>
</property> </property>
<property name="fieldSetMapper"> <property name="fieldSetMapper">
<bean <bean
class="org.baeldung.spring_batch_intro.service.RecordFieldSetMapper" /> class="org.baeldung.spring_batch_intro.service.RecordFieldSetMapper" />
</property> </property>
</bean> </bean>
</property> </property>
<property name="linesToSkip" value="1" />
</bean> </bean>
<bean id="itemProcessor" <bean id="itemProcessor" class="org.baeldung.spring_batch_intro.service.CustomItemProcessor" />
class="org.baeldung.spring_batch_intro.service.CustomItemProcessor" />
<bean id="itemWriter" <bean id="itemWriter" class="org.springframework.batch.item.xml.StaxEventItemWriter">
class="org.springframework.batch.item.xml.StaxEventItemWriter">
<property name="resource" value="file:xml/output.xml" /> <property name="resource" value="file:xml/output.xml" />
<property name="marshaller" ref="recordMarshaller" /> <property name="marshaller" ref="recordMarshaller" />
<property name="rootTagName" value="transactionRecord" /> <property name="rootTagName" value="transactionRecord" />
@ -45,13 +40,11 @@
<bean id="recordMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller"> <bean id="recordMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="classesToBeBound"> <property name="classesToBeBound">
<list> <list>
<value>org.baeldung.spring_batch_intro.model.Transaction <value>org.baeldung.spring_batch_intro.model.Transaction</value>
</value>
</list> </list>
</property> </property>
</bean> </bean>
<batch:job id="firstBatchJob"> <batch:job id="firstBatchJob">
<batch:step id="step1"> <batch:step id="step1">
<batch:tasklet> <batch:tasklet>

View File

@ -1 +1 @@
<?xml version="1.0" encoding="UTF-8"?><transactionRecord><transactionRecord><amount>10000.0</amount><transactionDate>2015-10-31T00:00:00+08:00</transactionDate><userId>1234</userId><username>devendra</username></transactionRecord><transactionRecord><amount>12321.0</amount><transactionDate>2015-12-03T00:00:00+08:00</transactionDate><userId>2134</userId><username>john</username></transactionRecord><transactionRecord><amount>23411.0</amount><transactionDate>2015-02-02T00:00:00+08:00</transactionDate><userId>2134</userId><username>robin</username></transactionRecord></transactionRecord> <?xml version="1.0" encoding="UTF-8"?><transactionRecord><transactionRecord><amount>10000.0</amount><transactionDate>2015-10-31T00:00:00+05:30</transactionDate><userId>1234</userId><username>devendra</username></transactionRecord><transactionRecord><amount>12321.0</amount><transactionDate>2015-12-03T00:00:00+05:30</transactionDate><userId>2134</userId><username>john</username></transactionRecord><transactionRecord><amount>23411.0</amount><transactionDate>2015-02-02T00:00:00+05:30</transactionDate><userId>2134</userId><username>robin</username></transactionRecord></transactionRecord>