| /* |
| * Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. |
| * |
| * This program and the accompanying materials are made available under the |
| * terms of the Eclipse Public License v. 2.0, which is available at |
| * http://www.eclipse.org/legal/epl-2.0. |
| * |
| * This Source Code may also be made available under the following Secondary |
| * Licenses when the conditions for such availability set forth in the |
| * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, |
| * version 2 with the GNU Classpath Exception, which is available at |
| * https://www.gnu.org/software/classpath/license.html. |
| * |
| * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 |
| */ |
| |
| package Data; |
| |
| import jakarta.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 jakarta.ejb.SessionBean { |
| private jakarta.ejb.SessionContext context; |
| private LocalSuppliersHome suppliersHome = null; |
| private LocalPartsHome partsHome = null; |
| |
| |
| /** |
| * @see jakarta.ejb.SessionBean#setSessionContext(jakarta.ejb.SessionContext) |
| */ |
| public void setSessionContext(jakarta.ejb.SessionContext aContext) { |
| context=aContext; |
| } |
| |
| |
| /** |
| * @see jakarta.ejb.SessionBean#ejbActivate() |
| */ |
| public void ejbActivate() { |
| |
| } |
| |
| |
| /** |
| * @see jakarta.ejb.SessionBean#ejbPassivate() |
| */ |
| public void ejbPassivate() { |
| |
| } |
| |
| |
| /** |
| * @see jakarta.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()); |
| } |
| } |
| |
| } |