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(); } }
protected void deleteChange(Change change) { SqlRunner runner = getSqlRunner(); try { runner.delete("delete from " + changelogTable() + " where id = ?", change.getId()); } catch (SQLException e) { throw new MigrationException("Error querying last applied migration. Cause: " + e, e); } finally { runner.closeConnection(); } }
protected void insertChangelog(Change change) { SqlRunner runner = getSqlRunner(); change.setAppliedTimestamp(generateAppliedTimeStampAsString()); try { runner.insert("insert into " + changelogTable() + " (ID, APPLIED_AT, DESCRIPTION) values (?,?,?)", change.getId(), change.getAppliedTimestamp(), change.getDescription()); } catch (SQLException e) { throw new MigrationException("Error querying last applied migration. Cause: " + e, e); } finally { runner.closeConnection(); } }