Skip to content

Commit 7b96e06

Browse files
Sriyshprasanth
authored andcommitted
Spring Batch xml to mysql db app - build and run successfully
1 parent 8c7c00a commit 7b96e06

File tree

13 files changed

+359
-0
lines changed

13 files changed

+359
-0
lines changed

.idea/compiler.xml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
4+
<output url="file://$MODULE_DIR$/target/classes" />
5+
<output-test url="file://$MODULE_DIR$/target/test-classes" />
6+
<content url="file://$MODULE_DIR$">
7+
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
8+
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
9+
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
10+
<excludeFolder url="file://$MODULE_DIR$/target" />
11+
</content>
12+
<orderEntry type="inheritedJdk" />
13+
<orderEntry type="sourceFolder" forTests="false" />
14+
<orderEntry type="library" name="Maven: org.springframework:spring-core:4.1.4.RELEASE" level="project" />
15+
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
16+
<orderEntry type="library" name="Maven: org.springframework:spring-jdbc:4.1.4.RELEASE" level="project" />
17+
<orderEntry type="library" name="Maven: org.springframework:spring-beans:4.1.4.RELEASE" level="project" />
18+
<orderEntry type="library" name="Maven: org.springframework:spring-tx:4.1.4.RELEASE" level="project" />
19+
<orderEntry type="library" name="Maven: org.springframework:spring-oxm:4.1.4.RELEASE" level="project" />
20+
<orderEntry type="library" name="Maven: mysql:mysql-connector-java:5.1.25" level="project" />
21+
<orderEntry type="library" name="Maven: org.springframework.batch:spring-batch-core:3.0.8.RELEASE" level="project" />
22+
<orderEntry type="library" name="Maven: com.ibm.jbatch:com.ibm.jbatch-tck-spi:1.0" level="project" />
23+
<orderEntry type="library" name="Maven: javax.batch:javax.batch-api:1.0" level="project" />
24+
<orderEntry type="library" name="Maven: com.thoughtworks.xstream:xstream:1.4.7" level="project" />
25+
<orderEntry type="library" name="Maven: xmlpull:xmlpull:1.1.3.1" level="project" />
26+
<orderEntry type="library" name="Maven: xpp3:xpp3_min:1.1.4c" level="project" />
27+
<orderEntry type="library" name="Maven: org.codehaus.jettison:jettison:1.2" level="project" />
28+
<orderEntry type="library" name="Maven: org.springframework:spring-aop:4.0.5.RELEASE" level="project" />
29+
<orderEntry type="library" name="Maven: aopalliance:aopalliance:1.0" level="project" />
30+
<orderEntry type="library" name="Maven: org.springframework:spring-context:4.0.5.RELEASE" level="project" />
31+
<orderEntry type="library" name="Maven: org.springframework:spring-expression:4.0.5.RELEASE" level="project" />
32+
<orderEntry type="library" name="Maven: org.springframework.batch:spring-batch-infrastructure:3.0.8.RELEASE" level="project" />
33+
<orderEntry type="library" name="Maven: org.springframework.retry:spring-retry:1.1.0.RELEASE" level="project" />
34+
<orderEntry type="library" name="Maven: org.springframework.batch:spring-batch-test:3.0.8.RELEASE" level="project" />
35+
<orderEntry type="library" name="Maven: commons-collections:commons-collections:3.2.1" level="project" />
36+
<orderEntry type="library" name="Maven: commons-io:commons-io:2.4" level="project" />
37+
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-library:1.3" level="project" />
38+
<orderEntry type="library" name="Maven: org.springframework:spring-test:4.0.5.RELEASE" level="project" />
39+
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-core:2.8.2" level="project" />
40+
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-api:2.8.2" level="project" />
41+
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.11" level="project" />
42+
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
43+
<orderEntry type="library" name="Maven: org.apache.pdfbox:pdfbox:2.0.7" level="project" />
44+
<orderEntry type="library" name="Maven: org.apache.pdfbox:fontbox:2.0.7" level="project" />
45+
</component>
46+
</module>

