transaction
Class TravelAgencyImpl

java.lang.Object
  extended by transaction.TravelAgencyImpl
All Implemented Interfaces:
ITravelAgency

public class TravelAgencyImpl
extends java.lang.Object
implements ITravelAgency


Constructor Summary
TravelAgencyImpl()
           
 
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.
static void main(java.lang.String[] args)
           
 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.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TravelAgencyImpl

public TravelAgencyImpl()
Method Detail

abort

public boolean abort()
Description copied from interface: ITravelAgency
Abort the current transaction. Uses the Transaction Manager to abort the distributed transaction.

Specified by:
abort in interface ITravelAgency
Returns:
true

commit

public boolean commit()
Description copied from interface: ITravelAgency
Commit the current transaction. Uses the Transaction Manager to commit the distributed transaction.

Specified by:
commit in interface ITravelAgency
Returns:
true

reserve

public boolean reserve(ResourceType resourceType,
                       java.lang.String rid,
                       java.lang.String customerName)
Description copied from interface: ITravelAgency
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.

Specified by:
reserve in interface ITravelAgency
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

public boolean reserveItinerary(java.lang.String hotelName,
                                java.lang.String flightNumber,
                                java.lang.String agencyName,
                                java.lang.String customerName)
Description copied from interface: ITravelAgency
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.

Specified by:
reserveItinerary in interface ITravelAgency
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

queryAvailability

public int queryAvailability(ResourceType resourceType,
                             java.lang.String rid)
Description copied from interface: ITravelAgency
Query the availability of a resource.

Specified by:
queryAvailability in interface ITravelAgency
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

queryPrice

public int queryPrice(ResourceType resourceType,
                      java.lang.String rid)
Description copied from interface: ITravelAgency
Query the price of a resource.

Specified by:
queryPrice in interface ITravelAgency
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

queryBill

public int queryBill(java.lang.String customerName)
Description copied from interface: ITravelAgency
Calculate the bill for a certain customer. Queries all three RMs to sum up the bill.

Specified by:
queryBill in interface ITravelAgency
Parameters:
customerName - the unique customer name
Returns:
the sum over all costs for hotel, flight and car reservations

addResource

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

Specified by:
addResource in interface ITravelAgency
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)

newCustomer

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

Specified by:
newCustomer in interface ITravelAgency
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.)

updateResource

public boolean updateResource(ResourceType resourceType,
                              int xid,
                              java.lang.String rid,
                              int num,
                              int price)
Description copied from interface: ITravelAgency
Update the attributes (total capacity and price) of a resource.

Specified by:
updateResource in interface ITravelAgency
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)

main

public static void main(java.lang.String[] args)