use of liquibase.exception.CustomChangeException in project webanno by webanno.
the class RemoveDanglingFeatures method execute.
@Override
public void execute(Database aDatabase) throws CustomChangeException {
JdbcConnection dbConn = (JdbcConnection) aDatabase.getConnection();
try {
PreparedStatement selection = dbConn.prepareStatement(//
String.join(//
"\n", //
"SELECT f.id", //
"FROM annotation_feature f", //
"LEFT JOIN annotation_type l ON f.annotation_type = l.id \n", "WHERE l.id IS NULL"));
PreparedStatement deletion = dbConn.prepareStatement("DELETE FROM annotation_feature WHERE id = ?");
try (ResultSet danglingFeatures = selection.executeQuery()) {
while (danglingFeatures.next()) {
long danglingFeatureId = danglingFeatures.getLong(1);
deletion.setLong(1, danglingFeatureId);
deletion.execute();
changed++;
}
}
if (changed > 0) {
log.info("DATABASE UPGRADE PERFORMED: [{}] dangling features were removed.", changed);
}
} catch (Exception e) {
// swallow the exception !
}
}
Aggregations