public long countByTypeAndCreationDate(DbSession dbSession, BranchType branchType, long sinceDate) { return mapper(dbSession).countByTypeAndCreationDate(branchType.name(), sinceDate); }
public boolean hasNonMainBranches(DbSession dbSession) { return mapper(dbSession).countNonMainBranches() > 0L; }
public Collection<BranchDto> selectByComponent(DbSession dbSession, ComponentDto component) { String projectUuid = component.getMainBranchProjectUuid(); if (projectUuid == null) { projectUuid = component.projectUuid(); } return mapper(dbSession).selectByProjectUuid(projectUuid); }
private static Optional<BranchDto> selectByKey(DbSession dbSession, String projectUuid, String key, KeyType keyType) { return Optional.ofNullable(mapper(dbSession).selectByKey(projectUuid, key, keyType)); }
public Optional<BranchDto> selectByUuid(DbSession session, String uuid) { return Optional.ofNullable(mapper(session).selectByUuid(uuid)); }
public int updateMainBranchName(DbSession dbSession, String projectUuid, String newBranchKey) { long now = system2.now(); return mapper(dbSession).updateMainBranchName(projectUuid, newBranchKey, now); }
public void insert(DbSession dbSession, BranchDto dto) { setKeyType(dto); mapper(dbSession).insert(dto, system2.now()); }
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 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 void updateKey(DbSession dbSession, String projectOrModuleUuid, String newKey) { ComponentKeyUpdaterMapper mapper = dbSession.getMapper(ComponentKeyUpdaterMapper.class); if (mapper.countResourceByKey(newKey) > 0) { throw new IllegalArgumentException("Impossible to update key: a component with key \"" + newKey + "\" already exists."); } // must SELECT first everything ResourceDto project = mapper.selectProjectByUuid(projectOrModuleUuid); String projectOldKey = project.getKey(); List<ResourceDto> resources = mapper.selectProjectResources(projectOrModuleUuid); resources.add(project); // add branch components dbSession.getMapper(BranchMapper.class).selectByProjectUuid(projectOrModuleUuid) .stream() .filter(branch -> !projectOrModuleUuid.equals(branch.getUuid())) .forEach(branch -> { resources.addAll(mapper.selectProjectResources(branch.getUuid())); resources.add(mapper.selectProjectByUuid(branch.getUuid())); }); // and then proceed with the batch UPDATE at once runBatchUpdateForAllResources(resources, projectOldKey, newKey, mapper, (resource, oldKey) -> { }); }
session.getMapper(BranchMapper.class).selectByProjectUuid(projectUuid) .stream() .filter(branch -> !projectUuid.equals(branch.getUuid()))
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)); }