StoreAccessBean.java
资源名称:MyStore.rar [点击查看]
上传用户:hgs128
上传日期:2007-02-03
资源大小:166k
文件大小:8k
源码类别:
百货/超市行业
开发平台:
WINDOWS
- /*
- * Created on 1999-5-17
- *
- * TODO To change the template for this generated file go to Window -
- * Preferences - Java - Code Generation - Code and Comments
- */
- package stateless;
- import java.util.ArrayList;
- import java.util.Collection;
- import java.util.Iterator;
- import javax.ejb.FinderException;
- import javax.ejb.SessionBean;
- import javax.ejb.SessionContext;
- import cmp.ItemData;
- import cmp.ItemLocal;
- import cmp.ItemLocalHome;
- import cmp.ItemUtil;
- import cmp.SupplierData;
- import cmp.SupplierLocal;
- import cmp.SupplierLocalHome;
- import cmp.SupplierUtil;
- import bmp.CustomerData;
- import bmp.CustomerLocal;
- import bmp.CustomerLocalHome;
- import bmp.CustomerUtil;
- import bmp.ManagerData;
- import bmp.ManagerLocal;
- import bmp.ManagerLocalHome;
- import bmp.ManagerUtil;
- /**
- * @ejb.bean name="StoreAccess"
- * jndi-name="StoreAccessBean"
- * type="Stateless"
- *
- *--
- * This is needed for JOnAS.
- * If you are not using JOnAS you can safely remove the tags below.
- * @jonas.bean ejb-name="StoreAccess"
- * jndi-name="StoreAccessBean"
- *
- * @ejb.dao class="dao.StoreAccessDAO"
- * impl-class="dao.StoreAccessDAOImpl"
- *
- * @ejb.resource-ref res-ref-name="jdbc/OracleDS"
- * res-type="javax.sql.Datasource"
- * res-auth="Container"
- *
- * @jboss.resource-ref res-ref-name="jdbc/OracleDS"
- * jndi-name="java:/OracleDS"
- *
- * @ejb.ejb-ref ejb-name="Customer"
- * view-type="local"
- * ref-name="ejb/CustomerLocal"
- *
- * @jboss.ejb-ref-jndi
- * ref-name="CustomerLocal"
- * jndi-name="CustomerLocal"
- *
- * @ejb.ejb-ref ejb-name="Manager"
- * view-type="local"
- * ref-name="ejb/ManagerLocal"
- *
- * @jboss.ejb-ref-jndi ref-name="ManagerLocal"
- * jndi-name="ManagerLocal"
- *
- * @ejb.ejb-ref ejb-name="Item"
- * view-type="local"
- * ref-name="ejb/ItemLocal"
- *
- * @jboss.ejb-ref-jndi ref-name="ItemLocal"
- * jndi-name="ItemLocal"
- *
- * @ejb.ejb-ref ejb-name="Supplier"
- * view-type="local"
- * ref-name="ejb/SupplierLocal"
- *
- * @jboss.ejb-ref-jndi ref-name="SupplierLocal"
- * jndi-name="SupplierLocal"
- *--
- **/
- public abstract class StoreAccessBean implements SessionBean {
- protected SessionContext ctx;
- private CustomerLocalHome customerLocalHome;
- private ManagerLocalHome managerLocalHome;
- private ItemLocalHome itemLocalHome;
- private SupplierLocalHome supplierLocalHome;
- /**
- * @ejb.interface-method
- * @dao.call name="loginUser"
- **/
- public String loginUser(String username, String password) {
- return null;
- }
- public void setSessionContext(SessionContext ctx) {
- this.ctx = ctx;
- }
- public void unsetSessionContext() {
- this.ctx = null;
- }
- /**
- * The ejbCreate method
- * @ejb.create-method
- * @throws javax.ejb.CreateException
- */
- public void ejbCreate() throws javax.ejb.CreateException {
- System.out.println("Entering StoreAccessBeam.ejbCreate()");
- try {
- customerLocalHome = CustomerUtil.getLocalHome();
- managerLocalHome = ManagerUtil.getLocalHome();
- itemLocalHome = ItemUtil.getLocalHome();
- supplierLocalHome = SupplierUtil.getLocalHome();
- } catch (Exception e) {
- e.printStackTrace();
- }
- System.out.println("Leaving StoreAccessBean.ejbCreate()");
- }
- /**
- * @ejb.interface-method
- * view-type="remote"
- **/
- public CustomerData getCustomerData(String userID) {
- System.out.println("Entering StoreAccessBean.getCustomerData()");
- CustomerData cd = null;
- try {
- CustomerLocal myCustomer = customerLocalHome.findByUserID(userID);
- if (myCustomer != null) {
- cd = myCustomer.getCustomerData();
- }
- } catch (Exception e) {
- System.out
- .println("Error in StoreAccessBean.getCustomerData()" + e);
- }
- System.out.println("Leaving StoreAccessBean.getCustomerData()");
- return cd;
- }
- /**
- * @ejb.interface-method
- * view-type="remote"
- **/
- public ManagerData getManagerData(String mgrID) {
- System.out.println(" Entering StoreAccessBean.getManagerData() ");
- ManagerData md = null;
- try {
- ManagerLocal myManager = managerLocalHome.findByUserID(mgrID);
- if (myManager != null) {
- md = myManager.getManagerData();
- }
- } catch (Exception e) {
- System.out.println(" Error in StoreAccessBean.getManagerData() "
- + e);
- }
- System.out.println(" Leaving StoreAccessBean.getMangerData() ");
- return md;
- }
- /**
- * @ejb.interface-method
- * view-type="remote"
- **/
- public ItemData getItemData(String itemID) {
- ItemData myItem = null;
- System.out.println(" Entering StoreAccessBean.getItemData() ");
- try {
- ItemLocal item = itemLocalHome.findByPrimaryKey(itemID);
- if (item != null)
- myItem = item.getItemData();
- } catch (FinderException e) {
- System.out.println(" Error in StoreAccessBean.getItemData() " + e);
- }
- System.out.println(" Leaving StoreAccessBean.getItemData() ");
- return myItem;
- }
- /**
- * Returns ArrayList of Items which are out of Stock.
- * @ejb.interface-method
- * tview-type="remote"
- **/
- public java.util.ArrayList getOutOfStockItems() {
- System.out.println(" Entering StoreAccessBean.getItemsOutOfStock() ");
- Collection items = null;
- ArrayList itemsOutOfStock = new ArrayList();
- try {
- items = itemLocalHome.findByOutOfStock();
- Iterator iterate = items.iterator();
- while (iterate.hasNext()) {
- ItemLocal myItemLocal = (ItemLocal) iterate.next();
- itemsOutOfStock.add(myItemLocal.getItemData());
- }
- } catch (Exception e) {
- System.out
- .println(" Error in StoreAccessBean.getItemsOutOfStock() "
- + e);
- System.out.println(e.getMessage());
- }
- System.out.println(" Leaving StoreAccessBean.getItemsOutOfStock() ");
- return itemsOutOfStock;
- }
- /**
- * Returns ArrayList of Items supplied by a supplier
- * @ejb.interface-method
- * tview-type="remote"
- **/
- public java.util.ArrayList getItemsBySupplier(String supplierID) {
- System.out.println(" Entering StoreAccessBean.getItemsBySupplier() ");
- Collection suppliedItems = null;
- ArrayList itemsBySupplier = new ArrayList();
- try {
- suppliedItems = itemLocalHome.findBySupplierID(supplierID);
- Iterator iterate = suppliedItems.iterator();
- while (iterate.hasNext()) {
- ItemLocal myItemsLocal = (ItemLocal) iterate.next();
- itemsBySupplier.add(myItemsLocal.getItemData());
- }
- } catch (Exception e) {
- System.out
- .println(" Error in StoreAccessBean.getItemsBySupplier() "
- + e);
- }
- System.out.println(" Leaving StoreAccessBean.getItemsbySupplier() ");
- return itemsBySupplier;
- }
- /**
- * Returns object SupplierData
- * @ejb.interface-method
- * tview-type="remote"
- **/
- public SupplierData getSupplierData(String userID) {
- System.out.println(" Entering StoreAccessBean.getSupplierData() ");
- SupplierData sd = null;
- try {
- SupplierLocal mySupplier = supplierLocalHome.findUserID(userID);
- if (mySupplier != null) {
- sd = mySupplier.getSupplierData();
- }
- } catch (Exception e) {
- System.out.println(" Error in StoreAccessBean.getSupplierData() "
- + e);
- }
- System.out.println(" Leaving StoreAccessBean.getSupplierData() ");
- return sd;
- }
- /**
- * @ejb.interface-method
- * view-type="remote"
- **/
- public java.util.ArrayList getAllItems() {
- System.out.println("Entering StoreAccessBean.getAllItems()");
- Collection items=null;
- ArrayList itemsList=new ArrayList();
- try {
- items=itemLocalHome.findAll();
- Iterator iterate=items.iterator();
- while(iterate.hasNext()) {
- ItemLocal itemsLocal=(ItemLocal)iterate.next();
- itemsList.add(itemsLocal.getItemData());
- }
- } catch (FinderException e) {
- System.out.println("Error in StoreAccessBean.getAllitems()");
- }
- System.out.println("Leaving StoreAccessBean.getAllItems()");
- return itemsList;
- }
- }