Add getAvailable on Movie, Projection, Room and Slot
This commit is contained in:
parent
480d8bd62c
commit
9d7216673f
4 changed files with 84 additions and 8 deletions
|
@ -66,6 +66,20 @@ public class Movie extends Table {
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static public ArrayList<Movie> getAvailable(Competition competition) {
|
||||||
|
ArrayList<Movie> list = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
PreparedStatement ps = DB.getConnection().prepareStatement("SELECT name FROM Movie WHERE CompetitionName = ?");
|
||||||
|
ps.setString(1, competition.getName());
|
||||||
|
for (ResultSet rs = ps.executeQuery(); rs.next();)
|
||||||
|
list.add(new Movie(rs.getString("name")));
|
||||||
|
ps.close();
|
||||||
|
} catch (SQLException | NullPointerException | NotFoundInTable e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
public ArrayList<Projection> getProjections() {
|
public ArrayList<Projection> getProjections() {
|
||||||
ArrayList<Projection> list = new ArrayList<>();
|
ArrayList<Projection> list = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -18,12 +18,13 @@ public class Projection extends Table {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Projection(Date startDate, Competition competition, Room room, Movie movie) {
|
public Projection(Date startDate, Competition competition, Room room, Movie movie, Slot slot) {
|
||||||
super("Projection", "id", Map.ofEntries(
|
super("Projection", "id", Map.ofEntries(
|
||||||
Map.entry("startDate", startDate.toString()),
|
Map.entry("startDate", startDate.toString()),
|
||||||
Map.entry("CompetitionName", competition.getName()),
|
Map.entry("CompetitionName", competition.getName()),
|
||||||
Map.entry("RoomName", room.getName()),
|
Map.entry("RoomName", room.getName()),
|
||||||
Map.entry("MovieName", movie.getName())
|
Map.entry("MovieName", movie.getName()),
|
||||||
|
Map.entry("SlotId", Integer.toString(slot.getId()))
|
||||||
));
|
));
|
||||||
this.id = Integer.parseInt(super.checkValue);
|
this.id = Integer.parseInt(super.checkValue);
|
||||||
}
|
}
|
||||||
|
@ -44,6 +45,10 @@ public class Projection extends Table {
|
||||||
return get(Movie.class, "MovieName");
|
return get(Movie.class, "MovieName");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Slot getSlot() {
|
||||||
|
return get(Slot.class, "SlotId");
|
||||||
|
}
|
||||||
|
|
||||||
public boolean setStartDate(Date startDate) {
|
public boolean setStartDate(Date startDate) {
|
||||||
return set("startDate", startDate.toString());
|
return set("startDate", startDate.toString());
|
||||||
}
|
}
|
||||||
|
@ -73,6 +78,20 @@ public class Projection extends Table {
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static public ArrayList<Projection> getAvailable(Competition competition) {
|
||||||
|
ArrayList<Projection> list = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
PreparedStatement ps = DB.getConnection().prepareStatement("SELECT id FROM Projection WHERE CompetitionName = ?");
|
||||||
|
ps.setString(1, competition.getName());
|
||||||
|
for (ResultSet rs = ps.executeQuery(); rs.next();)
|
||||||
|
list.add(new Projection(rs.getInt("id")));
|
||||||
|
ps.close();
|
||||||
|
} catch (SQLException | NullPointerException | NotFoundInTable e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean delete() {
|
public boolean delete() {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -4,6 +4,7 @@ import Exceptions.AlreadyOnTable;
|
||||||
import Exceptions.NotFoundInTable;
|
import Exceptions.NotFoundInTable;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.sql.Date;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
@ -47,6 +48,22 @@ public class Room extends Table {
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static public ArrayList<Room> getAvailable(Movie movie, Slot slot, Date date) {
|
||||||
|
ArrayList<Room> list = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
PreparedStatement ps = DB.getConnection().prepareStatement("SELECT R.name FROM Room R INNER JOIN CompetitionRoom CR on R.name = CR.RoomName LEFT JOIN Projection P on R.name = P.RoomName LEFT JOIN Slot S on S.id = P.SlotId WHERE CR.CompetitionName = ? AND NOT (S.id = ? AND P.startDate = ?) OR P.id IS NULL");
|
||||||
|
ps.setString(1, movie.getCompetition().getName());
|
||||||
|
ps.setInt(2, slot.getId());
|
||||||
|
ps.setDate(3, date);
|
||||||
|
for (ResultSet rs = ps.executeQuery(); rs.next();)
|
||||||
|
list.add(new Room(rs.getString("name")));
|
||||||
|
ps.close();
|
||||||
|
} catch (SQLException | NullPointerException | NotFoundInTable e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
public ArrayList<Competition> getCompetitions() {
|
public ArrayList<Competition> getCompetitions() {
|
||||||
ArrayList<Competition> list = new ArrayList<>();
|
ArrayList<Competition> list = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -3,10 +3,7 @@ package DB;
|
||||||
import Exceptions.NotFoundInTable;
|
import Exceptions.NotFoundInTable;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.sql.Date;
|
import java.sql.*;
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -26,8 +23,8 @@ public class Slot extends Table {
|
||||||
this.id = Integer.parseInt(super.checkValue);
|
this.id = Integer.parseInt(super.checkValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getStartTime() {
|
public Time getStartTime() {
|
||||||
return get(Date.class, "startTime");
|
return get(Time.class, "startTime");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Competition getCompetition() {
|
public Competition getCompetition() {
|
||||||
|
@ -42,6 +39,20 @@ public class Slot extends Table {
|
||||||
return set("startTime", startTime.toString());
|
return set("startTime", startTime.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ArrayList<Projection> getProjections() {
|
||||||
|
ArrayList<Projection> list = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
PreparedStatement ps = DB.getConnection().prepareStatement("SELECT id FROM Projection WHERE SlotId = ?");
|
||||||
|
ps.setInt(1, id);
|
||||||
|
for (ResultSet rs = ps.executeQuery(); rs.next();)
|
||||||
|
list.add(new Projection(rs.getInt("id")));
|
||||||
|
ps.close();
|
||||||
|
} catch (SQLException | NullPointerException | NotFoundInTable e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
static public ArrayList<Slot> getAll() {
|
static public ArrayList<Slot> getAll() {
|
||||||
ArrayList<Slot> list = new ArrayList<>();
|
ArrayList<Slot> list = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
|
@ -54,4 +65,19 @@ public class Slot extends Table {
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static public ArrayList<Slot> getAvailable(Competition competition, Date date) {
|
||||||
|
ArrayList<Slot> list = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
PreparedStatement ps = DB.getConnection().prepareStatement("SELECT S.id FROM Slot S LEFT JOIN Projection P ON S.id = P.SlotId WHERE S.CompetitionName = ? AND P.startDate != ? OR P.id IS NULL");
|
||||||
|
ps.setString(1, competition.getName());
|
||||||
|
ps.setDate(2, date);
|
||||||
|
for (ResultSet rs = ps.executeQuery(); rs.next();)
|
||||||
|
list.add(new Slot(rs.getInt("id")));
|
||||||
|
ps.close();
|
||||||
|
} catch (SQLException | NullPointerException | NotFoundInTable e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue