Refactor to remove abstraction
This commit is contained in:
@@ -16,9 +16,10 @@ import engine.objects.ItemBase;
|
|||||||
import engine.objects.MobEquipment;
|
import engine.objects.MobEquipment;
|
||||||
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.ArrayList;
|
|
||||||
|
|
||||||
public class dbContractHandler extends dbHandlerBase {
|
public class dbContractHandler extends dbHandlerBase {
|
||||||
|
|
||||||
@@ -28,48 +29,37 @@ public class dbContractHandler extends dbHandlerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Contract GET_CONTRACT(final int objectUUID) {
|
public Contract GET_CONTRACT(final int objectUUID) {
|
||||||
|
|
||||||
Contract contract = (Contract) DbManager.getFromCache(Enum.GameObjectType.Contract, objectUUID);
|
Contract contract = (Contract) DbManager.getFromCache(Enum.GameObjectType.Contract, objectUUID);
|
||||||
|
|
||||||
if (contract != null)
|
if (contract != null)
|
||||||
return contract;
|
return contract;
|
||||||
|
|
||||||
if (objectUUID == 0)
|
if (objectUUID == 0)
|
||||||
return null;
|
return null;
|
||||||
prepareCallable("SELECT * FROM `static_npc_contract` WHERE `ID` = ?");
|
|
||||||
setInt(1, objectUUID);
|
|
||||||
return (Contract) getObjectSingle(objectUUID);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<Contract> GET_CONTRACT_BY_RACE(final int objectUUID) {
|
try (Connection connection = DbManager.getConnection();
|
||||||
|
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_building`.*, `object`.`parent` FROM `object` INNER JOIN `obj_building` ON `obj_building`.`UID` = `object`.`UID` WHERE `object`.`UID` = ?;")) {
|
||||||
|
|
||||||
ArrayList<Contract> contracts = new ArrayList<>();
|
preparedStatement.setInt(1, objectUUID);
|
||||||
|
|
||||||
prepareCallable("SELECT * FROM static_npc_contract WHERE `mobbaseID` =?;");
|
ResultSet rs = preparedStatement.executeQuery();
|
||||||
setLong(1, objectUUID);
|
contract = (Contract) getObjectFromRs(rs);
|
||||||
|
|
||||||
try {
|
|
||||||
ResultSet rs = executeQuery();
|
|
||||||
|
|
||||||
//shrines cached in rs for easy cache on creation.
|
|
||||||
while (rs.next()) {
|
|
||||||
Contract contract = new Contract(rs);
|
|
||||||
if (contract != null)
|
|
||||||
contracts.add(contract);
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
Logger.error( e.getErrorCode() + ' ' + e.getMessage(), e);
|
Logger.error(e);
|
||||||
} finally {
|
|
||||||
closeCallable();
|
|
||||||
}
|
}
|
||||||
return contracts;
|
return contract;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void GET_GENERIC_INVENTORY(final Contract contract) {
|
public void LOAD_CONTRACT_INVENTORY(final Contract contract) {
|
||||||
|
|
||||||
prepareCallable("SELECT * FROM `static_npc_inventoryset` WHERE `inventorySet` = ?;");
|
try (Connection connection = DbManager.getConnection();
|
||||||
setInt(1, contract.inventorySet);
|
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_inventoryset` WHERE `inventorySet` = ?;")) {
|
||||||
|
|
||||||
try {
|
preparedStatement.setInt(1, contract.inventorySet);
|
||||||
ResultSet rs = executeQuery();
|
|
||||||
|
ResultSet rs = preparedStatement.executeQuery();
|
||||||
|
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
|
|
||||||
@@ -102,56 +92,78 @@ public class dbContractHandler extends dbHandlerBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
Logger.error("SQL Error number: " + e.getErrorCode() + ' ' + e.getMessage());
|
Logger.error(e);
|
||||||
} finally {
|
|
||||||
closeCallable();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void GET_SELL_LISTS(final Contract con) {
|
public void LOAD_SELL_LIST_FOR_CONTRACT(final Contract contract) {
|
||||||
prepareCallable("SELECT * FROM `static_npc_contract_selltype` WHERE `contractID` = ?;");
|
|
||||||
setInt(1, con.getObjectUUID());
|
try (Connection connection = DbManager.getConnection();
|
||||||
try {
|
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_contract_selltype` WHERE `contractID` = ?;")) {
|
||||||
ResultSet rs = executeQuery();
|
|
||||||
ArrayList<Integer> item = con.getBuyItemType();
|
preparedStatement.setInt(1, contract.getObjectUUID());
|
||||||
ArrayList<Integer> skill = con.getBuySkillToken();
|
|
||||||
ArrayList<Integer> unknown = con.getBuyUnknownToken();
|
ResultSet rs = preparedStatement.executeQuery();
|
||||||
|
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
|
|
||||||
int type = rs.getInt("type");
|
int type = rs.getInt("type");
|
||||||
int value = rs.getInt("value");
|
int value = rs.getInt("value");
|
||||||
if (type == 1) {
|
|
||||||
item.add(value);
|
switch (type) {
|
||||||
} else if (type == 2) {
|
case 1:
|
||||||
skill.add(value);
|
contract.getBuyItemType().add(value);
|
||||||
} else if (type == 3) {
|
break;
|
||||||
unknown.add(value);
|
case 2:
|
||||||
|
contract.getBuySkillToken().add(value);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
contract.getBuyUnknownToken().add(value);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
Logger.error("SQL Error number: " + e.getErrorCode() + ' ' + e.getMessage());
|
Logger.error(e);
|
||||||
} finally {
|
|
||||||
closeCallable();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean updateAllowedBuildings(final Contract con, final long slotbitvalue) {
|
public boolean updateAllowedBuildings(final Contract con, final long slotbitvalue) {
|
||||||
prepareCallable("UPDATE `static_npc_contract` SET `allowedBuildingTypeID`=? WHERE `contractID`=?");
|
|
||||||
setLong(1, slotbitvalue);
|
try (Connection connection = DbManager.getConnection();
|
||||||
setInt(2, con.getContractID());
|
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `static_npc_contract` SET `allowedBuildingTypeID`=? WHERE `contractID`=?")) {
|
||||||
return (executeUpdate() > 0);
|
|
||||||
|
preparedStatement.setLong(1, slotbitvalue);
|
||||||
|
preparedStatement.setInt(2, con.getContractID());
|
||||||
|
|
||||||
|
return (preparedStatement.executeUpdate() > 0);
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
Logger.error(e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean updateDatabase(final Contract con) {
|
public boolean updateDatabase(final Contract con) {
|
||||||
prepareCallable("UPDATE `static_npc_contract` SET `contractID`=?, `name`=?, "
|
|
||||||
+ "`mobbaseID`=?, `classID`=?, vendorDialog=?, iconID=?, allowedBuildingTypeID=? WHERE `ID`=?");
|
try (Connection connection = DbManager.getConnection();
|
||||||
setInt(1, con.getContractID());
|
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `static_npc_contract` SET `contractID`=?, `name`=?, "
|
||||||
setString(2, con.getName());
|
+ "`mobbaseID`=?, `classID`=?, vendorDialog=?, iconID=?, allowedBuildingTypeID=? WHERE `ID`=?")) {
|
||||||
setInt(3, con.getMobbaseID());
|
|
||||||
setInt(4, con.getClassID());
|
preparedStatement.setInt(1, con.getContractID());
|
||||||
setInt(5, (con.getVendorDialog() != null) ? con.getVendorDialog().getObjectUUID() : 0);
|
preparedStatement.setString(2, con.getName());
|
||||||
setInt(6, con.getIconID());
|
preparedStatement.setInt(3, con.getMobbaseID());
|
||||||
setInt(8, con.getObjectUUID());
|
preparedStatement.setInt(4, con.getClassID());
|
||||||
setLong(7, con.getAllowedBuildings().toLong());
|
preparedStatement.setInt(5, (con.getVendorDialog() != null) ? con.getVendorDialog().getObjectUUID() : 0);
|
||||||
return (executeUpdate() > 0);
|
preparedStatement.setInt(6, con.getIconID());
|
||||||
|
preparedStatement.setInt(8, con.getObjectUUID());
|
||||||
|
preparedStatement.setLong(7, con.getAllowedBuildings().toLong());
|
||||||
|
|
||||||
|
return (preparedStatement.executeUpdate() > 0);
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
Logger.error(e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -138,8 +138,8 @@ public class Contract extends AbstractGameObject {
|
|||||||
|
|
||||||
//Specify if trainer, merchant, banker, etc via classID
|
//Specify if trainer, merchant, banker, etc via classID
|
||||||
private void setBools() {
|
private void setBools() {
|
||||||
DbManager.ContractQueries.GET_GENERIC_INVENTORY(this);
|
DbManager.ContractQueries.LOAD_CONTRACT_INVENTORY(this);
|
||||||
DbManager.ContractQueries.GET_SELL_LISTS(this);
|
DbManager.ContractQueries.LOAD_SELL_LIST_FOR_CONTRACT(this);
|
||||||
|
|
||||||
this.isTrainer = this.classID > 2499 && this.classID < 3050 || this.classID == 2028;
|
this.isTrainer = this.classID > 2499 && this.classID < 3050 || this.classID == 2028;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user