|
|
@ -9,6 +9,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
package engine.db.handlers; |
|
|
|
package engine.db.handlers; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import engine.gameManager.DbManager; |
|
|
|
import engine.objects.Bane; |
|
|
|
import engine.objects.Bane; |
|
|
|
import engine.objects.Building; |
|
|
|
import engine.objects.Building; |
|
|
|
import engine.objects.City; |
|
|
|
import engine.objects.City; |
|
|
@ -16,10 +17,10 @@ import engine.objects.PlayerCharacter; |
|
|
|
import org.joda.time.DateTime; |
|
|
|
import org.joda.time.DateTime; |
|
|
|
import org.pmw.tinylog.Logger; |
|
|
|
import org.pmw.tinylog.Logger; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.sql.Connection; |
|
|
|
|
|
|
|
import java.sql.PreparedStatement; |
|
|
|
import java.sql.ResultSet; |
|
|
|
import java.sql.ResultSet; |
|
|
|
import java.sql.SQLException; |
|
|
|
import java.sql.SQLException; |
|
|
|
import java.util.concurrent.ConcurrentHashMap; |
|
|
|
|
|
|
|
import java.util.logging.Level; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class dbBaneHandler extends dbHandlerBase { |
|
|
|
public class dbBaneHandler extends dbHandlerBase { |
|
|
|
|
|
|
|
|
|
|
@ -29,78 +30,63 @@ public class dbBaneHandler extends dbHandlerBase { |
|
|
|
|
|
|
|
|
|
|
|
public boolean CREATE_BANE(City city, PlayerCharacter owner, Building stone) { |
|
|
|
public boolean CREATE_BANE(City city, PlayerCharacter owner, Building stone) { |
|
|
|
|
|
|
|
|
|
|
|
prepareCallable("INSERT INTO `dyn_banes` (`cityUUID`, `ownerUUID`, `stoneUUID`, `placementDate`) VALUES(?,?,?,?)"); |
|
|
|
try (Connection connection = DbManager.getConnection(); |
|
|
|
setLong(1, (long) city.getObjectUUID()); |
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_banes` (`cityUUID`, `ownerUUID`, `stoneUUID`, `placementDate`) VALUES(?,?,?,?)")) { |
|
|
|
setLong(2, (long) owner.getObjectUUID()); |
|
|
|
|
|
|
|
setLong(3, (long) stone.getObjectUUID()); |
|
|
|
|
|
|
|
setTimeStamp(4, System.currentTimeMillis()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (executeUpdate() > 0); |
|
|
|
preparedStatement.setLong(1, city.getObjectUUID()); |
|
|
|
|
|
|
|
preparedStatement.setLong(2, owner.getObjectUUID()); |
|
|
|
|
|
|
|
preparedStatement.setLong(3, stone.getObjectUUID()); |
|
|
|
|
|
|
|
preparedStatement.setTimestamp(4, new java.sql.Timestamp(System.currentTimeMillis())); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
preparedStatement.execute(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
|
|
|
Logger.error(e); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Bane LOAD_BANE(int cityUUID) { |
|
|
|
public Bane LOAD_BANE(int cityUUID) { |
|
|
|
|
|
|
|
|
|
|
|
Bane newBane = null; |
|
|
|
Bane bane = null; |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
prepareCallable("SELECT * from dyn_banes WHERE `dyn_banes`.`cityUUID` = ?"); |
|
|
|
try (Connection connection = DbManager.getConnection(); |
|
|
|
|
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * from dyn_banes WHERE `dyn_banes`.`cityUUID` = ?")) { |
|
|
|
|
|
|
|
|
|
|
|
setLong(1, (long) cityUUID); |
|
|
|
preparedStatement.setLong(1, cityUUID); |
|
|
|
ResultSet rs = executeQuery(); |
|
|
|
ResultSet rs = preparedStatement.executeQuery(); |
|
|
|
|
|
|
|
|
|
|
|
if (rs.next()) { |
|
|
|
if (rs.next()) { |
|
|
|
newBane = new Bane(rs); |
|
|
|
bane = new Bane(rs); |
|
|
|
Bane.addBane(newBane); |
|
|
|
Bane.addBane(bane); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException ex) { |
|
|
|
} catch (SQLException e) { |
|
|
|
java.util.logging.Logger.getLogger(dbBaneHandler.class.getName()).log(Level.SEVERE, null, ex); |
|
|
|
Logger.error(e); |
|
|
|
} finally { |
|
|
|
|
|
|
|
closeCallable(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return newBane; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return bane; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public ConcurrentHashMap<Integer, Bane> LOAD_ALL_BANES() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ConcurrentHashMap<Integer, Bane> baneList; |
|
|
|
|
|
|
|
Bane thisBane; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
baneList = new ConcurrentHashMap<>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int recordsRead = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
prepareCallable("SELECT * FROM dyn_banes"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
ResultSet rs = executeQuery(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (rs.next()) { |
|
|
|
public boolean SET_BANE_TIME(DateTime toSet, int cityUUID) { |
|
|
|
|
|
|
|
|
|
|
|
recordsRead++; |
|
|
|
try (Connection connection = DbManager.getConnection(); |
|
|
|
thisBane = new Bane(rs); |
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_banes` SET `liveDate`=? WHERE `cityUUID`=?")) { |
|
|
|
baneList.put(thisBane.getCityUUID(), thisBane); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
preparedStatement.setTimestamp(1, new java.sql.Timestamp(toSet.getMillis())); |
|
|
|
|
|
|
|
preparedStatement.setLong(2, cityUUID); |
|
|
|
|
|
|
|
|
|
|
|
Logger.info("read: " + recordsRead + " cached: " + baneList.size()); |
|
|
|
preparedStatement.execute(); |
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) { |
|
|
|
} catch (SQLException e) { |
|
|
|
Logger.error( e.toString()); |
|
|
|
Logger.error(e); |
|
|
|
} finally { |
|
|
|
return false; |
|
|
|
closeCallable(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return baneList; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean SET_BANE_TIME(DateTime toSet, int cityUUID) { |
|
|
|
return true; |
|
|
|
prepareCallable("UPDATE `dyn_banes` SET `liveDate`=? WHERE `cityUUID`=?"); |
|
|
|
|
|
|
|
setTimeStamp(1, toSet.getMillis()); |
|
|
|
|
|
|
|
setLong(2, cityUUID); |
|
|
|
|
|
|
|
return (executeUpdate() > 0); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public boolean REMOVE_BANE(Bane bane) { |
|
|
|
public boolean REMOVE_BANE(Bane bane) { |
|
|
@ -108,8 +94,17 @@ public class dbBaneHandler extends dbHandlerBase { |
|
|
|
if (bane == null) |
|
|
|
if (bane == null) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
prepareCallable("DELETE FROM `dyn_banes` WHERE `cityUUID` = ?"); |
|
|
|
try (Connection connection = DbManager.getConnection(); |
|
|
|
setLong(1, (long) bane.getCity().getObjectUUID()); |
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_banes` WHERE `cityUUID` = ?")) { |
|
|
|
return (executeUpdate() > 0); |
|
|
|
|
|
|
|
|
|
|
|
preparedStatement.setLong(1, bane.getCity().getObjectUUID()); |
|
|
|
|
|
|
|
preparedStatement.execute(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
|
|
|
Logger.error(e); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|