mysqlToXmlBatchApp/pom.xml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>SpringBatch</artifactId>
7+
<groupId>com.sai.sri.siddhi</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>mysqlToXmlBatchApp</artifactId>
13+
14+
<build>
15+
<plugins>
16+
<plugin>
17+
<groupId>org.apache.maven.plugins</groupId>
18+
<artifactId>maven-jar-plugin</artifactId>
19+
<version>3.0.2</version>
20+
<configuration>
21+
<archive>
22+
<manifest>
23+
<addClasspath>true</addClasspath>
24+
<mainClass>com.sai.sri.siddhi.batch.sqltoxml.main.MainApp</mainClass>
25+
</manifest>
26+
</archive>
27+
</configuration>
28+
</plugin>
29+
30+
<plugin>
31+
<groupId>org.codehaus.mojo</groupId>
32+
<artifactId>exec-maven-plugin</artifactId>
33+
<version>1.6.0</version>
34+
<executions>
35+
<execution>
36+
<goals>
37+
<goal>java</goal>
38+
</goals>
39+
</execution>
40+
</executions>
41+
<configuration>
42+
<includePluginDependencies>true</includePluginDependencies>
43+
<includeProjectDependencies>true</includeProjectDependencies>
44+
<mainClass>com.sai.sri.siddhi.batch.sqltoxml.main.MainApp</mainClass>
45+
</configuration>
46+
</plugin>
47+
</plugins>
48+
</build>
49+
</project>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.sai.sri.siddhi.batch.sqltoxml.main;
2+
3+
import org.apache.logging.log4j.LogManager;
4+
import org.apache.logging.log4j.Logger;
5+
import org.springframework.batch.core.Job;
6+
import org.springframework.batch.core.JobExecution;
7+
import org.springframework.batch.core.JobParameters;
8+
import org.springframework.batch.core.JobParametersInvalidException;
9+
import org.springframework.batch.core.launch.JobLauncher;
10+
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
11+
import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException;
12+
import org.springframework.batch.core.repository.JobRestartException;
13+
import org.springframework.context.ApplicationContext;
14+
import org.springframework.context.support.ClassPathXmlApplicationContext;
15+
16+
public class MainApp {
17+
18+
private static Logger logger = LogManager.getLogger(MainApp.class);
19+
20+
public static void main(String[] args) throws JobParametersInvalidException, JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException {
21+
String[] springConfig = {"jobConfig.xml"};
22+
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(springConfig);
23+
JobLauncher jobLauncher = (JobLauncher) applicationContext.getBean("jobLauncher");
24+
Job job = (Job) applicationContext.getBean("sqlToXmlJob");
25+
JobExecution jobExecution = jobLauncher.run(job, new JobParameters());
26+
logger.info("job execution completed: " + jobExecution.getStatus());
27+
}
28+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.sai.sri.siddhi.batch.sqltoxml.mapper;
2+
3+
import com.sai.sri.siddhi.batch.sqltoxml.pojo.Tutorial;
4+
import org.springframework.jdbc.core.RowMapper;
5+
6+
import java.sql.ResultSet;
7+
import java.sql.SQLException;
8+
9+
public class TutorialRowMapper implements RowMapper<Tutorial>{
10+
11+
12+
@Override
13+
public Tutorial mapRow(ResultSet resultSet, int i) throws SQLException {
14+
Tutorial tutorial = new Tutorial();
15+
16+
tutorial.setTutorial_id(resultSet.getInt("id"));
17+
tutorial.setTitle(resultSet.getString("title"));
18+
tutorial.setAuthor(resultSet.getString("author"));
19+
tutorial.setDate(resultSet.getString("date"));
20+
tutorial.setIcon(resultSet.getString("icon"));
21+
tutorial.setDescription(resultSet.getString("description"));
22+
23+
return tutorial;
24+
}
25+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package com.sai.sri.siddhi.batch.sqltoxml.pojo;
2+
3+
import javax.xml.bind.annotation.XmlAttribute;
4+
import javax.xml.bind.annotation.XmlElement;
5+
import javax.xml.bind.annotation.XmlRootElement;
6+
7+
@XmlRootElement(name="tutorial")
8+
public class Tutorial {
9+
private int tutorial_id;
10+
private String author;
11+
private String title;
12+
private String date;
13+
private String icon;
14+
private String description;
15+
16+
@XmlAttribute(name="id")
17+
public int getTutorial_id() {
18+
return tutorial_id;
19+
}
20+
21+
public void setTutorial_id(int tutorial_id) {
22+
this.tutorial_id = tutorial_id;
23+
}
24+
25+
@XmlElement(name="Author")
26+
public String getAuthor() {
27+
return author;
28+
}
29+
30+
public void setAuthor(String author) {
31+
this.author = author;
32+
}
33+
34+
@XmlElement(name="Title")
35+
public String getTitle() {
36+
return title;
37+
}
38+
39+
public void setTitle(String title) {
40+
this.title = title;
41+
}
42+
43+
@XmlElement(name="Date")
44+
public String getDate() {
45+
return date;
46+
}
47+
48+
public void setDate(String date) {
49+
this.date = date;
50+
}
51+
52+
@XmlElement(name="Icon")
53+
public String getIcon() {
54+
return icon;
55+
}
56+
57+
public void setIcon(String icon) {
58+
this.icon = icon;
59+
}
60+
61+
@XmlElement(name="Description")
62+
public String getDescription() {
63+
return description;
64+
}
65+
66+
public void setDescription(String description) {
67+
this.description = description;
68+
}
69+
70+
@Override
71+
public String toString() {
72+
return "Tutorial{" +
73+
"tutorial_id=" + tutorial_id +
74+
", author='" + author + '\'' +
75+
", title='" + title + '\'' +
76+
", date='" + date + '\'' +
77+
", icon='" + icon + '\'' +
78+
", description='" + description + '\'' +
79+
'}';
80+
}
81+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.sai.sri.siddhi.batch.sqltoxml.processor;
2+
3+
import com.sai.sri.siddhi.batch.sqltoxml.pojo.Tutorial;
4+
import org.apache.logging.log4j.LogManager;
5+
import org.apache.logging.log4j.Logger;
6+
import org.springframework.batch.item.ItemProcessor;
7+
8+
public class CustomItemProcessor implements ItemProcessor<Tutorial, Tutorial> {
9+
10+
private Logger logger = LogManager.getLogger();
11+
12+
@Override
13+
public Tutorial process(Tutorial tutorial) throws Exception {
14+
logger.info("process()..");
15+
return tutorial;
16+
}
17+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<beans xmlns="http://www.springframework.org/schema/beans"
3+
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
4+
xmlns:util="http://www.springframework.org/schema/util"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6+
xsi:schemaLocation="http://www.springframework.org/schema/beans
7+
http://www.springframework.org/schema/beans/spring-beans.xsd
8+
http://www.springframework.org/schema/jdbc
9+
http://www.springframework.org/schema/jdbc/spring-jdbc.xsd">
10+
11+
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
12+
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
13+
<property name="url" value="jdbc:mysql://localhost:3306/yalamanchili" />
14+
<property name="username" value="root" />
15+
<property name="password" value="welcome" />
16+
</bean>
17+
18+
<bean id="transactionManager" class="org.springframework.batch.support.transaction.ResourcelessTransactionManager" />
19+
20+
<bean id="jobRepository" class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean">
21+
<property name="dataSource" ref="dataSource"/>
22+
<property name="transactionManager" ref="transactionManager" />
23+
<property name="databaseType" value="mysql" />
24+
</bean>
25+
26+
<bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
27+
<property name="jobRepository" ref="jobRepository" />
28+
</bean>
29+
30+
<!--
31+
<jdbc:initialize-database>
32+
<jdbc:script location="org/springframework/batch/core/schema-drop-mysql.sql"/>
33+
<jdbc:script location="org/springframework/batch/core/schema-mysql.sql"/>
34+
</jdbc:initialize-database>
35+
-->
36+
</beans>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<beans xmlns="http://www.springframework.org/schema/beans"
3+
xmlns:batch="http://www.springframework.org/schema/batch"
4+
xmlns:util="http://www.springframework.org/schema/util"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6+
xsi:schemaLocation="http://www.springframework.org/schema/beans
7+
http://www.springframework.org/schema/beans/spring-beans.xsd
8+
http://www.springframework.org/schema/batch
9+
http://www.springframework.org/schema/batch/spring-batch.xsd
10+
http://www.springframework.org/schema/util
11+
http://www.springframework.org/schema/util/spring-util.xsd">
12+
13+
<import resource="context.xml" />
14+
15+
<bean id="itemProcessor" class="com.sai.sri.siddhi.batch.sqltoxml.processor.CustomItemProcessor" />
16+
17+
<bean id="dbItemReader" class="org.springframework.batch.item.database.JdbcCursorItemReader" scope="step">
18+
<property name="dataSource" ref="dataSource" />
19+
<property name="sql" value="select * from yalamanchili.tutorials" />
20+
<property name="rowMapper">
21+
<bean class="com.sai.sri.siddhi.batch.sqltoxml.mapper.TutorialRowMapper" />
22+
</property>
23+
</bean>
24+
25+
<bean id="reportMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
26+
<property name="classesToBeBound">
27+
<list>
28+
<value>com.sai.sri.siddhi.batch.sqltoxml.pojo.Tutorial</value>
29+
</list>
30+
</property>
31+
</bean>
32+
33+
<bean id="xmlItemWriter" class="org.springframework.batch.item.xml.StaxEventItemWriter">
34+
<property name="resource" value="classpath:report/output.xml" />
35+
<property name="marshaller" ref="reportMarshaller" />
36+
<property name="rootTagName" value="tutorials" />
37+
</bean>
38+
39+
<batch:job id="sqlToXmlJob" >
40+
<batch:step id="step1">
41+
<batch:tasklet>
42+
<batch:chunk commit-interval="10" reader="dbItemReader" writer="xmlItemWriter" processor="itemProcessor" />
43+
</batch:tasklet>
44+
</batch:step>
45+
</batch:job>
46+
47+
</beans>

0 commit comments

Comments
 (0)