|
|
|
@ -1,13 +1,15 @@
|
|
|
|
|
package space.kklochko.jpa_hospital_example.db.repositories;
|
|
|
|
|
|
|
|
|
|
import jakarta.persistence.EntityGraph;
|
|
|
|
|
import jakarta.persistence.EntityManager;
|
|
|
|
|
import jakarta.persistence.TypedQuery;
|
|
|
|
|
import space.kklochko.jpa_hospital_example.db.repositories.blocks.TransactionalInsert;
|
|
|
|
|
import space.kklochko.jpa_hospital_example.db.repositories.blocks.TransactionalRemove;
|
|
|
|
|
import space.kklochko.jpa_hospital_example.db.repositories.blocks.TransactionalUpdate;
|
|
|
|
|
import space.kklochko.jpa_hospital_example.models.Department;
|
|
|
|
|
import space.kklochko.jpa_hospital_example.models.Patient;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
|
|
public class DepartmentRepository extends AbstractRepository<Department> {
|
|
|
|
@ -25,10 +27,28 @@ public class DepartmentRepository extends AbstractRepository<Department> {
|
|
|
|
|
return manager.find(Department.class, id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ArrayList<Department> readAll() {
|
|
|
|
|
public List<Department> readAll() {
|
|
|
|
|
EntityGraph<Department> entityGraph = manager.createEntityGraph(Department.class);
|
|
|
|
|
entityGraph.addAttributeNodes("patients");
|
|
|
|
|
//entityGraph.addSubgraph("patients")
|
|
|
|
|
//.addAttributeNodes("indicators");
|
|
|
|
|
|
|
|
|
|
TypedQuery<Department> query = manager.createQuery("SELECT d FROM Department d", Department.class);
|
|
|
|
|
query.setHint( "javax.persistence.fetchgraph", entityGraph);
|
|
|
|
|
|
|
|
|
|
List<Department> departments = query.getResultList();
|
|
|
|
|
|
|
|
|
|
for(Department department : departments) {
|
|
|
|
|
EntityGraph<Patient> patientEntityGraph = manager.createEntityGraph(Patient.class);
|
|
|
|
|
patientEntityGraph.addAttributeNodes("indicators");
|
|
|
|
|
|
|
|
|
|
TypedQuery<Patient> patientQuery = manager.createQuery("SELECT p FROM Patient p", Patient.class);
|
|
|
|
|
patientQuery.setHint( "javax.persistence.fetchgraph", patientEntityGraph);
|
|
|
|
|
|
|
|
|
|
department.setPatients(patientQuery.getResultList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (ArrayList<Department>) query.getResultList();
|
|
|
|
|
return departments;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean update(Department object) {
|
|
|
|
|