예제 #1
0
  // Deletes customer from the database.
  public boolean deleteCustomer(int id, int customerID) throws RemoteException {
    Trace.info("RM::deleteCustomer(" + id + ", " + customerID + ") called");
    Customer cust = (Customer) readData(id, Customer.getKey(customerID));

    if (cust == null) {
      Trace.warn(
          "RM::deleteCustomer(" + id + ", " + customerID + ") failed--customer doesn't exist");
      return false;
    } else {
      Customer temp = cust.clone();
      // Increase the reserved numbers of all reservable items which the customer reserved.
      RMHashtable reservationHT = cust.getReservations();
      for (Enumeration e = reservationHT.keys(); e.hasMoreElements(); ) {
        String reservedkey = (String) (e.nextElement());
        ReservedItem reserveditem = cust.getReservedItem(reservedkey);
        Trace.info(
            "RM::deleteCustomer("
                + id
                + ", "
                + customerID
                + ") has reserved "
                + reserveditem.getKey()
                + " "
                + reserveditem.getCount()
                + " times");
        ReservableItem item = (ReservableItem) readData(id, reserveditem.getKey());
        Trace.info(
            "RM::deleteCustomer("
                + id
                + ", "
                + customerID
                + ") has reserved "
                + reserveditem.getKey()
                + "which is reserved"
                + item.getReserved()
                + " times and is still available "
                + item.getCount()
                + " times");
        Flight tempItem =
            new Flight(Integer.parseInt(item.getLocation()), item.getCount(), item.getPrice());
        tempItem.setReserved(item.getReserved());
        tempItem.setType(0);
        item.setReserved(item.getReserved() - reserveditem.getCount());
        item.setCount(item.getCount() + reserveditem.getCount());
        if (readDataFromLog(id, item.getKey(), id) == null)
          writeDataToLog(id, item.getKey(), tempItem);
      }

      // remove the customer from the storage
      temp.setType(1);
      if (readDataFromLog(id, cust.getKey(), id) == null) writeDataToLog(id, cust.getKey(), temp);
      removeData(id, cust.getKey());

      Trace.info("RM::deleteCustomer(" + id + ", " + customerID + ") succeeded");
      return true;
    } // if
  }
예제 #2
0
 // Returns data structure containing customer reservation info. Returns null if the
 //  customer doesn't exist. Returns empty RMHashtable if customer exists but has no
 //  reservations.
 public RMHashtable getCustomerReservations(int id, int customerID) throws RemoteException {
   Trace.info("RM::getCustomerReservations(" + id + ", " + customerID + ") called");
   Customer cust = (Customer) readData(id, Customer.getKey(customerID));
   if (cust == null) {
     Trace.warn(
         "RM::getCustomerReservations failed("
             + id
             + ", "
             + customerID
             + ") failed--customer doesn't exist");
     return null;
   } else {
     return cust.getReservations();
   } // if
 }
예제 #3
0
 // Return data structure containing customer reservation info.
 // Returns null if the customer doesn't exist.
 // Returns empty RMHashtable if customer exists but has no reservations.
 public RMHashtable getCustomerReservations(int id, int customerId) {
   Trace.info("RM::getCustomerReservations(" + id + ", " + customerId + ") called.");
   synchronized (syncLock) {
     Customer cust = (Customer) readData(id, Customer.getKey(customerId));
     if (cust == null) {
       Trace.info(
           "RM::getCustomerReservations("
               + id
               + ", "
               + customerId
               + ") failed: customer doesn't exist.");
       return null;
     } else {
       return cust.getReservations();
     }
   }
 }