transaction
Interface ITravelAgency

All Known Implementing Classes:
TravelAgencyImpl

public interface ITravelAgency

This interface describes the booking system of a travel agency. A travel agency uses several autonomous resource managers to book an itinerary. This interface defines an agency that can book hotels, flights and rental cars. An implementation must use a separate resource manager for each booking type. That is, one RM is responsible for hotels, one for flights and another one for rental cars. Transactions are started implicitly by calling one of the RMs. At most one transaction is active in one TravelAgency terminal. However, there may exist more than one TravelAgency terminal in parallel. Each transaction started implicitly by a travel agency terminal is always a distributed transaction. Use the transaction manager's begin() method to retrieve a unique global ID for the distributed transaction. Use the RM.beginDistributed(int globalXID) method to start an new subtransaction.

Author:
bross

Method Summary
 boolean abort()
          Abort the current transaction.
 boolean addResource(ResourceType resourceType, int xid, java.lang.String rid, int num, int price)
          Add a new resource (e.g. hotel) to the database.
 boolean commit()
          Commit the current transaction.
 boolean newCustomer(ResourceType resourceType, int xid, java.lang.String custName)
          Add a new customer to the database.
 int queryAvailability(ResourceType resourceType, java.lang.String rid)
          Query the availability of a resource.
 int queryBill(java.lang.String customerName)
          Calculate the bill for a certain customer.
 int queryPrice(ResourceType resourceType, java.lang.String rid)
          Query the price of a resource.
 boolean reserve(ResourceType resourceType, java.lang.String rid, java.lang.String customerName)
          Reserve a resource.
 boolean reserveItinerary(java.lang.String hotelName, java.lang.String flightNumber, java.lang.String agencyName, java.lang.String customerName)
          Convenience method for reserving a whole itinerary.
 boolean updateResource(ResourceType resourceType, int xid, java.lang.String rid, int num, int price)
          Update the attributes (total capacity and price) of a resource.
 

Method Detail

reserve

boolean reserve(ResourceType resourceType,
                java.lang.String rid,
                java.lang.String customerName)
Reserve a resource. Uses the RM responsible for the given type of resource to book. If the customer is not known to the RM, add a new customer. Only book the resource if it is available.

Parameters:
resourceType - the type of resource (e.g. HOTEL)
rid - the unique name of the hotel
customerName - the unique customer name
Returns:
true if successfull, false otherwise

reserveItinerary

boolean reserveItinerary(java.lang.String hotelName,
                         java.lang.String flightNumber,
                         java.lang.String agencyName,
                         java.lang.String customerName)
Convenience method for reserving a whole itinerary. Uses all three RMs to book. If the customer is not known to one of the RM, add a new customer to this RM. Only book the resources if they are available.

Parameters:
hotelName - the unique hotel name
flightNumber - the unique flight number
agencyName - the unique name of the car rental agency
customerName - the unique customer name
Returns:
true if successfull, false otherwise

queryPrice

int queryPrice(ResourceType resourceType,
               java.lang.String rid)
Query the price of a resource.

Parameters:
resourceType - the type of resource (e.g. HOTEL)
rid - the unique name of the resource
Returns:
the price of the resource or a value < 0 if resource does not exist

queryAvailability

int queryAvailability(ResourceType resourceType,
                      java.lang.String rid)
Query the availability of a resource.

Parameters:
resourceType - the type of resource (e.g. HOTEL)
rid - the unique name of the resource
Returns:
remaining capacity of the resource or value < 0 if resource does not exist

queryBill

int queryBill(java.lang.String customerName)
Calculate the bill for a certain customer. Queries all three RMs to sum up the bill.

Parameters:
customerName - the unique customer name
Returns:
the sum over all costs for hotel, flight and car reservations

newCustomer

boolean newCustomer(ResourceType resourceType,
                    int xid,
                    java.lang.String custName)
Add a new customer to the database. A customer is identified by his unique customer name (e.g. Smith)

Parameters:
resourceType - the type of resource (e.g. HOTEL)
xid - the id of the transaction requesting this operation
custName - the unique customer name
Returns:
true if the operation succeeded, false otherwise (e.g. customer already exists or name is null, etc.)

addResource

boolean addResource(ResourceType resourceType,
                    int xid,
                    java.lang.String rid,
                    int num,
                    int price)
Add a new resource (e.g. hotel) to the database. A resource is identified by a unique name (e.g. HotelA).

Parameters:
resourceType - the type of resource (e.g. HOTEL)
xid - the id of the transaction requesting this operation
rid - the unique identifier of the resource which is to be added (e.g. HotelA)
num - the total capacity of this resource
price - the price a customer needs to pay for reserving this resource
Returns:
true if the operation succeeded, false otherwise (e.g. resource already exists)

updateResource

boolean updateResource(ResourceType resourceType,
                       int xid,
                       java.lang.String rid,
                       int num,
                       int price)
Update the attributes (total capacity and price) of a resource.

Parameters:
resourceType - the type of resource (e.g. HOTEL)
xid - the id of the transaction requesting this operation
rid - the unique identifier of the resource which is to be added (e.g. HotelA)
num - a number indicating the change in total capacity, negative numbers decrease capacity, positive values increase capacity
price - the price a customer needs to pay for reserving this resource
Returns:
true if the operation succeeded, false otherwise (e.g. decrease > total capacity - reservations)

commit

boolean commit()
               throws TransactionAbortedException,
                      InvalidTransactionException
Commit the current transaction. Uses the Transaction Manager to commit the distributed transaction.

Returns:
true
Throws:
InvalidTransactionException
TransactionAbortedException

abort

boolean abort()
              throws TransactionAbortedException,
                     InvalidTransactionException
Abort the current transaction. Uses the Transaction Manager to abort the distributed transaction.

Returns:
true
Throws:
TransactionAbortedException
InvalidTransactionException