public static void main(String[] args) throws Exception {
    int argCount = args.length;
    String filein =
        argCount == 1
            ? args[0]
            : "marshalpeople.xml"; // Checks if there's a file as argument, otherwise uses the
                                   // default

    /* Sets up the unmarshaller and extrapolates the data */
    JAXBContext jc = JAXBContext.newInstance(Storage.class);
    Unmarshaller um = jc.createUnmarshaller();
    Storage people = (Storage) um.unmarshal(new FileReader(filein));
    List<Person> list = people.getData();

    /* Prints the data out in a proper way */
    for (Person person : list) {
      HealthProfile hp = person.gethProfile();
      System.out.println("Person " + person.getPersonId() + ":");
      System.out.println("\tName: " + person.getFirstname());
      System.out.println("\tSurname: " + person.getLastname());
      System.out.println("\tBirthdate: " + person.getBirthdate());
      System.out.println("\tHealth Profile (updated on " + hp.getLastupdate() + "):");
      System.out.println("\t\tHeight: " + hp.getHeight());
      System.out.println("\t\tWeight: " + hp.getWeight());
      System.out.println("\t\tBMI: " + hp.getBMI());
      System.out.println();
    }
  }
예제 #2
0
  public void updatePerson(Person person) {

    Person personDao = em.find(Person.class, person.getId());
    em.getTransaction().begin();

    System.out.println("--->" + person);

    personDao.setFirstname(person.getFirstname());
    personDao.setLastname(person.getLastname());
    personDao.setBirthdate(person.getBirthdate());
    personDao.setEmail(person.getEmail());
    personDao.setWebsite(person.getWebsite());

    if (person.getGroup() != null) {
      Group group = new Group();
      group.setGroupID(person.getGroup().getGroupID());
      group.setName(person.getGroup().getName());
      personDao.setGroup(group);
    }

    em.getTransaction().commit();
  }
예제 #3
0
파일: PersonDAO.java 프로젝트: pkkann/his
  public int insertPerson(Person p) throws SQLException {
    conn = DBTool.getInstance();

    System.out.println("Inserting person...");
    if (conn.isValid(10000)) {
      Statement s = conn.createStatement();

      String firstname = p.getFirstname();
      String middlename = p.getMiddlename();
      String lastname = p.getLastname();
      String address = p.getAddress();
      String birthday = ADate.formatADate(p.getBirthdayDate(), "");
      String expirationDate = ADate.formatADate(p.getExpirationDate(), "");
      File picturePathF = p.getPicturePath();
      String picturePath = FileTool.getDefaultFolder() + "/" + picturePathF.getName();
      int quarantine = 0;
      String quarantineExpirationDate = "";
      if (p.getQuarantineExpirationDate() != null) {
        quarantineExpirationDate = p.getQuarantineExpirationDate().toString();
      }
      int oneOne = 0;
      String creationDate = ADate.formatADate(p.getCreationDate(), "");
      if (p.isQuarantine()) {
        quarantine = 1;
      }
      if (p.isOneOne()) {
        oneOne = 1;
      }
      int enrolled = 0;
      if (p.isEnrolled()) {
        enrolled = 1;
      }
      int hone = 0;
      if (p.isHone()) {
        hone = 1;
      }

      s.executeUpdate(
          "INSERT INTO person (firstname, middlename, lastname, address, birthday, expirationdate, picturepath, quarantine, quarantineexpirationdate, oneone, creationdate, enrolled, hone) "
              + "VALUES('"
              + firstname
              + "', '"
              + middlename
              + "', '"
              + lastname
              + "', '"
              + address
              + "', '"
              + birthday
              + "', '"
              + expirationDate
              + "', '"
              + picturePath
              + "', '"
              + quarantine
              + "', '"
              + quarantineExpirationDate
              + "', '"
              + oneOne
              + "', '"
              + creationDate
              + "', '"
              + enrolled
              + "', '"
              + hone
              + "');");
      ResultSet rs = s.executeQuery("SELECT LAST_INSERT_ID();");
      rs.next();
      int idback = rs.getInt(1);
      System.out.println("Insertion complete!");
      rs.close();
      s.close();
      conn.close();
      return idback;
    } else {
      System.out.println("Connection not valid");
      conn.close();
      return -1;
    }
  }
예제 #4
0
파일: PersonDAO.java 프로젝트: pkkann/his
  public void savePerson(Person p) throws SQLException {
    conn = DBTool.getInstance();

    System.out.println("Saving person...");
    if (conn.isValid(10000)) {
      Statement s = conn.createStatement();

      int idperson = p.getId();
      String firstname = p.getFirstname();
      String middlename = p.getMiddlename();
      String lastname = p.getLastname();
      String address = p.getAddress();
      String birthday = ADate.formatADate(p.getBirthdayDate(), "");
      String expirationDate = ADate.formatADate(p.getExpirationDate(), "");
      File picturePathF = p.getPicturePath();
      String picturePath = FileTool.getDefaultFolder() + "/" + picturePathF.getName();
      int quarantine = 0;
      String quarantineExpirationDate = "";
      if (p.getQuarantineExpirationDate() != null) {
        quarantineExpirationDate = p.getQuarantineExpirationDate().toString();
      }
      int oneOne = 0;
      if (p.isQuarantine()) {
        quarantine = 1;
      }
      if (p.isOneOne()) {
        oneOne = 1;
      }
      int enrolled = 0;
      if (p.isEnrolled()) {
        enrolled = 1;
      }
      int hone = 0;
      if (p.isHone()) {
        hone = 1;
      }

      s.executeUpdate(
          "UPDATE person SET firstname = '"
              + firstname
              + "', middlename = '"
              + middlename
              + "', lastname = '"
              + lastname
              + "', address = '"
              + address
              + "', birthday = '"
              + birthday
              + "', expirationdate = '"
              + expirationDate
              + "', picturepath = '"
              + picturePath
              + "', oneone = "
              + oneOne
              + ", quarantine = "
              + quarantine
              + ", enrolled = "
              + enrolled
              + ", hone= "
              + hone
              + " WHERE idperson = "
              + idperson
              + ";");
      System.out.println("Save complete!");
      s.close();
      conn.close();
    } else {
      System.out.println("Connection not valid");
      conn.close();
    }
  }