package Data; import javax.ejb.*; import javax.naming.*; /** * Created Dec 16, 2002 2:08:21 PM * Code generated by the Forte For Java EJB Builder * @author mvatkina */ public class SPSessionBean implements javax.ejb.SessionBean { private javax.ejb.SessionContext context; private LocalSuppliersHome suppliersHome = null; private LocalPartsHome partsHome = null; /** * @see javax.ejb.SessionBean#setSessionContext(javax.ejb.SessionContext) */ public void setSessionContext(javax.ejb.SessionContext aContext) { context=aContext; } /** * @see javax.ejb.SessionBean#ejbActivate() */ public void ejbActivate() { } /** * @see javax.ejb.SessionBean#ejbPassivate() */ public void ejbPassivate() { } /** * @see javax.ejb.SessionBean#ejbRemove() */ public void ejbRemove() { } /** * See section 7.10.3 of the EJB 2.0 specification */ public void ejbCreate() throws CreateException { System.out.println("Debug: SPSession ejbCreate"); try { suppliersHome = lookupSuppliers(); partsHome = lookupParts(); } catch (NamingException ex) {System.out.println("lookupSuppliers"); throw new CreateException(ex.getMessage()); } } private LocalSuppliersHome lookupSuppliers() throws NamingException { System.out.println("Debug: SPSession lookupSuppliers"); Context initial = new InitialContext(); Object objref = initial.lookup("java:comp/env/ejb/SimpleSuppliers"); return (LocalSuppliersHome) objref; } private LocalPartsHome lookupParts() throws NamingException { System.out.println("Debug: SPSession lookupParts"); Context initial = new InitialContext(); Object objref = initial.lookup("java:comp/env/ejb/SimpleParts"); return (LocalPartsHome) objref; } public int checkAllParts() { System.out.println("Debug: SPSessionBean getAllParts"); java.util.Collection parts = null; try { parts = partsHome.findAll(); } catch (Exception ex) { ex.printStackTrace(); throw new EJBException(ex.getMessage()); } return parts.size(); } public int checkAllSuppliers() { System.out.println("Debug: SPSessionBean getAllSuppliers"); java.util.Collection suppliers = null; try { suppliers = suppliersHome.findAll(); } catch (Exception ex) { ex.printStackTrace(); throw new EJBException(ex.getMessage()); } return suppliers.size(); } public void createPartsAndSuppliers() { try { System.out.println("InsertData"); java.lang.Integer partid1 = new java.lang.Integer(807); java.lang.Integer partid2 = new java.lang.Integer(200); java.lang.Integer partid3 = new java.lang.Integer(145); java.lang.Integer supplierid1= new java.lang.Integer(103); java.lang.Integer supplierid2= new java.lang.Integer(145); java.lang.Integer supplierid3= new java.lang.Integer(122); partsHome.create(partid1,"partname1","red", new java.math.BigDecimal(45), new java.lang.Double(99)); partsHome.create(partid2,"partname2","blue", new java.math.BigDecimal(37), new java.lang.Double(50)); partsHome.create(partid3,"partname3","green", new java.math.BigDecimal(222), new java.lang.Double(65)); suppliersHome.create(partid1,supplierid1,"suppliername1",1,"San Jose"); suppliersHome.create(partid1,supplierid2,"suppliername2",1,"Oakland"); suppliersHome.create(partid1,supplierid3,"suppliername3",1,"Menlo Park"); suppliersHome.create(partid2,supplierid2,"suppliername2",1,"Oakland"); suppliersHome.create(partid2,supplierid3,"suppliername3",1,"Menlo Park"); suppliersHome.create(partid3,supplierid2,"suppliername2",1,"Oakland"); } catch (Exception ex) { System.err.println("Caught an exception during createPartsAndSuppliers:"); ex.printStackTrace(); } } public void removePart(java.lang.Integer partid) { System.out.println("Debug: SPSession removePart"); try { LocalParts parts = partsHome.findByPrimaryKey(partid); parts.remove(); } catch (Exception ex) { System.out.println("inside removePart exception"); ex.printStackTrace(); throw new EJBException(ex.getMessage()); } } public void removeSupplier(java.lang.Integer partid, java.lang.Integer supplierid) { System.out.println("Debug: SPSession removeSupplier"); try { SuppliersKey key = new SuppliersKey(); key.partid = partid; key.supplierid = supplierid; LocalSuppliers supplier = suppliersHome.findByPrimaryKey(key); supplier.remove(); } catch (Exception ex) { System.out.println("inside removeSupplier exception"); ex.printStackTrace(); throw new EJBException(ex.getMessage()); } } }