/** * Decompressed value of serialized protobuf message {@link org.sonar.db.protobuf.DbFileSources.Data} */ public DbFileSources.Data getSourceData() { return decodeSourceData(binaryData); }
private void insertFileWithData(ComponentDto file, DbFileSources.Data fileData) { db.getDbClient().fileSourceDao().insert(db.getSession(), new FileSourceDto() .setProjectUuid(file.projectUuid()) .setFileUuid(file.uuid()) .setSourceData(fileData)); db.commit(); }
@Test public void insert_does_not_fail_on_FileSourceDto_with_only_non_nullable_data() { FileSourceDto fileSourceDto = new FileSourceDto() .setProjectUuid("Foo") .setFileUuid("Bar") .setCreatedAt(1500000000000L) .setUpdatedAt(1500000000001L); underTest.insert(dbSession, fileSourceDto); dbSession.commit(); }
@Test public void getSourceData_reads_Data_object_bigger_than_default_size_limit() { DbFileSources.Data build = createOver64MBDataStructure(); byte[] bytes = FileSourceDto.encodeSourceData(build); DbFileSources.Data data = new FileSourceDto().decodeSourceData(bytes); assertThat(data.getLinesCount()).isEqualTo(build.getLinesCount()); }
private static void verifyLinesHashes(LineHashesWithKeyDtoHandler handler, ComponentDto file, FileSourceDto fileSource) { LineHashesWithUuidDto dto = handler.getByUuid(file.uuid()).get(); assertThat(dto.getPath()).isEqualTo(file.path()); assertThat(dto.getRawLineHashes()).isEqualTo(fileSource.getRawLineHashes()); assertThat(dto.getLineHashes()).isEqualTo(fileSource.getLineHashes()); }
public FileSourceDto setSourceData(DbFileSources.Data data) { this.binaryData = encodeSourceData(data); return this; }
@CheckForNull public LineHashVersion selectLineHashesVersion(DbSession dbSession, String fileUuid) { Integer version = mapper(dbSession).selectLineHashesVersion(fileUuid); return version == null ? LineHashVersion.WITHOUT_SIGNIFICANT_CODE : LineHashVersion.valueOf(version); }
public int getLineHashesVersion() { return lineHashesVersion != null ? lineHashesVersion : LineHashVersion.WITHOUT_SIGNIFICANT_CODE.getDbValue(); }
@Test public void select_line_hashes() { dbTester.prepareDbUnit(getClass(), "shared.xml"); ReaderToStringConsumer fn = new ReaderToStringConsumer(); underTest.readLineHashesStream(dbSession, "FILE1_UUID", fn); assertThat(fn.result).isEqualTo("ABC\\nDEF\\nGHI"); }
private LineHashesWithKeyDtoHandler scrollLineHashes(String... uuids) { LineHashesWithKeyDtoHandler handler = new LineHashesWithKeyDtoHandler(); underTest.scrollLineHashes(dbSession, ImmutableSet.copyOf(uuids), handler); return handler; }
@CheckForNull public FileSourceDto selectByFileUuid(DbSession session, String fileUuid) { return mapper(session).selectByFileUuid(fileUuid); }
/** * Scroll line hashes of all <strong>enabled</strong> components (should be files, but not enforced) with specified * uuids in no specific order with 'SOURCE' source and a non null path. */ public void scrollLineHashes(DbSession dbSession, Collection<String> fileUUids, ResultHandler<LineHashesWithUuidDto> rowHandler) { for (List<String> partition : toUniqueAndSortedPartitions(fileUUids)) { mapper(dbSession).scrollLineHashes(partition, rowHandler); } }
/** * @return the value of column {@code line_count} if populated, otherwise the size of {@link #getLineHashes()}. */ public int getLineCount() { if (lineCount == LINE_COUNT_NOT_POPULATED) { return getLineHashes().size(); } return lineCount; }
public static LineHashVersion valueOf(int version) { if (version > 1 || version < 0) { throw new IllegalArgumentException("Unknown line hash version: " + version); } return LineHashVersion.values()[version]; } }
private ComponentDto insertFileWithData(DbFileSources.Data fileData, ComponentDto project) { ComponentDto file = insertFile(project); db.getDbClient().fileSourceDao().insert(db.getSession(), new FileSourceDto() .setProjectUuid(project.projectUuid()) .setFileUuid(file.uuid()) .setSourceData(fileData)); db.commit(); return file; }
@Override public int getLineHashesVersion(Component component) { if (significantCodeRepository.getRangesPerLine(component).isPresent()) { return LineHashVersion.WITH_SIGNIFICANT_CODE.getDbValue(); } else { return LineHashVersion.WITHOUT_SIGNIFICANT_CODE.getDbValue(); } }
@Test public void no_line_hashes_when_only_test_data() { dbTester.prepareDbUnit(getClass(), "no_line_hashes_when_only_test_data.xml"); ReaderToStringConsumer fn = new ReaderToStringConsumer(); underTest.readLineHashesStream(dbSession, "FILE1_UUID", fn); assertThat(fn.result).isNull(); }
@Before public void injectFakeLines() throws IOException { FileSourceDto dto = new FileSourceDto(); dto.setFileUuid(FILE_UUID).setProjectUuid("PROJECT_UUID"); dto.setSourceData(FileSourceTesting.newFakeData(10).build()); dbTester.getDbClient().fileSourceDao().insert(dbTester.getSession(), dto); dbTester.commit(); }