/** * Calculate the rank for this new version about to be inserted. * * @param version The version to calculated for. * @return The rank. */ private int calculateVersionRank(MigrationVersion version) throws SQLException { List<String> versions = jdbcTemplate.queryForStringList("select " + dbSupport.quote("version") + " from " + table); List<MigrationVersion> migrationVersions = new ArrayList<MigrationVersion>(); for (String versionStr : versions) { migrationVersions.add(new MigrationVersion(versionStr)); } Collections.sort(migrationVersions); for (int i = 0; i < migrationVersions.size(); i++) { if (version.compareTo(migrationVersions.get(i)) < 0) { return i + 1; } } return migrationVersions.size() + 1; }