Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package movieBookingSystem;
- import java.sql.Array;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- public class MovieBookingSystem {
- public enum BookingStatus {
- REQUESTED, PENDING, CONFIRMED, CHECKED_IN, CANCELED, ABANDONED
- }
- public enum SeatType {
- REGULAR, PREMIUM, ACCESSIBLE, SHIPPED, EMERGENCY_EXIT, OTHER
- }
- public enum AccountStatus {
- ACTIVE, BLOCKED, BANNED, COMPROMISED, ARCHIVED, UNKNOWN
- }
- public enum PaymentStatus {
- UNPAID, PENDING, COMPLETED, FILLED, DECLINED, CANCELLED, ABANDONED, SETTLING, SETTLED, REFUNDED
- }
- public class City {
- String name;
- String latitude;
- String longitude;
- String cityId;
- String countryName;
- String statename;
- }
- public class Address {
- String street, landmark, state, city, country, pincode;
- }
- public class Cinema {
- String cityId;
- String cinemaId;
- String name;
- Address address;
- List<CinemaHall> halls;
- }
- public class CinemaHall {
- String name;
- int totalNoOFSeat;
- List<CinemaHallSeat> seatList;
- private List<Show> shows;
- }
- public class CinemaHallSeat {
- String seatRow;
- String seatColumn;
- SeatType sType;
- }
- public class ShowSeat extends CinemaHallSeat {
- private int showSeatId;
- private boolean isReserved;
- private double price;
- }
- public class Show {
- private int showId;
- private Date createdOn;
- private Date startTime;
- private Date endTime;
- private CinemaHall playedAt;
- private Movie movie;
- }
- public class Movie {
- String name;
- String genre;
- String language;
- double duration;
- Date releaseDate;
- String description;
- String country;
- Admin addedBy;
- }
- public class Account {
- String name;
- String userName;
- String password;
- Date createdOn;
- AccountStatus status;
- String email;
- String phoneNo;
- }
- public class Admin extends Account {
- // add movies
- // delete movies
- }
- public class FrontDeskExecutive extends Account {
- // book tickets
- // cancel tickets
- }
- public class Guest extends Account {
- // register
- }
- public class Booking {
- String bokingId;
- Date bookingTime;
- BookingStatus status;
- int noOfSeats;
- List<ShowSeat> seats;
- Show show;
- Payment paymentData;
- // make payment
- // show payment
- // show details
- // cancel
- // assignSeats
- }
- public class Payment {
- double amount;
- String payId;
- Date createdDate;
- PaymentStatus staus;
- }
- // Search
- public interface Search {
- public List<Movie> searchByTitle(String title);
- public List<Movie> searchByLanguage(String language);
- public List<Movie> searchByGenre(String genre);
- public List<Movie> searchByReleaseDate(Date relDate);
- public List<Movie> searchByCity(String cityName);
- }
- public class Catalog implements Search {
- HashMap<String, List<Movie>> movieTitles;
- HashMap<String, List<Movie>> movieLanguages;
- HashMap<String, List<Movie>> movieGenres;
- HashMap<Date, List<Movie>> movieReleaseDates;
- HashMap<String, List<Movie>> movieCities;
- @Override
- public List<Movie> searchByTitle(String title) {
- // TODO Auto-generated method stub
- return movieTitles.get(title);
- }
- @Override
- public List<Movie> searchByLanguage(String language) {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public List<Movie> searchByGenre(String genre) {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public List<Movie> searchByReleaseDate(Date relDate) {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public List<Movie> searchByCity(String cityName) {
- // TODO Auto-generated method stub
- return null;
- }
- }
- // How to handle concurrency
- public class Customer extends Account {
- // login,logout
- // can search/selct moveiw
- // can book,cancel
- // apply voucher
- public boolean makeBooking(Booking bookingData) throws SQLException {
- List<ShowSeat> seats = bookingData.seats;
- Integer seatIds[] = new Integer[seats.size()];
- int index = 0;
- for (ShowSeat seat : seats) {
- seatIds[index++] = seat.showSeatId;
- }
- Connection dbConnection = null;// get DBConnection here
- dbConnection.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
- String selectSQL = "Select * From ShowSeat where ShowID=? && ShowSeatID in (?) && isReserved=0";
- PreparedStatement preparedStatement = dbConnection.prepareStatement(selectSQL);
- preparedStatement.setInt(1, bookingData.show.showId);
- Array array = dbConnection.createArrayOf("INTEGER", seatIds);
- preparedStatement.setArray(2, array);
- ResultSet rs = preparedStatement.executeQuery();
- // With TRANSACTION_SERIALIZABLE all the read rows will have the
- // write lock, so we can
- // safely assume that no one else is modifying them.
- if (rs.next()) {
- rs.last(); // move to the last row, to calculate the row count
- int rowCount = rs.getRow();
- // check if we have expected number of rows, if not, this means
- // another process is
- // trying to process at least one of the same row, if that is
- // the case we
- // should not process this booking.
- if (rowCount == seats.size()) {
- // update ShowSeat table...
- // update Booking table ...
- dbConnection.commit();
- return true;
- }
- }
- return false;
- }
- }
- }
Add Comment
Please, Sign In to add comment