import org.apache.ibatis.session.RowBounds;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
-import org.sonar.db.RowNotFoundException;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.FluentIterable.from;
return mapper(session).selectByKey(id);
}
- /**
- * @deprecated use {@link #selectByUuid(DbSession, String)}
- */
- @Deprecated
- public SnapshotDto selectOrFailById(DbSession session, long id) {
- SnapshotDto value = selectById(session, id);
- if (value == null) {
- throw new RowNotFoundException(String.format("Snapshot id does not exist: %d", id));
- }
- return value;
- }
-
- public List<SnapshotDto> selectByIds(DbSession dbSession, Collection<Long> snapshotIds) {
- return executeLargeInputs(snapshotIds, mapper(dbSession)::selectByIds);
- }
-
public Optional<SnapshotDto> selectByUuid(DbSession dbSession, String analysisUuid) {
List<SnapshotDto> dtos = mapper(dbSession).selectByUuids(Collections.singletonList(analysisUuid));
if (dtos.isEmpty()) {
@CheckForNull
SnapshotDto selectByKey(long id);
- List<SnapshotDto> selectByIds(@Param("ids") List<Long> ids);
-
List<SnapshotDto> selectByUuids(@Param("uuids") List<String> uuids);
void insert(SnapshotDto snapshot);
where s.id=#{key,jdbcType=BIGINT}
</select>
- <select id="selectByIds" parameterType="Long" resultType="Snapshot">
- SELECT
- <include refid="snapshotColumns" />
- FROM
- snapshots s
- WHERE
- s.id in
- <foreach collection="ids" item="id" separator="," open="(" close=")">
- #{id,jdbcType=BIGINT}
- </foreach>
- </select>
-
<select id="selectByUuids" parameterType="List" resultType="Snapshot">
SELECT
<include refid="snapshotColumns"/>
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
-import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.organization.OrganizationTesting;
import static com.google.common.collect.Lists.newArrayList;
assertThat(underTest.selectById(db.getSession(), 999L)).isNull();
}
- @Test
- public void test_selectByIds() {
- OrganizationDto organizationDto = db.organizations().insert();
- SnapshotDto snapshot1 = componentDb.insertProjectAndSnapshot(newProjectDto(organizationDto));
- SnapshotDto snapshot2 = componentDb.insertProjectAndSnapshot(newProjectDto(organizationDto));
- SnapshotDto snapshot3 = componentDb.insertProjectAndSnapshot(newProjectDto(organizationDto));
-
- List<SnapshotDto> result = underTest.selectByIds(dbSession, newArrayList(snapshot1.getId(), snapshot2.getId(), snapshot3.getId(), 42L));
-
- assertThat(result).hasSize(3);
- assertThat(result).extracting("id").containsOnly(snapshot1.getId(), snapshot2.getId(), snapshot3.getId());
- }
-
@Test
public void selectLastSnapshotByRootComponentUuid_returns_absent_when_no_last_snapshot() {
Optional<SnapshotDto> snapshot = underTest.selectLastAnalysisByRootComponentUuid(db.getSession(), "uuid_123");