public Map<String, Object> selectOne(String sql, Object... args) throws SQLException { List<Map<String, Object>> results = selectAll(sql, args); if (results.size() != 1) { throw new SQLException("Statement returned " + results.size() + " results where exactly one (1) was expected."); } return results.get(0); }
/** * Executes a SELECT statement that returns one row. * * @param sql The SQL * @param args The arguments to be set on the statement. * @return The row expected. * @throws SQLException If less or more than one row is returned */ public Map<String, Object> selectOne(String sql, Object... args) throws SQLException { List<Map<String, Object>> results = selectAll(sql, args); if (results.size() != 1) { throw new SQLException("Statement returned " + results.size() + " results where exactly one (1) was expected."); } return results.get(0); }
/** * Executes a SELECT statement that returns one row. * * @param sql The SQL * @param args The arguments to be set on the statement. * @return The number of rows impacted or BATCHED_RESULTS if the statements are being batched. * @throws SQLException If more than one row is returned */ public Map<String, Object> selectOne(String sql, Object... args) throws SQLException { List<Map<String, Object>> results = selectAll(sql, args); if (results.size() != 1) { throw new SQLException("Statement returned " + results.size() + " results where exactly one (1) was expected."); } return results.get(0); }
protected List<Change> getChangelog() { SqlRunner runner = getSqlRunner(); try { List<Map<String, Object>> changelog = runner.selectAll("select ID, APPLIED_AT, DESCRIPTION from " + changelogTable() + " order by id"); List<Change> changes = new ArrayList<Change>(); for (Map<String, Object> change : changelog) { String id = change.get("ID") == null ? null : change.get("ID").toString(); String appliedAt = change.get("APPLIED_AT") == null ? null : change.get("APPLIED_AT").toString(); String description = change.get("DESCRIPTION") == null ? null : change.get("DESCRIPTION").toString(); changes.add(new Change(new BigDecimal(id), appliedAt, description)); } return changes; } catch (SQLException e) { throw new MigrationException("Error querying last applied migration. Cause: " + e, e); } finally { runner.closeConnection(); } }
protected boolean changelogExists() { SqlRunner runner = getSqlRunner(); try { runner.selectAll("select ID, APPLIED_AT, DESCRIPTION from " + changelogTable()); return true; } catch (SQLException e) { return false; } finally { runner.closeConnection(); } }