diff options
author | Jenkins CI <ci@sonarsource.com> | 2015-03-18 09:37:34 +0100 |
---|---|---|
committer | Jenkins CI <ci@sonarsource.com> | 2015-03-18 09:37:34 +0100 |
commit | 82559b6218822b7a1e4f63aa50aec1cd8e7e5272 (patch) | |
tree | 2577de62fb91dd8d9511762ead12b370c5dbe4a7 /sonar-core | |
parent | 8f376a0a64dac99cfddfafcded66445997a65670 (diff) | |
parent | a17301de1b5050815a9219003f138330ffc707bb (diff) | |
download | sonarqube-82559b6218822b7a1e4f63aa50aec1cd8e7e5272.tar.gz sonarqube-82559b6218822b7a1e4f63aa50aec1cd8e7e5272.zip |
Automatic merge from branch-5.1
* origin/branch-5.1:
Batch should set updated date to 0 on updated sources and Compute should update this sources for current project
improve significantly memore consumption while using a disk cache
catch Throwable instead of Exception in Computation threads
Diffstat (limited to 'sonar-core')
6 files changed, 63 insertions, 4 deletions
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 index eced8499a4d..16864674f20 100644 --- 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 @@ -121,4 +121,8 @@ public class FileSourceDao implements BatchComponent, ServerComponent, DaoCompon } } + 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/db/FileSourceMapper.java b/sonar-core/src/main/java/org/sonar/core/source/db/FileSourceMapper.java index e8876892357..633e4d140ed 100644 --- a/sonar-core/src/main/java/org/sonar/core/source/db/FileSourceMapper.java +++ b/sonar-core/src/main/java/org/sonar/core/source/db/FileSourceMapper.java @@ -20,6 +20,8 @@ package org.sonar.core.source.db; +import org.apache.ibatis.annotations.Param; + import javax.annotation.CheckForNull; import java.util.List; @@ -35,6 +37,8 @@ public interface FileSourceMapper { void update(FileSourceDto dto); + void updateDateWhenUpdatedDateIsZero(@Param("projectUuid") String projectUuid, @Param("date") Long updateDate); + @CheckForNull String selectLineHashes(String fileUuid); } diff --git a/sonar-core/src/main/resources/org/sonar/core/source/db/FileSourceMapper.xml b/sonar-core/src/main/resources/org/sonar/core/source/db/FileSourceMapper.xml index 2edae7f055c..49ede1dfb30 100644 --- a/sonar-core/src/main/resources/org/sonar/core/source/db/FileSourceMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/source/db/FileSourceMapper.xml @@ -18,20 +18,27 @@ </select> <insert id="insert" parameterType="org.sonar.core.source.db.FileSourceDto" useGeneratedKeys="false"> - insert into file_sources (project_uuid, file_uuid, created_at, updated_at, binary_data, line_hashes, data_hash, src_hash) - values (#{projectUuid,jdbcType=VARCHAR}, #{fileUuid,jdbcType=VARCHAR}, #{createdAt,jdbcType=BIGINT}, + INSERT INTO file_sources (project_uuid, file_uuid, created_at, updated_at, binary_data, line_hashes, data_hash, src_hash) + VALUES (#{projectUuid,jdbcType=VARCHAR}, #{fileUuid,jdbcType=VARCHAR}, #{createdAt,jdbcType=BIGINT}, #{updatedAt,jdbcType=BIGINT}, #{binaryData,jdbcType=BLOB}, #{lineHashes,jdbcType=CLOB}, #{dataHash,jdbcType=VARCHAR}, #{srcHash,jdbcType=VARCHAR}) </insert> <update id="update" parameterType="org.sonar.core.source.db.FileSourceDto" useGeneratedKeys="false"> - update file_sources set + UPDATE file_sources SET updated_at = #{updatedAt,jdbcType=BIGINT}, binary_data = #{binaryData,jdbcType=BLOB}, line_hashes = #{lineHashes,jdbcType=CLOB}, data_hash = #{dataHash,jdbcType=VARCHAR}, src_hash = #{srcHash,jdbcType=VARCHAR} - where id = #{id} + WHERE id = #{id} + </update> + + <update id="updateDateWhenUpdatedDateIsZero" parameterType="org.sonar.core.source.db.FileSourceDto" useGeneratedKeys="false"> + UPDATE file_sources SET + updated_at = #{date,jdbcType=BIGINT} + WHERE project_uuid = #{projectUuid} + AND updated_at = 0 </update> <select id="selectLineHashes" parameterType="string" resultType="String"> 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 index aed0f04fd71..8f2ed1fb45a 100644 --- 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 @@ -128,6 +128,16 @@ public class FileSourceDaoTest extends AbstractDaoTestCase { 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; 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 new file mode 100644 index 00000000000..931bab04e18 --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/source/db/FileSourceDaoTest/update_date_when_updated_date_is_zero-result.xml @@ -0,0 +1,18 @@ +<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" + 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" + 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" + 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 new file mode 100644 index 00000000000..9782d5c3837 --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/source/db/FileSourceDaoTest/update_date_when_updated_date_is_zero.xml @@ -0,0 +1,16 @@ +<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" + 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" + 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" + created_at="1500000000000" updated_at="0"/> + +</dataset> |