Вы находитесь на странице: 1из 20

CS317 Database Systems Project

AIRLINE RESERVATION SYSTEM

CS317 Database Systems Project AIRLINE RESERVATION SYSTEM Final Stage Report Group Members: Sanchit Garg (03D05005) Vipul

Final Stage Report

Group Members:

Sanchit Garg (03D05005) Vipul Shingde (03D05013) Rakesh Venkat (03D10026)

Guide: Prof. N. L. Sarda

1. Introduction

Overview

This Project aims to model the working of an on­line airway reservation system. The project has been built and tested on the Oracle database, and uses JAVA as the programming language. JDBC was used as the interface between the database and JAVA.

This Project is built to model the reservation system as closely as possible. Some features are:

Separate profiles for users, containing all their personal data.

Possibility of multiple bookings per profile.

Finding flight schedule information according to various constraints and conditions.

Handling of flight schedules across multiple stops, and multiple airports in one city.

Handling of different kinds of schemes for frequent fliers, and for flights.

Separate profile type for officials.

Appropriate error checking.

All these and other transactions and features have been described in detail in the following section.

Definitions

1. Plane type: This defines the physical type of the plane. It dictates the capacity of first, executive, business and economy seats that a flight can have.

2. Airport: An airport consists of a name, the city it is in, and its airport id.

3. Flight : A flight is identified by its flight­id. A flight denotes an unique “plane”, i.e. one which is scheduled to run at a certain time, from one place to another. A flight runs over a set of routes.

4. Route: A route is simply a tuple of airports: (StartAirport, EndAirport), and every route has a unique route id. A flight runs over a route only if it runs from the start­airport to the end­airport, possibly halting in between at other airports. A route is elementary for a flight if the flight runs non­stop from the start airport to the end airport.

5. Ticket : A ticket is uniquely identified by a ticket­id. The ticket may be a passenger ticket or a cargo ticket, and can be booked under a passenger profile or a user profile. A ticket is booked on a flight for a route that the flight is associated with. A passenger ticket contains details about the passenger, and a cargo ticket about a cargo. The

6.

Scheme : A scheme consists of discount percentages on various classes awarded on certain flights, and for certain people or round trips. Scheme ids have a type code defining what they they are valid for, and a period code showing whether they are valid as of now or no. A scheme is defined for a flight and for a particular route.

7. Official: An official is a person who can book tickets for others, and can find retrieve the complete list of passengers boarding a flight. An official works at an airport.

8. Profile: A profile denotes that a person has been verified to be genuine and can book tickets/ execute certain queries.

The above descriptions more or less define all the entities that are in the E­R diagram of the database project. Some of the important and not­so­obvious relationships are explained :

1. Flight­Route­Scheme: This is a ternary relation that says that a flight runs over a route using a particular scheme. The scheme can be null, but not the flight id and route id. The attributes in this include:

1. Fare for the flight between the two stops given by the route specified.

2. Any scheme valid on this flight, for this route

3. Number of booked seats on this flight, route.

4. A flag value indicating whether this is an elementary or complex route for this flight.

2. Flight­Route­Ticket: This ternary relation says that a ticket is booked on a certain flight over one route that the flight allows. It has only the primary keys of each entity.

3. Profile­Ticket relation: This consists of two relations: user profile related to ticket and the official profile related to ticket. This is done to keep the user and official profiles separate and independent from each other.

The Entity­Relationship diagram for the database is shown in the following page.

2. E­R Diagram

2. E­R Diagram

3. Data Dictionary

List of Tables in the Database with Constraints

1. Table Airport :

Fields

Domains

Constraints

Description

name

varchar(100)

Not null

Name of airport

city

varchar2(100)

Not null

City of airport

airportid

char(5)

Primary key

Unique Id

2. Table Flight :

 

Fields

Domains

Constraints

Description

flightid

Char(5)

Primary key

Flight ID

Status

varchar2(10)

Not null

Denotes the status of flight *

*The Status will be either Active/Passive/Cancelled according to whether the flight is yet to fly/ has flown/ has been cancelled.

3.

Table Route:

Fields

Domains

Constraints

Description

Rid

char(5)

Primary key

Id of route

Startairport

Char(5)

References airport (airportid)

Start Airport ID

Endairport

char(5)

References airport (airportid)

End Airport ID

Miles

Integer

Miles>0

Miles for this route.

Check: Startairport != endairport

4. Table Scheme:

Fields

Domains

Constraints

Description

