BAEL-3961 Remove address field of Employee class.
This commit is contained in:
parent
78e180f35d
commit
c68c7648a3
|
@ -7,13 +7,11 @@ public class Employee {
|
||||||
|
|
||||||
private String lastName;
|
private String lastName;
|
||||||
|
|
||||||
private String address;
|
|
||||||
|
|
||||||
public Employee(int id, String firstName, String lastName, String address) {
|
public Employee(int id, String firstName, String lastName) {
|
||||||
setId(id);
|
this.id = id;
|
||||||
setFirstName(firstName);
|
this.firstName = firstName;
|
||||||
setLastName(lastName);
|
this.lastName = lastName;
|
||||||
setAddress(address);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
|
@ -40,12 +38,5 @@ public class Employee {
|
||||||
this.lastName = lastName;
|
this.lastName = lastName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAddress() {
|
|
||||||
return address;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAddress(final String address) {
|
|
||||||
this.address = address;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,23 +30,22 @@ public class EmployeeDAO {
|
||||||
SqlParameterSource parameters = new MapSqlParameterSource("ids", ids);
|
SqlParameterSource parameters = new MapSqlParameterSource("ids", ids);
|
||||||
List<Employee> employees = namedJdbcTemplate.query("SELECT * FROM EMPLOYEE WHERE id IN (:ids)",
|
List<Employee> employees = namedJdbcTemplate.query("SELECT * FROM EMPLOYEE WHERE id IN (:ids)",
|
||||||
parameters,
|
parameters,
|
||||||
(rs, rowNum) -> new Employee(rs.getInt("id"), rs.getString("first_name"), rs.getString("last_name"), rs.getString("address")));
|
(rs, rowNum) -> new Employee(rs.getInt("id"), rs.getString("first_name"), rs.getString("last_name")));
|
||||||
|
|
||||||
return employees;
|
return employees;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Employee> getEmployeesFromIdList(List<Integer> ids) {
|
public List<Employee> getEmployeesFromIdList(List<Integer> ids) {
|
||||||
String inSql = String.join(",", Collections.nCopies(ids.size(), "?"));
|
String inSql = String.join(",", Collections.nCopies(ids.size(), "?"));
|
||||||
List<Employee> employees = jdbcTemplate.query("SELECT * FROM EMPLOYEE WHERE id IN (" + inSql +")",
|
List<Employee> employees = jdbcTemplate.query(String.format("SELECT * FROM EMPLOYEE WHERE id IN (%s)", inSql),
|
||||||
ids.toArray(),
|
ids.toArray(),
|
||||||
(rs, rowNum) -> new Employee(rs.getInt("id"), rs.getString("first_name"), rs.getString("last_name"), rs.getString("address")));
|
(rs, rowNum) -> new Employee(rs.getInt("id"), rs.getString("first_name"), rs.getString("last_name")));
|
||||||
|
|
||||||
return employees;
|
return employees;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Employee> getEmployeesFromLargeIdList(List<Integer> ids) {
|
public List<Employee> getEmployeesFromLargeIdList(List<Integer> ids) {
|
||||||
jdbcTemplate.execute("CREATE TEMPORARY TABLE IF NOT EXISTS employee_tmp (id INT NOT NULL)");
|
jdbcTemplate.execute("CREATE TEMPORARY TABLE IF NOT EXISTS employee_tmp (id INT NOT NULL)");
|
||||||
jdbcTemplate.update("DELETE FROM employee_tmp");
|
|
||||||
|
|
||||||
List<Object[]> employeeIds = new ArrayList<>();
|
List<Object[]> employeeIds = new ArrayList<>();
|
||||||
for (Integer id : ids) {
|
for (Integer id : ids) {
|
||||||
|
@ -55,7 +54,9 @@ public class EmployeeDAO {
|
||||||
jdbcTemplate.batchUpdate("INSERT INTO employee_tmp VALUES(?)", employeeIds);
|
jdbcTemplate.batchUpdate("INSERT INTO employee_tmp VALUES(?)", employeeIds);
|
||||||
|
|
||||||
List<Employee> employees = jdbcTemplate.query("SELECT * FROM EMPLOYEE WHERE id IN (SELECT id FROM employee_tmp)",
|
List<Employee> employees = jdbcTemplate.query("SELECT * FROM EMPLOYEE WHERE id IN (SELECT id FROM employee_tmp)",
|
||||||
(rs, rowNum) -> new Employee(rs.getInt("id"), rs.getString("first_name"), rs.getString("last_name"), rs.getString("address")));
|
(rs, rowNum) -> new Employee(rs.getInt("id"), rs.getString("first_name"), rs.getString("last_name")));
|
||||||
|
|
||||||
|
jdbcTemplate.update("DELETE FROM employee_tmp");
|
||||||
|
|
||||||
return employees;
|
return employees;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,5 @@ CREATE TABLE EMPLOYEE
|
||||||
(
|
(
|
||||||
ID int NOT NULL PRIMARY KEY,
|
ID int NOT NULL PRIMARY KEY,
|
||||||
FIRST_NAME varchar(255),
|
FIRST_NAME varchar(255),
|
||||||
LAST_NAME varchar(255),
|
LAST_NAME varchar(255)
|
||||||
ADDRESS varchar(255)
|
|
||||||
);
|
);
|
|
@ -1,4 +1,4 @@
|
||||||
INSERT INTO EMPLOYEE VALUES (1, 'James', 'Gosling', 'Canada');
|
INSERT INTO EMPLOYEE VALUES (1, 'James', 'Gosling');
|
||||||
INSERT INTO EMPLOYEE VALUES (2, 'Donald', 'Knuth', 'USA');
|
INSERT INTO EMPLOYEE VALUES (2, 'Donald', 'Knuth');
|
||||||
INSERT INTO EMPLOYEE VALUES (3, 'Linus', 'Torvalds', 'Finland');
|
INSERT INTO EMPLOYEE VALUES (3, 'Linus', 'Torvalds');
|
||||||
INSERT INTO EMPLOYEE VALUES (4, 'Dennis', 'Ritchie', 'USA');
|
INSERT INTO EMPLOYEE VALUES (4, 'Dennis', 'Ritchie');
|
Loading…
Reference in New Issue