if (unInitializedFileSources != null && unInitializedFileSources > 0) {
MassUpdate massUpdate = context.prepareMassUpdate();
- massUpdate.select("select id,line_hashes from file_sources where line_count = ? and project_uuid = ?")
+ massUpdate.select("select uuid,line_hashes from file_sources where line_count = ? and project_uuid = ?")
.setInt(1, LINE_COUNT_NOT_POPULATED)
.setString(2, componentUuid);
- massUpdate.update("update file_sources set line_count = ? where id = ?");
+ massUpdate.update("update file_sources set line_count = ? where uuid = ?");
massUpdate.rowPluralName("line counts of sources of project " + componentUuid);
massUpdate.execute(PopulateFileSourceLineCount::handle);
}
}
private static boolean handle(Select.Row row, SqlStatement update) throws SQLException {
- int rowId = row.getInt(1);
+ String rowUuid = row.getString(1);
String rawData = row.getNullableString(2);
int lineCount = rawData == null ? 0 : Iterables.size(FileSourceDto.LINES_HASHES_SPLITTER.split(rawData));
update.setInt(1, lineCount);
- update.setInt(2, rowId);
+ update.setString(2, rowUuid);
return true;
}
}
import org.junit.rules.ExpectedException;
import org.sonar.api.utils.System2;
import org.sonar.ce.task.CeTask;
+import org.sonar.core.util.SequenceUuidFactory;
+import org.sonar.core.util.UuidFactory;
import org.sonar.db.DbTester;
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
public ExpectedException expectedException = ExpectedException.none();
@Rule
- public DbTester db = DbTester.createForSchema(System2.INSTANCE, PopulateFileSourceLineCountTest.class, "file_sources.sql");
+ public DbTester db = DbTester.create(System2.INSTANCE);
+
+ private UuidFactory uuidFactory = new SequenceUuidFactory();
private Random random = new Random();
private CeTask ceTask = mock(CeTask.class);
private void insertFileSource(String projectUuid, String fileUuid, @Nullable String lineHashes, int lineCount) {
db.executeInsert(
"FILE_SOURCES",
+ "UUID", uuidFactory.create(),
"PROJECT_UUID", projectUuid,
"FILE_UUID", fileUuid,
"LINE_HASHES", lineHashes,
+++ /dev/null
-CREATE TABLE "FILE_SOURCES" (
- "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
- "PROJECT_UUID" VARCHAR(50) NOT NULL,
- "FILE_UUID" VARCHAR(50) NOT NULL,
- "LINE_HASHES" CLOB,
- "LINE_COUNT" INTEGER NOT NULL,
- "BINARY_DATA" BLOB,
- "DATA_TYPE" VARCHAR(20),
- "DATA_HASH" VARCHAR(50),
- "SRC_HASH" VARCHAR(50),
- "REVISION" VARCHAR(100),
- "CREATED_AT" BIGINT NOT NULL,
- "UPDATED_AT" BIGINT NOT NULL
-);
-CREATE INDEX "FILE_SOURCES_PROJECT_UUID" ON "FILE_SOURCES" ("PROJECT_UUID");
-CREATE UNIQUE INDEX "FILE_SOURCES_UUID_TYPE" ON "FILE_SOURCES" ("FILE_UUID", "DATA_TYPE");
-CREATE INDEX "FILE_SOURCES_UPDATED_AT" ON "FILE_SOURCES" ("UPDATED_AT");
return new DbTester(system2, null, new DbTesterMyBatisConfExtension(firstMapperClass, otherMapperClasses));
}
- public static DbTester createForSchema(System2 system2, Class testClass, String filename) {
- String path = StringUtils.replaceChars(testClass.getCanonicalName(), '.', '/');
- String schemaPath = path + "/" + filename;
- return new DbTester(system2, schemaPath).setDisableDefaultOrganization(true);
- }
-
private void initDbClient() {
TransientPicoContainer ioc = new TransientPicoContainer();
ioc.addComponent(db.getMyBatis());