All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class JBMSTours.serializabletypes.HotelStay

java.lang.Object
   |
   +----JBMSTours.serializabletypes.HotelStay

public class HotelStay
extends Object
implements Serializable
Look at the source.

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.


Variable Index

 o arrival
 o cityId
 o cityName
 o departure
 o fixedRate
 o gid
 o hotelId
 o hotelName
 o level
 o numberInParty
 o numberRooms
 o totalCost

Constructor Index

 o HotelStay()
Create a new HotelStay, initializing it with default/uset values.
 o HotelStay(Connection, City, Group, CustomerFlight, CustomerFlight)
Constructs a HotelStay group object.
 o HotelStay(Connection, int, int, Date, Date)
Constructs a HotelStay group object.

Method Index

 o archiveRecords(Date)
Move records of reservations into the History Database.
 o archiveRecordsReadWriteVTI(Connection, Date)
Move records of reservations into the History Database.
 o bookHotel(Connection)
Books the hotel stay.
 o checkRate(Connection)
Check the rate of the current hotel stay.
 o checkTotalCost(Connection)
Returns the total cost of the group's stay at the hotel.
 o equals(Object)
 o getInfo(Connection)
Gets info about a HotelStay..
 o getNumberOfDays()
Return number of days of the current Hotel Stay.
 o getTheHotel(Connection)
Return the hotel where the group is staying.
 o makeHistoryDatabase()
Create the History database and a HotelBookings table for it.
 o prepareStatements(Connection)
Prepares all the PreparedStatements for this class.
 o proposeHotelStay(Connection, BigDecimal)
Suggests a hotel stay.
 o proposeHotelStay(Connection, BigDecimal, int)
Suggests a hotel stay, given a hotel_id to avoid.
 o proposeHotelStay(Connection, BigDecimal, short, int)
Suggests a hotel stay given a hotel_id to avoid, allowing you to temporarily change level.
 o storeBookingInfoForHotel(Connection)
Store the booking information into the database.
 o toString()
Convert the object to a string.

Variables

 o arrival
 public Date arrival
 o departure
 public Date departure
 o cityName
 public String cityName
 o cityId
 public int cityId
 o numberRooms
 public int numberRooms
 o numberInParty
 public int numberInParty
 o level
 public short level
 o gid
 public int gid
 o hotelId
 public int hotelId
 o hotelName
 public String hotelName
 o fixedRate
 public BigDecimal fixedRate
 o totalCost
 public BigDecimal totalCost

Constructors

 o HotelStay
 public HotelStay()
Create a new HotelStay, initializing it with default/uset values.

 o HotelStay
 public HotelStay(Connection conn,
                  City acity,
                  Group agroup,
                  CustomerFlight arrivalFlight,
                  CustomerFlight departureFlight) throws SQLException
Constructs a HotelStay group object.

A basic constructor taking the information from the passed in objects and initializing the state of the HotelStay object.

Parameters:
acity - The city to stay in.
agroup - Description of group (size, number of rooms, ...)
arrivalFlight - The flight the group is arriving on.
departureFlight - The flight the group is departing on.
Throws: SQLException
a error occurred.
 o HotelStay
 public HotelStay(Connection conn,
                  int cid,
                  int gid,
                  Date arrival,
                  Date departure) throws SQLException
Constructs a HotelStay group object.

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.

Parameters:
conn - Connection to the database.
cid - The id of the city to stay in.
gid - Id of the group (size, number of rooms, ...)
arrival - Date the group arrives.
departure - Date the group departs.
Throws: SQLException
a error occurred.

Methods

 o proposeHotelStay
 public BigDecimal proposeHotelStay(Connection conn,
                                    BigDecimal availableFunds) throws SQLException, AvailabilityException, BudgetException
Suggests a hotel stay.

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.

Parameters:
conn - a Connection object
availableFunds - the group's available funds for the stay.
Throws: SQLException
if a SQLException occurs
Throws: BudgetException
if the hotel stay is over budget
Throws: AvailabilityException
if the hotel stay is not available.
 o proposeHotelStay
 public BigDecimal proposeHotelStay(Connection conn,
                                    BigDecimal availableFunds,
                                    int bad_hotel_id) throws SQLException, AvailabilityException, BudgetException
