Skip to content

Commit cd6f856

Browse files
committed
Changed Person entity id generation to be manually assigned.
Removed hibernate sequence.
1 parent 6c724a5 commit cd6f856

File tree

5 files changed

+15
-23
lines changed

5 files changed

+15
-23
lines changed

batch/chunk-csv-database/src/main/java/org/javaee7/batch/chunk/csv/database/MyItemProcessor.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@
5050
*/
5151
@Named
5252
public class MyItemProcessor implements ItemProcessor {
53-
SimpleDateFormat format = new SimpleDateFormat("M/dd/yy");
53+
private static int id = 1;
54+
private SimpleDateFormat format = new SimpleDateFormat("M/dd/yy");
5455

5556
@Override
5657
public Person processItem(Object t) {
@@ -69,6 +70,6 @@ public Person processItem(Object t) {
6970
return null;
7071
}
7172

72-
return new Person(name, date);
73+
return new Person(id++, name, date);
7374
}
7475
}

batch/chunk-csv-database/src/main/java/org/javaee7/batch/chunk/csv/database/Person.java

+10-16
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,11 @@
3939
*/
4040
package org.javaee7.batch.chunk.csv.database;
4141

42-
import java.io.Serializable;
43-
import javax.persistence.Basic;
44-
import javax.persistence.Column;
45-
import javax.persistence.Entity;
46-
import javax.persistence.GeneratedValue;
47-
import javax.persistence.GenerationType;
48-
import javax.persistence.Id;
49-
import javax.persistence.NamedQueries;
50-
import javax.persistence.NamedQuery;
51-
import javax.persistence.Table;
42+
import javax.persistence.*;
5243
import javax.validation.constraints.NotNull;
5344
import javax.validation.constraints.Size;
5445
import javax.xml.bind.annotation.XmlRootElement;
46+
import java.io.Serializable;
5547

5648
/**
5749
* @author Arun Gupta
@@ -66,7 +58,6 @@
6658
public class Person implements Serializable {
6759

6860
@Id
69-
@GeneratedValue(strategy = GenerationType.AUTO)
7061
private int id;
7162

7263
private static final long serialVersionUID = 1L;
@@ -94,6 +85,12 @@ public Person(String name, String hiredate) {
9485
this.hiredate = hiredate;
9586
}
9687

88+
public Person(int id, String name, String hiredate) {
89+
this.id = id;
90+
this.name = name;
91+
this.hiredate = hiredate;
92+
}
93+
9794
public int getId() {
9895
return id;
9996
}
@@ -132,15 +129,12 @@ public boolean equals(Object object) {
132129
return false;
133130
}
134131
Person other = (Person) object;
135-
if ((this.name == null && other.name != null) || (this.name != null && !this.name.equals(other.name))) {
136-
return false;
137-
}
138-
return true;
132+
return !((this.name == null && other.name != null) || (this.name != null && !this.name.equals(other.name)));
139133
}
140134

141135
@Override
142136
public String toString() {
143-
return name;
137+
return name + id;
144138
}
145139

146140
}
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
CREATE SEQUENCE HIBERNATE_SEQUENCE
21
CREATE TABLE CHUNK_CSV_DATABASE ("ID" INTEGER not null primary key, "NAME" VARCHAR(50) not null, "HIREDATE" VARCHAR(50) not null)
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
DROP TABLE CHUNK_CSV_DATABASE
2-
DROP SEQUENCE HIBERNATE_SEQUENCE
1+
DROP TABLE CHUNK_CSV_DATABASE

batch/chunk-csv-database/src/test/java/org/javaee7/batch/chunk/csv/database/BatchCSVDatabaseTest.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,14 @@ public void testBatchCSVDatabase() throws Exception {
5656
for (StepExecution stepExecution : stepExecutions) {
5757
if (stepExecution.getStepName().equals("myStep")) {
5858
Map<Metric.MetricType, Long> metricsMap = BatchTestHelper.getMetricsMap(stepExecution.getMetrics());
59-
System.out.println(metricsMap);
6059

6160
assertEquals(7L, (long) metricsMap.get(Metric.MetricType.READ_COUNT));
6261
assertEquals(7L, (long) metricsMap.get(Metric.MetricType.WRITE_COUNT));
6362
assertEquals(3L, (long) metricsMap.get(Metric.MetricType.COMMIT_COUNT));
6463
}
6564
}
6665

67-
Query query = entityManager.createQuery("SELECT p FROM Person p");
66+
Query query = entityManager.createNamedQuery("Person.findAll");
6867
@SuppressWarnings("unchecked")
6968
List<Person> persons = query.getResultList();
7069

0 commit comments

Comments
 (0)