FileDocCategorySizeDatePackage
PetstoreBean.javaAPI DocJBoss 4.2.112806Fri Jul 13 20:55:58 BST 2007xpetstore.services.petstore.ejb

PetstoreBean

public class PetstoreBean extends Object implements Petstore
author
Herve Tchepannou
ejb.bean name="Petstore" type="Stateless" view-type="local"
ejb.transaction type="Required"
ejb.ejb-ref ejb-name="Category" view-type="local" ref-name="ejb/CategoryLocal"
ejb.ejb-ref ejb-name="Item" view-type="local" ref-name="ejb/ItemLocal"
ejb.ejb-ref ejb-name="Product" view-type="local" ref-name="ejb/ProductLocal"
ejb.ejb-ref ejb-name="Customer" view-type="local" ref-name="ejb/CustomerLocal"
ejb.ejb-ref ejb-name="Account" view-type="local" ref-name="ejb/AccountLocal"
ejb.ejb-ref ejb-name="Order" view-type="local" ref-name="ejb/OrderLocal"
ejb.resource-ref res-ref-name="${jndi.queue.ConnectionFactory}" res-type="javax.jms.QueueConnectionFactory" res-auth="Container" jndi-name="${orion.queue.ConnectionFactory}"
ejb.resource-ref res-ref-name="${jndi.queue.order}" res-type="javax.jms.Queue" res-auth="Container" jndi-name="${orion.queue.order}"
ejb.resource-ref res-ref-name="${jndi.datasource}" res-type="javax.sql.DataSource" res-auth="Container" jndi-name="${orion.datasource}"
jboss.resource-ref res-ref-name="${jndi.queue.ConnectionFactory}" jndi-name="${jboss.queue.ConnectionFactory}"
jboss.resource-ref res-ref-name="${jndi.queue.order}" jndi-name="${jboss.queue.order}"
jboss.resource-ref res-ref-name="${jndi.datasource}" jndi-name="${jboss.datasource}"
weblogic.resource-description res-ref-name="${jndi.queue.ConnectionFactory}" jndi-name="${weblogic.queue.ConnectionFactory}"
weblogic.resource-description res-ref-name="${jndi.queue.order}" jndi-name="${weblogic.queue.order}"
weblogic.resource-description res-ref-name="${jndi.datasource}" jndi-name="${weblogic.datasource}"

Fields Summary
private EntityManager
manager
Constructors Summary
Methods Summary
public booleanauthenticate(java.lang.String userId, java.lang.String password)

ejb.interface-method
ejb.transaction type="NotSupported"
ejb.transaction type="NotSupported"

       try
       {
         Account act = manager.find(Account.class, userId );
         System.out.println("!! PetstoreBean.authenticate " + act + " " + userId + " " + password);
         if (act == null)
            return false;
         return act.matchPassword( password );
       }
       catch (Exception e)
       {
          e.printStackTrace();
          return false;
       }
    
public java.lang.StringcreateCustomer(xpetstore.domain.customer.ejb.Customer customer)

ejb.interface-method

       System.out.println("!!PetstoreBean.createCustomer " + customer);
       
        /* Make sure that the customer email is unique */
         String email = customer.getEmail(  );
         List customers = null;
         try
         {
            customers = manager.createQuery("SELECT c FROM Customer c WHERE c.email = '" + email + "'").getResultList();
            
         } 
         catch (Exception e)
         {
            
         }
         
         if (customers != null && customers.size() > 0)
            throw new DuplicateEmailException( email );
      
         /* create the account */
         Account account = customer.getAccount(  );
         
         customer.setUserId(account.getUserId());

         manager.persist(account);
         
         manager.persist(customer);
         
         System.out.println("!!PetstoreBean.createCustomer userId " + customer);
         
         return customer.getUserId(  );
    
public java.lang.IntegercreateOrder(java.lang.String userId, java.util.Date orderDate, java.util.Map items)

param
userId Id of the customer
param
orderDate Creation date of the order
param
items java.lang.Map containing the items ordered. The key is the itemId, and the value a java.lang.Integer representing the quantity ordered
ejb.interface-method

        /* Make sure that the cart is not empty */
        if ( items.size(  ) == 0 )
        {
            throw new CartEmptyOrderException(  );
        }

        /* Get the customer */
        Customer cst = manager.find( Customer.class, userId );

        /* Create the order */
        Order order = new Order(  );
        order.setOrderDate( orderDate );
        order.setStatus( OrderStatus.PENDING );
        order.setStreet1( cst.getStreet1(  ) );
        order.setStreet2( cst.getStreet2(  ) );
        order.setCity( cst.getCity(  ) );
        order.setState( cst.getState(  ) );
        order.setZipcode( cst.getZipcode(  ) );
        order.setCountry( cst.getCountry(  ) );
        order.setCreditCardNumber( cst.getCreditCardNumber(  ) );
        order.setCreditCardType( cst.getCreditCardType(  ) );
        order.setCreditCardExpiryDate( cst.getCreditCardExpiryDate(  ) );

        order.setCustomer( cst );
        
        manager.persist(order);

        /* Add the items */
        Iterator keys = items.keySet(  ).iterator(  );
        while ( keys.hasNext(  ) )
        {
            String  itemId = ( String ) keys.next(  );
            Integer qty = ( Integer ) items.get( itemId );
            
            Item item = manager.find(Item.class, itemId);
            
            System.out.println("!!PetstoreBean.createOrder item " + item + " " + itemId);
            
            OrderItem orderItem = new OrderItem( qty, item.getListPrice(  ) );
            orderItem.setItem( item );
            
            manager.persist(orderItem);
            
            order.addOrderItem(orderItem);
            
            order.addOrderItem( orderItem );
        }

        /* Process the item ansynchronously */
        try
        {
            JMSUtil.sendToJMSQueue( JNDINames.QUEUE_ORDER, order.getOrderUId(  ), false );
        }
        catch ( Exception e )
        {
            throw new EJBException( e );
        }

        return order.getOrderUId(  );
    
