コード例 #1
0
  private void readtblfirma() {
    try {
      CSVReader reader =
          new CSVReader(
              new InputStreamReader(ConverterExecutor.class.getResourceAsStream("tblfirma.csv")));
      List<String[]> input = reader.readAll();

      for (String[] values : input) {
        String id = values[0];
        String firma = values[1];
        String brancheId = values[2];
        String size = values[3];

        Company comp = new Company();
        comp.setId(Long.parseLong(id));
        comp.setCompany(firma);
        comp.setSize(size);

        Sector sec = sectorDao.findById(Long.parseLong(brancheId));
        comp.setSector(sec);

        companyDao.persist(comp);

        companyId_company.put(comp.getId(), comp);
      }

      reader.close();
    } catch (RuntimeException e) {

    } catch (IOException ioe) {

    }
  }
コード例 #2
0
  private void readtblabteilung() {
    try {
      CSVReader reader =
          new CSVReader(
              new InputStreamReader(
                  ConverterExecutor.class.getResourceAsStream("tblabteilung.csv")));
      List<String[]> input = reader.readAll();

      Map<Long, List<Department>> comp_departments = new HashMap<>();

      for (String[] values : input) {
        String id = values[0];
        String abteilung = values[1];
        String companyId = values[2];
        String strasse = values[3];
        String hausnr = values[4];
        String zusatz = values[5];
        String plz = values[6];
        String ort = values[7];
        String land = values[8];
        String internet = values[9];

        Long companyIdLong = Long.parseLong(companyId);
        // Company comp =
        // companyDao.findById(Long.parseLong(companyId));

        Department dep = new Department();
        dep.setId(Long.parseLong(id));
        dep.setDepartment(abteilung);
        dep.setAddon(zusatz);
        dep.setCountry(land);
        dep.setInternet(internet);
        dep.setNumber(hausnr);
        dep.setPostCode(plz);
        dep.setStreet(strasse);
        dep.setTown(ort);

        departmentDao.persist(dep);

        departmentId_department.put(dep.getId(), dep);

        if (comp_departments.get(companyIdLong) == null) {
          ArrayList<Department> departments = new ArrayList<Department>();
          departments.add(dep);
          comp_departments.put(companyIdLong, departments);
        } else {
          comp_departments.get(companyIdLong).add(dep);
        }
      }

      reader.close();

      for (Long compId : comp_departments.keySet()) {
        Company company = companyDao.findById(compId);
        company.setDepartments(comp_departments.get(compId));
        companyDao.persist(company);

        for (Department dep : comp_departments.get(compId)) {
          dep.setCompany(company);
          departmentDao.persist(dep);
        }
      }
    } catch (RuntimeException e) {

    } catch (IOException ioe) {

    }
  }