/** * On MySQL, as PROJECTS.KEE is not unique, if the same project is provisioned multiple times, then it will be duplicated in the database. * So, after creating a project, we commit, and we search in the db if their are some duplications and we remove them. * * SONAR-6332 */ private void removeDuplicatedProjects(DbSession session, String projectKey) { List<ComponentDto> duplicated = dbClient.componentDao().selectComponentsHavingSameKeyOrderedById(session, projectKey); for (int i = 1; i < duplicated.size(); i++) { dbClient.componentDao().delete(session, duplicated.get(i).getId()); } }
@Test public void return_nothing() { assertThat(underTest.selectComponentsHavingSameKeyOrderedById(db.getSession(), PROJECT_KEY)).isEmpty(); }
@Test public void select_components_having_same_key() { OrganizationDto organizationDto = db.organizations().insert(); insertProject(ComponentTesting.newPrivateProjectDto(organizationDto).setDbKey(PROJECT_KEY)); insertProject(ComponentTesting.newPrivateProjectDto(organizationDto).setDbKey(PROJECT_KEY)); insertProject(ComponentTesting.newPrivateProjectDto(organizationDto).setDbKey(PROJECT_KEY)); insertProject(ComponentTesting.newPrivateProjectDto(organizationDto).setDbKey("ANOTHER_PROJECT_KEY")); assertThat(underTest.selectComponentsHavingSameKeyOrderedById(db.getSession(), PROJECT_KEY)).hasSize(3); }
/** * On MySQL, as PROJECTS.KEE is not unique, if the same project is provisioned multiple times, then it will be duplicated in the database. * So, after creating a project, we commit, and we search in the db if their are some duplications and we remove them. * * SONAR-6332 */ private void removeDuplicatedProjects(DbSession session, String projectKey) { List<ComponentDto> duplicated = dbClient.componentDao().selectComponentsHavingSameKeyOrderedById(session, projectKey); for (int i = 1; i < duplicated.size(); i++) { dbClient.componentDao().delete(session, duplicated.get(i).getId()); } }