Beispiel #1
0
        /// <param name="c">Customer</param>
        /// <param name="flights">array of flight names</param>
        /// <param name="location">room location if room is true</param>
        /// <param name="car">true if request is for a car</param>
        /// <param name="room">true if request is for a room</param>
        /// <returns>price of reservation</returns>
        public bool ReserveItinerary(TP.Customer c, string[] flights, string location, bool car, bool room)
        {
            TP.Transaction tid = TransactionManager.Start();

            try
            {
                if (car)
                {
                    Cars.Reserve(tid, c, RID.forCar(location));
                }

                if (room)
                {
                    Rooms.Reserve(tid, c, RID.forRoom(location));
                }

                foreach (string flight in flights)
                {
                    Flights.Reserve(tid, c, RID.forFlight(flight));
                }

                TransactionManager.Commit(tid);
            }
            catch (Exception e)
            {
                TransactionManager.Abort(tid);
                throw;
            }
            return(true);
        }
Beispiel #2
0
        /// <param name="c">Customer</param>
        /// <param name="flights">array of flight names</param>
        /// <param name="location">room location if room is true</param>
        /// <param name="car">true if request is for a car</param>
        /// <param name="room">true if request is for a room</param>
        /// <returns>price of reservation</returns>
        public bool ReserveItinerary(TP.Customer c, string[] flights, string location, bool car, bool room)
        {
            TP.Transaction tid = TransactionManager.Start();

            try
            {
                if (car)
                {
                    bool result = Cars.Reserve(tid, c, RID.forCar(location));
                    if (!result)
                    {
                        throw new InvalidOperationException();
                    }
                }

                if (room)
                {
                    bool result = Rooms.Reserve(tid, c, RID.forRoom(location));
                    if (!result)
                    {
                        throw new InvalidOperationException();
                    }
                }

                foreach (string flight in flights)
                {
                    bool result = Flights.Reserve(tid, c, RID.forFlight(flight));
                    if (!result)
                    {
                        throw new InvalidOperationException();
                    }
                }

                Commit(tid);
            }
            catch (AbortTransationException)
            {
                Abort(tid);
                return(false);
            }
            catch (ArgumentException)
            {
                Abort(tid);
                return(false);
            }
            catch (DeadLockDetected)
            {
                Abort(tid);
                return(false);
            }
            catch (InvalidOperationException)
            {
                Abort(tid);
                return(false);
            }
            catch (Exception e)
            {
                Abort(tid);
                throw e;
            }

            return(true);
        }
Beispiel #3
0
 public int QueryCarPrice(Transaction context, String location)
 {
     return(Cars.QueryPrice(context, RID.forCar(location)));
 }
Beispiel #4
0
 public bool DeleteCars(Transaction context, String location, int numCars)
 {
     return(Cars.Delete(context, RID.forCar(location), numCars));
 }
Beispiel #5
0
 public bool AddCars(Transaction context, String location, int numCars,
                     int price)
 {
     return(Cars.Add(context, RID.forCar(location), numCars, price));
 }