FileDocCategorySizeDatePackage
SalesFacadeBean.javaAPI DocExample1929Mon Nov 24 10:33:04 GMT 2003com.oreilly.patterns.chapter9

SaleFacadeBean

public class SaleFacadeBean extends Object implements SessionBean

Fields Summary
private SessionContext
context
private LocalCustomerHome
customerHome
private LocalItemHome
itemHome
private LocalSalesRecordHome
recordHome
Constructors Summary
Methods Summary
public ReceiptDTOdoSale(int[] itemNumbers, int customerId)

    
        try {
           LocalCustomer cust =     
          customerHome.findByPrimaryKey(customerId);
      
           LocalItem items[] = new LocalItem[itemNumbers.length];
		for (int i = 0; i < itemNumbers.length; i++) {
               items[i] = itemHome.findByPrimaryKey(itemNumbers[i]);
           }
  
           LocalSalesRecord record = 
           recordHome.createRecord(items, cust);
		
           return (new ReceiptDTO(record));
	    } catch(Exception ex) {
        	throw new 
           EJBException("Error processing sale: " + ex, ex);
        }
    
public voidejbActivate()

public voidejbCreate()

        try {
            InitialContext ic = new InitialContext();
            customerHome = 
               (LocalCustomerHome)
               ic.lookup("java:comp/env/ejb/local/Customer");
            itemHome = 
               (LocalItemHome)
               ic.lookup("java:comp/env/ejb/local/Item");
            recordHome = 
               (LocalSalesRecordHome)
             ic.lookup("java:comp/env/ejb/local/Record");
        } catch(Exception ex) {
            throw new EJBException(
           "Error looking up home object: " + ex, ex);
        }
    
public voidejbPassivate()

public voidejbRemove()

        customerHome = null;
        itemHome = null;
        recordHome = null;
    
public voidsetSessionContext(SessionContext aContext)

        context=aContext;