SteamWar/SpigotCore
Archiviert
13
0

Safe Historic Data in CheckedNode
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: Chaoscaot <chaoscaot444@gmail.com>
Dieser Commit ist enthalten in:
Chaoscaot 2021-11-05 22:09:24 +01:00
Ursprung 474212a340
Commit dfb38c7cda

Datei anzeigen

@ -19,80 +19,78 @@
package de.steamwar.sql; package de.steamwar.sql;
import org.bukkit.Bukkit;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.logging.Level;
public class CheckedSchematic { public class CheckedNode {
private static final SQL.Statement checkHistory = new SQL.Statement("SELECT * FROM CheckedSchematic WHERE NodeId IN (SELECT NodeId FROM SchematicNode WHERE NodeOwner = ?) AND DeclineReason != '' AND DeclineReason != 'Prüfvorgang abgebrochen' ORDER BY EndTime DESC"); private static final SQL.Statement checkHistory = new SQL.Statement("SELECT * FROM CheckedNode WHERE NodeId IN (SELECT NodeId FROM SchematicNode WHERE NodeOwner = ?) AND DeclineReason != '' AND DeclineReason != 'Prüfvorgang abgebrochen' ORDER BY EndTime DESC");
private static final SQL.Statement nodeHistory = new SQL.Statement("SELECT * FROM CheckedSchematic WHERE NodeId = ? AND DeclineReason != '' AND DeclineReason != 'Prüfvorgang abgebrochen' ORDER BY EndTime DESC"); private static final SQL.Statement nodeHistory = new SQL.Statement("SELECT * FROM CheckedNode WHERE NodeId = ? AND DeclineReason != '' AND DeclineReason != 'Prüfvorgang abgebrochen' ORDER BY EndTime DESC");
private final int node; private final Integer node;
private final int validator; private final int validator;
private final Timestamp startTime; private final Timestamp startTime;
private final Timestamp endTime; private final Timestamp endTime;
private final String declineReason; private final String declineReason;
private CheckedSchematic(int node, int validator, Timestamp startTime, Timestamp endTime, String declineReason, boolean insertDB){ private CheckedNode(int node, int validator, Timestamp startTime, Timestamp endTime, String declineReason, boolean insertDB){
this.node = node; this.node = node;
this.validator = validator; this.validator = validator;
this.startTime = startTime; this.startTime = startTime;
this.endTime = endTime; this.endTime = endTime;
this.declineReason = declineReason; this.declineReason = declineReason;
if(insertDB) if(insertDB) {
insertDB(); insertDB();
}
} }
public CheckedSchematic(int node, int validator, Timestamp startTime, Timestamp endTime, String declineReason){ public CheckedNode(int node, int validator, Timestamp startTime, Timestamp endTime, String declineReason){
this(node, validator, startTime, endTime, declineReason, true); this(node, validator, startTime, endTime, declineReason, true);
} }
public CheckedSchematic(int node, UUID validator, Timestamp startTime, Timestamp endTime, String declineReason){ public CheckedNode(int node, UUID validator, Timestamp startTime, Timestamp endTime, String declineReason){
this(node, SteamwarUser.get(validator).getId(), startTime, endTime, declineReason, true); this(node, SteamwarUser.get(validator).getId(), startTime, endTime, declineReason, true);
} }
private void insertDB(){ private void insertDB() {
SchematicNode sNode = SchematicNode.getSchematicNode(node);
String nodeName = sNode.getName();
int nodeOwner = sNode.getOwner();
SQL.update("INSERT INTO CheckedSchematic" + SQL.update("INSERT INTO CheckedSchematic" +
" (NodeId, Validator, StartTime, EndTime, DeclineReason) VALUES (?, ?, ?, ?, ?)", " (NodeId, NodeName, NodeOwner, Validator, StartTime, EndTime, DeclineReason) VALUES (?, ?, ?, ?, ?)",
node, validator, startTime, endTime, declineReason); node, nodeName, nodeOwner, validator, startTime, endTime, declineReason);
} }
public static List<CheckedSchematic> getLastDeclinedOfNode(SchematicNode node){ public static List<CheckedNode> getLastDeclinedOfNode(SchematicNode node){
return getLastDeclinedOfNode(node.getId()); return getLastDeclinedOfNode(node.getId());
} }
public static List<CheckedSchematic> getLastDeclinedOfNode(int node){ public static List<CheckedNode> getLastDeclinedOfNode(int node){
return nodeHistory.select(rs -> { return nodeHistory.select(rs -> {
List<CheckedSchematic> lastDeclined = new ArrayList<>(); List<CheckedNode> lastDeclined = new ArrayList<>();
while(rs.next()){ while(rs.next()){
int validator = rs.getInt("Validator"); int validator = rs.getInt("Validator");
Timestamp startTime = rs.getTimestamp("StartTime"); Timestamp startTime = rs.getTimestamp("StartTime");
Timestamp endTime = rs.getTimestamp("EndTime"); Timestamp endTime = rs.getTimestamp("EndTime");
String declineReason = rs.getString("DeclineReason"); String declineReason = rs.getString("DeclineReason");
lastDeclined.add(new CheckedSchematic(node, validator, startTime, endTime, declineReason, false)); lastDeclined.add(new CheckedNode(node, validator, startTime, endTime, declineReason, false));
} }
return lastDeclined; return lastDeclined;
}, node); }, node);
} }
public static List<CheckedSchematic> getLastDeclined(UUID uuid){ public static List<CheckedNode> getLastDeclined(UUID uuid){
return getLastDelined(SteamwarUser.get(uuid).getId()); return getLastDelined(SteamwarUser.get(uuid).getId());
} }
public static List<CheckedSchematic> getLastDelined(int schemOwner){ public static List<CheckedNode> getLastDelined(int schemOwner){
return checkHistory.select(rs -> { return checkHistory.select(rs -> {
List<CheckedSchematic> history = new ArrayList<>(); List<CheckedNode> history = new ArrayList<>();
while(rs.next()) while(rs.next())
history.add(new CheckedSchematic(rs.getInt("NodeId"), rs.getInt("Validator"), rs.getTimestamp("StartTime"), rs.getTimestamp("EndTime"), rs.getString("DeclineReason"), false)); history.add(new CheckedNode(rs.getInt("NodeId"), rs.getInt("Validator"), rs.getTimestamp("StartTime"), rs.getTimestamp("EndTime"), rs.getString("DeclineReason"), false));
return history; return history;
}, schemOwner); }, schemOwner);
} }