Schemeid

char(5)

Primary key

Id of scheme

name

varChar2(100)

References airport (airportid)

Name of the Scheme

Periodcode

Number(0,1)

References airport (airportid)

*period of the scheme

Typecode

Number(0,1)

­­

*type of scheme

Description

Varchar2(1000)

­­

Description

first_discount

Number(4,2)

­­

Discounts in %

bus_discount

Number(4,2)

­­

exec_discount

Number(4,2)

­­

econ_discount

Number(4,2)

­­

* The type and period codes are subject to the following interpretation:

1.

type 0 :scheme valid for all

2.

type 2: scheme applicable only for frequent fliers

3.

period code 0: discounts applicable for any time

4.

period code 1: discounts applicable if time of booking is 1 month before flight date.

5.

period code 2: discounts applicable if time of booking is 2 months before flight date.

5.

Table Planetype:

Fields

Domains

Constraints

first_seats

Integer

­­

bus_seats

Integer

­­

exec_seats

Integer

­­

econ_seats

Integer

­­

Cargocap

Integer

­­

Typeid

Char(5)

Primary Key

Description

Seat capacities for various classes

Cargo capacity in kgs

Unique Type ID

6.

Table Ticket:

Fields

Domains

Constraints

Description

Ticketid

Char(10)

Primary key

Id of Ticket

Booking Date

Date

­­

Start Airport ID

Farepaid

Float

­­

Fare paid including discount.

Status

Varchar2(10)

­­

*Status of ticket

This table stores information about a ticket. It is a superclass of the passenger ticket and cargo ticket class, both of which inherit from this. It is a complete generalization.

*Status of the ticket may be :

1. Active: Valid ticket booking

2. Passive: The ticket has been invalidated due to a flight cancellation

3. Cancelled : The ticket has been cancelled by the user.

 

7.

Table cargoticket :

 

Fields

Domains

Constraints

Description

Owner

Varchar2(60)

­­

Stores name of owner

weight

Number(4,3)

­­

Stores weight of cargo

Commodity

Varchar(100)

­­

Details of commodity being shipped.

Ticketid

Char(10)

Primary Key

Unique ticketid.

Note: The fare for a cargo ticket is calculated as being proportional to the weight of the cargo. The proportionality factor depends on the flight and the route.

8.

Table passengerticket:

Fields

Domains

Constraints

Description

Ticketid

char(10)

Primary key ;

Ticket ID

Fields

Domains

Constraints

References ticket

name

varchar2(100)

Not null

age

integer

­­

sex

char(1)

Sex in (‘M’, ‘F’)

passportid

char(7)

­­

Address

Varchar2(160)

­­

Schemeid

char(2)

References scheme

class

char(3)

class in ('Bus','Exe','Fir','Eco')

Description

Personal Details of Passenger

ID of scheme under which ticket was booked

Class of ticket.

Check : (class in ('Bus','Exe','Fir','Eco')),

This table stores all ticket specific data, and the passenger details. The ticket ID is what relates it to the ticket table.

9. Table profile_official :

Fields

Domains

Constraints

username

varchar2(20)

primary key

password

varchar2(20)

­­

name

varchar2(100)

­­

Address

varchar2(160)

­­

age

integer

­­

Sex

char(1)

­­

emailid

varchar2(100)

­­

Nationality

varchar2(30)

­­

Description

Username for the official

Password for profile

Official’s personal details.

This contains all the information about an official. It is kept separate for independence from user profiles, and different requirements as regard to information storage for the users and officials.

10.

Table profile_user :

Fields

Domains

Constraints

username

varchar2(20)

primary key

password

varchar2(20)

­­

miles_flown

integer

(miles_flown >= 0)

miles_granted

integer

(miles_granted >=0)

Passportid

Char(10)

­­

name

varchar2(100)

­­

Address

varchar2(160)

­­

age

integer

­­

Sex

char(1)

sex in ('M','F'))

emailid

varchar2(100)

­­

Nationality

varchar2(30)

­­

Description

Username for the user

Password for profile

*Miles flown by user

**Miles granted to the user

Official’s personal details.

*Miles Flown denotes the miles flown by the user. It is incremented everytime the user books one or more tickets through his/her profile. ** Miles granted is the number of miles that are granted to the user as desired by an appropriate official. This functionality has not yet been implemented in the project, but has been kept with a view towards extending the functionality of the application later.

11. Table flight_type:

Fields

Domains

Constraints

Description

flightid

char(5),

