aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2015-04-17 12:02:07 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2015-04-17 12:18:28 +0200
commitfc072f94584c18f8312a2622475d7ce3e1eaa2d4 (patch)
tree3b77734c61feef7c0fa6caab01df3ec1167449cc /sonar-core
parentdcd816933e779686ffe43b2b094f1191e5195cec (diff)
downloadsonarqube-fc072f94584c18f8312a2622475d7ce3e1eaa2d4.tar.gz
sonarqube-fc072f94584c18f8312a2622475d7ce3e1eaa2d4.zip
SONAR-6253 Cleanup SourcePersister on batch side
and move FileSourceDao to sonar-server
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java6
-rw-r--r--sonar-core/src/main/java/org/sonar/core/source/SnapshotDataTypes.java27
-rw-r--r--sonar-core/src/main/java/org/sonar/core/source/db/FileSourceDao.java136
-rw-r--r--sonar-core/src/main/java/org/sonar/core/source/package-info.java24
-rw-r--r--sonar-core/src/test/java/org/sonar/core/source/db/FileSourceDaoTest.java170
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/source/db/FileSourceDaoTest/insert-result.xml19
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/source/db/FileSourceDaoTest/shared.xml10
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/source/db/FileSourceDaoTest/update-result.xml12
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/source/db/FileSourceDaoTest/update_date_when_updated_date_is_zero-result.xml21
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/source/db/FileSourceDaoTest/update_date_when_updated_date_is_zero.xml19
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/source/db/SnapshotDataDaoTest/shared.xml8
11 files changed, 2 insertions, 450 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java b/sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java
index 92f36946428..052120c913b 100644
--- a/sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java
+++ b/sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java
@@ -38,7 +38,6 @@ import org.sonar.core.resource.ResourceDao;
import org.sonar.core.resource.ResourceIndexerDao;
import org.sonar.core.resource.ResourceKeyUpdaterDao;
import org.sonar.core.rule.RuleDao;
-import org.sonar.core.source.db.FileSourceDao;
import org.sonar.core.technicaldebt.db.CharacteristicDao;
import org.sonar.core.template.LoadedTemplateDao;
import org.sonar.core.user.*;
@@ -68,7 +67,6 @@ public final class DaoUtils {
AuthorizationDao.class,
DashboardDao.class,
DuplicationDao.class,
- FileSourceDao.class,
GraphDao.class,
GroupMembershipDao.class,
IssueDao.class,
@@ -90,7 +88,7 @@ public final class DaoUtils {
RuleDao.class,
SemaphoreDao.class,
UserDao.class
- );
+ );
}
/**
@@ -116,7 +114,7 @@ public final class DaoUtils {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < count; i++) {
sb.append(sql);
- if (i < count-1) {
+ if (i < count - 1) {
sb.append(" ").append(separator).append(" ");
}
}
diff --git a/sonar-core/src/main/java/org/sonar/core/source/SnapshotDataTypes.java b/sonar-core/src/main/java/org/sonar/core/source/SnapshotDataTypes.java
deleted file mode 100644
index 96d11d51652..00000000000
--- a/sonar-core/src/main/java/org/sonar/core/source/SnapshotDataTypes.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * 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.core.source;
-
-public interface SnapshotDataTypes {
-
- String SYNTAX_HIGHLIGHTING = "highlight_syntax";
- String SYMBOL_HIGHLIGHTING = "symbol";
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/source/db/FileSourceDao.java b/sonar-core/src/main/java/org/sonar/core/source/db/FileSourceDao.java
deleted file mode 100644
index cbd920455e9..00000000000
--- a/sonar-core/src/main/java/org/sonar/core/source/db/FileSourceDao.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * 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.core.source.db;
-
-import com.google.common.base.Function;
-import org.apache.commons.dbutils.DbUtils;
-import org.apache.commons.io.IOUtils;
-import org.sonar.api.BatchComponent;
-import org.sonar.api.ServerComponent;
-import org.sonar.core.persistence.DaoComponent;
-import org.sonar.core.persistence.DbSession;
-import org.sonar.core.persistence.MyBatis;
-
-import javax.annotation.CheckForNull;
-
-import java.io.InputStream;
-import java.io.Reader;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-
-public class FileSourceDao implements BatchComponent, ServerComponent, DaoComponent {
-
- private final MyBatis mybatis;
-
- public FileSourceDao(MyBatis myBatis) {
- this.mybatis = myBatis;
- }
-
- @CheckForNull
- public FileSourceDto select(String fileUuid) {
- DbSession session = mybatis.openSession(false);
- try {
- FileSourceMapper mapper = session.getMapper(FileSourceMapper.class);
- return mapper.select(fileUuid);
- } finally {
- MyBatis.closeQuietly(session);
- }
- }
-
- public <T> void readDataStream(String fileUuid, Function<InputStream, T> function) {
- DbSession dbSession = mybatis.openSession(false);
- Connection connection = dbSession.getConnection();
- PreparedStatement pstmt = null;
- ResultSet rs = null;
- InputStream input = null;
- try {
- pstmt = connection.prepareStatement("SELECT binary_data FROM file_sources WHERE file_uuid=?");
- pstmt.setString(1, fileUuid);
- rs = pstmt.executeQuery();
- if (rs.next()) {
- input = rs.getBinaryStream(1);
- function.apply(input);
- }
- } catch (SQLException e) {
- throw new IllegalStateException("Fail to read FILE_SOURCES.BINARY_DATA of file " + fileUuid, e);
- } finally {
- IOUtils.closeQuietly(input);
- DbUtils.closeQuietly(connection, pstmt, rs);
- MyBatis.closeQuietly(dbSession);
- }
- }
-
- public <T> void readLineHashesStream(DbSession dbSession, String fileUuid, Function<Reader, T> function) {
- Connection connection = dbSession.getConnection();
- PreparedStatement pstmt = null;
- ResultSet rs = null;
- Reader reader = null;
- try {
- pstmt = connection.prepareStatement("SELECT line_hashes FROM file_sources WHERE file_uuid=?");
- pstmt.setString(1, fileUuid);
- rs = pstmt.executeQuery();
- if (rs.next()) {
- reader = rs.getCharacterStream(1);
- function.apply(reader);
- }
- } catch (SQLException e) {
- throw new IllegalStateException("Fail to read FILE_SOURCES.LINE_HASHES of file " + fileUuid, e);
- } finally {
- IOUtils.closeQuietly(reader);
- DbUtils.closeQuietly(connection, pstmt, rs);
- }
- }
-
- public void insert(FileSourceDto dto) {
- DbSession session = mybatis.openSession(false);
- try {
- insert(session, dto);
- session.commit();
- } finally {
- MyBatis.closeQuietly(session);
- }
- }
-
- public void insert(DbSession session, FileSourceDto dto) {
- session.getMapper(FileSourceMapper.class).insert(dto);
- }
-
- public void update(FileSourceDto dto) {
- DbSession session = mybatis.openSession(false);
- try {
- update(session, dto);
- session.commit();
- } finally {
- MyBatis.closeQuietly(session);
- }
- }
-
- public void update(DbSession session, FileSourceDto dto) {
- session.getMapper(FileSourceMapper.class).update(dto);
- }
-
- public void updateDateWhenUpdatedDateIsZero(DbSession session, String projectUuid, long updateDate) {
- session.getMapper(FileSourceMapper.class).updateDateWhenUpdatedDateIsZero(projectUuid, updateDate);
- }
-
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/source/package-info.java b/sonar-core/src/main/java/org/sonar/core/source/package-info.java
deleted file mode 100644
index 6e1e0aeb926..00000000000
--- a/sonar-core/src/main/java/org/sonar/core/source/package-info.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * 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.
- */
-
-@ParametersAreNonnullByDefault
-package org.sonar.core.source;
-
-import javax.annotation.ParametersAreNonnullByDefault;
diff --git a/sonar-core/src/test/java/org/sonar/core/source/db/FileSourceDaoTest.java b/sonar-core/src/test/java/org/sonar/core/source/db/FileSourceDaoTest.java
deleted file mode 100644
index 8f2ed1fb45a..00000000000
--- a/sonar-core/src/test/java/org/sonar/core/source/db/FileSourceDaoTest.java
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- * 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.core.source.db;
-
-import com.google.common.base.Function;
-import org.apache.commons.io.IOUtils;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.core.persistence.AbstractDaoTestCase;
-import org.sonar.core.persistence.DbSession;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Reader;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class FileSourceDaoTest extends AbstractDaoTestCase {
-
- DbSession session;
-
- FileSourceDao dao;
-
- @Before
- public void setUpTestData() {
- session = getMyBatis().openSession(false);
- dao = new FileSourceDao(getMyBatis());
- }
-
- @After
- public void tearDown() throws Exception {
- session.close();
- }
-
- @Test
- public void select() throws Exception {
- setupData("shared");
-
- FileSourceDto fileSourceDto = dao.select("FILE1_UUID");
-
- assertThat(fileSourceDto.getBinaryData()).isNotEmpty();
- assertThat(fileSourceDto.getDataHash()).isEqualTo("hash");
- assertThat(fileSourceDto.getProjectUuid()).isEqualTo("PRJ_UUID");
- assertThat(fileSourceDto.getFileUuid()).isEqualTo("FILE1_UUID");
- assertThat(fileSourceDto.getCreatedAt()).isEqualTo(1500000000000L);
- assertThat(fileSourceDto.getUpdatedAt()).isEqualTo(1500000000000L);
- }
-
- @Test
- public void select_data() throws Exception {
- setupData("shared");
-
- InputStreamToStringFunction fn = new InputStreamToStringFunction();
- dao.readDataStream("FILE1_UUID", fn);
-
- assertThat(fn.result).isNotEmpty();
- }
-
- @Test
- public void select_line_hashes() throws Exception {
- setupData("shared");
-
- ReaderToStringFunction fn = new ReaderToStringFunction();
- dao.readLineHashesStream(session, "FILE1_UUID", fn);
-
- assertThat(fn.result).isEqualTo("ABC\\nDEF\\nGHI");
- }
-
- @Test
- public void no_line_hashes_on_unknown_file() throws Exception {
- setupData("shared");
-
- ReaderToStringFunction fn = new ReaderToStringFunction();
- dao.readLineHashesStream(session, "unknown", fn);
-
- assertThat(fn.result).isNull();
- }
-
- @Test
- public void insert() throws Exception {
- setupData("shared");
-
- dao.insert(new FileSourceDto()
- .setProjectUuid("PRJ_UUID")
- .setFileUuid("FILE2_UUID")
- .setBinaryData("FILE2_BINARY_DATA".getBytes())
- .setDataHash("FILE2_DATA_HASH")
- .setLineHashes("LINE1_HASH\\nLINE2_HASH")
- .setSrcHash("FILE2_HASH")
- .setCreatedAt(1500000000000L)
- .setUpdatedAt(1500000000001L));
-
- checkTable("insert", "file_sources", "project_uuid", "file_uuid", "data_hash", "line_hashes", "src_hash", "created_at", "updated_at");
- }
-
- @Test
- public void update() throws Exception {
- setupData("shared");
-
- dao.update(new FileSourceDto().setId(101L)
- .setProjectUuid("PRJ_UUID")
- .setFileUuid("FILE1_UUID")
- .setBinaryData("updated data".getBytes())
- .setDataHash("NEW_DATA_HASH")
- .setSrcHash("NEW_FILE_HASH")
- .setLineHashes("NEW_LINE_HASHES")
- .setUpdatedAt(1500000000002L));
-
- checkTable("update", "file_sources", "project_uuid", "file_uuid", "data_hash", "line_hashes", "src_hash", "created_at", "updated_at");
- }
-
- @Test
- public void update_date_when_updated_date_is_zero() throws Exception {
- setupData("update_date_when_updated_date_is_zero");
-
- dao.updateDateWhenUpdatedDateIsZero(session, "ABCD", 1500000000002L);
- session.commit();
-
- checkTable("update_date_when_updated_date_is_zero", "file_sources", "project_uuid", "file_uuid", "data_hash", "line_hashes", "src_hash", "created_at", "updated_at");
- }
-
- private static class ReaderToStringFunction implements Function<Reader, String> {
-
- String result = null;
-
- @Override
- public String apply(Reader input) {
- try {
- result = IOUtils.toString(input);
- return IOUtils.toString(input);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
- }
-
- private static class InputStreamToStringFunction implements Function<InputStream, String> {
-
- String result = null;
-
- @Override
- public String apply(InputStream input) {
- try {
- result = IOUtils.toString(input);
- return IOUtils.toString(input);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
- }
-}
diff --git a/sonar-core/src/test/resources/org/sonar/core/source/db/FileSourceDaoTest/insert-result.xml b/sonar-core/src/test/resources/org/sonar/core/source/db/FileSourceDaoTest/insert-result.xml
deleted file mode 100644
index 67fb0ae86e7..00000000000
--- a/sonar-core/src/test/resources/org/sonar/core/source/db/FileSourceDaoTest/insert-result.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-<dataset>
-
- <file_sources id="101" project_uuid="PRJ_UUID" file_uuid="FILE1_UUID"
- binary_data="abcde" data_hash="hash"
- test_data="[null]"
- line_hashes="ABC\nDEF\nGHI"
- src_hash="FILE_HASH"
- created_at="1500000000000" updated_at="1500000000000" />
-
-
- <file_sources id="102" project_uuid="PRJ_UUID" file_uuid="FILE2_UUID"
- binary_data="[ignore]"
- test_data="[null]"
- data_hash="FILE2_DATA_HASH"
- line_hashes="LINE1_HASH\nLINE2_HASH"
- src_hash="FILE2_HASH"
- created_at="1500000000000" updated_at="1500000000001" />
-
-</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/source/db/FileSourceDaoTest/shared.xml b/sonar-core/src/test/resources/org/sonar/core/source/db/FileSourceDaoTest/shared.xml
deleted file mode 100644
index c04c92d5c9b..00000000000
--- a/sonar-core/src/test/resources/org/sonar/core/source/db/FileSourceDaoTest/shared.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-<dataset>
-
- <file_sources id="101" project_uuid="PRJ_UUID" file_uuid="FILE1_UUID"
- binary_data="abcde" data_hash="hash"
- test_data="[null]"
- line_hashes="ABC\nDEF\nGHI"
- src_hash="FILE_HASH"
- created_at="1500000000000" updated_at="1500000000000" />
-
-</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/source/db/FileSourceDaoTest/update-result.xml b/sonar-core/src/test/resources/org/sonar/core/source/db/FileSourceDaoTest/update-result.xml
deleted file mode 100644
index 2d71f379cf2..00000000000
--- a/sonar-core/src/test/resources/org/sonar/core/source/db/FileSourceDaoTest/update-result.xml
+++ /dev/null
@@ -1,12 +0,0 @@
-<dataset>
-
- <file_sources id="101" project_uuid="PRJ_UUID" file_uuid="FILE1_UUID"
- binary_data="[ignore]"
- test_data="[null]"
- data_hash="NEW_DATA_HASH"
- line_hashes="NEW_LINE_HASHES"
- src_hash="NEW_FILE_HASH"
- created_at="1500000000000" updated_at="1500000000002" />
-
-
-</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/source/db/FileSourceDaoTest/update_date_when_updated_date_is_zero-result.xml b/sonar-core/src/test/resources/org/sonar/core/source/db/FileSourceDaoTest/update_date_when_updated_date_is_zero-result.xml
deleted file mode 100644
index 0450883e306..00000000000
--- a/sonar-core/src/test/resources/org/sonar/core/source/db/FileSourceDaoTest/update_date_when_updated_date_is_zero-result.xml
+++ /dev/null
@@ -1,21 +0,0 @@
-<dataset>
-
- <!-- Updated -->
- <file_sources id="101" project_uuid="ABCD" file_uuid="FILE1_UUID"
- binary_data="abcde" data_hash="hash" line_hashes="ABC\nDEF\nGHI" src_hash="FILE_HASH"
- test_data="[null]"
- created_at="1500000000000" updated_at="1500000000002"/>
-
- <!-- Not updated because updated_at is not null -->
- <file_sources id="102" project_uuid="ABCD" file_uuid="FILE2_UUID"
- binary_data="abcde" data_hash="hash" line_hashes="ABC\nDEF\nGHI" src_hash="FILE_HASH"
- test_data="[null]"
- created_at="1500000000000" updated_at="1500000000000"/>
-
- <!-- Not updated because on another project -->
- <file_sources id="103" project_uuid="BCDE" file_uuid="FILE3_UUID"
- binary_data="abcde" data_hash="hash" line_hashes="ABC\nDEF\nGHI" src_hash="FILE_HASH"
- test_data="[null]"
- created_at="1500000000000" updated_at="0"/>
-
-</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/source/db/FileSourceDaoTest/update_date_when_updated_date_is_zero.xml b/sonar-core/src/test/resources/org/sonar/core/source/db/FileSourceDaoTest/update_date_when_updated_date_is_zero.xml
deleted file mode 100644
index 5444e33435f..00000000000
--- a/sonar-core/src/test/resources/org/sonar/core/source/db/FileSourceDaoTest/update_date_when_updated_date_is_zero.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-<dataset>
-
- <!-- Only this source should be updated -->
- <file_sources id="101" project_uuid="ABCD" file_uuid="FILE1_UUID"
- binary_data="abcde" data_hash="hash" line_hashes="ABC\nDEF\nGHI" src_hash="FILE_HASH"
- test_data="[null]"
- created_at="1500000000000" updated_at="0"/>
-
- <file_sources id="102" project_uuid="ABCD" file_uuid="FILE2_UUID"
- binary_data="abcde" data_hash="hash" line_hashes="ABC\nDEF\nGHI" src_hash="FILE_HASH"
- test_data="[null]"
- created_at="1500000000000" updated_at="1500000000000"/>
-
- <file_sources id="103" project_uuid="BCDE" file_uuid="FILE3_UUID"
- binary_data="abcde" data_hash="hash" line_hashes="ABC\nDEF\nGHI" src_hash="FILE_HASH"
- test_data="[null]"
- created_at="1500000000000" updated_at="0"/>
-
-</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/source/db/SnapshotDataDaoTest/shared.xml b/sonar-core/src/test/resources/org/sonar/core/source/db/SnapshotDataDaoTest/shared.xml
deleted file mode 100644
index 0b64abea2ae..00000000000
--- a/sonar-core/src/test/resources/org/sonar/core/source/db/SnapshotDataDaoTest/shared.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-<dataset>
-
- <projects id="1" kee="org.apache.struts:struts:Dispatcher" enabled="[true]"/>
-
- <snapshot_data id="101" resource_id="1" snapshot_id="10" snapshot_data="0,10,k;" data_type="highlight_syntax"/>
- <snapshot_data id="102" resource_id="1" snapshot_id="10" snapshot_data="20,25,20,35,45;" data_type="symbol"/>
-
-</dataset>