@Override public List<Event> findAllEvents(Person person) { List<Event> allEvents = new ArrayList<Event>(); // Polymorphic queries don't work for // @MappedSuperclass entities ! :-( Event e = findBirthRecord(person); if (e != null) { allEvents.add(e); } e = findDeathRecord(person); if (e != null) { allEvents.add(e); } e = findAdoptionRecord(person); if (e != null) { allEvents.add(e); } allEvents.addAll(findMarriages(person)); allEvents.addAll(findDivorces(person)); allEvents.addAll(getChildrenBirths(person)); allEvents.addAll(getChildAdoptionRecords(person)); System.out.println("findAllEvents: size of allEvents = " + allEvents.size()); return allEvents; }
@Override public List<Event> getChildAdoptionRecords(Person person) { // get the birth records of the children of this parent List<Adoption> adoptionRecords = new ArrayList<Adoption>(); em.getTransaction().begin(); TypedQuery<Adoption> q = em.createQuery( "select b from Adoption b, IN(b.parents) p WHERE p.id = :idParam", Adoption.class); q.setParameter("idParam", person.getId()); adoptionRecords.addAll(q.getResultList()); List<Event> adoptions = new ArrayList<Event>(); for (Adoption b : adoptionRecords) { if (b != null) { AdoptedChildRecord cr = new AdoptedChildRecord(); cr.setEventDate(b.getEventDate()); cr.setPerson(person); cr.setChild(b.getPerson()); cr.setTown(b.getTown()); cr.setState_province(b.getState_province()); cr.setCountry(b.getCountry()); adoptions.add(cr); } } em.getTransaction().commit(); return adoptions; }
@Override public List<Event> getChildrenBirths(Person person) { // get the birth records of the children of this parent List<Birth> birthRecords = new ArrayList<Birth>(); em.getTransaction().begin(); Query q = em.createQuery("select b from Birth b, IN(b.parents) p WHERE p.id = :idParam"); q.setParameter("idParam", person.getId()); birthRecords.addAll((Collection<? extends Birth>) q.getResultList()); List<Event> childrenBirths = new ArrayList<Event>(); for (Birth b : birthRecords) { if (b != null) { ChildRecord cr = new ChildRecord(); cr.setEventDate(b.getEventDate()); cr.setPerson(person); cr.setChild(b.getPerson()); cr.setTown(b.getTown()); cr.setState_province(b.getState_province()); cr.setCountry(b.getCountry()); childrenBirths.add(cr); } } em.getTransaction().commit(); return childrenBirths; }