aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-db
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2016-08-25 11:33:31 +0200
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2016-08-29 09:48:22 +0200
commit5984a93e9dab139174cfdfc920e8e1fcd3947f1e (patch)
tree68528f8872bc53c9df89d16e33f068105e1372dc /sonar-db
parent349dc013f9bec35932baa075d86104832a33d35b (diff)
downloadsonarqube-5984a93e9dab139174cfdfc920e8e1fcd3947f1e.tar.gz
sonarqube-5984a93e9dab139174cfdfc920e8e1fcd3947f1e.zip
SONAR-7844 ScannerContextDao => CeScannerContextDao
Diffstat (limited to 'sonar-db')
-rw-r--r--sonar-db/src/main/java/org/sonar/db/DaoModule.java4
-rw-r--r--sonar-db/src/main/java/org/sonar/db/DbClient.java14
-rw-r--r--sonar-db/src/main/java/org/sonar/db/ce/CeScannerContextDao.java (renamed from sonar-db/src/main/java/org/sonar/db/scannercontext/ScannerContextDao.java)22
-rw-r--r--sonar-db/src/main/java/org/sonar/db/ce/LogsIteratorInputStream.java (renamed from sonar-db/src/main/java/org/sonar/db/scannercontext/LogsIteratorInputStream.java)2
-rw-r--r--sonar-db/src/main/java/org/sonar/db/scannercontext/package-info.java24
-rw-r--r--sonar-db/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml14
-rw-r--r--sonar-db/src/test/java/org/sonar/db/ce/CeActivityDaoTest.java11
-rw-r--r--sonar-db/src/test/java/org/sonar/db/ce/CeScannerContextDaoTest.java (renamed from sonar-db/src/test/java/org/sonar/db/scannercontext/ScannerContextDaoTest.java)14
-rw-r--r--sonar-db/src/test/java/org/sonar/db/ce/LogsIteratorInputStreamTest.java (renamed from sonar-db/src/test/java/org/sonar/db/scannercontext/LogsIteratorInputStreamTest.java)2
-rw-r--r--sonar-db/src/test/java/org/sonar/db/purge/PurgeDaoTest.java2
10 files changed, 42 insertions, 67 deletions
diff --git a/sonar-db/src/main/java/org/sonar/db/DaoModule.java b/sonar-db/src/main/java/org/sonar/db/DaoModule.java
index d18f35a86dd..e17fc4911fc 100644
--- a/sonar-db/src/main/java/org/sonar/db/DaoModule.java
+++ b/sonar-db/src/main/java/org/sonar/db/DaoModule.java
@@ -60,7 +60,7 @@ import org.sonar.db.qualitygate.QualityGateDao;
import org.sonar.db.qualityprofile.ActiveRuleDao;
import org.sonar.db.qualityprofile.QualityProfileDao;
import org.sonar.db.rule.RuleDao;
-import org.sonar.db.scannercontext.ScannerContextDao;
+import org.sonar.db.ce.CeScannerContextDao;
import org.sonar.db.source.FileSourceDao;
import org.sonar.db.user.AuthorDao;
import org.sonar.db.user.AuthorizationDao;
@@ -108,7 +108,7 @@ public class DaoModule extends Module {
QualityGateDao.class,
QualityGateConditionDao.class,
QualityProfileDao.class,
- ScannerContextDao.class,
+ CeScannerContextDao.class,
RuleDao.class,
ActiveRuleDao.class,
ResourceIndexDao.class,
diff --git a/sonar-db/src/main/java/org/sonar/db/DbClient.java b/sonar-db/src/main/java/org/sonar/db/DbClient.java
index 929813bfd66..48761c376d8 100644
--- a/sonar-db/src/main/java/org/sonar/db/DbClient.java
+++ b/sonar-db/src/main/java/org/sonar/db/DbClient.java
@@ -60,7 +60,7 @@ import org.sonar.db.qualitygate.QualityGateDao;
import org.sonar.db.qualityprofile.ActiveRuleDao;
import org.sonar.db.qualityprofile.QualityProfileDao;
import org.sonar.db.rule.RuleDao;
-import org.sonar.db.scannercontext.ScannerContextDao;
+import org.sonar.db.ce.CeScannerContextDao;
import org.sonar.db.source.FileSourceDao;
import org.sonar.db.user.AuthorDao;
import org.sonar.db.user.AuthorizationDao;
@@ -102,6 +102,7 @@ public class DbClient {
private final CeActivityDao ceActivityDao;
private final CeQueueDao ceQueueDao;
private final CeTaskInputDao ceTaskInputDao;
+ private final CeScannerContextDao ceScannerContextDao;
private final DashboardDao dashboardDao;
private final ActiveDashboardDao activeDashboardDao;
private final WidgetDao widgetDao;
@@ -122,7 +123,6 @@ public class DbClient {
private final GroupDao groupDao;
private final RuleDao ruleDao;
private final ActiveRuleDao activeRuleDao;
- private final ScannerContextDao scannerContextDao;
public DbClient(Database database, MyBatis myBatis, Dao... daos) {
this.database = database;
@@ -159,6 +159,7 @@ public class DbClient {
ceActivityDao = getDao(map, CeActivityDao.class);
ceQueueDao = getDao(map, CeQueueDao.class);
ceTaskInputDao = getDao(map, CeTaskInputDao.class);
+ ceScannerContextDao = getDao(map, CeScannerContextDao.class);
dashboardDao = getDao(map, DashboardDao.class);
activeDashboardDao = getDao(map, ActiveDashboardDao.class);
widgetDao = getDao(map, WidgetDao.class);
@@ -179,7 +180,6 @@ public class DbClient {
groupDao = getDao(map, GroupDao.class);
ruleDao = getDao(map, RuleDao.class);
activeRuleDao = getDao(map, ActiveRuleDao.class);
- scannerContextDao = getDao(map, ScannerContextDao.class);
doOnLoad(map);
}
@@ -308,6 +308,10 @@ public class DbClient {
return ceTaskInputDao;
}
+ public CeScannerContextDao ceScannerContextDao() {
+ return ceScannerContextDao;
+ }
+
public DashboardDao dashboardDao() {
return dashboardDao;
}
@@ -388,10 +392,6 @@ public class DbClient {
return activeRuleDao;
}
- public ScannerContextDao scannerContextDao() {
- return scannerContextDao;
- }
-
protected <K extends Dao> K getDao(Map<Class, Dao> map, Class<K> clazz) {
return (K) map.get(clazz);
}
diff --git a/sonar-db/src/main/java/org/sonar/db/scannercontext/ScannerContextDao.java b/sonar-db/src/main/java/org/sonar/db/ce/CeScannerContextDao.java
index 7d81688094d..946eea53581 100644
--- a/sonar-db/src/main/java/org/sonar/db/scannercontext/ScannerContextDao.java
+++ b/sonar-db/src/main/java/org/sonar/db/ce/CeScannerContextDao.java
@@ -17,7 +17,7 @@
* 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.db.scannercontext;
+package org.sonar.db.ce;
import java.io.IOException;
import java.io.InputStream;
@@ -35,34 +35,34 @@ import org.sonar.db.DbSession;
import static com.google.common.base.Preconditions.checkArgument;
-public class ScannerContextDao implements Dao {
+public class CeScannerContextDao implements Dao {
private static final Charset UTF_8 = Charset.forName("UTF-8");
private final System2 system;
- public ScannerContextDao(System2 system) {
+ public CeScannerContextDao(System2 system) {
this.system = system;
}
/**
* @throws IllegalArgumentException if {@code scannerContextLines} is empty or fully read.
*/
- public void insert(DbSession dbSession, String analysisUuid, CloseableIterator<String> scannerContextLines) {
+ public void insert(DbSession dbSession, String taskUuid, CloseableIterator<String> scannerContextLines) {
checkArgument(scannerContextLines.hasNext(), "Scanner context can not be empty");
long now = system.now();
Connection connection = dbSession.getConnection();
try (PreparedStatement stmt = connection.prepareStatement(
- "INSERT INTO scanner_context (analysis_uuid, created_at, updated_at, data) VALUES (?, ?, ?, ?)");
+ "INSERT INTO ce_scanner_context (task_uuid, created_at, updated_at, data) VALUES (?, ?, ?, ?)");
InputStream inputStream = new LogsIteratorInputStream(scannerContextLines, UTF_8)) {
- stmt.setString(1, analysisUuid);
+ stmt.setString(1, taskUuid);
stmt.setLong(2, now);
stmt.setLong(3, now);
stmt.setBinaryStream(4, inputStream);
stmt.executeUpdate();
connection.commit();
} catch (SQLException | IOException e) {
- throw new IllegalStateException("Fail to insert scanner context for analysis " + analysisUuid, e);
+ throw new IllegalStateException("Fail to insert scanner context for task " + taskUuid, e);
}
}
@@ -70,9 +70,9 @@ public class ScannerContextDao implements Dao {
* The scanner context is very likely to contain lines, which are forcefully separated by {@code \n} characters,
* whichever the platform SQ is running on ({@see LogsIteratorInputStream}).
*/
- public Optional<String> selectScannerContext(DbSession dbSession, String analysisUuid) {
- try (PreparedStatement stmt = dbSession.getConnection().prepareStatement("select data from scanner_context where analysis_uuid=?")) {
- stmt.setString(1, analysisUuid);
+ public Optional<String> selectScannerContext(DbSession dbSession, String taskUuid) {
+ try (PreparedStatement stmt = dbSession.getConnection().prepareStatement("select data from ce_scanner_context where task_uuid=?")) {
+ stmt.setString(1, taskUuid);
try (ResultSet rs = stmt.executeQuery()) {
if (rs.next()) {
return Optional.of(IOUtils.toString(rs.getBinaryStream(1), UTF_8));
@@ -80,7 +80,7 @@ public class ScannerContextDao implements Dao {
return Optional.empty();
}
} catch (SQLException | IOException e) {
- throw new IllegalStateException("Fail to retrieve scanner context of analysis " + analysisUuid, e);
+ throw new IllegalStateException("Fail to retrieve scanner context of task " + taskUuid, e);
}
}
diff --git a/sonar-db/src/main/java/org/sonar/db/scannercontext/LogsIteratorInputStream.java b/sonar-db/src/main/java/org/sonar/db/ce/LogsIteratorInputStream.java
index ab55e461818..6eb239a655d 100644
--- a/sonar-db/src/main/java/org/sonar/db/scannercontext/LogsIteratorInputStream.java
+++ b/sonar-db/src/main/java/org/sonar/db/ce/LogsIteratorInputStream.java
@@ -17,7 +17,7 @@
* 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.db.scannercontext;
+package org.sonar.db.ce;
import java.io.IOException;
import java.io.InputStream;
diff --git a/sonar-db/src/main/java/org/sonar/db/scannercontext/package-info.java b/sonar-db/src/main/java/org/sonar/db/scannercontext/package-info.java
deleted file mode 100644
index de8b7394f01..00000000000
--- a/sonar-db/src/main/java/org/sonar/db/scannercontext/package-info.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.
- */
-@ParametersAreNonnullByDefault
-package org.sonar.db.scannercontext;
-
-import javax.annotation.ParametersAreNonnullByDefault;
-
diff --git a/sonar-db/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml b/sonar-db/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml
index 27b3df87f2c..77d2ccd60f5 100644
--- a/sonar-db/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml
+++ b/sonar-db/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml
@@ -4,15 +4,15 @@
<mapper namespace="org.sonar.db.ce.CeActivityMapper">
- <!--assumes query includes an left left outer join on table scanner_context with alias ct -->
+ <!--assumes query includes an left left outer join on table ce_scanner_context with alias csc -->
<sql id="hasScannerContextColumn" databaseId="mssql">
- cast(case when ct.analysis_uuid is null then 0 else 1 end as bit) as hasScannerContext
+ cast(case when csc.task_uuid is null then 0 else 1 end as bit) as hasScannerContext
</sql>
<sql id="hasScannerContextColumn" databaseId="oracle">
- case when ct.analysis_uuid is null then 0 else 1 end as hasScannerContext
+ case when csc.task_uuid is null then 0 else 1 end as hasScannerContext
</sql>
<sql id="hasScannerContextColumn">
- ct.analysis_uuid is not null as hasScannerContext
+ csc.task_uuid is not null as hasScannerContext
</sql>
<sql id="columns">
@@ -40,7 +40,7 @@
<include refid="columns"/>,
ca.error_stacktrace as errorStacktrace
from ce_activity ca
- left outer join scanner_context ct on ca.analysis_uuid = ct.analysis_uuid
+ left outer join ce_scanner_context csc on ca.uuid = csc.task_uuid
where ca.uuid=#{uuid}
</select>
@@ -84,7 +84,7 @@
<sql id="sqlSelectByQuery">
from ce_activity ca
- left outer join scanner_context ct on ct.analysis_uuid = ca.analysis_uuid
+ left outer join ce_scanner_context csc on csc.task_uuid = ca.uuid
<where>
<if test="query.onlyCurrents">
and ca.is_last=${_true}
@@ -117,7 +117,7 @@
select
<include refid="columns"/>
from ce_activity ca
- left outer join scanner_context ct on ct.analysis_uuid = ca.analysis_uuid
+ left outer join ce_scanner_context csc on csc.task_uuid = ca.uuid
where
ca.created_at &lt; #{beforeDate,jdbcType=BIGINT}
</select>
diff --git a/sonar-db/src/test/java/org/sonar/db/ce/CeActivityDaoTest.java b/sonar-db/src/test/java/org/sonar/db/ce/CeActivityDaoTest.java
index 7b49b1d5a11..45b8b41271a 100644
--- a/sonar-db/src/test/java/org/sonar/db/ce/CeActivityDaoTest.java
+++ b/sonar-db/src/test/java/org/sonar/db/ce/CeActivityDaoTest.java
@@ -41,8 +41,6 @@ import static org.sonar.db.ce.CeTaskTypes.REPORT;
public class CeActivityDaoTest {
- private static final String AN_ANALYSIS_UUID = "U1";
-
private TestSystem2 system2 = new TestSystem2().setNow(1_450_000_000_000L);
@Rule
@@ -196,7 +194,7 @@ public class CeActivityDaoTest {
public void selectByQuery_populates_hasScannerContext_flag() {
insert("TASK_1", REPORT, "PROJECT_1", SUCCESS);
CeActivityDto dto2 = insert("TASK_2", REPORT, "PROJECT_2", SUCCESS);
- insertScannerContext(dto2.getAnalysisUuid());
+ insertScannerContext(dto2.getUuid());
CeActivityDto dto = underTest.selectByQuery(db.getSession(), new CeTaskQuery().setComponentUuid("PROJECT_1"), 0, 100).iterator().next();
assertThat(dto.isHasScannerContext()).isFalse();
@@ -275,7 +273,7 @@ public class CeActivityDaoTest {
public void selectOlder_populates_hasScannerContext_flag() {
insertWithCreationDate("TASK_1", 1_450_000_000_000L);
CeActivityDto dto2 = insertWithCreationDate("TASK_2", 1_450_000_000_000L);
- insertScannerContext(dto2.getAnalysisUuid());
+ insertScannerContext(dto2.getUuid());
List<CeActivityDto> dtos = underTest.selectOlderThan(db.getSession(), 1_465_000_000_000L);
assertThat(dtos).hasSize(2);
@@ -369,8 +367,9 @@ public class CeActivityDaoTest {
return dto;
}
- private void insertScannerContext(String analysisUuid) {
- db.getDbClient().scannerContextDao().insert(dbSession, analysisUuid, CloseableIterator.from(singletonList("scanner context of " + analysisUuid).iterator()));
+ private void insertScannerContext(String taskUuid) {
+ db.getDbClient().ceScannerContextDao().insert(dbSession, taskUuid, CloseableIterator.from(singletonList("scanner context of " + taskUuid).iterator()));
+ dbSession.commit();
}
private List<String> selectPageOfUuids(int offset, int pageSize) {
diff --git a/sonar-db/src/test/java/org/sonar/db/scannercontext/ScannerContextDaoTest.java b/sonar-db/src/test/java/org/sonar/db/ce/CeScannerContextDaoTest.java
index ef635a53f2d..e270a947532 100644
--- a/sonar-db/src/test/java/org/sonar/db/scannercontext/ScannerContextDaoTest.java
+++ b/sonar-db/src/test/java/org/sonar/db/ce/CeScannerContextDaoTest.java
@@ -17,7 +17,7 @@
* 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.db.scannercontext;
+package org.sonar.db.ce;
import java.util.Collections;
import org.junit.Rule;
@@ -32,9 +32,9 @@ import static java.lang.System.lineSeparator;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
-public class ScannerContextDaoTest {
+public class CeScannerContextDaoTest {
- private static final String TABLE_NAME = "scanner_context";
+ private static final String TABLE_NAME = "ce_scanner_context";
private static final String SOME_UUID = "some UUID";
@Rule
@@ -45,7 +45,7 @@ public class ScannerContextDaoTest {
private System2 system = mock(System2.class);
private DbSession dbSession = dbTester.getSession();
- private ScannerContextDao underTest = new ScannerContextDao(system);
+ private CeScannerContextDao underTest = new CeScannerContextDao(system);
@Test
public void selectScannerContext_returns_empty_on_empty_table() {
@@ -53,7 +53,7 @@ public class ScannerContextDaoTest {
}
@Test
- public void selectScannerContext_returns_empty_when_no_row_exist_for_analysisUuid() {
+ public void selectScannerContext_returns_empty_when_no_row_exist_for_taskUuid() {
String data = "some data";
underTest.insert(dbSession, SOME_UUID, scannerContextInputStreamOf(data));
dbSession.commit();
@@ -82,14 +82,14 @@ public class ScannerContextDaoTest {
}
@Test
- public void insert_fails_if_row_already_exists_for_analysis_uuid() {
+ public void insert_fails_if_row_already_exists_for_taskUuid() {
underTest.insert(dbSession, SOME_UUID, scannerContextInputStreamOf("bla"));
dbSession.commit();
assertThat(dbTester.countRowsOfTable(dbSession, TABLE_NAME)).isEqualTo(1);
expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage("Fail to insert scanner context for analysis " + SOME_UUID);
+ expectedException.expectMessage("Fail to insert scanner context for task " + SOME_UUID);
underTest.insert(dbSession, SOME_UUID, scannerContextInputStreamOf("blo"));
}
diff --git a/sonar-db/src/test/java/org/sonar/db/scannercontext/LogsIteratorInputStreamTest.java b/sonar-db/src/test/java/org/sonar/db/ce/LogsIteratorInputStreamTest.java
index 06d6e1b3b79..1e259ce9b7f 100644
--- a/sonar-db/src/test/java/org/sonar/db/scannercontext/LogsIteratorInputStreamTest.java
+++ b/sonar-db/src/test/java/org/sonar/db/ce/LogsIteratorInputStreamTest.java
@@ -17,7 +17,7 @@
* 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.db.scannercontext;
+package org.sonar.db.ce;
import java.io.IOException;
import java.nio.charset.Charset;
diff --git a/sonar-db/src/test/java/org/sonar/db/purge/PurgeDaoTest.java b/sonar-db/src/test/java/org/sonar/db/purge/PurgeDaoTest.java
index 55dd7318bdc..ee48762f5a2 100644
--- a/sonar-db/src/test/java/org/sonar/db/purge/PurgeDaoTest.java
+++ b/sonar-db/src/test/java/org/sonar/db/purge/PurgeDaoTest.java
@@ -254,7 +254,7 @@ public class PurgeDaoTest {
}
private void insertScannerContext(String analysisUuid, String scannerContext) {
- dbTester.getDbClient().scannerContextDao().insert(dbSession, analysisUuid, CloseableIterator.from(singleton(scannerContext).iterator()));
+ dbTester.getDbClient().ceScannerContextDao().insert(dbSession, analysisUuid, CloseableIterator.from(singleton(scannerContext).iterator()));
dbTester.commit();
}