コード例 #1
0
  @Override
  public void addParent(Person child, Person parent) {
    em.getTransaction().begin();
    TypedQuery<Birth> q =
        em.createQuery("select b from Birth b where b.person.id = :idParam", Birth.class);
    q.setParameter("idParam", child.getId());

    List<Birth> results = (List<Birth>) q.getResultList();
    Birth b = (results != null && results.size() > 0) ? results.get(0) : null;
    if (b != null) {
      b.addParent(parent);
      em.merge(b);
    }
    em.getTransaction().commit();
  }
コード例 #2
0
  private void initialize() {

    Person JohnLennon = newPerson("John", "Lennon", Person.Gender.MALE);
    JohnLennon.setNotes("Famous songwriter and member of the Beatles musical group.");

    Person yoko = newPerson("Yoko", "Ono", Person.Gender.FEMALE);
    Person cynthia = newPerson("Cynthia", "Powell", Person.Gender.FEMALE);
    Person julian = newPerson("Julian", "Lennon", Person.Gender.MALE);

    Birth b = new Birth();
    b.setEventDate(new GregorianCalendar(1963, 3, 8).getTime());
    b.setPerson(julian);
    b.addParent(JohnLennon);
    b.addParent(cynthia);
    b.setTown("Liverpool");
    b.setCountry("England");
    addBirth(b);

    Person sean = newPerson("Sean", "Lennon", Person.Gender.MALE);
    b = new Birth();
    b.setEventDate(new GregorianCalendar(1975, 9, 9).getTime());
    b.setPerson(sean);
    b.setTown("Liverpool");
    b.setCountry("England");
    b.addParent(JohnLennon);
    b.addParent(yoko);
    addBirth(b);

    Person mimi = newPerson("Mary Elizabeth", "Smith", Person.Gender.FEMALE);

    mimi.setMiddle("Mimi");
    mimi.setNotes("Mimi became nephew John's guardian");

    Person Isoko = newPerson("Isoko", "Ono", Person.Gender.FEMALE);
    Person Yeisuke = newPerson("Yeisuke", "Ono", Person.Gender.MALE);

    // Get person JohnLennon
    Person person = getPerson(JohnLennon.getId());
    person.setMiddle("Winston");
    mydisplay(person.toString());

    mydisplay(JohnLennon.getMiddle());

    // birth = October 9, 1940
    // death = December 8, 1980
    b = new Birth();
    b.setEventDate(new GregorianCalendar(1940, 9, 9).getTime());
    b.setPerson(JohnLennon);
    b.setTown("Liverpool");
    b.setCountry("England");
    addBirth(b);

    Death dd = new Death();
    dd.setPerson(JohnLennon);
    dd.setEventDate(new GregorianCalendar(1980, 11, 8).getTime());
    dd.setTown("New York");
    dd.setState_province("New York");
    dd.setCountry("USA");
    addDeath(dd);

    // add more people to John Lennon's ancestry
    Person julia = newPerson("Julia", "Stanley", Person.Gender.FEMALE);

    Person alf = newPerson("Alfred", "Lennon", Person.Gender.MALE);
    addParent(JohnLennon, alf);
    addParent(JohnLennon, julia);

    Adoption a = new Adoption();
    a.setEventDate(new GregorianCalendar(1946, 6, 1).getTime());
    a.setPerson(JohnLennon);
    a.setTown("Liverpool");
    a.setCountry("England");
    // a.addParent(mimi);
    addAdoption(a);
    addAdoptedParent(JohnLennon, mimi);

    dd = new Death();
    dd.setPerson(mimi);
    dd.setEventDate(new GregorianCalendar(1991, 11, 6).getTime());
    dd.setTown("Poole");
    dd.setState_province("Dorset");
    dd.setCountry("England");
    addDeath(dd);

    b = new Birth();
    b.setEventDate(new GregorianCalendar(1933, 1, 18).getTime());
    b.setPerson(yoko);
    b.setTown("Tokyo");
    b.setCountry("Japan");
    addBirth(b);

    Marriage m = new Marriage();
    m.setEventDate(new GregorianCalendar(1969, 2, 20).getTime());
    m.setPerson(JohnLennon);
    m.setSpouse(yoko);
    m.setTown("Gilbraltar");
    m.setCountry("Gibraltar");
    addMarriage(m);

    addParent(yoko, Isoko);
    addParent(yoko, Yeisuke);
    List<Person> thesepeople = getAllPeople();
    mydisplay("\nGetting All People");
    for (Person p : thesepeople) {
      mydisplay(p.toString());
    }

    Set<Person> thesechildren = getChildren(JohnLennon);
    mydisplay("\nGetting Children of " + JohnLennon);
    for (Person p : thesechildren) {
      mydisplay(p.toString());
    }

    thesechildren = getChildren(JohnLennon, yoko);
    mydisplay("\nGetting Children of both " + JohnLennon + " and " + yoko);
    for (Person p : thesechildren) {
      mydisplay(p.toString());
    }

    thesechildren = getChildrenAll(JohnLennon, yoko);
    mydisplay("\nGetting Children of either " + JohnLennon + " and " + yoko);
    for (Person p : thesechildren) {
      mydisplay(p.toString());
    }

    // Events stuff
    List<Event> events = findAllEvents(JohnLennon);
    mydisplay("Finding all events for " + JohnLennon);
    for (Event e : events) {
      if (e != null) {
        mydisplay(e.toString());
      }
    }

    events = findAllEvents(yoko);
    mydisplay("Finding all events for " + yoko);
    for (Event e : events) {
      if (e != null) {
        mydisplay(e.toString());
      }
    }

    events = findAllEvents(cynthia);

    mydisplay("Finding all events for " + cynthia);
    for (Event e : events) {
      if (e != null) {
        mydisplay(e.toString());
      }
    }
  }