Suggests a hotel stay, given a hotel_id to avoid.

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.

Parameters:
conn - a Connection object
availableFunds - the group's available funds for the stay.
bad_hotel_id - the hotel id to avoid
Throws: SQLException
if a SQLException occurs
Throws: BudgetException
if the hotel stay is over budget
Throws: AvailabilityException
if the hotel stay is not available.
 o proposeHotelStay
 public BigDecimal proposeHotelStay(Connection conn,
                                    BigDecimal availableFunds,
                                    short templevel,
                                    int bad_hotel_id) throws SQLException, AvailabilityException, BudgetException
Suggests a hotel stay given a hotel_id to avoid, allowing you to temporarily change level.

Parameters:
conn - a Connection object
availableFunds - the group's available funds for the stay.
templevel - the new level
Throws: SQLException
if a SQLException occurs
Throws: BudgetException
if the hotel stay is over budget
Throws: AvailabilityException
if the hotel stay is not available.
 o bookHotel
 public BigDecimal bookHotel(Connection conn) throws SQLException
Books the hotel stay.

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 (?, ?, ?, ?)

Parameters:
conn - The current database connection.
Throws: SQLException
if a SQLException occurs
 o getTheHotel
 public Hotel getTheHotel(Connection conn) throws SQLException
Return the hotel where the group is staying.

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 = ?

Parameters:
conn - The current database connection.
Throws: SQLException
if a SQLException occurs
 o storeBookingInfoForHotel
 public int storeBookingInfoForHotel(Connection conn) throws SQLException
Store the booking information into the database.

Insert a new row into the HotelBookings table which represents this HotelStay. This is done with the following SQL statement:

INSERT INTO HotelBookings VALUES (?, ?, ?, ?, ?)

Parameters:
conn - The current database connection.
Returns:
The number of rows inserted into the HotelBookings table, 1 row indicates success, anything else is failure.
Throws: SQLException
if a SQLException occurs
 o makeHistoryDatabase
 public static void makeHistoryDatabase() throws SQLException
Create the History database and a HotelBookings table for it.

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))

Throws: SQLException
if a SQLException occurs
 o archiveRecords
 public static void archiveRecords(Date theDate) throws SQLException
Move records of reservations into the History Database.

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.

Parameters:
theDate - The date up to which to archive records.
Throws: SQLException
if a SQLException occurs
 o archiveRecordsReadWriteVTI
 public static void archiveRecordsReadWriteVTI(Connection conn,
                                               Date theDate) throws SQLException
Move records of reservations into the History Database.

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.

Parameters:
conn - A connection to the database.
theDate - The date up to which to archive records.
Throws: SQLException
if an SQLException occurs
 o checkRate
 public BigDecimal checkRate(Connection conn) throws SQLException
Check the rate of the current hotel stay. It does not fix the rate.

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.

Parameters:
conn - The current SQL connection.
Returns:
The current rate from the hotel object.
Throws: SQLException
Standard SQL exception thrown on error.
 o checkTotalCost
 public BigDecimal checkTotalCost(Connection conn) throws SQLException
Returns the total cost of the group's stay at the hotel.

Returns:
The total cost of the group's stay at the hotel.
Throws: SQLException
Standard SQL exception thrown on error.
 o getNumberOfDays
 public int getNumberOfDays()
Return number of days of the current Hotel Stay.

Returns:
The number of days of the current hotel stay.
 o getInfo
 public String getInfo(Connection conn) throws SQLException
Gets info about a HotelStay..

Returns:
String object information about the HotelStay
Throws: SQLException
Standard SQL exception thrown on error.
 o toString
 public String toString()
Convert the object to a string. Supplies the arrival and departure dates, hotel name, and city name.

Returns:
string for the group object.
Overrides:
toString in class Object
 o prepareStatements
 public boolean prepareStatements(Connection conn) throws SQLException
Prepares all the PreparedStatements for this class.

Returns:
boolean if statements are prepared without error
Throws: SQLException
If there is a SQL error
 o equals
 public boolean equals(Object o) throws ClassCastException
Returns:
boolean if the two objects are equals.
Throws: ClassCastException
if the passed-in object is not a HotelStay
Overrides:
equals in class Object

All Packages  Class Hierarchy  This Package  Previous  Next  Index