コード例 #1
0
  public JsonObject createCompanyObject(Company c) {
    JsonObject company = new JsonObject();
    company.addProperty("id", c.getId());
    company.addProperty("name", c.getName());
    company.addProperty("description", c.getDescription());
    company.addProperty("cvr", c.getCvr());
    company.addProperty("email", c.getEmail());
    company.addProperty("street", c.getAddress().getStreet());
    company.addProperty("additionalinfo", c.getAddress().getAdditionalinfo());
    company.addProperty("zipcode", c.getAddress().getCityInfo().getZip());
    company.addProperty("city", c.getAddress().getCityInfo().getCity());

    JsonArray phones = new JsonArray();
    List<Phone> phs = c.getPhones();
    for (Phone ph : phs) {
      JsonObject phone = new JsonObject();
      phone.addProperty("number", ph.getNumber());
      phone.addProperty("description", ph.getDescription());
      phones.add(phone);
    }
    company.add("phones", phones);
    company.addProperty("numemployees", c.getNumEmployees());
    company.addProperty("marketvalue", c.getMarketValue());
    return company;
  }
コード例 #2
0
ファイル: CompanyFacade.java プロジェクト: Athinodoros/ca2
 public Company updateCompany(Company comp)
 {
     EntityManager em = getEntityManager();
     try {
         Company updated = em.find(Company.class, comp.getId());
         //insert exception handling here
         updated.setName(comp.getName());
         updated.setAddress(comp.getAddress());
         updated.setCvr(comp.getCvr());
         updated.setDescription(comp.getDescription());
         updated.setMarketValue(comp.getMarketValue());
         updated.setNumOfEmployees(comp.getNumOfEmployees());
         updated.setEmail(comp.getEmail());
         updated.setPhones(comp.getPhones());
         em.getTransaction().begin();
         em.merge(updated);
         em.getTransaction().commit();
         return updated;
     } finally {
         em.close();
     }
 }