* EnvironmentType that is to say list of environments belonging to the world.
* If no world found in database returns null.
* @throws SQLException
*/
public static World getPrivateWorldByWorldNameAndPassword(World world) throws SQLException {
World returnWorld = null;
String query = "SELECT * FROM `world` WHERE `access_type` = ? AND `game_name` = ? AND `password` = ?";
Connection connection = null;
PreparedStatement pstmt = null;
try {
connection = DAO.getDataSource().getConnection();
pstmt = connection.prepareStatement(query);
pstmt.setShort(1, world.getAccessType());
pstmt.setString(2, world.getGameName());
pstmt.setString(3, world.getPassword());
ResultSet rs = pstmt.executeQuery();
if (rs.next()) {
returnWorld = new World(rs.getInt("world_id"));
returnWorld.setGameName(rs.getString("game_name"));
returnWorld.setSeconds(rs.getLong("seconds"));
returnWorld.setDays(rs.getInt("days"));
returnWorld.setMaxPlayers(rs.getInt("max_players"));
returnWorld.setEnvType(rs.getString("env_type"));
returnWorld.setAccessType(rs.getShort("access_type"));
returnWorld.setGameMode(rs.getShort("game_mode"));
returnWorld.setCreatorID(rs.getInt("creator_id"));
returnWorld.setPassword(rs.getString("password"));
}
rs.close();
pstmt.close();
returnWorld.setCreatorID(returnWorld.getCreatorID());
returnWorld.setEnvironments(EnvironmentDAO.getEnvironmentByWorldID(returnWorld.getID()));
} finally {
if (connection != null) {
connection.close();
}
}