Methods Summary |
---|
public boolean | authenticate(java.lang.String userId, java.lang.String password)
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.String | createCustomer(xpetstore.domain.customer.ejb.Customer customer)
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.Integer | createOrder(java.lang.String userId, java.util.Date orderDate, java.util.Map items)
/* 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.Page | getCategories(int start, int count)
return toPage( manager.createQuery("SELECT Category c FROM Category").getResultList(), start, count, Category.class );
|
public xpetstore.domain.catalog.ejb.Category | getCategory(java.lang.String categoryId)
return manager.find(Category.class, categoryId );
|
public xpetstore.domain.customer.ejb.Customer | getCustomer(java.lang.String userId)
return manager.find( Customer.class, userId );
|
public xpetstore.util.Page | getCustomerOrders(java.lang.String userId, int start, int count)
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.Item | getItem(java.lang.String itemId)
return manager.find( Item.class, itemId );
|
public xpetstore.util.Page | getItems(java.lang.String productId, int start, int count)
Product prod = manager.find( Product.class, productId );
return toPage( prod.getItems( ), start, count, Item.class );
|
public xpetstore.domain.order.ejb.Order | getOrder(java.lang.Integer orderUId)
return manager.find( Order.class, orderUId );
|
public xpetstore.util.Page | getOrderItems(java.lang.Integer orderUId, int start, int count)
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.Product | getProduct(java.lang.String productId)
return manager.find( Product.class, productId );
|
public xpetstore.domain.catalog.ejb.Product | getProductByItem(java.lang.String itemId)
Item item = manager.find( Item.class, itemId );
return item.getProduct( );
|
public xpetstore.util.Page | getProducts(java.lang.String categoryId, int start, int count)
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.Page | searchProducts(java.lang.String key, int start, int count)
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.Page | toPage(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 void | updateCustomer(xpetstore.domain.customer.ejb.Customer customer)
manager.merge(customer);
|