private Optional<ComponentDto> selectProjectById(DbSession dbSession, @Nullable String projectId) { if (projectId == null) { return Optional.empty(); } try { long dbId = Long.parseLong(projectId); return Optional.ofNullable(dbClient.componentDao().selectById(dbSession, dbId).orElse(null)); } catch (NumberFormatException e) { return Optional.empty(); } }
private Optional<ComponentDto> selectProjectById(DbSession dbSession, @Nullable String projectId) { if (projectId == null) { return Optional.empty(); } try { long dbId = Long.parseLong(projectId); return Optional.ofNullable(dbClient.componentDao().selectById(dbSession, dbId).orElse(null)); } catch (NumberFormatException e) { return Optional.empty(); } }
private Optional<ComponentDto> getProjectByKeyOrId(DbSession dbSession, String component) { try { long componentId = Long.parseLong(component); return ofNullable(dbClient.componentDao().selectById(dbSession, componentId).orElse(null)); } catch (NumberFormatException e) { return ofNullable(dbClient.componentDao().selectByKey(dbSession, component).orElse(null)); } }
private Optional<ComponentDto> loadComponent(DbSession dbSession, String component) { try { long componentId = Long.parseLong(component); return Optional.ofNullable(dbClient.componentDao().selectById(dbSession, componentId).orElse(null)); } catch (NumberFormatException e) { return Optional.ofNullable(dbClient.componentDao().selectByKey(dbSession, component).orElse(null)); } }
@Test public void get_nullable_by_id() { ComponentDto project = db.components().insertPrivateProject(); assertThat(underTest.selectById(dbSession, project.getId())).isPresent(); assertThat(underTest.selectById(dbSession, 0L)).isEmpty(); }
@Test public void get_by_id() { ComponentDto project = db.components().insertPrivateProject(); assertThat(underTest.selectById(dbSession, project.getId())).isNotNull(); }
@Test public void get_by_id_on_disabled_component() { ComponentDto enabledProject = db.components().insertPrivateProject(); ComponentDto disabledProject = db.components().insertPrivateProject(p -> p.setEnabled(false)); Optional<ComponentDto> result = underTest.selectById(dbSession, disabledProject.getId()); assertThat(result).isPresent(); assertThat(result.get().isEnabled()).isFalse(); }
private Optional<ComponentDto> selectProjectById(DbSession dbSession, @Nullable String projectId) { if (projectId == null) { return Optional.empty(); } try { long dbId = Long.parseLong(projectId); return Optional.ofNullable(dbClient.componentDao().selectById(dbSession, dbId).orNull()); } catch (NumberFormatException e) { return Optional.empty(); } }
public ComponentDto selectOrFailById(DbSession session, long id) { Optional<ComponentDto> componentDto = selectById(session, id); if (!componentDto.isPresent()) { throw new RowNotFoundException(String.format("Component id does not exist: %d", id)); } return componentDto.get(); }
private Optional<ComponentDto> selectProjectById(DbSession dbSession, @Nullable String projectId) { if (projectId == null) { return Optional.empty(); } try { long dbId = Long.parseLong(projectId); return Optional.ofNullable(dbClient.componentDao().selectById(dbSession, dbId).orNull()); } catch (NumberFormatException e) { return Optional.empty(); } }
private Optional<ComponentDto> loadComponent(DbSession dbSession, String component) { try { Long componentId = Long.parseLong(component); return Optional.ofNullable(dbClient.componentDao().selectById(dbSession, componentId).orNull()); } catch (NumberFormatException e) { return Optional.ofNullable(dbClient.componentDao().selectByKey(dbSession, component).orNull()); } }
private Optional<ComponentDto> getProjectByKeyOrId(DbSession dbSession, String component) { try { Long componentId = Long.parseLong(component); return ofNullable(dbClient.componentDao().selectById(dbSession, componentId).orNull()); } catch (NumberFormatException e) { return ofNullable(dbClient.componentDao().selectByKey(dbSession, component).orNull()); } }