diff options
author | simonbrandhof <simon.brandhof@gmail.com> | 2011-11-01 07:58:20 +0100 |
---|---|---|
committer | simonbrandhof <simon.brandhof@gmail.com> | 2011-11-01 08:02:22 +0100 |
commit | 3d544314e585b7c65bc6156f7b7f5748012d50ad (patch) | |
tree | 554fb661f49d6a604ffac3dab425781746430836 /sonar-core/src/main | |
parent | 03d3eaac31c3bec1b80e2f7163f84857a59d75ea (diff) | |
download | sonarqube-3d544314e585b7c65bc6156f7b7f5748012d50ad.tar.gz sonarqube-3d544314e585b7c65bc6156f7b7f5748012d50ad.zip |
Improve insertion of rows in DUPLICATIONS_INDEX: use BATCH mode
Diffstat (limited to 'sonar-core/src/main')
5 files changed, 11 insertions, 6 deletions
diff --git a/sonar-core/src/main/java/org/sonar/persistence/dao/DuplicationDao.java b/sonar-core/src/main/java/org/sonar/persistence/dao/DuplicationDao.java index c0a545feca3..da308dc4643 100644 --- a/sonar-core/src/main/java/org/sonar/persistence/dao/DuplicationDao.java +++ b/sonar-core/src/main/java/org/sonar/persistence/dao/DuplicationDao.java @@ -22,6 +22,7 @@ package org.sonar.persistence.dao; import java.util.Collection; import java.util.List; +import org.apache.ibatis.session.ExecutorType; import org.apache.ibatis.session.SqlSession; import org.sonar.api.BatchComponent; import org.sonar.api.ServerComponent; @@ -47,12 +48,16 @@ public class DuplicationDao implements BatchComponent, ServerComponent { } } + /** + * Insert rows in the table DUPLICATIONS_INDEX. + * Note that generated ids are not returned. + */ public void insert(Collection<DuplicationUnit> units) { - SqlSession session = mybatis.openSession(); + SqlSession session = mybatis.openSession(ExecutorType.BATCH); try { DuplicationMapper mapper = session.getMapper(DuplicationMapper.class); for (DuplicationUnit unit : units) { - mapper.insert(unit); + mapper.batchInsert(unit); } session.commit(); } finally { diff --git a/sonar-core/src/main/java/org/sonar/persistence/model/DuplicationMapper.java b/sonar-core/src/main/java/org/sonar/persistence/model/DuplicationMapper.java index 79c0bc36992..4bf65ce760a 100644 --- a/sonar-core/src/main/java/org/sonar/persistence/model/DuplicationMapper.java +++ b/sonar-core/src/main/java/org/sonar/persistence/model/DuplicationMapper.java @@ -29,7 +29,7 @@ public interface DuplicationMapper { @Param("resource_snapshot_id") int resourceSnapshotId, @Param("last_project_snapshot_id") Integer lastSnapshotId); - void insert(DuplicationUnit unit); + void batchInsert(DuplicationUnit unit); } diff --git a/sonar-core/src/main/resources/org/sonar/persistence/model/DuplicationMapper-mssql.xml b/sonar-core/src/main/resources/org/sonar/persistence/model/DuplicationMapper-mssql.xml index fe3e76926dd..bc1837a35fa 100644 --- a/sonar-core/src/main/resources/org/sonar/persistence/model/DuplicationMapper-mssql.xml +++ b/sonar-core/src/main/resources/org/sonar/persistence/model/DuplicationMapper-mssql.xml @@ -16,7 +16,7 @@ </if> </select> - <insert id="insert" parameterType="DuplicationUnit" keyColumn="id" useGeneratedKeys="true"> + <insert id="batchInsert" parameterType="DuplicationUnit" keyColumn="id" useGeneratedKeys="false"> INSERT INTO duplications_index (snapshot_id, project_snapshot_id, hash, index_in_file, start_line, end_line) VALUES (#{snapshotId}, #{projectSnapshotId}, #{hash}, #{indexInFile}, #{startLine}, #{endLine}) </insert> diff --git a/sonar-core/src/main/resources/org/sonar/persistence/model/DuplicationMapper-oracle.xml b/sonar-core/src/main/resources/org/sonar/persistence/model/DuplicationMapper-oracle.xml index b7f15344b49..7b0e5682753 100644 --- a/sonar-core/src/main/resources/org/sonar/persistence/model/DuplicationMapper-oracle.xml +++ b/sonar-core/src/main/resources/org/sonar/persistence/model/DuplicationMapper-oracle.xml @@ -16,7 +16,7 @@ </if> </select> - <insert id="insert" parameterType="DuplicationUnit" keyColumn="id" useGeneratedKeys="true"> + <insert id="batchInsert" parameterType="DuplicationUnit" keyColumn="id" useGeneratedKeys="false"> INSERT INTO duplications_index (id, snapshot_id, project_snapshot_id, hash, index_in_file, start_line, end_line) VALUES (duplications_index_seq.NEXTVAL, #{snapshotId}, #{projectSnapshotId}, #{hash}, #{indexInFile}, #{startLine}, #{endLine}) </insert> diff --git a/sonar-core/src/main/resources/org/sonar/persistence/model/DuplicationMapper.xml b/sonar-core/src/main/resources/org/sonar/persistence/model/DuplicationMapper.xml index 1217ed03ddc..5f39d7dea7c 100644 --- a/sonar-core/src/main/resources/org/sonar/persistence/model/DuplicationMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/persistence/model/DuplicationMapper.xml @@ -16,7 +16,7 @@ </if> </select> - <insert id="insert" parameterType="DuplicationUnit" keyColumn="id" useGeneratedKeys="true"> + <insert id="batchInsert" parameterType="DuplicationUnit" useGeneratedKeys="false"> INSERT INTO duplications_index (snapshot_id, project_snapshot_id, hash, index_in_file, start_line, end_line) VALUES (#{snapshotId}, #{projectSnapshotId}, #{hash}, #{indexInFile}, #{startLine}, #{endLine}) </insert> |