import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
+import java.util.concurrent.*;
public class JavaCpdEngine extends CpdEngine {
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.computation;
+
+import org.sonar.core.computation.db.AnalysisReportDto;
+
+import java.util.concurrent.TimeUnit;
+
+public class AnalysisReportTask extends Thread {
+ private static final String TASK_NAME = "AnalysisReportTask";
+ private static final int SLEEP_DURATION_IN_SECONDS = 10;
+
+ private final ComputationService service;
+
+ // TODO to improve – the computationService singleton should be retrieved directly in the pico container
+ public AnalysisReportTask(ComputationService service) {
+ super(TASK_NAME);
+ this.service = service;
+ }
+
+ @Override
+ public void run() {
+ while (!this.isInterrupted()) {
+ AnalysisReportDto report = service.findAndBookNextAnalysisReport();
+ if (report == null) {
+ sleepBeforeNextAttempt();
+ } else {
+ service.analyzeReport(report);
+ }
+ }
+ }
+
+ private void sleepBeforeNextAttempt() {
+ try {
+ TimeUnit.SECONDS.sleep(SLEEP_DURATION_IN_SECONDS);
+ } catch (InterruptedException e) {
+ // thread interrupted while sleeping, no action needed
+ }
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.computation;
+
+import org.picocontainer.Startable;
+import org.sonar.api.ServerComponent;
+import org.sonar.api.platform.ServerUpgradeStatus;
+import org.sonar.core.persistence.DbSession;
+import org.sonar.core.persistence.MyBatis;
+import org.sonar.server.computation.db.AnalysisReportDao;
+import org.sonar.server.db.DbClient;
+
+public class AnalysisReportTaskCleaner implements Startable, ServerComponent {
+ private final ServerUpgradeStatus serverUpgradeStatus;
+ private final DbClient dbClient;
+
+ public AnalysisReportTaskCleaner(ServerUpgradeStatus serverUpgradeStatus, DbClient dbClient) {
+ this.serverUpgradeStatus = serverUpgradeStatus;
+ this.dbClient = dbClient;
+ }
+
+ @Override
+ public void start() {
+ DbSession session = dbClient.openSession(false);
+ AnalysisReportDao dao = dbClient.analysisReportDao();
+
+ try {
+ if (serverUpgradeStatus.isUpgraded()) {
+ dao.cleanWithTruncate(session);
+ } else {
+ dao.cleanWithUpdateAllToPendingStatus(session);
+ }
+
+ session.commit();
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+
+ @Override
+ public void stop() {
+ // do nothing
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.computation;
+
+import org.picocontainer.Startable;
+import org.sonar.api.ServerComponent;
+
+public class AnalysisReportTaskLauncher implements Startable, ServerComponent {
+
+ private final ComputationService service;
+
+ private AnalysisReportTask task;
+
+ public AnalysisReportTaskLauncher(ComputationService service) {
+ this.service = service;
+ }
+
+ @Override
+ public void start() {
+ task = new AnalysisReportTask(service);
+ task.start();
+ }
+
+ @Override
+ public void stop() {
+ task.interrupt();
+ }
+
+}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.computation;
-
-import org.picocontainer.Startable;
-import org.sonar.api.ServerComponent;
-import org.sonar.api.platform.ServerUpgradeStatus;
-import org.sonar.core.persistence.DbSession;
-import org.sonar.core.persistence.MyBatis;
-import org.sonar.server.computation.db.AnalysisReportDao;
-import org.sonar.server.db.DbClient;
-
-public class AnalysisReportTasksCleaner implements Startable, ServerComponent {
- private final ServerUpgradeStatus serverUpgradeStatus;
- private final DbClient dbClient;
-
- public AnalysisReportTasksCleaner(ServerUpgradeStatus serverUpgradeStatus, DbClient dbClient) {
- this.serverUpgradeStatus = serverUpgradeStatus;
- this.dbClient = dbClient;
- }
-
- @Override
- public void start() {
- DbSession session = dbClient.openSession(false);
- AnalysisReportDao dao = dbClient.analysisReportDao();
-
- try {
- if (serverUpgradeStatus.isUpgraded()) {
- dao.cleanWithTruncate(session);
- } else {
- dao.cleanWithUpdateAllToPendingStatus(session);
- }
-
- session.commit();
- } finally {
- MyBatis.closeQuietly(session);
- }
- }
-
- @Override
- public void stop() {
- // do nothing
- }
-}
* since 5.0
*/
public class ComputationService implements ServerComponent {
- private DbClient dbClient;
+ private final DbClient dbClient;
+ private final AnalysisReportDao dao;
public ComputationService(DbClient dbClient) {
this.dbClient = dbClient;
+ dao = this.dbClient.analysisReportDao();
}
public void create(String projectKey) {
.setProjectKey(projectKey)
.setStatus(PENDING);
- AnalysisReportDao dao = dbClient.analysisReportDao();
-
DbSession session = dbClient.openSession(false);
try {
dao.insert(session, report);
}
public List<AnalysisReportDto> findByProjectKey(String projectKey) {
- AnalysisReportDao dao = dbClient.analysisReportDao();
-
DbSession session = dbClient.openSession(false);
try {
return dao.findByProjectKey(session, projectKey);
MyBatis.closeQuietly(session);
}
}
+
+ public AnalysisReportDto findAndBookNextAnalysisReport() {
+ // TODO TBE – implementation needed
+ return null;
+ }
+
+ public void analyzeReport(AnalysisReportDto report) {
+ // TODO TBE – implementation needed
+ }
}
import com.google.common.annotations.VisibleForTesting;
import org.sonar.api.utils.System2;
import org.sonar.core.computation.db.AnalysisReportDto;
-import org.sonar.core.computation.db.AnalysisReportDto.Status;
import org.sonar.core.computation.db.AnalysisReportMapper;
import org.sonar.core.persistence.DaoComponent;
import org.sonar.core.persistence.DbSession;
import java.util.List;
import java.util.Map;
+import static org.sonar.core.computation.db.AnalysisReportDto.Status.PENDING;
+import static org.sonar.core.computation.db.AnalysisReportDto.Status.WORKING;
+
public class AnalysisReportDao extends BaseDao<AnalysisReportMapper, AnalysisReportDto, String> implements DaoComponent {
private System2 system2;
* startup task use only
*/
public void cleanWithUpdateAllToPendingStatus(DbSession session) {
- mapper(session).cleanWithUpdateAllToPendingStatus(Status.PENDING, new Date(system2.now()));
+ mapper(session).cleanWithUpdateAllToPendingStatus(PENDING, new Date(system2.now()));
}
/**
return mapper(session).selectByProjectKey(projectKey);
}
+ public AnalysisReportDto getNextAvailableReport(DbSession session) {
+ // TODO to improve – the query should return one element or null
+ List<AnalysisReportDto> reports = mapper(session).selectNextAvailableReport(PENDING, WORKING);
+
+ if (reports.isEmpty()) {
+ return null;
+ }
+
+ return reports.get(0);
+ }
+
+ public int tryToBookReport(DbSession session, AnalysisReportDto report) {
+ // checkArgument(report.getId() != null);
+ //
+ // report.setStatus(WORKING);
+ //
+ // return mapper(session).update(report);
+ throw new UnsupportedOperationException();
+ }
+
@Override
protected AnalysisReportDto doGetNullableByKey(DbSession session, String projectKey) {
throw new UnsupportedOperationException();
}
@Override
- protected AnalysisReportDto doUpdate(DbSession session, AnalysisReportDto issue) {
+ protected AnalysisReportDto doUpdate(DbSession session, AnalysisReportDto report) {
+ // int nbOfReportsChanged = mapper(session).update(report);
+ // checkState(nbOfReportsChanged < 2);
+ //
+ // if (nbOfReportsChanged == 0) {
+ // return null;
+ // }
+ //
+ // return report;
throw new UnsupportedOperationException();
}
import org.sonar.server.component.db.ComponentDao;
import org.sonar.server.component.db.SnapshotDao;
import org.sonar.server.component.ws.*;
-import org.sonar.server.computation.AnalysisReportTasksCleaner;
+import org.sonar.server.computation.AnalysisReportTaskCleaner;
import org.sonar.server.computation.ComputationService;
import org.sonar.server.computation.db.AnalysisReportDao;
import org.sonar.server.config.ws.PropertiesWs;
startupContainer.addSingleton(RegisterServletFilters.class);
startupContainer.addSingleton(CleanPreviewAnalysisCache.class);
startupContainer.addSingleton(CopyRequirementsFromCharacteristicsToRules.class);
- startupContainer.addSingleton(AnalysisReportTasksCleaner.class);
+ startupContainer.addSingleton(AnalysisReportTaskCleaner.class);
DoPrivileged.execute(new DoPrivileged.Task() {
@Override
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.computation;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.api.platform.ServerUpgradeStatus;
+import org.sonar.core.persistence.DbSession;
+import org.sonar.server.computation.db.AnalysisReportDao;
+import org.sonar.server.db.DbClient;
+
+import static org.mockito.Mockito.*;
+
+public class AnalysisReportTaskCleanerTest {
+
+ AnalysisReportTaskCleaner sut;
+ ServerUpgradeStatus serverUpgradeStatus;
+ DbClient dbClient;
+ AnalysisReportDao analysisReportDao;
+ DbSession session;
+
+ @Before
+ public void before() {
+ analysisReportDao = mock(AnalysisReportDao.class);
+ serverUpgradeStatus = mock(ServerUpgradeStatus.class);
+ dbClient = mock(DbClient.class);
+ session = mock(DbSession.class);
+
+ when(dbClient.analysisReportDao()).thenReturn(analysisReportDao);
+ when(dbClient.openSession(false)).thenReturn(session);
+
+ sut = new AnalysisReportTaskCleaner(serverUpgradeStatus, dbClient);
+ }
+
+ @Test
+ public void start_must_call_dao_clean_update_to_pending_by_default() {
+ sut.start();
+ verify(analysisReportDao).cleanWithUpdateAllToPendingStatus(any(DbSession.class));
+ sut.stop();
+ }
+
+ @Test
+ public void start_must_call_dao_truncate_when_upgrading() {
+ when(serverUpgradeStatus.isUpgraded()).thenReturn(Boolean.TRUE);
+ sut.start();
+ verify(analysisReportDao).cleanWithTruncate(any(DbSession.class));
+ sut.stop();
+ }
+}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.computation;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.api.platform.ServerUpgradeStatus;
-import org.sonar.core.persistence.DbSession;
-import org.sonar.server.computation.db.AnalysisReportDao;
-import org.sonar.server.db.DbClient;
-
-import static org.mockito.Mockito.*;
-
-public class AnalysisReportTasksCleanerTest {
-
- AnalysisReportTasksCleaner sut;
- ServerUpgradeStatus serverUpgradeStatus;
- DbClient dbClient;
- AnalysisReportDao analysisReportDao;
- DbSession session;
-
- @Before
- public void before() {
- analysisReportDao = mock(AnalysisReportDao.class);
- serverUpgradeStatus = mock(ServerUpgradeStatus.class);
- dbClient = mock(DbClient.class);
- session = mock(DbSession.class);
-
- when(dbClient.analysisReportDao()).thenReturn(analysisReportDao);
- when(dbClient.openSession(false)).thenReturn(session);
-
- sut = new AnalysisReportTasksCleaner(serverUpgradeStatus, dbClient);
- }
-
- @Test
- public void start_must_call_dao_clean_update_to_pending_by_default() {
- sut.start();
- verify(analysisReportDao).cleanWithUpdateAllToPendingStatus(any(DbSession.class));
- sut.stop();
- }
-
- @Test
- public void start_must_call_dao_truncate_when_upgrading() {
- when(serverUpgradeStatus.isUpgraded()).thenReturn(Boolean.TRUE);
- sut.start();
- verify(analysisReportDao).cleanWithTruncate(any(DbSession.class));
- sut.stop();
- }
-}
import org.sonar.server.db.DbClient;
import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
}
@Test
- public void create_must_call_dao_insert() throws Exception {
+ public void create_must_call_dao_insert() {
sut.create("ANY-KEY");
verify(analysisReportDao).insert(any(DbSession.class), any(AnalysisReportDto.class));
}
+
+ @Test
+ public void findByProjectKey_call_corresponding_dao() {
+ sut.findByProjectKey("ANY_STRING");
+ verify(analysisReportDao).findByProjectKey(any(DbSession.class), anyString());
+ }
+
+ @Test
+ public void test_unimplemented_methods_for_code_coverage_purpose_only() {
+ sut.analyzeReport(new AnalysisReportDto());
+ sut.findAndBookNextAnalysisReport();
+ }
+
}
\ No newline at end of file
import org.sonar.core.persistence.DbSession;
import org.sonar.core.persistence.TestDatabase;
+import java.util.Date;
+import java.util.HashMap;
import java.util.List;
import static org.fest.assertions.Assertions.assertThat;
}
@Test
- public void select_one_report_by_project_key() {
+ public void find_one_report_by_project_key() {
db.prepareDbUnit(getClass(), "select.xml");
final String projectKey = "123456789-987654321";
}
@Test
- public void select_several_reports_by_project_key() {
+ public void find_several_reports_by_project_key() {
db.prepareDbUnit(getClass(), "select.xml");
final String projectKey = "987654321-123456789";
assertThat(reports).hasSize(2);
}
+
+ @Test
+ public void get_oldest_available_report() {
+ db.prepareDbUnit(getClass(), "select_oldest_available_report.xml");
+
+ final String projectKey = "123456789-987654321";
+ AnalysisReportDto nextAvailableReport = dao.getNextAvailableReport(session);
+
+ assertThat(nextAvailableReport.getId()).isEqualTo(2);
+ assertThat(nextAvailableReport.getProjectKey()).isEqualTo(projectKey);
+ }
+
+ @Test
+ public void get_oldest_available_report_with_working_reports_older() {
+ db.prepareDbUnit(getClass(), "select_oldest_available_report_with_working_reports_older.xml");
+
+ final String projectKey = "123456789-987654321";
+ AnalysisReportDto nextAvailableReport = dao.getNextAvailableReport(session);
+
+ assertThat(nextAvailableReport.getId()).isEqualTo(2);
+ assertThat(nextAvailableReport.getProjectKey()).isEqualTo(projectKey);
+ }
+
+ @Test
+ public void null_when_no_available_pending_report_because_working_report_on_the_same_project() {
+ db.prepareDbUnit(getClass(), "select-with-no-available-report.xml");
+
+ AnalysisReportDto nextAvailableReport = dao.getNextAvailableReport(session);
+
+ assertThat(nextAvailableReport).isNull();
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void doGetNullableByKey_is_not_implemented_yet() {
+ dao.doGetNullableByKey(session, "ANY_STRING");
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void getSynchronizationParams_is_not_implemented_yet() {
+ dao.getSynchronizationParams(new Date(), new HashMap<String, String>());
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void doUpdate_is_not_implemented_yet() {
+ dao.doUpdate(session, new AnalysisReportDto());
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void tryToBookReport_is_not_implemented_yet() {
+ dao.tryToBookReport(session, new AnalysisReportDto());
+ }
+
}
--- /dev/null
+<dataset>
+ <analysis_reports
+ id="1"
+ project_key="111111111-987654321"
+ report_data="data-project"
+ report_status="WORKING"
+ created_at="2014-09-25"
+ updated_at="2014-09-26"
+ />
+ <analysis_reports
+ id="2"
+ project_key="123456789-987654321"
+ report_data="data-project"
+ report_status="WORKING"
+ created_at="2014-09-24"
+ updated_at="2014-09-26"
+ />
+ <!-- not select as the previous report which is working is on the same project -->
+ <analysis_reports
+ id="3"
+ project_key="123456789-987654321"
+ report_data="data-project"
+ report_status="PENDING"
+ created_at="2014-09-25"
+ updated_at="2014-09-26"
+ />
+</dataset>
\ No newline at end of file
--- /dev/null
+<dataset>
+ <analysis_reports
+ id="1"
+ project_key="111111111-987654321"
+ report_data="data-project"
+ report_status="PENDING"
+ created_at="2014-09-25"
+ updated_at="2014-09-26"
+ />
+ <analysis_reports
+ id="2"
+ project_key="123456789-987654321"
+ report_data="data-project"
+ report_status="PENDING"
+ created_at="2014-09-24"
+ updated_at="2014-09-26"
+ />
+ <analysis_reports
+ id="3"
+ project_key="333333333-123456789"
+ report_data="data-project"
+ report_status="PENDING"
+ created_at="2014-09-25"
+ updated_at="2014-09-26"
+ />
+</dataset>
\ No newline at end of file
--- /dev/null
+<dataset>
+ <analysis_reports
+ id="1"
+ project_key="111111111-987654321"
+ report_data="data-project"
+ report_status="WORKING"
+ created_at="2014-09-23"
+ updated_at="2014-09-26"
+ />
+ <analysis_reports
+ id="2"
+ project_key="123456789-987654321"
+ report_data="data-project"
+ report_status="PENDING"
+ created_at="2014-09-24"
+ updated_at="2014-09-26"
+ />
+ <analysis_reports
+ id="3"
+ project_key="333333333-123456789"
+ report_data="data-project"
+ report_status="WORKING"
+ created_at="2014-09-25"
+ updated_at="2014-09-26"
+ />
+</dataset>
\ No newline at end of file
import javax.annotation.Nullable;
-/**
- * since 5.0
- */
public class AnalysisReportDto extends Dto<String> {
private Long id;
private Status status;
private String data;
- public enum Status {
- PENDING, WORKING
- }
-
public String getProjectKey() {
return projectKey;
}
return id;
}
- public AnalysisReportDto setId(Long id) {
- this.id = id;
- return this;
+ public enum Status {
+ PENDING, WORKING
}
}
import org.apache.ibatis.annotations.Param;
import java.util.Date;
+import java.util.List;
-/**
- * since 5.0
- */
public interface AnalysisReportMapper {
void insert(AnalysisReportDto report);
- java.util.List<AnalysisReportDto> selectByProjectKey(String projectKey);
+ List<AnalysisReportDto> selectByProjectKey(String projectKey);
+
+ List<AnalysisReportDto> selectNextAvailableReport(@Param("availableStatus") AnalysisReportDto.Status availableStatus, @Param("busyStatus") AnalysisReportDto.Status busyStatus);
/**
* startup task use only
* startup task use only
*/
void cleanWithTruncate();
+
+ int update(AnalysisReportDto report);
}
<mapper namespace="org.sonar.core.computation.db.AnalysisReportMapper">
<sql id="reportColumns">
- id,
- project_key as projectKey,
- report_status as status,
- report_data as data,
- created_at as createdAt,
- updated_at as updatedAt
+ ar.id,
+ ar.project_key as projectKey,
+ ar.report_status as status,
+ ar.report_data as data,
+ ar.created_at as createdAt,
+ ar.updated_at as updatedAt
</sql>
<insert id="insert" parameterType="AnalysisReport" useGeneratedKeys="true">
<select id="selectByProjectKey" parameterType="String" resultType="AnalysisReport">
select
<include refid="reportColumns"/>
- from analysis_reports
+ from analysis_reports ar
where project_key = #{projectKey}
</select>
+
+ <select id="selectNextAvailableReport" parameterType="map" resultType="AnalysisReport">
+ select
+ <include refid="reportColumns"/>
+ from analysis_reports ar
+ where ar.report_status=#{availableStatus}
+ and not exists(
+ select 1
+ from analysis_reports ar2
+ where ar.project_key = ar2.project_key
+ and ar2.report_status=#{busyStatus}
+ )
+ order by created_at asc
+ </select>
</mapper>
\ No newline at end of file