Skip to content

Commit e43e90e

Browse files
committed
Adding Batch specific files
1 parent b0480a9 commit e43e90e

File tree

6 files changed

+129
-0
lines changed

6 files changed

+129
-0
lines changed

Diff for: HelloJavaEE7/src/META-INF/batch-jobs/myJob.xml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<job id="myJob" xmlns="http://xmlns.jcp.org/xml/ns/javaee" version="1.0">
3+
<step id="myStep" >
4+
<chunk item-count="3">
5+
<reader ref="myItemReader"/>
6+
<processor ref="myItemProcessor"/>
7+
<writer ref="myItemWriter"/>
8+
</chunk>
9+
</step>
10+
</job>
11+

Diff for: HelloJavaEE7/src/org/sample/batch/MyInputRecord.java

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.sample.batch;
2+
3+
/**
4+
* @author Arun Gupta
5+
*/
6+
public class MyInputRecord {
7+
private int id;
8+
9+
public MyInputRecord() { }
10+
11+
public MyInputRecord(int id) {
12+
this.id = id;
13+
}
14+
15+
public int getId() {
16+
return id;
17+
}
18+
19+
public void setId(int id) {
20+
this.id = id;
21+
}
22+
23+
@Override
24+
public String toString() {
25+
return "MyInputRecord: " + id;
26+
}
27+
}
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.sample.batch;
2+
3+
import javax.batch.api.chunk.ItemProcessor;
4+
import javax.inject.Named;
5+
6+
/**
7+
* @author Arun Gupta
8+
*/
9+
@Named
10+
public class MyItemProcessor implements ItemProcessor {
11+
12+
@Override
13+
public MyOutputRecord processItem(Object t) {
14+
System.out.println("processItem: " + t);
15+
16+
return (((MyInputRecord)t).getId() % 2 == 0) ? null : new MyOutputRecord(((MyInputRecord)t).getId() * 2);
17+
}
18+
}

Diff for: HelloJavaEE7/src/org/sample/batch/MyItemReader.java

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package org.sample.batch;
2+
3+
import java.io.Serializable;
4+
import java.util.StringTokenizer;
5+
import javax.batch.api.chunk.AbstractItemReader;
6+
import javax.inject.Named;
7+
8+
/**
9+
* @author Arun Gupta
10+
*/
11+
@Named
12+
public class MyItemReader extends AbstractItemReader {
13+
14+
private StringTokenizer tokens;
15+
16+
17+
@Override
18+
public void open(Serializable checkpoint) throws Exception {
19+
tokens = new StringTokenizer("1,2,3,4,5,6,7,8,9,10", ",");
20+
}
21+
22+
@Override
23+
public MyInputRecord readItem() {
24+
if (tokens.hasMoreTokens()) {
25+
return new MyInputRecord(Integer.valueOf(tokens.nextToken()));
26+
}
27+
return null;
28+
}
29+
}

Diff for: HelloJavaEE7/src/org/sample/batch/MyItemWriter.java

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.sample.batch;
2+
3+
import java.util.List;
4+
import javax.batch.api.chunk.AbstractItemWriter;
5+
import javax.inject.Named;
6+
7+
/**
8+
* @author Arun Gupta
9+
*/
10+
@Named
11+
public class MyItemWriter extends AbstractItemWriter {
12+
13+
@Override
14+
public void writeItems(List list) {
15+
System.out.println("writeItems: " + list);
16+
}
17+
}
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.sample.batch;
2+
3+
/**
4+
* @author Arun Gupta
5+
*/
6+
public class MyOutputRecord {
7+
private int id;
8+
9+
public MyOutputRecord() { }
10+
11+
public MyOutputRecord(int id) {
12+
this.id = id;
13+
}
14+
15+
public int getId() {
16+
return id;
17+
}
18+
19+
public void setId(int id) {
20+
this.id = id;
21+
}
22+
23+
@Override
24+
public String toString() {
25+
return "MyOutputRecord: " + id;
26+
}
27+
}

0 commit comments

Comments
 (0)