Make chapter or puzzle optional for group
This commit is contained in:
parent
eac490f040
commit
7dee5b60f9
3 changed files with 14 additions and 10 deletions
|
@ -11,13 +11,15 @@ import org.json.simple.JSONObject;
|
|||
|
||||
public class Group implements Comparable<Group> {
|
||||
private String name;
|
||||
private int linkToChapter;
|
||||
private int linkToPuzzle;
|
||||
private Integer linkToChapter;
|
||||
private Integer linkToPuzzle;
|
||||
private List<Player> players;
|
||||
|
||||
public Group(JSONObject json) {
|
||||
this.name = (String) json.get("name");
|
||||
if (json.containsKey("chapter"))
|
||||
this.linkToChapter = ((Number) json.get("chapter")).intValue();
|
||||
if (json.containsKey("puzzle"))
|
||||
this.linkToPuzzle = ((Number) json.get("puzzle")).intValue();
|
||||
}
|
||||
|
||||
|
@ -67,11 +69,11 @@ public class Group implements Comparable<Group> {
|
|||
return name;
|
||||
}
|
||||
|
||||
public int getLinkToChapter() {
|
||||
public Integer getLinkToChapter() {
|
||||
return linkToChapter;
|
||||
}
|
||||
|
||||
public int getLinkToPuzzle() {
|
||||
public Integer getLinkToPuzzle() {
|
||||
return linkToPuzzle;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ public enum DatabaseQuery {
|
|||
|
||||
// GROUPS
|
||||
ALL_GROUPS("SELECT * FROM groups"),
|
||||
GET_GROUP_ID_BY_DATA("SELECT id_group FROM groups WHERE name = ? AND fk_chapter = ? AND fk_puzzle = ?"),
|
||||
GET_GROUP_ID_BY_DATA("SELECT id_group FROM groups WHERE name = ? AND (fk_chapter = ? OR fk_puzzle = ?)"),
|
||||
INSERT_GROUP("INSERT INTO groups (name, fk_chapter, fk_puzzle) VALUES (?,?,?)"),
|
||||
INSERT_PLAYER_IN_GROUP("INSERT INTO containsGroups (fk_player, fk_group) VALUES (?,?)"),
|
||||
LEAVE_GROUP("DELETE FROM containsGroups WHERE fk_player = ? AND fk_group = ?"),
|
||||
|
|
|
@ -504,8 +504,8 @@ public class DatabaseRepository {
|
|||
ensureConnection();
|
||||
PreparedStatement stmt = DatabaseQuery.GET_GROUP_ID_BY_DATA.prepare(this.con);
|
||||
stmt.setString(1, group.getName());
|
||||
stmt.setInt(2, group.getLinkToChapter());
|
||||
stmt.setInt(3, group.getLinkToPuzzle());
|
||||
stmt.setObject(2, group.getLinkToChapter());
|
||||
stmt.setObject(3, group.getLinkToPuzzle());
|
||||
|
||||
ResultSet result = stmt.executeQuery();
|
||||
if(result.next()) return result.getInt("id_group");
|
||||
|
@ -521,7 +521,9 @@ public class DatabaseRepository {
|
|||
stmt.setInt(2, id);
|
||||
|
||||
return stmt.executeUpdate() >= 0;
|
||||
}catch(Exception e){}
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue