Esempio n. 1
0
  // Create a new flight, or add seats to existing flight
  //  NOTE: if flightPrice <= 0 and the flight already exists, it maintains its current price
  public boolean addFlight(int id, int flightNum, int flightSeats, int flightPrice)
      throws RemoteException, InvalidTransactionException, TransactionAbortedException {
    Trace.info(
        "RM::addFlight("
            + id
            + ", "
            + flightNum
            + ", $"
            + flightPrice
            + ", "
            + flightSeats
            + ") called");
    Flight curObj = (Flight) readData(id, Flight.getKey(flightNum));
    if (curObj == null) {
      // doesn't exist...add it
      Flight newObj = new Flight(flightNum, flightSeats, flightPrice);

      writeData(id, newObj.getKey(), newObj);
      String key = newObj.getKey();
      if (readDataFromLog(id, key, id) == null) {
        Flight logObj = (Flight) newObj.clone();
        logObj.setCount(-1);
        logObj.type = 0;
        writeDataToLog(id, key, logObj);
      }
      Trace.info(
          "RM::addFlight("
              + id
              + ") created new flight "
              + flightNum
              + ", seats="
              + flightSeats
              + ", price=$"
              + flightPrice);
    } else {
      // add seats to existing flight and update the price...
      Flight logObj = (Flight) curObj.clone();
      if (readDataFromLog(id, curObj.getKey(), id) == null)
        writeDataToLog(id, curObj.getKey(), logObj);

      curObj.setCount(curObj.getCount() + flightSeats);
      if (flightPrice > 0) {
        curObj.setPrice(flightPrice);
      } // if
      writeData(id, curObj.getKey(), curObj);
      Trace.info(
          "RM::addFlight("
              + id
              + ") modified existing flight "
              + flightNum
              + ", seats="
              + curObj.getCount()
              + ", price=$"
              + flightPrice);
    } // else
    return (true);
  }
Esempio n. 2
0
  // Adds flight reservation to this customer.
  public boolean reserveFlight(int id, int customerID, int flightNum) throws RemoteException {

    return reserveItem(id, customerID, Flight.getKey(flightNum), String.valueOf(flightNum));
  }
Esempio n. 3
0
 // Returns price of this flight
 public int queryFlightPrice(int id, int flightNum) throws RemoteException {
   return queryPrice(id, Flight.getKey(flightNum));
 }
Esempio n. 4
0
 public boolean deleteFlight(int id, int flightNum) throws RemoteException {
   return deleteItem(id, Flight.getKey(flightNum));
 }