Skip to content

Commit 1d63b1c

Browse files
Update EmployeeDAOJpaImpl.java
1 parent e9fd11c commit 1d63b1c

File tree

1 file changed

+7
-32
lines changed
  • 11-spring-boot-rest-crud-with-jpa/22-jpa-cruddemo/src/main/java/com/luv2code/springboot/cruddemo/dao

1 file changed

+7
-32
lines changed

11-spring-boot-rest-crud-with-jpa/22-jpa-cruddemo/src/main/java/com/luv2code/springboot/cruddemo/dao/EmployeeDAOJpaImpl.java

+7-32
Original file line numberDiff line numberDiff line change
@@ -22,60 +22,35 @@ public EmployeeDAOJpaImpl(EntityManager theEntityManager) {
2222

2323
@Override
2424
public List<Employee> findAll() {
25-
2625
// create a query
27-
Query theQuery =
28-
entityManager.createQuery("from Employee");
29-
26+
Query theQuery = entityManager.createQuery("from Employee");
3027
// execute query and get result list
31-
List<Employee> employees = theQuery.getResultList();
32-
28+
List<Employee> employees = theQuery.getResultList();
3329
// return the results
3430
return employees;
3531
}
3632

3733
@Override
3834
public Employee findById(int theId) {
39-
4035
// get employee
41-
Employee theEmployee =
42-
entityManager.find(Employee.class, theId);
43-
36+
Employee theEmployee = entityManager.find(Employee.class, theId);
4437
// return employee
4538
return theEmployee;
4639
}
4740

4841
@Override
4942
public void save(Employee theEmployee) {
50-
5143
// save or update the employee
52-
Employee dbEmployee = entityManager.merge(theEmployee);
53-
44+
Employee dbEmployee = entityManager.merge(theEmployee);
5445
// update with id from db ... so we can get generated id for save/insert
55-
theEmployee.setId(dbEmployee.getId());
56-
46+
theEmployee.setId(dbEmployee.getId());
5747
}
5848

5949
@Override
6050
public void deleteById(int theId) {
61-
6251
// delete object with primary key
63-
Query theQuery = entityManager.createQuery(
64-
"delete from Employee where id=:employeeId");
65-
66-
theQuery.setParameter("employeeId", theId);
67-
52+
Query theQuery = entityManager.createQuery("delete from Employee where id=:employeeId");
53+
theQuery.setParameter("employeeId", theId);
6854
theQuery.executeUpdate();
6955
}
70-
7156
}
72-
73-
74-
75-
76-
77-
78-
79-
80-
81-

0 commit comments

Comments
 (0)