001: /**
002: * Copyright (c) 2004 Red Hat, Inc. All rights reserved.
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
017: * USA
018: *
019: * Component of: Red Hat Application Server
020: *
021: * Initial Developers: Greg Lapouchnian
022: * Patrick Smith
023: *
024: */package olstore.domain.manager;
025:
026: import java.util.ArrayList;
027: import java.util.Collection;
028: import java.util.Iterator;
029:
030: import javax.ejb.EJBException;
031: import javax.ejb.FinderException;
032:
033: import olstore.dto.OrderEntry;
034: import olstore.entity.OrderLocal;
035: import olstore.entity.OrderLocalHome;
036:
037: /**
038: * A wrapper class for order actions so that there is no need to reference the
039: * beans directly, allowing us to swap out the backend beans for a different
040: * implementation.
041: */
042: public class OrderManager {
043:
044: /** The olstore bean instance that is provided via Spring. */
045: private OrderLocalHome home;
046:
047: /**
048: * Constructs a new order manager with the LocalHome bean injected by
049: * spring
050: * @param home the LocalHome interface of the Order EJB
051: */
052: public OrderManager(OrderLocalHome home) {
053: this .home = home;
054: }
055:
056: /**
057: * Updates the status of a given order.
058: * @param id the id of the order
059: * @param status the new status of the order
060: */
061: public void setStatus(Integer id, String status) {
062: try {
063: home.findByPrimaryKey(id).setStatus(status);
064: } catch (FinderException ex) {
065: throw new EJBException("Unable to find order", ex);
066: }
067: }
068:
069: /**
070: * Load orders whose status needs to be updated by the admin.
071: * @param status the status of the orders to load
072: * @return a list of OrderEntry objects for each order that can be updated
073: */
074: public ArrayList loadOrdersForUpdate() {
075: ArrayList entries = new ArrayList();
076: Collection orderLocals;
077: try {
078: orderLocals = home.findStatusWithout("Delivered");
079: } catch (FinderException e) {
080: throw new EJBException(
081: "Unable to find orders that are not 'Delivered'", e);
082: }
083: Iterator orderIterator = orderLocals.iterator();
084: while (orderIterator.hasNext()) {
085: OrderLocal orderLocal = (OrderLocal) orderIterator.next();
086: OrderEntry orderEntry = new OrderEntry(orderLocal);
087: entries.add(orderEntry);
088: }
089:
090: return entries;
091: }
092:
093: /**
094: * Load orders whose status needs to be updated by the admin.
095: * @param status the status of the orders to load
096: * @return a list of OrderEntry objects for each order that can be updated
097: */
098: public Collection findOrdersForUpdate() {
099: Collection orders;
100: try {
101: orders = home.findStatusWithout("Delivered");
102: } catch (FinderException ex) {
103: throw new EJBException("Unable to find orders for update.",
104: ex);
105: }
106: return orders;
107: }
108: }
|