public List<String> locateVendorsByPartialName(String name) { List<String> names = new ArrayList<>(); try { List vendors = em.createNamedQuery("findVendorsByPartialName") .setParameter("name", name) .getResultList(); for (Iterator iterator = vendors.iterator(); iterator.hasNext(); ) { Vendor vendor = (Vendor) iterator.next(); names.add(vendor.getName()); } } catch (Exception e) { throw new EJBException(e.getMessage()); } return names; }
public void createVendorPart( String partNumber, int revision, String description, double price, int vendorId) { try { PartKey pkey = new PartKey(); pkey.setPartNumber(partNumber); pkey.setRevision(revision); Part part = em.find(Part.class, pkey); VendorPart vendorPart = new VendorPart(description, price, part); em.persist(vendorPart); Vendor vendor = em.find(Vendor.class, vendorId); vendor.addVendorPart(vendorPart); vendorPart.setVendor(vendor); } catch (Exception e) { throw new EJBException(e.getMessage()); } }
public String reportVendorsByOrder(Integer orderId) { StringBuilder report = new StringBuilder(); try { List vendors = em.createNamedQuery("findVendorByOrder").setParameter("id", orderId).getResultList(); for (Iterator iterator = vendors.iterator(); iterator.hasNext(); ) { Vendor vendor = (Vendor) iterator.next(); report .append(vendor.getVendorId()) .append(' ') .append(vendor.getName()) .append(' ') .append(vendor.getContact()) .append('\n'); } } catch (Exception e) { throw new EJBException(e); } return report.toString(); }