foreign key (flightid) references flight

The Flight ID

typeid

char(5)

foreign key (typeid) references planetype

The Type ID

primary key(flightid,typeid)

This table stores the relation between flight and the planetype.

12.

Table flight_route_scheme:

Fields

Domains

Constraints

Description

flightid

char(5)

foreign key (flightid) references flight

Flight id

rid

char(5)

foreign key (rid) references route

Route ID

schemeid

char(2)

foreign key (schemeid) references scheme

SchemeID

flag

number(1,0)

flag in ( 0 ,1)

*Stores whether the route is elementary or not for this flight.

first fare_seat

**fare_seat

­­

Stores fares and seats

bus fare_seat

­­

booked for various

exec fare_seat

­­

classes.

econ fare_seat,

­­

start_time

timestamp

­­

end_time

timestamp

­­

primary key(flightid,rid,schemeid)

As explained in the definitions section, this table stores the relationship between flight­route­ scheme. This allows a lot of flexibility in defining the schemes. *The route is elementary if flag=1, else not. **type fare_seat is defined as:

create type fare_seat as object( fare number(7,2), seats integer);

13. Table flight_route_ticket :

flightid

Fields

Domains

char(5)

Constraints

foreign key (flightid) references flight

Description

Flight id

Fields

Domains

Constraints

Description

rid

char(5)

foreign key (rid) references route

Route ID

ticketid

char(2)

foreign key (ticketid) references scheme

SchemeID

Primary key(flightid, ticketid, rid)

As explained earlier, this stores the relation between flight, route and ticket. A ticket is booked over a certain flight and a certain route.

14. Table official_airport:

Fields

Domains

Constraints

Description

username

varchar2(20),

foreign key (username) references profile_official

Official userid

airportid

char(5)

foreign key (airportid) references airport

Airport at which official works

14. Table official_ticket:

Fields

Domains

Constraints

Description

username

varchar2(20),

foreign key (username) references profile_official

Flight id

airportid

char(5)

foreign key (airportid) references airport

Airport at which official works

15. Table user_ticket:

Fields

Domains

Constraints

Description

ticketid

char(10)

foreign key (ticketid) references ticket

Ticket ID

username

varchar2(20)

foreign key (username) references profile_user

Username of profile under which booked.

3. Data Flow in the project

The data flow within the database components is explained below through some examples.

The main entities in the model are: Flight, Route, Ticket and Scheme.

1. An example of data flow between these entities is as soon as a user makes a query for flights

running between two cities on a certain date.

The Route table is scanned in conjunction with the airport tables to get a listing of all the airports in the start and end cities (note that there can be multiple airports in a city).

The flight­route­scheme relationship is checked for appropriate dates.

Data about flight seat availability is retrieved by a loop in the JAVA program. This is done to take into account multiple stops.

Roundtrip requests are correctly managed to match start and end points. Steps above are repeated to get data regarding the return flight.

Finally the results found are filtered/sorted according to the advanced query and displayed in proper format.

2. The other major part of the model is the interrelation between profiles and ticket bookings.

Data flow occurs between the profiles, passenger­tickets and the flight­and route entities

through the flight­ route­ticket relation.

An example of the data flow is as follows:

A person logged in wants to retrieve info about all tickets booked by him:

The booking profile is scanned to find the list of all ticket ids.

The ticket ids are used to find the flightids and routeids through the flight­route­scheme relation.

The route id is then used to scan the route table and get the start and end airport ids.

This is used to scan the airport tables to find the cities.

The times of arrival/departure are found from the flight­route­scheme table.

3. Another important part of the project was to ensure consistent booking across multiple stops.

Suppose we need to query for seat availability in a flight which runs from A­>B­>C­>D­>E , for the route A­>E. Then the number of seats available is the min. number of seats among all the

elementary routes that the flight takes in it’s path from A to E. All changes to the ‘seats remaining’ are done only for the elementary routes. Here,

seats(A,E)=min(seats(A,B), seats(B,C), seats(C,D), seats(D,E)).

This means that on booking a ticket from A­>E, each of these routes’ booked seats must be increased by 1.

The main objects used are : User and QueryResult. The class user stores information about the currently logged in user. The class queryresult has information about a successful query to the flight schedule. This is later used in booking tickets.

4. Transactions and sample queries:

Some of the functionalities are:

Any person can query for flight scheduled according to specified conditions.

A Person can book/cancel a ticket only after he logs in.

A user can sign up for a profile if he doesnt have one already.

