All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object | +----JBMSTours.serializabletypes.HotelStay
Definition of class HotelStay.
A HotelStay defines a group's stay at a particular hotel. It includes methods to calculate the price of the stay, to book the stay, and the like. In a Tour, a group has one HotelStay per city (except their home city.)
a HotelStay is stored only as part of a Tour object.
public Date arrival
public Date departure
public String cityName
public int cityId
public int numberRooms
public int numberInParty
public short level
public int gid
public int hotelId
public String hotelName
public BigDecimal fixedRate
public BigDecimal totalCost
public HotelStay()
public HotelStay(Connection conn, City acity, Group agroup, CustomerFlight arrivalFlight, CustomerFlight departureFlight) throws SQLException
A basic constructor taking the information from the passed in objects and initializing the state of the HotelStay object.
public HotelStay(Connection conn, int cid, int gid, Date arrival, Date departure) throws SQLException
A constructor taking the information from the passed in objects and initializing the state of the HotelStay object. Takes dates instead of flights as parameters.
public BigDecimal proposeHotelStay(Connection conn, BigDecimal availableFunds) throws SQLException, AvailabilityException, BudgetException
Selects all hotels which can fulfill the reservation request and then returns a hotel which is within the price range of the Group.
Results of this query are then looked at one at a time to see if they meet the price requirements of the group.
public BigDecimal proposeHotelStay(Connection conn, BigDecimal availableFunds, int bad_hotel_id) throws SQLException, AvailabilityException, BudgetException
Selects all hotels (except the one specified) that can fulfill the reservation request and then returns a hotel which is within the price range of the Group.
Results of this query are then looked at one at a time to see if they meet the price requirements of the group.
public BigDecimal proposeHotelStay(Connection conn, BigDecimal availableFunds, short templevel, int bad_hotel_id) throws SQLException, AvailabilityException, BudgetException
public BigDecimal bookHotel(Connection conn) throws SQLException
This function is responsible for actually booking the hotel stay. It updates the HotelAvailability and the HotelBookings tables and fixes the rate.
It calls the storeBookingInfoForHotel method to update the HotelBookings table.
It alters the HotelAvailability table as follows: For each day in the hotel stay, the method finds out whether there is any data for that particular hotel for that particular day. If so it updates that row. If not, it inserts a row. Using PreparedStatements is most efficient because the method must loop through multiple days. The statements get prepared only once, even though they are executed multiple times.
query to check if any rooms for this hotel have been booked on a given date:
SELECT rooms_taken FROM HotelAvailability WHERE hotel_id = ? AND booking_date = ?
If there is already a row for this hotel and date, update the "rooms_taken" column (increase it by the number of rooms in this hotelstay)
UPDATE HotelAvailability SET rooms_taken = (rooms_taken + ?) WHERE hotel_id = ? AND booking_date = ?
If there are no rows for this hotel and date, add a row showing the number of rooms taken in this hotelstay
INSERT INTO HotelAvailability (hotel_id, booking_date, rooms_taken) VALUES (?, ?, ?, ?)
public Hotel getTheHotel(Connection conn) throws SQLException
Return the hotel where the group is staying. This information may either be stored in the object or may require a database lookup. The database lookup executes the following SQL query:
SELECT Hotel from Hotels WHERE hotel_id = ?
public int storeBookingInfoForHotel(Connection conn) throws SQLException
Insert a new row into the HotelBookings table which represents this HotelStay. This is done with the following SQL statement:
INSERT INTO HotelBookings VALUES (?, ?, ?, ?, ?)
public static void makeHistoryDatabase() throws SQLException
The HotelBookings table contains the history of all bookings made. There is one row per booking made. This routine connects to the History database, * creating the database in the process, it does this by connecting to the following url:
"jdbc:cloudscape:History;create=true;autocommit=false"
Once the database is created, the HotelBookings table is created with the following SQL statement:
CREATE TABLE HotelBookings (hotel_id INT, group_id INT, arrival DATE, departure DATE, number_rooms INT, CONSTRAINT HOTELBOOKINGS_PK PRIMARY KEY (hotel_id, group_id, arrival))
public static void archiveRecords(Date theDate) throws SQLException
This method is an example of how you can connect to two different databases at once. You can execute this method as an application-side or as a server-side method.
In this example, the old bookings are selected from the HotelBookings table and inserted into the History database. The method must handle the results.
Execute the method makeHistoryDatabase() if the database doesn't exist yet. Since the actions span two connections, they exist within two separate transactions and are thus not protected by transaction control.
See archiveRecordsReadWriteVTI for an example of method in which Cloudscape handles the results (use the Cloudscape VirtualTableInterface feature). Note how much simpler that method is.
public static void archiveRecordsReadWriteVTI(Connection conn, Date theDate) throws SQLException
This method is an example of using a class that implements Cloudscape's Read-Write virtual table interface to create an ExternalVirtualTable. We select rows from HotelBookings and insert them into the external table.
public BigDecimal checkRate(Connection conn) throws SQLException
This method gets the current rate from the hotel object. If the stay is during the the "high season", this routine prints a message to "System.out" indicating the high season rate.
public BigDecimal checkTotalCost(Connection conn) throws SQLException
public int getNumberOfDays()
public String getInfo(Connection conn) throws SQLException
public String toString()
public boolean prepareStatements(Connection conn) throws SQLException
public boolean equals(Object o) throws ClassCastException
All Packages Class Hierarchy This Package Previous Next Index