@Override public ProblemSet find(long id) { ProblemSet ps = new ProblemSet(); try { Connection conn = ConnectionFactory.getInstance().getConnection(); String query = "SELECT * FROM sequences WHERE id = ?"; PreparedStatement pstm = conn.prepareStatement(query); pstm.setLong(1, id); ResultSet rs = pstm.executeQuery(); if (rs.next()) { ps.setDecodedID(rs.getInt("id")); ps.setName(rs.getString("name")); ps.setHeadSectionId(rs.getLong("head_section_id")); ps.setParameters(rs.getString("parameters")); } else { throw new RuntimeException("Cannot find Problem Set with this " + id); } if (rs != null) rs.close(); if (pstm != null) pstm.close(); if (conn != null) conn.close(); } catch (SQLException e) { throw new RuntimeException(e); } return ps; }
@Override public boolean isPseudoSkillBuilder(long problemSetId) { ProblemSet ps = find(problemSetId); String parameters = ps.getParameters(); if (parameters.contains("pseudo_skill_builder: \"true\"")) { return true; } else { return false; } }
@Override public long getPseudoSkillBuilderId(long problemSetId) { long id = 0; ProblemSet ps = find(problemSetId); String parameters = ps.getParameters(); String pattern = "arrs_skill_builder: \"(\\d+)\""; Pattern r = Pattern.compile(pattern); Matcher m = r.matcher(parameters); if (m.find()) { id = Long.valueOf(m.group(1)); } else { throw new RuntimeException( "Cannot find pseudo skill builder for problem set " + problemSetId); } return id; }