On logging in, the user has options to

1. Book tickets

2. Edit Profile information

3. Cancellation of tickets

4. View all current tickets booked by him

5. Logout

A person can get all information regarding a ticket if he keys in the ticketID.

A person can get all information about a flight if he keys in the flightID.

A person can get the schedule of all flights running for the next 20 days.

The above transactions in general involve a sequence of queries to the database. Some of these queries are as follows:

Sample Queries:

1.

Get all cities

select distinct city

from airport

where (airportid in (select startairport from route)) or airportid in ((select endairport from route));

2. Get flight data on a particular date:

with ridtable as

(select rid

from route

where (route.startairport in (select airportid

from airport

where city="CITYNAME") and route.endairport in (select airportid from airport where city="CITYNAME2")))

select flightid, rid, start_time, end_time, (bus).seats, (exec).seats, (econ).seats, (first).seats

from flight_route_scheme, flight

where (flight.flightid = flight_route_scheme.flightid ) and (flight.status="Active") and (rid in ridtable) and (YEAR=extract(year from start_time)) and (MONTH=extract(month from start_time) and DAY=extract(day from start_time)) ;

3. For morning flights:

Replace the select clause in query 2 by:

select flightid, rid, start_time, end_time, (bus).seats, (exec).seats, (econ).seats, (first).seats

from flight_route_scheme, flight

where (flight.flightid = flight_route_scheme.flightid ) and (flight.status="Active") and (rid in ridtable) and TRUNC(start_time)=DATE and (cast(start_time as time))>'05:00:00 AM' and (cast(start_time as time))<'04:00:00 PM';

For AM/PM flights, we modify the last part of the where clause appropriately

4.

Ordering the flights in the above queries:

Add the clause : order by(cast(start_time as time)) desc; to the above query to order the flights in order of departure times.

5. To get all info about a ticket from the ticket id:

select username, name, age, sex, booking_date, status, schemeid, rid, flightid, class

from flight_route_ticket natural inner join user_ticket natural inner join passengerticket natural inner join ticket

where ticketid='0000000001';

6. Get city and airport names of start and destination from the airport id:

select S.city, T.city , S.name, T.name

from (airport) S, (airport) T

where (S.airportid in(select startairport from route where rid='R0001')) and (T.airportid in (select endairport from route where

rid='R0001'));

7. Get city and airport names of start and destination from the route id

select S.city, T.city , S.name, T.name

from (airport) S, (airport) T

where (S.airportid in(select startairport from route where rid='R0001')) and (T.airportid in (select endairport from route where

rid='R0001'));

8. Get all tickets booked by a user profile:

select username, name, age, sex, booking_date, status, schemeid, rid, flightid

from flight_route_ticket natural inner join user_ticket natural inner join passengerticket natural inner join ticket

where user_ticket.username= 'san';

9.

Get all information about a flight from the flightid:

select flightid, cast(start_time as date) as A, startairport, cast(end_time as date) as B, endairport , S.city, T.city

from (flight_route_scheme) F ,route,(airport) S, (airport) T

where flightid='I0004' and F.rid=route.rid and startairport=S.airportid and endairport=T.airportid;

Below is a snippet of JAVA code used to book the flight tickets:

rs = jdbc.execute("select max(ticketid)+1 from ticket");

String ticketgenid="0000000000";

if(rs.next()){

String temp=Integer.toString(rs.getInt(1));

ticketgenid=ticketgenid+temp;

ticketgenid=ticketgenid.substring(ticketgenid.length()­10);

}

else{

ticketgenid="0000000000";

}

rs = jdbc.execute("select route.rid,("+queryobject.getStartClass()+").fare from flight_route_scheme,route,(airport)S,(airport)T where T.airportid=route.startairport and S.airportid=route.endairport and T.city='"+queryobject.getFromPlace()+"' and S.city='"+queryobject.getToPlace()+"' and route.rid=flight_route_scheme.rid and flightid='"+queryobject.getStartFlight()+"'");

String routerid="";

int fare_paid=0;

gotoPage("/index.jsp",request,response);

if(rs.next()){

//

routerid=rs.getString(1);

//

fare_paid = rs.getInt(2);

}

else{

String error="Sorry No such flight available";

session.setAttribute("errormessage",error);

gotoPage("/error.jsp",request,response);

}

String qinsert=" ";

