* Environment is retrieved by matching all three inWorldIDFk, envRow, and
* envColumn in the database. If no Environment is found the returns null.
* @throws SQLException
*/
public static Environment getEnvironmentByWorldIDAndRowAndCol(Environment environment) throws SQLException {
Environment returnEnvironment = null;
String query = "SELECT * FROM `environment` WHERE `world_id` = ? AND `row` = ? AND `column` = ?";
Connection connection = null;
PreparedStatement pstmt = null;
try {
connection = DAO.getDataSource().getConnection();
pstmt = connection.prepareStatement(query);
pstmt.setInt(1, environment.getWorldID());
pstmt.setInt(2, environment.getRow());
pstmt.setInt(3, environment.getColumn());
ResultSet rs = pstmt.executeQuery();
if (rs.next()) {
returnEnvironment = new Environment(rs.getInt("env_id"));
returnEnvironment.setWorldID(rs.getInt("world_id"));
returnEnvironment.setOwnerID(rs.getInt("player_id"));
returnEnvironment.setRow(rs.getInt("row"));
returnEnvironment.setColumn(rs.getInt("column"));
returnEnvironment.setEnvironmentScore(rs.getInt("score"));
returnEnvironment.setHighEnvScore(rs.getInt("high_score"));
returnEnvironment.setAccumulatedEnvScore(rs.getInt("accumulated_score"));
}
rs.close();
pstmt.close();
List<Zone> zoneList = ZoneDAO.getZoneByEnvironmentID(returnEnvironment.getID());
for (Zone zone : zoneList) {
zone.setEnvironment(returnEnvironment);
}
returnEnvironment.setZones(zoneList);
} finally {
if (connection != null) {
connection.close();
}
}