I have to create for test reason tables in SQL format. They should be loaded for the test set up. And after it, Service and DAO layer should be tested.
I have stuck at creating middle for Entities.
Here is User
class:
public class User {
private Integer id;
private String name;
private Calendar birthday;
private String email;
private String role;
private Set<Ticket> bookedTickets = new HashSet<>();
It contains a Set of Tickets.
Here is Ticket
POJO:
public class Ticket {
private Integer id;
private Event event;
private Double price;
private User user;
It has User and Event instances. If Ticket isn't assigned to any User (user == null) => it is free. If is => it is purchased.
Event
and Auditorium
POJO:
public class Event {
private Integer id;
private String name;
private Double price;
private EventRating eventRating;
private Set<Calendar> eventDateTime;
public class Auditorium {
private Integer id;
private String name;
private Integer numberOfSeats;
private Set<Integer> vipSeats;
Event has Set of available dates, coz some event can be repeated during one day few times.
Getters and setters were omitted at code snippets.
Here is my create-db.sql
script:
----------------------
-- Create Users table
----------------------
CREATE TABLE Users (
user_id INTEGER PRIMARY KEY NOT NULL,
user_name VARCHAR(30) NULL,
user_birthday DATETIME NULL,
user_email VARCHAR(30) NULL,
user_role VARCHAR(20) NULL,
user_tickets VARCHAR(100) NULL, -- Here should be collection of objects
);
----------------------
-- Create Events table
----------------------
CREATE TABLE Events (
event_id INTEGER PRIMARY KEY NOT NULL,
event_name VARCHAR(30),
event_price DECIMAL(8,2),
event_rating VARCHAR(30),
event_date DATETIME,
);
---------------------------
-- Create Auditoriums table
---------------------------
CREATE TABLE Auditoriums (
aud_id INTEGER PRIMARY KEY NOT NULL,
aud_name VARCHAR(30),
aud_seats INTEGER,
aud_vip INTEGER,
);
-----------------------
-- Create Tickets table
-----------------------
CREATE TABLE Tickets (
tick_id INTEGER PRIMARY KEY NOT NULL,
event_id VARCHAR(30),
tick_price DECIMAL(8,2),
user_id INTEGER,
);
here is insert-data.sql
:
------------------------
-- Populate Users table
------------------------
INSERT INTO Users VALUES (1, 'Garry Potter', '2001-05-01', 'potter@gmail.com', 'admin', NULL);
INSERT INTO Users VALUES (2, 'Ron Weasley', '2000-05-01', 'ron@gmail.com', 'user', NULL);
INSERT INTO Users VALUES (3, 'Germiona Grendjer', '2000-05-01', 'germiona@gmail.com', 'user', NULL);
------------------------
-- Populate Events table
------------------------
INSERT INTO Events (event_id, event_name, event_price, event_rating, event_date)
VALUES (1, 'Green Mile', 60.0, 'high', '2016-02-28');
INSERT INTO Events (event_id, event_name, event_price, event_rating, event_date)
VALUES (2, 'Gone by the wind', 50.0, 'middle', '2016-02-28');
I am using Spring JDBC
for working with DB.
How to manage saving Set<Ticket>
and Set<Calendar>
with SQL script and support their unique as well?