public void persist(DbSession dbSession) { Branch branch = analysisMetadataHolder.getBranch(); String branchUuid = treeRootHolder.getRoot().getUuid(); ComponentDto branchComponentDto = dbClient.componentDao().selectByUuid(dbSession, branchUuid) .orElseThrow(() -> new IllegalStateException("Component has been deleted by end-user during analysis")); // insert or update in table project_branches dbClient.branchDao().upsert(dbSession, toBranchDto(branchComponentDto, branch)); }
private BranchDto createMainBranch(DbSession session, String componentUuid) { BranchDto branch = new BranchDto() .setBranchType(BranchType.LONG) .setUuid(componentUuid) .setKey(BranchDto.DEFAULT_MAIN_BRANCH_NAME) .setMergeBranchUuid(null) .setProjectUuid(componentUuid); dbClient.branchDao().upsert(session, branch); return branch; }
@Test public void upsert_branch() { BranchDto dto = new BranchDto(); dto.setProjectUuid("U1"); dto.setUuid("U2"); dto.setBranchType(BranchType.LONG); dto.setKey("foo"); underTest.insert(dbSession, dto); // the fields that can be updated dto.setMergeBranchUuid("U3"); // the fields that can't be updated. New values are ignored. dto.setProjectUuid("ignored"); dto.setBranchType(BranchType.SHORT); underTest.upsert(dbSession, dto); BranchDto loaded = underTest.selectByBranchKey(dbSession, "U1", "foo").get(); assertThat(loaded.getMergeBranchUuid()).isEqualTo("U3"); assertThat(loaded.getProjectUuid()).isEqualTo("U1"); assertThat(loaded.getBranchType()).isEqualTo(BranchType.LONG); }
underTest.upsert(dbSession, dto);
dto.setPullRequestData(pullRequestData); underTest.upsert(dbSession, dto);
public void persist(DbSession dbSession) { Branch branch = analysisMetadataHolder.getBranch(); String branchUuid = treeRootHolder.getRoot().getUuid(); com.google.common.base.Optional<ComponentDto> branchComponentDtoOpt = dbClient.componentDao().selectByUuid(dbSession, branchUuid); ComponentDto branchComponentDto; if (branch.isMain()) { checkState(branchComponentDtoOpt.isPresent(), "Project has been deleted by end-user during analysis"); branchComponentDto = branchComponentDtoOpt.get(); } else { // inserts new row in table projects if it's the first time branch is analyzed branchComponentDto = branchComponentDtoOpt.or(() -> insertIntoProjectsTable(dbSession, branchUuid)); } // insert or update in table project_branches dbClient.branchDao().upsert(dbSession, toBranchDto(branchComponentDto, branch)); }
private BranchDto createBranch(DbSession session, String componentUuid) { BranchDto branch = new BranchDto() .setBranchType(BranchType.LONG) .setUuid(componentUuid) .setKey(BranchDto.DEFAULT_MAIN_BRANCH_NAME) .setMergeBranchUuid(null) .setProjectUuid(componentUuid); dbClient.branchDao().upsert(session, branch); return branch; }