/** Find services based on their address */ @WebMethod(operationName = "findServiceByAddress") public List<org.hyperpath.persistence.entities.Services> findServiceByAddress( @WebParam(name = "address") Address address) throws Exception, NonexistentEntityException { try { if (address.getId() == null) throw new Exception("Address id must be initialiazed before using search"); EntityManager em = emf.createEntityManager(); Query qr = em.createNamedQuery("Address.findServiceByAddress"); qr.setParameter("addressId", address.getId()); List<Services> rs = qr.getResultList(); if (rs.isEmpty()) throw new NonexistentEntityException("There is no service in this address"); return rs; } catch (Exception e) { throw e; } }
/** Find clients based on their address */ @WebMethod(operationName = "findClientByAddress") public List<Clients> findClientByAddress(@WebParam(name = "address") Address address) throws Exception, NonexistentEntityException { try { if (address.getId() == null) { throw new Exception("Address id must be initialiazed before using search"); } EntityManager em = emf.createEntityManager(); Query qr = em.createNamedQuery("Address.findClientByAddress"); qr.setParameter("clientId", address.getId()); List<Clients> result = qr.getResultList(); if (result.isEmpty()) { throw new NonexistentEntityException("There is no client living at this address"); } return result; } catch (Exception e) { throw e; } }
/** Update existing address */ @WebMethod(operationName = "updateAddress") public void updateAddress(@WebParam(name = "address") Address address) throws Exception, RollbackFailureException, PreexistingEntityException { AddressJpaController controller = new AddressJpaController(utx, emf); try { if (address.getId() != null) { controller.edit(address); } else { throw new Exception("To update address the id field must be specified"); } } catch (Exception e) { throw e; } }
/** Delete an existing address */ @WebMethod(operationName = "deleteAddress") public void deleteAddress(@WebParam(name = "address") Address address) throws Exception, RollbackFailureException, NonexistentEntityException { AddressJpaController controller = new AddressJpaController(utx, emf); try { Integer id; if ((id = address.getId()) != null || controller.findAddress(address) != null) { controller.destroy(id); } else { throw new Exception( "To delete address the id field must be specified or the address must match one in the database"); } } catch (Exception e) { throw e; } }