public void updateAdministrator(
     Long id, String username, String password, String name, String email)
     throws EntityDoesNotExistsException, MyConstraintViolationException {
   try {
     Administrator administrator = em.find(Administrator.class, id);
     if (administrator == null) {
       throw new EntityDoesNotExistsException("There is no administrator with that id.");
     }
     List<Administrator> administrators =
         (List<Administrator>) em.createNamedQuery("getAllAdministrators").getResultList();
     for (Administrator a : administrators) {
       if (username.equals(a.getUserName())) {
         throw new EntityAlreadyExistsException(
             "A administrator with that username already exists.");
       }
     }
     administrator.setUsername(username);
     administrator.setPassword(password);
     administrator.setName(name);
     administrator.setEmail(email);
     em.merge(administrator);
   } catch (EntityDoesNotExistsException e) {
     throw e;
   } catch (ConstraintViolationException e) {
     throw new MyConstraintViolationException(Utils.getConstraintViolationMessages(e));
   } catch (Exception e) {
     throw new EJBException(e.getMessage());
   }
 }
예제 #2
0
 public void updateManager(Long id, String username, String password, String name, String email)
     throws EntityDoesNotExistsException, MyConstraintViolationException,
         EntityAlreadyExistsException {
   try {
     Manager manager = em.find(Manager.class, id);
     if (manager == null) {
       throw new EntityDoesNotExistsException("There is no manager with that id.");
     }
     List<Manager> Managers =
         (List<Manager>) em.createNamedQuery("getAllManagers").getResultList();
     for (Manager m : Managers) {
       if (username.equals(m.getUserName()) && !m.getId().equals(manager.getId())) {
         throw new EntityAlreadyExistsException("That username already exists.");
       }
     }
     manager.setUsername(username);
     manager.setPassword(password);
     manager.setName(name);
     manager.setEmail(email);
     em.merge(manager);
   } catch (EntityDoesNotExistsException | EntityAlreadyExistsException e) {
     throw e;
   } catch (ConstraintViolationException e) {
     throw new MyConstraintViolationException(Utils.getConstraintViolationMessages(e));
   } catch (Exception e) {
     throw new EJBException(e.getMessage());
   }
 }
 public void createAdministrator(String username, String password, String name, String email)
     throws EntityAlreadyExistsException, MyConstraintViolationException {
   try {
     List<Administrator> administrators =
         (List<Administrator>) em.createNamedQuery("getAllAdministrators").getResultList();
     for (Administrator a : administrators) {
       if (username.equals(a.getUserName())) {
         throw new EntityAlreadyExistsException(
             "A administrator with that username already exists.");
       }
     }
     Administrator admin = new Administrator(username, password, name, email);
     em.persist(admin);
   } catch (EntityAlreadyExistsException e) {
     throw e;
   } catch (ConstraintViolationException e) {
     throw new MyConstraintViolationException(Utils.getConstraintViolationMessages(e));
   } catch (Exception e) {
     throw new EJBException(e.getMessage());
   }
 }