import org.sonar.db.Dao;
import org.sonar.db.DatabaseUtils;
import org.sonar.db.DbSession;
+import org.sonar.db.util.RowNotFoundException;
import static com.google.common.collect.Maps.newHashMapWithExpectedSize;
public ComponentDto selectOrFailById(DbSession session, long id) {
Optional<ComponentDto> componentDto = selectById(session, id);
if (!componentDto.isPresent()) {
- throw new IllegalArgumentException(String.format("Component id does not exist: %d", id));
+ throw new RowNotFoundException(String.format("Component id does not exist: %d", id));
}
return componentDto.get();
}
public ComponentDto selectOrFailByUuid(DbSession session, String uuid) {
Optional<ComponentDto> componentDto = selectByUuid(session, uuid);
if (!componentDto.isPresent()) {
- throw new IllegalArgumentException(String.format("Component with uuid '%s' not found", uuid));
+ throw new RowNotFoundException(String.format("Component with uuid '%s' not found", uuid));
}
return componentDto.get();
}
return mapper(session).selectByKeys(keys);
}
- public ComponentDto selectNonNullByKey(DbSession session, String key) {
+ public ComponentDto selectOrFailByKey(DbSession session, String key) {
Optional<ComponentDto> component = selectByKey(session, key);
if (!component.isPresent()) {
- throw new IllegalArgumentException(String.format("Component key '%s' not found", key));
+ throw new RowNotFoundException(String.format("Component key '%s' not found", key));
}
return component.get();
}
import org.sonar.api.resources.Scopes;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
+import org.sonar.db.util.RowNotFoundException;
public class SnapshotDao implements Dao {
public SnapshotDto selectOrFailById(DbSession session, long id) {
SnapshotDto value = selectById(session, id);
if (value == null) {
- throw new IllegalArgumentException(String.format("Snapshot id does not exist: %d", id));
+ throw new RowNotFoundException(String.format("Snapshot id does not exist: %d", id));
}
return value;
}
import org.sonar.db.Dao;
import org.sonar.db.DatabaseUtils;
import org.sonar.db.DbSession;
+import org.sonar.db.util.RowNotFoundException;
@ServerSide
public class CustomMeasureDao implements Dao {
public CustomMeasureDto selectOrFail(DbSession session, long id) {
CustomMeasureDto customMeasure = selectById(session, id);
if (customMeasure == null) {
- throw new IllegalArgumentException(String.format("Custom measure '%d' not found.", id));
+ throw new RowNotFoundException(String.format("Custom measure '%d' not found.", id));
}
return customMeasure;
}
import org.sonar.db.Dao;
import org.sonar.db.DatabaseUtils;
import org.sonar.db.DbSession;
+import org.sonar.db.util.RowNotFoundException;
import static com.google.common.collect.Lists.newArrayList;
public MetricDto selectOrFailByKey(DbSession session, String key) {
MetricDto metric = selectByKey(session, key);
if (metric == null) {
- throw new IllegalStateException(String.format("Metric key '%s' not found", key));
+ throw new RowNotFoundException(String.format("Metric key '%s' not found", key));
}
return metric;
}
public MetricDto selectOrFailById(DbSession session, int id) {
MetricDto metric = mapper(session).selectById(id);
if (metric == null) {
- throw new IllegalStateException(String.format("Metric id '%d' not found", id));
+ throw new RowNotFoundException(String.format("Metric id '%d' not found", id));
}
return metric;
}
import org.sonar.db.DbSession;
import org.sonar.db.MyBatis;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.util.RowNotFoundException;
@ServerSide
public class QualityProfileDao implements Dao {
public QualityProfileDto selectOrFailByKey(DbSession session, String key) {
QualityProfileDto dto = selectByKey(session, key);
if (dto == null) {
- throw new IllegalArgumentException("Quality profile not found: " + key);
+ throw new RowNotFoundException("Quality profile not found: " + key);
}
return dto;
}
import org.sonar.api.utils.DateUtils;
import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
+import org.sonar.db.util.RowNotFoundException;
import org.sonar.test.DbTests;
import static com.google.common.collect.Lists.newArrayList;
@Test
public void fail_to_get_by_uuid_when_component_not_found() {
- thrown.expect(IllegalArgumentException.class);
+ thrown.expect(RowNotFoundException.class);
db.prepareDbUnit(getClass(), "shared.xml");
@Test
public void fail_to_get_by_key_when_component_not_found() {
- thrown.expect(IllegalArgumentException.class);
+ thrown.expect(RowNotFoundException.class);
db.prepareDbUnit(getClass(), "shared.xml");
assertThat(result.get().isEnabled()).isFalse();
}
- @Test(expected = IllegalArgumentException.class)
+ @Test(expected = RowNotFoundException.class)
public void fail_to_get_by_id_when_project_not_found() {
db.prepareDbUnit(getClass(), "shared.xml");
import org.sonar.api.utils.System2;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
+import org.sonar.db.RowNotFoundException;
import org.sonar.test.DbTests;
import static org.assertj.core.api.Assertions.assertThat;
@Test
public void select_by_id_fail_if_no_measure_found() {
- expectedException.expect(IllegalArgumentException.class);
+ expectedException.expect(RowNotFoundException.class);
underTest.selectOrFail(session, 42L);
}
import org.sonar.api.utils.System2;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
+import org.sonar.db.util.RowNotFoundException;
import org.sonar.test.DbTests;
import static org.assertj.core.api.Assertions.assertThat;
assertThat(result.isEnabled()).isFalse();
}
- @Test(expected = IllegalStateException.class)
+ @Test(expected = RowNotFoundException.class)
public void get_nullable_by_key() {
dao.selectOrFailByKey(session, "unknown");
}