aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2013-04-24 16:28:58 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2013-04-24 16:29:29 +0200
commitb593f8da030066b3690baa233fce833b87deffac (patch)
treeb2a15c39997e7e52046530ed16bb3e80d8035760
parent69bab4f4d7b9344ed379c6553ad39c09688c434b (diff)
downloadsonarqube-b593f8da030066b3690baa233fce833b87deffac.tar.gz
sonarqube-b593f8da030066b3690baa233fce833b87deffac.zip
SONAR-3340 Add primary key on duplications_index
-rw-r--r--sonar-core/src/main/java/org/sonar/core/duplication/DuplicationUnitDto.java11
-rw-r--r--sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java2
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/duplication/DuplicationMapper.xml8
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql1
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl1
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/db/migrate/391_add_id_to_duplications_index.rb58
6 files changed, 80 insertions, 1 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/duplication/DuplicationUnitDto.java b/sonar-core/src/main/java/org/sonar/core/duplication/DuplicationUnitDto.java
index 786330e547f..b8b7e3227c4 100644
--- a/sonar-core/src/main/java/org/sonar/core/duplication/DuplicationUnitDto.java
+++ b/sonar-core/src/main/java/org/sonar/core/duplication/DuplicationUnitDto.java
@@ -19,11 +19,13 @@
*/
package org.sonar.core.duplication;
+
/**
* A simple DTO (Data Transfer Object) class that provides the mapping of data to a table.
*/
public final class DuplicationUnitDto {
+ private Long id;
private Integer snapshotId;
private Integer projectSnapshotId;
@@ -46,6 +48,15 @@ public final class DuplicationUnitDto {
this.endLine = endLine;
}
+ public Long getId() {
+ return id;
+ }
+
+ public DuplicationUnitDto setId(Long id) {
+ this.id = id;
+ return this;
+ }
+
public Integer getSnapshotId() {
return snapshotId;
}
diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java
index aa818a4f8c6..703f03edf84 100644
--- a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java
+++ b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java
@@ -32,7 +32,7 @@ import java.util.List;
*/
public class DatabaseVersion implements BatchComponent, ServerComponent {
- public static final int LAST_VERSION = 390;
+ public static final int LAST_VERSION = 391;
public static enum Status {
UP_TO_DATE, REQUIRES_UPGRADE, REQUIRES_DOWNGRADE, FRESH_INSTALL
diff --git a/sonar-core/src/main/resources/org/sonar/core/duplication/DuplicationMapper.xml b/sonar-core/src/main/resources/org/sonar/core/duplication/DuplicationMapper.xml
index 745816df744..4b87e975d42 100644
--- a/sonar-core/src/main/resources/org/sonar/core/duplication/DuplicationMapper.xml
+++ b/sonar-core/src/main/resources/org/sonar/core/duplication/DuplicationMapper.xml
@@ -22,4 +22,12 @@
VALUES (#{snapshotId}, #{projectSnapshotId}, #{hash}, #{indexInFile}, #{startLine}, #{endLine})
</insert>
+ <!-- Oracle -->
+ <insert id="batchInsert" databaseId="oracle" parameterType="DuplicationUnit" useGeneratedKeys="false">
+ <selectKey order="BEFORE" resultType="Long" keyProperty="id">
+ select duplications_index_seq.NEXTVAL from DUAL
+ </selectKey>
+ INSERT INTO duplications_index (id, snapshot_id, project_snapshot_id, hash, index_in_file, start_line, end_line)
+ VALUES (#{id}, #{snapshotId}, #{projectSnapshotId}, #{hash}, #{indexInFile}, #{startLine}, #{endLine})
+ </insert>
</mapper>
diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql
index 3c89c36d704..dc7aa16b9b9 100644
--- a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql
+++ b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql
@@ -159,6 +159,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('387');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('388');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('389');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('390');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('391');
INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, 'admin', 'Administrator', '', 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '2011-09-26 22:27:48.0', '2011-09-26 22:27:48.0', null, null);
ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2;
diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl
index 805f80fe806..77f660d9bb0 100644
--- a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl
+++ b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl
@@ -204,6 +204,7 @@ CREATE TABLE "PROJECT_LINKS" (
);
CREATE TABLE "DUPLICATIONS_INDEX" (
+ "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
"PROJECT_SNAPSHOT_ID" INTEGER NOT NULL,
"SNAPSHOT_ID" INTEGER NOT NULL,
"HASH" VARCHAR(50) NOT NULL,
diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/391_add_id_to_duplications_index.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/391_add_id_to_duplications_index.rb
new file mode 100644
index 00000000000..0e51e2ba018
--- /dev/null
+++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/391_add_id_to_duplications_index.rb
@@ -0,0 +1,58 @@
+#
+# Sonar, entreprise quality control tool.
+# Copyright (C) 2008-2013 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.
+#
+
+#
+# Sonar 3.6
+# SONAR-3340
+class AddIdToDuplicationsIndex < ActiveRecord::Migration
+
+ class ProjectMeasure < ActiveRecord::Base
+ end
+
+ def self.up
+ case dialect()
+ when "oracle"
+ upgrade_oracle()
+ else
+ add_column :duplications_index, :id, :primary_key
+ end
+ end
+
+ private
+
+ def self.upgrade_oracle
+ execute_ddl('create sequence', 'CREATE SEQUENCE duplications_index_seq START WITH 1 INCREMENT BY 1 NOMAXVALUE')
+ execute_ddl('add id column', 'ALTER TABLE duplications_index add "ID" NUMBER(38)')
+ execute_ddl('create id for existing data','UPDATE duplications_index SET "ID" = duplications_index_seq.nextval')
+ execute_ddl('add primary key constraint', 'ALTER TABLE duplications_index ADD CONSTRAINT pk_duplications_index PRIMARY KEY( "ID" )')
+ end
+
+ def self.execute_ddl(message, ddl)
+ begin
+ say_with_time(message) do
+ ProjectMeasure.connection.execute(ddl)
+ end
+ rescue
+ # already executed
+ end
+ end
+
+end
+