1
0
Fork 0

Add getter and setter connected to DB

This commit is contained in:
Ethanell 2020-12-17 11:01:45 +01:00
parent 951b7ed30a
commit 2bd9311e29
10 changed files with 414 additions and 91 deletions

View file

@ -1,8 +1,10 @@
package DB; package DB;
import lombok.Getter; 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.ArrayList;
/** /**
@ -24,41 +26,121 @@ import java.util.ArrayList;
* <p> * <p>
* The maximum number of different movies projected * The maximum number of different movies projected
*/ */
public class Competition implements Table { public class Competition extends Table {
@Getter @Setter private String name; @Getter final private String name;
@Getter @Setter private int days;
@Getter @Setter private int movies;
@Getter @Setter private int movieMax;
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() { static public ArrayList<Competition> getAll() {
return null; ArrayList<Competition> list = new ArrayList<>();
} try {
PreparedStatement ps = DB.getConnection().prepareStatement("SELECT name FROM Competition");
static public ArrayList<Competition> getAvailable() { for (ResultSet rs = ps.executeQuery(); rs.next();)
return null; list.add(new Competition(rs.getString("name")));
ps.close();
} catch (SQLException | NullPointerException e) {
return null;
}
return list;
} }
public ArrayList<User> getUsers() { 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() { 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() { 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() { 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() { 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 @Override

View file

@ -1,5 +1,6 @@
package DB; package DB;
import lombok.Data;
import lombok.Getter; import lombok.Getter;
import java.sql.*; import java.sql.*;
@ -59,6 +60,8 @@ public class DB {
returnValue = rs.getInt(value); returnValue = rs.getInt(value);
else if (cl == Time.class) else if (cl == Time.class)
returnValue = rs.getTime(value); returnValue = rs.getTime(value);
else if (cl == Data.class)
returnValue = rs.getDate(value);
else else
returnValue = rs.getObject(value); returnValue = rs.getObject(value);
ps.close(); ps.close();

View file

@ -1,30 +1,72 @@
package DB; package DB;
import lombok.Getter; 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; import java.util.ArrayList;
public class Movie implements Table { public class Movie extends Table {
@Getter @Setter private String name; @Getter final private String name;
@Getter @Setter private User director;
@Getter @Setter private Duration duration;
@Getter @Setter private Competition competition;
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() { static public ArrayList<Movie> getAll() {
return null; ArrayList<Movie> list = new ArrayList<>();
} try {
PreparedStatement ps = DB.getConnection().prepareStatement("SELECT name FROM Movie");
static public ArrayList<Movie> getAvailable(Competition competition) { for (ResultSet rs = ps.executeQuery(); rs.next();)
return null; list.add(new Movie(rs.getString("name")));
ps.close();
} catch (SQLException | NullPointerException e) {
return null;
}
return list;
} }
public ArrayList<Projection> getProjections() { 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 @Override

View file

@ -1,26 +1,66 @@
package DB; package DB;
import lombok.Getter; 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.ArrayList;
import java.util.Date; import java.util.Date;
public class Projection implements Table { public class Projection extends Table {
@Getter @Setter private Date startDate; @Getter final private int id;
@Getter @Setter private Competition competition;
@Getter @Setter private Room room;
@Setter @Getter private Movie movie;
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() { static public ArrayList<Projection> getAll() {
return null; ArrayList<Projection> list = new ArrayList<>();
} try {
PreparedStatement ps = DB.getConnection().prepareStatement("SELECT id FROM Projection");
static public ArrayList<Projection> getAvailable(Competition competition) { for (ResultSet rs = ps.executeQuery(); rs.next();)
return null; list.add(new Projection(rs.getInt("id")));
ps.close();
} catch (SQLException | NullPointerException e) {
return null;
}
return list;
} }
@Override @Override

View file

@ -1,30 +1,69 @@
package DB; package DB;
import lombok.Getter; 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.ArrayList;
public class Room implements Table { public class Room extends Table {
@Getter @Setter private int places; @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() { static public ArrayList<Room> getAll() {
return null; ArrayList<Room> list = new ArrayList<>();
} try {
PreparedStatement ps = DB.getConnection().prepareStatement("SELECT name FROM Room");
static public ArrayList<Room> getAvailable(Movie movie, Slot slot) { for (ResultSet rs = ps.executeQuery(); rs.next();)
return null; list.add(new Room(rs.getString("name")));
ps.close();
} catch (SQLException | NullPointerException e) {
return null;
}
return list;
} }
public ArrayList<Competition> getCompetitions() { 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() { 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 @Override

View file

@ -1,28 +1,50 @@
package DB; package DB;
import lombok.Getter; 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.ArrayList;
import java.util.Date; import java.util.Date;
public class Slot implements Table { public class Slot extends Table {
@Getter @Setter private Date startTime; @Getter final private int id;
@Getter @Setter private Competition competition;
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() { static public ArrayList<Slot> getAll() {
return null; ArrayList<Slot> list = new ArrayList<>();
} try {
PreparedStatement ps = DB.getConnection().prepareStatement("SELECT id FROM Slot");
static public ArrayList<Slot> getAvailable(Movie movie) { for (ResultSet rs = ps.executeQuery(); rs.next();)
return null; list.add(new Slot(rs.getInt("id")));
} ps.close();
} catch (SQLException | NullPointerException e) {
static public ArrayList<Slot> getAvailable(Competition competition) { return null;
return null; }
return list;
} }
@Override @Override

View file

@ -1,7 +1,19 @@
package DB; package DB;
public interface Table {
public boolean save(); public abstract class Table {
public boolean update(); static protected String tableName;
public boolean delete(); 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);
}
} }

View file

@ -1,23 +1,67 @@
package DB; package DB;
import lombok.Getter; 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.ArrayList;
public class User implements Table { public class User extends Table {
@Getter @Setter private String firstName; @Getter final private String email;
@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 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; return null;
} }
@ -26,7 +70,16 @@ public class User implements Table {
} }
static public ArrayList<User> getAll() { 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 @Override

View file

@ -1,22 +1,47 @@
package DB; package DB;
import lombok.Getter; 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.ArrayList;
public class UserType implements Table { public class UserType extends Table {
@Getter @Setter private String name; @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() { 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() { 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 @Override

View file

@ -1,9 +1,14 @@
package ProjectionPlanning; package ProjectionPlanning;
import DB.*;
import GUI.GUI; import GUI.GUI;
public class Main { public class Main {
public static void main(String[] args) { 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());
} }
} }