*/
package org.sonar.server.platform;
+import org.apache.commons.dbutils.DbUtils;
import org.elasticsearch.index.query.QueryBuilders;
import org.sonar.api.ServerComponent;
import org.sonar.core.persistence.DatabaseVersion;
} finally {
dbSession.close();
+ DbUtils.closeQuietly(connection);
}
}
// Clear resource related tables
for (String relatedTable : RESOURCE_RELATED_TABLES) {
- deleteWhereResoureIdNotNull(relatedTable, connection);
+ deleteWhereResourceIdNotNull(relatedTable, connection);
}
deleteManualRules(connection);
} finally {
dbSession.close();
+ DbUtils.closeQuietly(connection);
}
}
- private void deleteWhereResoureIdNotNull(String tableName, Connection connection) {
+ private void deleteWhereResourceIdNotNull(String tableName, Connection connection) {
try {
connection.prepareStatement("DELETE FROM " + tableName + " WHERE resource_id IS NOT NULL").execute();
// commit is useless on some databases
connection.commit();
} catch (SQLException e) {
- // frequent use-case : the table does not exist
+ throw new IllegalStateException("Fail to delete table : " + tableName, e);
}
}
assertThat(result.attribute("jira-issue-key")).isEqualTo("SONAR-1234");
}
+ @Test(expected = IllegalStateException.class)
+ public void comments_field_is_not_available() throws Exception {
+ IssueDto issue = createIssue();
+ db.issueDao().insert(session, issue);
+ session.commit();
+
+ Issue result = index.getByKey(issue.getKey());
+ result.comments();
+ }
+
@Test(expected = IllegalStateException.class)
public void is_new_field_is_not_available() throws Exception {
IssueDto issue = createIssue();
LoggerFactory.getLogger(getClass()).error(message);
throw new IllegalArgumentException(message);
}
- String value = StringUtils.defaultString(readParam(definition.deprecatedKey()), readParam(key));
+ String deprecatedKey = definition.deprecatedKey();
+ String value = deprecatedKey != null ? StringUtils.defaultString(readParam(deprecatedKey), readParam(key)) : readParam(key);
value = StringUtils.defaultString(value, definition.defaultValue());
if (value == null) {
return null;