From a17301de1b5050815a9219003f138330ffc707bb Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Tue, 17 Mar 2015 16:43:27 +0100 Subject: Batch should set updated date to 0 on updated sources and Compute should update this sources for current project --- .../java/org/sonar/core/source/db/FileSourceDao.java | 4 ++++ .../org/sonar/core/source/db/FileSourceMapper.java | 4 ++++ .../org/sonar/core/source/db/FileSourceMapper.xml | 15 +++++++++++---- .../org/sonar/core/source/db/FileSourceDaoTest.java | 10 ++++++++++ .../update_date_when_updated_date_is_zero-result.xml | 18 ++++++++++++++++++ .../update_date_when_updated_date_is_zero.xml | 16 ++++++++++++++++ 6 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 sonar-core/src/test/resources/org/sonar/core/source/db/FileSourceDaoTest/update_date_when_updated_date_is_zero-result.xml create mode 100644 sonar-core/src/test/resources/org/sonar/core/source/db/FileSourceDaoTest/update_date_when_updated_date_is_zero.xml (limited to 'sonar-core') 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 @@ - 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}) - 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 file_sources SET + updated_at = #{date,jdbcType=BIGINT} + WHERE project_uuid = #{projectUuid} + AND updated_at = 0