/*

jdbc.executeUpdate("insert into ticket values('"+ticketgenid +"',trunc(current_date),'"+fare_paid+"')");

jdbc.executeUpdate("insert into passengerticket values('"+ticketgenid +"','"+name+"','"+age+"','"+sex+"','" +passportid+"','"+address+"','"+schemeid+"','"+queryobject.getStartClass() +"',trunc(current_date),'"+fare_paid+"')");

jdbc.executeUpdate("insert into user_ticket values('"+ticketgenid +"','"+userobject.getusername()+"')");

jdbc.executeUpdate("insert into flight_route_ticket values('"+queryobject.getStartFlight() +"','"+ "','"+routerid+"','" +ticketgenid +"')");

String from_place=queryobject.getToPlace();

String temp_place="";

while(!(queryobject.getFromPlace()).equals(from_place)){

String inquery="select T.city,("+queryobject.getStartClass()+").seats from flight_route_scheme,route,(airport) S,(airport) T where flight_route_scheme.flightid='"+queryobject.getStartFlight()+"' and flight_route_scheme.rid=route.rid and route.startairport=S.airportid and flight_route_scheme.flag=1 and S.city='"+from_place+"' and route.endairport=T.airportid" ;

rs = jdbc.execute(inquery);

if(rs.next()){

temp_place=rs.getString(1);

}

else{

String error="Sorry No such flight available";

session.setAttribute("errormessage",error);

gotoPage("/error.jsp",request,response);

}

rs = jdbc.execute("select route.rid,("+queryobject.getStartClass()+").fare from

flight_route_scheme,route,(airport)S,(airport)T where T.airportid=route.startairport and S.airportid=route.endairport and T.city='"+from_place+"' and S.city='"+temp_place+"' and route.rid=flight_route_scheme.rid and flightid='"+queryobject.getStartFlight()+"'");

String temprouteid="";

if(rs.next()){

temprouteid=rs.getString(1);

}

else{

String error1="Sorry No such flight available";

session.setAttribute("errormessage",error1);

gotoPage("/error.jsp",request,response);

}

jdbc.executeUpdate("update flight_route_scheme set ("+queryobject.getStartClass()+").seats =("+queryobject.getStartClass()+").seats+1 where flightid='"+queryobject.getStartFlight()+"' and rid='"+temprouteid +"'" );

}

if(returntrip=="yes"){

}

//

jdbc.executeUpdate(qinsert);

*/

//

}

jdbc.commitset(2);

jdbc.commitset(1);

//­­­­­­­­­end of JAVA CODE­­­­­­­­­­­­­­­­­­­­­­­­­­­

Session Management:

We have used session management to keep track of user profile, and when a user logs in/logs

out.

A new session is created when the page is accessed first. Within a session, information is stored about user (if any) logged in, and results of the query

that he/she executes in order to book or cancel tickets.

A session is invalidated when a user logs out, or when there are multiple logins on the same

account.

Storing the timetable for flights:

The date, time values are stored and compared using timestamp and date types in SQL. Extensive use is made of casting in order to obtain the appropriate values in the correct format from the queries.

Error Handling:

Appropriate error handling has been done in the project. All errors are routed to the pages which process the error according to some session attribute, and display appropriate messages. The following errors are detected and error messages are displayed:

Whenever a user tries to book a ticket/ cancel a ticket, he is asked to login if he hasnt already done so, and is redirected to the main page.

If a user tries to login using a wrong password, the system asks him/her to relogin.

On querying for a flight schedule, we check that if the round trip option is selected then the date

of the return journey must be after the date of the first trip.

Due to session management, a user cannot ‘copy paste’ the link(URL) of an old session and try

to run it again.

If fields like the flightid while booking are left unspecified then the system indicates error and

asks the user to correct it.

Booking transactions are carried out as atomic transactions.

5. External Interface Requirements

User Interfaces:

The web is used as an interface with the users.

Hardware Interfaces:

No special hardware is required for this product.

Software Interfaces:

1.

Java

2.

JDBC

3.

Apache Tomcat servlets

4.

Oracle 8i SQL server

7. Other Notes

We believe that this ER model is quite versatile and can handle situations much resembling real­life ones. The project can be extended to include many more features and functionalities. Due to lack of time, we couldn’t do it within the time­frame allotted for this project.

8. Acknowlegement

We would like to express our heartfelt gratitude towards our able guide, Professor N.L.Sarda, who was ever­willing to offer constructive suggestions, and help us out whenever we got stuck. We would also like to thank the friendly TA’s for the course who conducted the lab sessions.