public xpetstore.util.PagegetCategories(int start, int count)

ejb.interface-method
ejb.transaction type="NotSupported"

       return toPage( manager.createQuery("SELECT Category c FROM Category").getResultList(), start, count, Category.class );
    
public xpetstore.domain.catalog.ejb.CategorygetCategory(java.lang.String categoryId)

ejb.interface-method
ejb.transaction type="NotSupported"

        return manager.find(Category.class, categoryId );
    
public xpetstore.domain.customer.ejb.CustomergetCustomer(java.lang.String userId)

ejb.interface-method

        return manager.find( Customer.class, userId );
    
public xpetstore.util.PagegetCustomerOrders(java.lang.String userId, int start, int count)

ejb.interface-method
ejb.transaction type="NotSupported"

       List col = manager.createQuery("SELECT Order o FROM Order WHERE o.customer.userId = " + userId).getResultList();
       return toPage( col, start, count, Order.class );
    
public xpetstore.domain.catalog.ejb.ItemgetItem(java.lang.String itemId)

ejb.interface-method
ejb.transaction type="NotSupported"

        return manager.find( Item.class, itemId );
    
public xpetstore.util.PagegetItems(java.lang.String productId, int start, int count)

ejb.interface-method

         Product prod = manager.find( Product.class, productId );
         return toPage( prod.getItems(  ), start, count, Item.class );
    
public xpetstore.domain.order.ejb.OrdergetOrder(java.lang.Integer orderUId)

ejb.interface-method
ejb.transaction type="NotSupported"

        return manager.find( Order.class, orderUId );
    
public xpetstore.util.PagegetOrderItems(java.lang.Integer orderUId, int start, int count)

ejb.interface-method

        Collection col;
      
         Order order = manager.find( Order.class, orderUId );
         if (order != null)
            col = order.getOrderItems(  );
         else
            col = new ArrayList(  );
     
        return toPage( col, start, count, OrderItem.class );
    
public xpetstore.domain.catalog.ejb.ProductgetProduct(java.lang.String productId)

ejb.interface-method
ejb.transaction type="NotSupported"

        return manager.find( Product.class, productId );
    
public xpetstore.domain.catalog.ejb.ProductgetProductByItem(java.lang.String itemId)

ejb.interface-method

        Item item = manager.find( Item.class, itemId );
        return item.getProduct(  );
    
public xpetstore.util.PagegetProducts(java.lang.String categoryId, int start, int count)

ejb.interface-method

       try
       {
          System.out.println("!! PetstoreBean.getProducts manager " + manager);
         Category cat = manager.find( Category.class, categoryId );
         System.out.println("!! PetstoreBean.getProducts cat " + cat);
         if (cat != null)
            return toPage( cat.getProducts(  ), start, count, Product.class );
         else
            return Page.EMPTY_PAGE;
       }
       catch (Exception e)
       {
          e.printStackTrace();
          return null;
       }
    
public xpetstore.util.PagesearchProducts(java.lang.String key, int start, int count)

ejb.interface-method
ejb.transaction type="NotSupported"

    
       return toPage(manager.createNativeQuery("SELECT productId,name,description FROM T_PRODUCT WHERE (productId LIKE " + key + ") OR (name LIKE " + key + ") OR (description LIKE " + key + ")").getResultList(), start, count, Product.class);
    
private xpetstore.util.PagetoPage(java.util.Collection col, int start, int count, java.lang.Class type)

        int size = col.size(  );
        if ( size == 0 )
        {
            return Page.EMPTY_PAGE;
        }

        ArrayList lst = new ArrayList(  );
        Iterator  it = col.iterator(  );
        for ( int i = 0, imax = start + count; ( i < imax ) && it.hasNext(  );
              i++ )
        {
            Object obj = it.next(  );
            if ( i >= start )
            {
                lst.add( obj );
            }
        }

        return new Page( lst, start, ( start + count ) < size );
    
public voidupdateCustomer(xpetstore.domain.customer.ejb.Customer customer)

ejb.interface-method

       manager.merge(customer);