// 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); }
public void abort(int transactionId) throws RemoteException, InvalidTransactionException { int indx = logContains(transactionId); Log temp; if (indx > -1) { temp = (Log) logArray.elementAt(indx); } else { System.out.println("nothing in array"); return; } for (Enumeration e = temp.getKeys(); e.hasMoreElements(); ) { System.out.println("For loop"); String key = (String) (e.nextElement()); RMItem obj = temp.get(key); if (obj.getType() == 0) { Flight flight = (Flight) obj; if (flight.getCount() == -1) { System.out.println("entering count=-1 block"); removeData(transactionId, key); } else { System.out.println("entering other block"); writeData(transactionId, key, flight); } } else if (obj.getType() == 1) { Customer cust = (Customer) obj; if (cust.getID() == -1) { System.out.println("entering remove data for customer"); removeData(transactionId, key); } else { System.out.println("entering write data for customer"); writeData(transactionId, key, obj); } } } }