You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TrackerBaseInputFactory.java 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * SonarQube, open source software quality management tool.
  3. * Copyright (C) 2008-2014 SonarSource
  4. * mailto:contact AT sonarsource DOT com
  5. *
  6. * SonarQube is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * SonarQube is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonar.server.computation.issue;
  21. import com.google.common.base.Objects;
  22. import java.util.Collections;
  23. import java.util.List;
  24. import org.sonar.core.issue.DefaultIssue;
  25. import org.sonar.core.issue.tracking.Input;
  26. import org.sonar.core.issue.tracking.LazyInput;
  27. import org.sonar.core.issue.tracking.LineHashSequence;
  28. import org.sonar.db.DbSession;
  29. import org.sonar.db.MyBatis;
  30. import org.sonar.server.computation.component.Component;
  31. import org.sonar.server.db.DbClient;
  32. /**
  33. * Factory of {@link Input} of base data for issue tracking. Data are lazy-loaded.
  34. */
  35. public class TrackerBaseInputFactory {
  36. private final BaseIssuesLoader baseIssuesLoader;
  37. private final DbClient dbClient;
  38. public TrackerBaseInputFactory(BaseIssuesLoader baseIssuesLoader, DbClient dbClient) {
  39. this.baseIssuesLoader = baseIssuesLoader;
  40. this.dbClient = dbClient;
  41. }
  42. public Input<DefaultIssue> create(Component component) {
  43. return new BaseLazyInput(component);
  44. }
  45. private class BaseLazyInput extends LazyInput<DefaultIssue> {
  46. private final Component component;
  47. private BaseLazyInput(Component component) {
  48. this.component = component;
  49. }
  50. @Override
  51. protected LineHashSequence loadLineHashSequence() {
  52. DbSession session = dbClient.openSession(false);
  53. try {
  54. List<String> hashes = dbClient.fileSourceDao().selectLineHashes(session, component.getUuid());
  55. return new LineHashSequence(Objects.firstNonNull(hashes, Collections.<String>emptyList()));
  56. } finally {
  57. MyBatis.closeQuietly(session);
  58. }
  59. }
  60. @Override
  61. protected List<DefaultIssue> loadIssues() {
  62. return baseIssuesLoader.loadForComponentUuid(component.getUuid());
  63. }
  64. }
  65. }