From 725c0fd207f1566c194ee6ab06eaa2f790c864f9 Mon Sep 17 00:00:00 2001 From: graywolf336 Date: Wed, 5 Mar 2014 22:50:53 -0600 Subject: [PATCH] Start some work on loading the prisoners, for #18. --- .../java/com/graywolf336/jail/JailIO.java | 47 ++++++++++++++++--- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/graywolf336/jail/JailIO.java b/src/main/java/com/graywolf336/jail/JailIO.java index db5b245..2ecf121 100644 --- a/src/main/java/com/graywolf336/jail/JailIO.java +++ b/src/main/java/com/graywolf336/jail/JailIO.java @@ -361,17 +361,17 @@ public class JailIO { pl.getLogger().severe("Error while loading the jails, please check the error and fix what is wrong."); } + //This list contains an integer which refers to the cellid column in sql + //this list only gets populated if there are cells which reference a jail + //that doesn't exist anymore + //TODO: Implement this + List cellsToRemove = new LinkedList(); + try { if(con == null) this.prepareStorage(false); PreparedStatement ps = con.prepareStatement("SELECT * FROM " + prefix + "cells"); ResultSet set = ps.executeQuery(); - //This list contains an integer which refers to the cellid column in sql - //this list only gets populated if there are cells which reference a jail - //that doesn't exist anymore - //TODO: Implement this - List remove = new LinkedList(); - while(set.next()) { Jail j = pl.getJailManager().getJail(set.getString("jail")); @@ -390,10 +390,12 @@ public class JailIO { j.addCell(c, false); }else { - remove.add(set.getInt("cellid")); + cellsToRemove.add(set.getInt("cellid")); } } + pl.debug("There are " + cellsToRemove.size() + " cells we need to remove due to being invalid."); + set.close(); ps.close(); } catch (SQLException e) { @@ -402,6 +404,37 @@ public class JailIO { pl.getLogger().severe("Error while loading all of the cells, please check the error and fix what is wrong."); } + //TODO: prisoners + + try { + if(con == null) this.prepareStorage(false); + PreparedStatement ps = con.prepareStatement("SELECT * FROM " + prefix + "prisoners"); + ResultSet set = ps.executeQuery(); + + while(set.next()) { + Jail j = pl.getJailManager().getJail(set.getString("jail")); + + if(j != null) { + String cellname = set.getString("cell_n1"); + Cell c = j.getCell(cellname); + + if(cellname.isEmpty()) { + + }else if(c != null) { + + }else { + //the prisoner is assigned to a cell which doesn't exist, so just put them into the jail + } + } else { + //if the jail doesn't exist, do the same as the cells + } + } + } catch (SQLException e) { + e.printStackTrace(); + pl.getLogger().severe("---------- Jail Error!!! ----------"); + pl.getLogger().severe("Error while loading all of the prisoners, please check the error and fix what is wrong."); + } + pl.debug("Took " + (System.currentTimeMillis() - st) + " millis."); break; default: