/** * Remove a group from all templates (used when removing a group) */ public void deleteByGroup(DbSession session, int groupId) { session.getMapper(PermissionTemplateMapper.class).deleteByGroupId(groupId); }
/** * @return a non-null list ordered by key (as implemented by database, order may * depend on case sensitivity) */ public List<RuleRepositoryDto> selectAll(DbSession dbSession) { return dbSession.getMapper(RuleRepositoryMapper.class).selectAll(); }
/** * @return a non-null list ordered by key (as implemented by database, order may * depend on case sensitivity) */ public List<RuleRepositoryDto> selectByLanguage(DbSession dbSession, String language) { return dbSession.getMapper(RuleRepositoryMapper.class).selectByLanguage(language); }
/** * @param analysisUuid snapshot id of the project from the previous analysis (islast=true) */ public List<DuplicationUnitDto> selectCandidates(DbSession session, @Nullable String analysisUuid, String language, Collection<String> hashes) { return executeLargeInputs( hashes, partition -> session.getMapper(DuplicationMapper.class).selectCandidates(analysisUuid, language, partition)); }
public List<NotificationQueueDto> selectOldest(int count) { if (count < 1) { return Collections.emptyList(); } try (DbSession session = mybatis.openSession(false)) { return session.getMapper(NotificationQueueMapper.class).findOldest(count); } }
public long count() { try (DbSession session = mybatis.openSession(false)) { return session.getMapper(NotificationQueueMapper.class).count(); } } }
private void setPrivateForRootComponentUuid(DbSession dbSession, String uuid, boolean isPrivate) { dbClient.componentDao().setPrivateForRootComponentUuid(dbSession, uuid, isPrivate); ComponentMapper mapper = dbSession.getMapper(ComponentMapper.class); dbSession.getMapper(BranchMapper.class).selectByProjectUuid(uuid) .stream() .filter(branch -> !uuid.equals(branch.getUuid())) .forEach(branch -> mapper.setPrivateForRootComponentUuid(branch.getUuid(), isPrivate)); }
public void insert(List<NotificationQueueDto> dtos) { try (DbSession session = mybatis.openSession(true)) { NotificationQueueMapper mapper = session.getMapper(NotificationQueueMapper.class); for (NotificationQueueDto dto : dtos) { mapper.insert(dto); } session.commit(); } }
public void deleteProject(DbSession session, String uuid) { PurgeProfiler profiler = new PurgeProfiler(); PurgeMapper purgeMapper = mapper(session); PurgeCommands purgeCommands = new PurgeCommands(session, profiler); session.getMapper(BranchMapper.class).selectByProjectUuid(uuid) .stream() .filter(branch -> !uuid.equals(branch.getUuid())) .forEach(branch -> deleteRootComponent(branch.getUuid(), purgeMapper, purgeCommands)); deleteRootComponent(uuid, purgeMapper, purgeCommands); }
public ProjectLinkDto insert(DbSession session, ProjectLinkDto dto) { long now = system2.now(); session.getMapper(ProjectLinkMapper.class).insert(dto.setCreatedAt(now).setUpdatedAt(now)); return dto; }
public void delete(List<NotificationQueueDto> dtos) { try (DbSession session = mybatis.openSession(true)) { NotificationQueueMapper mapper = session.getMapper(NotificationQueueMapper.class); for (NotificationQueueDto dto : dtos) { mapper.delete(dto.getId()); } session.commit(); } }
public static void makeInProgress(DbSession dbSession, String workerUuid, long now, CeQueueDto... ceQueueDtos) { Stream.of(ceQueueDtos).forEach(ceQueueDto -> { CeQueueMapper mapper = dbSession.getMapper(CeQueueMapper.class); int touchedRows = mapper.updateIf(ceQueueDto.getUuid(), new UpdateIf.NewProperties(IN_PROGRESS, workerUuid, now, now), new UpdateIf.OldProperties(PENDING)); assertThat(touchedRows).isEqualTo(1); }); }
private static void ensureGroupPermissionConsistency(DbSession dbSession, GroupPermissionDto dto) { if (dto.getGroupId() == null) { return; } GroupMapper groupMapper = dbSession.getMapper(GroupMapper.class); checkArgument( groupMapper.countGroupByOrganizationAndId(dto.getOrganizationUuid(), dto.getGroupId()) == 1, "Can't insert permission '%s' for group with id '%s' in organization with uuid '%s' because this group does not belong to organization with uuid '%s'", dto.getRole(), dto.getGroupId(), dto.getOrganizationUuid(), dto.getOrganizationUuid()); }
private static void ensureComponentPermissionConsistency(DbSession dbSession, GroupPermissionDto dto) { if (dto.getResourceId() == null) { return; } ComponentMapper componentMapper = dbSession.getMapper(ComponentMapper.class); checkArgument( componentMapper.countComponentByOrganizationAndId(dto.getOrganizationUuid(), dto.getResourceId()) == 1, "Can't insert permission '%s' for component with id '%s' in organization with uuid '%s' because this component does not belong to organization with uuid '%s'", dto.getRole(), dto.getResourceId(), dto.getOrganizationUuid(), dto.getOrganizationUuid()); }
public static void reset(DbSession dbSession, long now, CeQueueDto... ceQueueDtos) { Stream.of(ceQueueDtos).forEach(ceQueueDto -> { checkArgument(ceQueueDto.getStatus() == IN_PROGRESS); checkArgument(ceQueueDto.getWorkerUuid() != null); CeQueueMapper mapper = dbSession.getMapper(CeQueueMapper.class); int touchedRows = mapper.updateIf(ceQueueDto.getUuid(), new UpdateIf.NewProperties(PENDING, ceQueueDto.getUuid(), now, now), new UpdateIf.OldProperties(IN_PROGRESS)); assertThat(touchedRows).isEqualTo(1); }); } }
@Before public void setUp() throws Exception { dbSession = db.getDbClient().openSession(false); purgeMapper = dbSession.getMapper(PurgeMapper.class); }
@Before public void setUp() { session = dbTester.myBatis().openSession(false); underTest = session.getMapper(IsAliveMapper.class); }
public void deleteByOrganization(DbSession dbSession, String organizationUuid) { PermissionTemplateMapper templateMapper = mapper(dbSession); PermissionTemplateCharacteristicMapper templateCharacteristicMapper = dbSession.getMapper(PermissionTemplateCharacteristicMapper.class); List<Long> templateIds = templateMapper.selectTemplateIdsByOrganization(organizationUuid); executeLargeInputsWithoutOutput(templateIds, subList -> { templateCharacteristicMapper.deleteByTemplateIds(subList); templateMapper.deleteGroupPermissionsByTemplateIds(subList); templateMapper.deleteUserPermissionsByTemplateIds(subList); templateMapper.deleteByIds(subList); }); } }
@Test public void shouldOpenBatchSession() { underTest.start(); try (DbSession session = underTest.openSession(false)) { assertThat(session.getConnection(), notNullValue()); assertThat(session.getMapper(RuleMapper.class), notNullValue()); } } }
public void purge(DbSession session, PurgeConfiguration conf, PurgeListener listener, PurgeProfiler profiler) { PurgeMapper mapper = session.getMapper(PurgeMapper.class); PurgeCommands commands = new PurgeCommands(session, mapper, profiler); String rootUuid = conf.rootProjectIdUuid().getUuid(); deleteAbortedAnalyses(rootUuid, commands); deleteDataOfComponentsWithoutHistoricalData(session, rootUuid, conf.getScopesWithoutHistoricalData(), commands); purgeAnalyses(commands, rootUuid); purgeDisabledComponents(session, conf, listener); deleteOldClosedIssues(conf, mapper, listener); purgeStaleBranches(commands, conf, mapper, rootUuid); }