Add getter and setter connected to DB
This commit is contained in:
parent
951b7ed30a
commit
2bd9311e29
10 changed files with 414 additions and 91 deletions
|
@ -1,8 +1,10 @@
|
|||
package DB;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
|
@ -24,41 +26,121 @@ import java.util.ArrayList;
|
|||
* <p>
|
||||
* The maximum number of different movies projected
|
||||
*/
|
||||
public class Competition implements Table {
|
||||
@Getter @Setter private String name;
|
||||
@Getter @Setter private int days;
|
||||
@Getter @Setter private int movies;
|
||||
@Getter @Setter private int movieMax;
|
||||
public class Competition extends Table {
|
||||
@Getter final private String name;
|
||||
|
||||
public Competition() {
|
||||
public Competition(String name) {
|
||||
this.name = name;
|
||||
tableName = "Competition";
|
||||
check = "name";
|
||||
this.checkValue = this.name;
|
||||
}
|
||||
|
||||
public Integer getDays() {
|
||||
return get(Integer.class, "days");
|
||||
}
|
||||
|
||||
public Integer getMovies() {
|
||||
return get(Integer.class, "movies");
|
||||
}
|
||||
|
||||
public Integer getMovieMax() {
|
||||
return get(Integer.class, "movieMax");
|
||||
}
|
||||
|
||||
public boolean setDays(int days) {
|
||||
return set("days", Integer.toString(days));
|
||||
}
|
||||
|
||||
public boolean setMovies(int movies) {
|
||||
return set("movies", Integer.toString(movies));
|
||||
}
|
||||
|
||||
public boolean setMovieMax(int movieMax) {
|
||||
return set("movieMax", Integer.toString(movieMax));
|
||||
}
|
||||
|
||||
static public ArrayList<Competition> getAll() {
|
||||
return null;
|
||||
}
|
||||
|
||||
static public ArrayList<Competition> getAvailable() {
|
||||
return null;
|
||||
ArrayList<Competition> list = new ArrayList<>();
|
||||
try {
|
||||
PreparedStatement ps = DB.getConnection().prepareStatement("SELECT name FROM Competition");
|
||||
for (ResultSet rs = ps.executeQuery(); rs.next();)
|
||||
list.add(new Competition(rs.getString("name")));
|
||||
ps.close();
|
||||
} catch (SQLException | NullPointerException e) {
|
||||
return null;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public ArrayList<User> getUsers() {
|
||||
return null;
|
||||
ArrayList<User> list = new ArrayList<>();
|
||||
try {
|
||||
PreparedStatement ps = DB.getConnection().prepareStatement("SELECT email FROM User WHERE CompetitionName = ?");
|
||||
ps.setString(1, name);
|
||||
for (ResultSet rs = ps.executeQuery(); rs.next();)
|
||||
list.add(new User(rs.getString("email")));
|
||||
ps.close();
|
||||
} catch (SQLException | NullPointerException e) {
|
||||
return null;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public ArrayList<Slot> getSlots() {
|
||||
return null;
|
||||
ArrayList<Slot> list = new ArrayList<>();
|
||||
try {
|
||||
PreparedStatement ps = DB.getConnection().prepareStatement("SELECT id FROM Slot WHERE CompetitionName = ?");
|
||||
ps.setString(1, name);
|
||||
for (ResultSet rs = ps.executeQuery(); rs.next();)
|
||||
list.add(new Slot(rs.getInt("idk")));
|
||||
ps.close();
|
||||
} catch (SQLException | NullPointerException e) {
|
||||
return null;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public ArrayList<Room> getRooms() {
|
||||
return null;
|
||||
ArrayList<Room> list = new ArrayList<>();
|
||||
try {
|
||||
PreparedStatement ps = DB.getConnection().prepareStatement("SELECT CompetitionName FROM CompetitionRoom WHERE CompetitionName = ?");
|
||||
ps.setString(1, name);
|
||||
for (ResultSet rs = ps.executeQuery(); rs.next();)
|
||||
list.add(new Room(rs.getString("name")));
|
||||
ps.close();
|
||||
} catch (SQLException | NullPointerException e) {
|
||||
return null;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public ArrayList<Projection> getProjections() {
|
||||
return null;
|
||||
ArrayList<Projection> list = new ArrayList<>();
|
||||
try {
|
||||
PreparedStatement ps = DB.getConnection().prepareStatement("SELECT id FROM Projection WHERE CompetitionName = ?");
|
||||
ps.setString(1, name);
|
||||
for (ResultSet rs = ps.executeQuery(); rs.next();)
|
||||
list.add(new Projection(rs.getInt("id")));
|
||||
ps.close();
|
||||
} catch (SQLException | NullPointerException e) {
|
||||
return null;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public ArrayList<Movie> getTableMovies() {
|
||||
return null;
|
||||
ArrayList<Movie> list = new ArrayList<>();
|
||||
try {
|
||||
PreparedStatement ps = DB.getConnection().prepareStatement("SELECT name FROM Movie WHERE CompetitionName = ?");
|
||||
ps.setString(1, name);
|
||||
for (ResultSet rs = ps.executeQuery(); rs.next();)
|
||||
list.add(new Movie(rs.getString("name")));
|
||||
ps.close();
|
||||
} catch (SQLException | NullPointerException e) {
|
||||
return null;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package DB;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.sql.*;
|
||||
|
@ -59,6 +60,8 @@ public class DB {
|
|||
returnValue = rs.getInt(value);
|
||||
else if (cl == Time.class)
|
||||
returnValue = rs.getTime(value);
|
||||
else if (cl == Data.class)
|
||||
returnValue = rs.getDate(value);
|
||||
else
|
||||
returnValue = rs.getObject(value);
|
||||
ps.close();
|
||||
|
|
|
@ -1,30 +1,72 @@
|
|||
package DB;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Time;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Movie implements Table {
|
||||
@Getter @Setter private String name;
|
||||
@Getter @Setter private User director;
|
||||
@Getter @Setter private Duration duration;
|
||||
@Getter @Setter private Competition competition;
|
||||
public class Movie extends Table {
|
||||
@Getter final private String name;
|
||||
|
||||
public Movie() {
|
||||
public Movie(String name) {
|
||||
this.name = name;
|
||||
tableName = "Movie";
|
||||
check = "name";
|
||||
this.checkValue = this.name;
|
||||
}
|
||||
|
||||
public String getDirector() {
|
||||
return get(String.class, "director");
|
||||
}
|
||||
|
||||
public Time getDuration() {
|
||||
return get(Time.class, "duration");
|
||||
}
|
||||
|
||||
public Competition getCompetition() {
|
||||
return new Competition(get(String.class, "CompetitionName"));
|
||||
}
|
||||
|
||||
public boolean setDirector(String director) {
|
||||
return set("director", director);
|
||||
}
|
||||
|
||||
public boolean setDuration(Time duration) {
|
||||
return set("duration", duration.toString());
|
||||
}
|
||||
|
||||
public boolean setCompetition(Competition competition) {
|
||||
return set("CompetitionName", competition.getName());
|
||||
}
|
||||
|
||||
static public ArrayList<Movie> getAll() {
|
||||
return null;
|
||||
}
|
||||
|
||||
static public ArrayList<Movie> getAvailable(Competition competition) {
|
||||
return null;
|
||||
ArrayList<Movie> list = new ArrayList<>();
|
||||
try {
|
||||
PreparedStatement ps = DB.getConnection().prepareStatement("SELECT name FROM Movie");
|
||||
for (ResultSet rs = ps.executeQuery(); rs.next();)
|
||||
list.add(new Movie(rs.getString("name")));
|
||||
ps.close();
|
||||
} catch (SQLException | NullPointerException e) {
|
||||
return null;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public ArrayList<Projection> getProjections() {
|
||||
return null;
|
||||
ArrayList<Projection> list = new ArrayList<>();
|
||||
try {
|
||||
PreparedStatement ps = DB.getConnection().prepareStatement("SELECT id FROM Projection WHERE MovieName = ?");
|
||||
ps.setString(1, name);
|
||||
for (ResultSet rs = ps.executeQuery(); rs.next();)
|
||||
list.add(new Projection(rs.getInt("id")));
|
||||
ps.close();
|
||||
} catch (SQLException | NullPointerException e) {
|
||||
return null;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,26 +1,66 @@
|
|||
package DB;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
|
||||
public class Projection implements Table {
|
||||
@Getter @Setter private Date startDate;
|
||||
@Getter @Setter private Competition competition;
|
||||
@Getter @Setter private Room room;
|
||||
@Setter @Getter private Movie movie;
|
||||
public class Projection extends Table {
|
||||
@Getter final private int id;
|
||||
|
||||
public Projection() {
|
||||
public Projection(int id) {
|
||||
this.id = id;
|
||||
tableName = "Projection";
|
||||
check = "id";
|
||||
this.checkValue = Integer.toString(this.id);
|
||||
}
|
||||
|
||||
public Date getStartDate() {
|
||||
return get(Date.class, "startDate");
|
||||
}
|
||||
|
||||
public Competition getCompetition() {
|
||||
return new Competition(get(String.class, "CompetitionName"));
|
||||
}
|
||||
|
||||
public Room getRoom() {
|
||||
return new Room(get(String.class, "RoomName"));
|
||||
}
|
||||
|
||||
public Movie getMovie() {
|
||||
return new Movie(get(String.class, "MovieName"));
|
||||
}
|
||||
|
||||
public boolean setStartDate(Date startDate) {
|
||||
return set("startDate", startDate.toString());
|
||||
}
|
||||
|
||||
public boolean setCompetition(Competition competition) {
|
||||
return set("CompetitionName", competition.getName());
|
||||
}
|
||||
|
||||
public boolean setRoom(Room room) {
|
||||
return set("RoomName", room.getName());
|
||||
}
|
||||
|
||||
public boolean setMovie(Movie movie) {
|
||||
return set("MovieName", movie.getName());
|
||||
}
|
||||
|
||||
static public ArrayList<Projection> getAll() {
|
||||
return null;
|
||||
}
|
||||
|
||||
static public ArrayList<Projection> getAvailable(Competition competition) {
|
||||
return null;
|
||||
ArrayList<Projection> list = new ArrayList<>();
|
||||
try {
|
||||
PreparedStatement ps = DB.getConnection().prepareStatement("SELECT id FROM Projection");
|
||||
for (ResultSet rs = ps.executeQuery(); rs.next();)
|
||||
list.add(new Projection(rs.getInt("id")));
|
||||
ps.close();
|
||||
} catch (SQLException | NullPointerException e) {
|
||||
return null;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,30 +1,69 @@
|
|||
package DB;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Room implements Table {
|
||||
@Getter @Setter private int places;
|
||||
public class Room extends Table {
|
||||
@Getter final private String name;
|
||||
|
||||
public Room() {
|
||||
public Room(String name) {
|
||||
this.name = name;
|
||||
tableName = "Room";
|
||||
check = "name";
|
||||
this.checkValue = this.name;
|
||||
}
|
||||
|
||||
public Integer getPlaces() {
|
||||
return get(Integer.class, "places");
|
||||
}
|
||||
|
||||
public boolean setPlaces(int places) {
|
||||
return set("places", Integer.toString(places));
|
||||
}
|
||||
|
||||
static public ArrayList<Room> getAll() {
|
||||
return null;
|
||||
}
|
||||
|
||||
static public ArrayList<Room> getAvailable(Movie movie, Slot slot) {
|
||||
return null;
|
||||
ArrayList<Room> list = new ArrayList<>();
|
||||
try {
|
||||
PreparedStatement ps = DB.getConnection().prepareStatement("SELECT name FROM Room");
|
||||
for (ResultSet rs = ps.executeQuery(); rs.next();)
|
||||
list.add(new Room(rs.getString("name")));
|
||||
ps.close();
|
||||
} catch (SQLException | NullPointerException e) {
|
||||
return null;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public ArrayList<Competition> getCompetitions() {
|
||||
return null;
|
||||
ArrayList<Competition> list = new ArrayList<>();
|
||||
try {
|
||||
PreparedStatement ps = DB.getConnection().prepareStatement("SELECT CompetitionName FROM CompetitionRoom WHERE RoomName = ?");
|
||||
ps.setString(1, name);
|
||||
for (ResultSet rs = ps.executeQuery(); rs.next();)
|
||||
list.add(new Competition(rs.getString("name")));
|
||||
ps.close();
|
||||
} catch (SQLException | NullPointerException e) {
|
||||
return null;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public ArrayList<Projection> getProjections() {
|
||||
return null;
|
||||
ArrayList<Projection> list = new ArrayList<>();
|
||||
try {
|
||||
PreparedStatement ps = DB.getConnection().prepareStatement("SELECT id FROM Projection WHERE RoomName = ?");
|
||||
ps.setString(1, name);
|
||||
for (ResultSet rs = ps.executeQuery(); rs.next();)
|
||||
list.add(new Projection(rs.getInt("id")));
|
||||
ps.close();
|
||||
} catch (SQLException | NullPointerException e) {
|
||||
return null;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,28 +1,50 @@
|
|||
package DB;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
|
||||
public class Slot implements Table {
|
||||
@Getter @Setter private Date startTime;
|
||||
@Getter @Setter private Competition competition;
|
||||
public class Slot extends Table {
|
||||
@Getter final private int id;
|
||||
|
||||
public Slot() {
|
||||
public Slot(int id) {
|
||||
this.id = id;
|
||||
tableName = "Slot";
|
||||
check = "id";
|
||||
this.checkValue = Integer.toString(this.id);
|
||||
}
|
||||
|
||||
public Date getStartTime() {
|
||||
return get(Date.class, "startTime");
|
||||
}
|
||||
|
||||
public Competition getCompetition() {
|
||||
return new Competition(get(String.class, "CompetitionName"));
|
||||
}
|
||||
|
||||
public boolean setCompetition(Competition competition) {
|
||||
return set("CompetitionName", competition.getName());
|
||||
}
|
||||
|
||||
public boolean setStartTime(Date startTime) {
|
||||
return set("startTime", startTime.toString());
|
||||
}
|
||||
|
||||
static public ArrayList<Slot> getAll() {
|
||||
return null;
|
||||
}
|
||||
|
||||
static public ArrayList<Slot> getAvailable(Movie movie) {
|
||||
return null;
|
||||
}
|
||||
|
||||
static public ArrayList<Slot> getAvailable(Competition competition) {
|
||||
return null;
|
||||
ArrayList<Slot> list = new ArrayList<>();
|
||||
try {
|
||||
PreparedStatement ps = DB.getConnection().prepareStatement("SELECT id FROM Slot");
|
||||
for (ResultSet rs = ps.executeQuery(); rs.next();)
|
||||
list.add(new Slot(rs.getInt("id")));
|
||||
ps.close();
|
||||
} catch (SQLException | NullPointerException e) {
|
||||
return null;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,7 +1,19 @@
|
|||
package DB;
|
||||
|
||||
public interface Table {
|
||||
public boolean save();
|
||||
public boolean update();
|
||||
public boolean delete();
|
||||
|
||||
public abstract class Table {
|
||||
static protected String tableName;
|
||||
static protected String check;
|
||||
protected String checkValue;
|
||||
abstract public boolean save();
|
||||
abstract public boolean update();
|
||||
abstract public boolean delete();
|
||||
|
||||
protected <T> T get(Class<T> cl, String value) {
|
||||
return DB.get(cl, tableName, value, check, checkValue);
|
||||
}
|
||||
|
||||
protected boolean set(String value, String newValue) {
|
||||
return DB.set(tableName, value, newValue, check, checkValue);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,23 +1,67 @@
|
|||
package DB;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class User implements Table {
|
||||
@Getter @Setter private String firstName;
|
||||
@Getter @Setter private String lastName;
|
||||
@Getter @Setter private String phoneNumber;
|
||||
@Getter @Setter private String email;
|
||||
@Getter @Setter private UserType type;
|
||||
@Getter @Setter private Competition competition;
|
||||
private String passwordHash;
|
||||
public class User extends Table {
|
||||
@Getter final private String email;
|
||||
|
||||
public User() {
|
||||
public User(String email) {
|
||||
this.email = email;
|
||||
tableName = "User";
|
||||
check = "email";
|
||||
this.checkValue = this.email;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
public String getFirstName() {
|
||||
return get(String.class, "firstName");
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return get(String.class, "lastName");
|
||||
}
|
||||
|
||||
public String getPhoneNumber() {
|
||||
return get(String.class, "phoneNumber");
|
||||
}
|
||||
|
||||
public UserType getType() {
|
||||
return new UserType(get(String.class, "UserTypeName"));
|
||||
}
|
||||
|
||||
public Competition getCompetition() {
|
||||
return new Competition(get(String.class, "competitionName"));
|
||||
}
|
||||
|
||||
private String getPasswordHash() {
|
||||
return get(String.class, "passwordHash");
|
||||
}
|
||||
|
||||
public boolean setFirstName(String firstName) {
|
||||
return set("firstName", firstName);
|
||||
}
|
||||
|
||||
public boolean setLastName(String lastName) {
|
||||
return set("lastName", lastName);
|
||||
}
|
||||
|
||||
public boolean setPhoneNumber(String phoneNumber) {
|
||||
return set("phoneNumber", phoneNumber);
|
||||
}
|
||||
|
||||
public boolean setType(UserType userType) {
|
||||
return set("UserTypeName", userType.getName());
|
||||
}
|
||||
|
||||
public boolean setCompetition(Competition competition) {
|
||||
return set("CompetitionName", competition.getName());
|
||||
}
|
||||
|
||||
public String checkPassword() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -26,7 +70,16 @@ public class User implements Table {
|
|||
}
|
||||
|
||||
static public ArrayList<User> getAll() {
|
||||
return null;
|
||||
ArrayList<User> list = new ArrayList<>();
|
||||
try {
|
||||
PreparedStatement ps = DB.getConnection().prepareStatement("SELECT email FROM User");
|
||||
for (ResultSet rs = ps.executeQuery(); rs.next();)
|
||||
list.add(new User(rs.getString("email")));
|
||||
ps.close();
|
||||
} catch (SQLException | NullPointerException e) {
|
||||
return null;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,22 +1,47 @@
|
|||
package DB;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class UserType implements Table {
|
||||
@Getter @Setter private String name;
|
||||
public class UserType extends Table {
|
||||
@Getter final private String name;
|
||||
|
||||
public UserType() {
|
||||
public UserType(String name) {
|
||||
this.name = name;
|
||||
tableName = "UserType";
|
||||
check = "name";
|
||||
this.checkValue = this.name;
|
||||
}
|
||||
|
||||
static public ArrayList<UserType> getAll() {
|
||||
return null;
|
||||
ArrayList<UserType> list = new ArrayList<>();
|
||||
try {
|
||||
PreparedStatement ps = DB.getConnection().prepareStatement("SELECT name FROM UserType");
|
||||
for (ResultSet rs = ps.executeQuery(); rs.next();)
|
||||
list.add(new UserType(rs.getString("name")));
|
||||
ps.close();
|
||||
} catch (SQLException | NullPointerException e) {
|
||||
return null;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public ArrayList<User> getUsers() {
|
||||
return null;
|
||||
ArrayList<User> list = new ArrayList<>();
|
||||
try {
|
||||
PreparedStatement ps = DB.getConnection().prepareStatement("SELECT email FROM User WHERE UserTypeName = ?");
|
||||
ps.setString(1, name);
|
||||
for (ResultSet rs = ps.executeQuery(); rs.next();)
|
||||
list.add(new User(rs.getString("name")));
|
||||
ps.close();
|
||||
} catch (SQLException | NullPointerException e) {
|
||||
return null;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
package ProjectionPlanning;
|
||||
|
||||
import DB.*;
|
||||
import GUI.GUI;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
new GUI();
|
||||
//new GUI();
|
||||
DB.connect();
|
||||
Competition u = new Competition("Court Métrage");
|
||||
System.out.println(Competition.getAll());
|
||||
System.out.println(u.getUsers());
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue