Merge pull request #4686 from smokeyrobot/bael-1908

Bael 1908 - Editor Feedback
This commit is contained in:
Tom Hombergs 2018-07-13 22:19:22 +02:00 committed by GitHub
commit 918e6a78d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 34 deletions

View File

@ -7,8 +7,6 @@ import javax.persistence.*;
classes = { @ConstructorResult(targetClass = com.baeldung.sqlresultsetmapping.ScheduledDay.class,
columns = { @ColumnResult(name = "id", type = Long.class),
@ColumnResult(name = "employeeId", type = Long.class),
@ColumnResult(name = "hourIn"),
@ColumnResult(name = "hourOut"),
@ColumnResult(name = "dayOfWeek") }) }),
@SqlResultSetMapping(name = "FridayEmployeeResult",
columns = { @ColumnResult(name = "employeeId") }),
@ -21,7 +19,7 @@ import javax.persistence.*;
resultSetMapping = "FridayEmployeeResult")
@NamedNativeQuery(name = "Schedules",
query = "SELECT * FROM schedule_days WHERE hourIn = 8",
query = "SELECT * FROM schedule_days WHERE employeeId = 3",
resultSetMapping = "ScheduleResult")
@Entity
@Table(name = "SCHEDULE_DAYS")
@ -31,18 +29,14 @@ public class ScheduledDay {
@GeneratedValue
private Long id;
private Long employeeId;
private Integer hourIn;
private Integer hourOut;
private String dayOfWeek;
public ScheduledDay() {
}
public ScheduledDay(Long id, Long employeeId, Integer hourIn, Integer hourOut, String dayofWeek) {
public ScheduledDay(Long id, Long employeeId, String dayofWeek) {
this.id = id;
this.employeeId = employeeId;
this.hourIn = hourIn;
this.hourOut = hourOut;
this.dayOfWeek = dayofWeek;
}
@ -54,22 +48,6 @@ public class ScheduledDay {
this.employeeId = employeeId;
}
public Integer getHourIn() {
return hourIn;
}
public void setHourIn(Integer hourIn) {
this.hourIn = hourIn;
}
public Integer getHourOut() {
return hourOut;
}
public void setHourOut(Integer hourOut) {
this.hourOut = hourOut;
}
public String getDayOfWeek() {
return dayOfWeek;
}

View File

@ -9,11 +9,9 @@ INSERT INTO EMPLOYEE VALUES (3, 'FRANK');
CREATE TABLE SCHEDULE_DAYS
(id IDENTITY,
employeeId BIGINT,
hourIn int,
hourOut int,
dayOfWeek VARCHAR(10));
INSERT INTO SCHEDULE_DAYS (employeeId, hourIn, hourOut, dayOfWeek) VALUES (1, 13, 21, 'FRIDAY');
INSERT INTO SCHEDULE_DAYS (employeeId, hourIn, hourOut, dayOfWeek) VALUES (2, 8, 4, 'SATURDAY');
INSERT INTO SCHEDULE_DAYS (employeeId, hourIn, hourOut, dayOfWeek) VALUES (3, 8, 4, 'MONDAY');
INSERT INTO SCHEDULE_DAYS (employeeId, hourIn, hourOut, dayOfWeek) VALUES (3, 8, 4, 'FRIDAY');
INSERT INTO SCHEDULE_DAYS (employeeId, dayOfWeek) VALUES (1, 'FRIDAY');
INSERT INTO SCHEDULE_DAYS (employeeId, dayOfWeek) VALUES (2, 'SATURDAY');
INSERT INTO SCHEDULE_DAYS (employeeId, dayOfWeek) VALUES (3, 'MONDAY');
INSERT INTO SCHEDULE_DAYS (employeeId, dayOfWeek) VALUES (3, 'FRIDAY');

View File

@ -31,8 +31,8 @@ public class SqlResultSetMappingUnitTest {
@Test
public void whenNamedQuery_thenConstructorResult() {
List<ScheduledDay> scheduleDays = Collections.checkedList(em.createNamedQuery("Schedules", ScheduledDay.class).getResultList(), ScheduledDay.class);
assertEquals(3, scheduleDays.size());
assertTrue(scheduleDays.stream().allMatch(c -> c.getHourIn().longValue() == 8));
assertEquals(2, scheduleDays.size());
assertTrue(scheduleDays.stream().allMatch(c -> c.getEmployeeId().longValue() == 3));
}
@Test
@ -44,8 +44,7 @@ public class SqlResultSetMappingUnitTest {
@Test
public void whenNamedQuery_thenMultipleEntityResult() {
final Query query = em.createNativeQuery("SELECT e.id, e.name, d.id, d.employeeId, "
+ " d.dayOfWeek, d.hourIn, d.hourOut "
final Query query = em.createNativeQuery("SELECT e.id, e.name, d.id, d.employeeId, d.dayOfWeek "
+ " FROM employee e, schedule_days d "
+ " WHERE e.id = d.employeeId", "EmployeeScheduleResults");
List<Object[]> results = query.getResultList();