public void hireEmployee(Employee hiredEmployee, Company toCompany) throws SQLException {
   Connection connection = oracleCM.getConnection();
   try {
     connection.setAutoCommit(false);
     employeeDAO.save(hiredEmployee, connection);
     Company company = companyDAO.find(toCompany.getId(), connection);
     company.getEmployees().add(hiredEmployee);
     companyDAO.update(company, connection);
     connection.commit();
   } finally {
     connection.setAutoCommit(true);
     connection.close();
   }
 }
 public void fireEmployee(Employee firedEmployee, Company fromCompany) throws SQLException {
   Connection connection = oracleCM.getConnection();
   try {
     connection.setAutoCommit(false);
     Company company = companyDAO.find(fromCompany.getId(), connection);
     company.getEmployees().remove(firedEmployee);
     companyDAO.update(company, connection);
     employeeDAO.delete(firedEmployee, connection);
     connection.commit();
   } finally {
     connection.setAutoCommit(true);
     connection.close();
   }
 }
예제 #3
0
  @Override
  public boolean createOrUpdateCompany(
      String electronicShopID,
      String clientID,
      String name,
      String contactPerson,
      String addressCity,
      String addressLine,
      String phoneNumber,
      String mail,
      String IBANNumber,
      String SWIFTCode,
      String registrationNumber,
      String VATNumber) {

    // check if we know that shop
    if (!ConfigurationProperties.getElectronicShopID().equals(electronicShopID)) {
      logger.warning("electronicShopID \"" + electronicShopID + "\" not known!");
      return false;
    }

    List<Client> cl = Client.queryGetByForeignID(clientID, 0, 1);
    List<Company> cmpnl = null;
    Client c;
    if (cl.size() == 0) {
      c = new Client();
    } else {
      c = cl.get(0);
      cmpnl = Company.queryGetAll(0, 1, c.getID());
    }

    Company cmpn;
    if ((cmpnl == null) || (cmpnl.size() == 0)) {
      cmpn = new Company();
    } else {
      cmpn = cmpnl.get(0);
    }
    try {
      c.setForeignID(clientID);
      c.setAddressCity(addressCity);
      c.setAddressLine(addressLine);
      c.setMail(mail);
      c.setPhoneNumber(phoneNumber);
      c.setIBANNumber(IBANNumber);
      c.setSWIFTCode(SWIFTCode);

      cmpn.setName(name);
      cmpn.setContactPerson(contactPerson);
      cmpn.setRegistrationNumber(registrationNumber);
      if (!"".equals(VATNumber)) {
        cmpn.setVATNumber(VATNumber);
      }
      c.setCompany(cmpn);
      c.writeToDB();

    } catch (RuntimeException e) {
      logger.log(Level.WARNING, "Can't write to DB!", e);
      return false;
    }

    return true;
  }