From 4ad73a8ade0de8d42b34480d387e77156017929c Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Mon, 9 Mar 2015 17:22:55 +0100 Subject: [PATCH] SONAR-6262 Add project_links.component_uuid column --- .../db/migrations/DatabaseMigrations.java | 6 +- .../v52/FeedProjectLinksComponentUuid.java | 56 +++++++++++++++++ .../db/migrations/v52/package-info.java | 25 ++++++++ .../FeedProjectLinksComponentUuidTest.java | 62 +++++++++++++++++++ .../migrate-result.xml | 24 +++++++ .../migrate.xml | 22 +++++++ .../not_migrate_already_migrated_data.xml | 24 +++++++ .../schema.sql | 31 ++++++++++ .../WEB-INF/app/models/measure_filter.rb | 10 ++- .../main/webapp/WEB-INF/app/models/project.rb | 2 +- .../webapp/WEB-INF/app/models/project_link.rb | 2 +- .../900_add_project_links_component_uuid.rb | 31 ++++++++++ .../901_feed_project_links_component_uuid.rb | 31 ++++++++++ .../902_remove_project_links_project_id.rb | 31 ++++++++++ .../core/persistence/DatabaseVersion.java | 2 +- .../org/sonar/core/purge/PurgeCommands.java | 4 +- .../org/sonar/core/purge/PurgeMapper.java | 3 +- .../org/sonar/core/persistence/rows-h2.sql | 3 + .../org/sonar/core/persistence/schema-h2.ddl | 2 +- .../org/sonar/core/purge/PurgeMapper.xml | 6 +- .../api/database/model/ResourceModel.java | 10 +-- .../org/sonar/api/resources/ProjectLink.java | 2 +- 22 files changed, 366 insertions(+), 23 deletions(-) create mode 100644 server/sonar-server/src/main/java/org/sonar/server/db/migrations/v52/FeedProjectLinksComponentUuid.java create mode 100644 server/sonar-server/src/main/java/org/sonar/server/db/migrations/v52/package-info.java create mode 100644 server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedProjectLinksComponentUuidTest.java create mode 100644 server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedProjectLinksComponentUuidTest/migrate-result.xml create mode 100644 server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedProjectLinksComponentUuidTest/migrate.xml create mode 100644 server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedProjectLinksComponentUuidTest/not_migrate_already_migrated_data.xml create mode 100644 server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedProjectLinksComponentUuidTest/schema.sql create mode 100644 server/sonar-web/src/main/webapp/WEB-INF/db/migrate/900_add_project_links_component_uuid.rb create mode 100644 server/sonar-web/src/main/webapp/WEB-INF/db/migrate/901_feed_project_links_component_uuid.rb create mode 100644 server/sonar-web/src/main/webapp/WEB-INF/db/migrate/902_remove_project_links_project_id.rb diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/DatabaseMigrations.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/DatabaseMigrations.java index 6afedd0a1f6..86cffa68afd 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/DatabaseMigrations.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/DatabaseMigrations.java @@ -31,6 +31,7 @@ import org.sonar.server.db.migrations.v451.AddMissingCustomRuleParametersMigrati import org.sonar.server.db.migrations.v451.DeleteUnescapedActivities; import org.sonar.server.db.migrations.v50.*; import org.sonar.server.db.migrations.v51.*; +import org.sonar.server.db.migrations.v52.FeedProjectLinksComponentUuid; import java.util.List; @@ -93,6 +94,9 @@ public interface DatabaseMigrations { FeedManualMeasuresLongDates.class, FeedEventsLongDates.class, AddNewCharacteristics.class, - RemovePermissionsOnModulesMigration.class + RemovePermissionsOnModulesMigration.class, + + // 5.2 + FeedProjectLinksComponentUuid.class ); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v52/FeedProjectLinksComponentUuid.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v52/FeedProjectLinksComponentUuid.java new file mode 100644 index 00000000000..a567bad6751 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v52/FeedProjectLinksComponentUuid.java @@ -0,0 +1,56 @@ +/* + * 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.server.db.migrations.v52; + +import org.sonar.core.persistence.Database; +import org.sonar.server.db.migrations.BaseDataChange; +import org.sonar.server.db.migrations.MassUpdate; +import org.sonar.server.db.migrations.MassUpdate.Handler; +import org.sonar.server.db.migrations.Select.Row; +import org.sonar.server.db.migrations.SqlStatement; + +import java.sql.SQLException; + +public class FeedProjectLinksComponentUuid extends BaseDataChange { + + public FeedProjectLinksComponentUuid(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + MassUpdate update = context.prepareMassUpdate().rowPluralName("project links"); + update.select( + "SELECT p.uuid, link.id " + + "FROM project_links link " + + "INNER JOIN projects p ON p.id=link.project_id " + + "WHERE link.component_uuid is null"); + update.update("UPDATE project_links SET component_uuid=? WHERE id=?"); + update.execute(new Handler() { + @Override + public boolean handle(Row row, SqlStatement update) throws SQLException { + update.setString(1, row.getString(1)); + update.setLong(2, row.getLong(2)); + return true; + } + }); + } +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v52/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v52/package-info.java new file mode 100644 index 00000000000..de542c43697 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v52/package-info.java @@ -0,0 +1,25 @@ +/* + * 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.server.db.migrations.v52; + +import javax.annotation.ParametersAreNonnullByDefault; + diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedProjectLinksComponentUuidTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedProjectLinksComponentUuidTest.java new file mode 100644 index 00000000000..256660c7ebf --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedProjectLinksComponentUuidTest.java @@ -0,0 +1,62 @@ +/* + * 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.server.db.migrations.v52; + +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Test; +import org.sonar.core.persistence.DbTester; +import org.sonar.server.db.migrations.DatabaseMigration; + +public class FeedProjectLinksComponentUuidTest { + + @ClassRule + public static DbTester db = new DbTester().schema(FeedProjectLinksComponentUuidTest.class, "schema.sql"); + + DatabaseMigration migration; + + @Before + public void setUp() throws Exception { + db.executeUpdateSql("truncate table project_links"); + + migration = new FeedProjectLinksComponentUuid(db.database()); + } + + @Test + public void migrate_empty_db() throws Exception { + migration.execute(); + } + + @Test + public void migrate() throws Exception { + db.prepareDbUnit(this.getClass(), "migrate.xml"); + migration.execute(); + db.assertDbUnit(this.getClass(), "migrate-result.xml", "project_links"); + } + + @Test + public void not_migrate_already_migrated_data() throws Exception { + db.prepareDbUnit(this.getClass(), "not_migrate_already_migrated_data.xml"); + migration.execute(); + db.assertDbUnit(this.getClass(), "not_migrate_already_migrated_data.xml", "project_links"); + } + +} diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedProjectLinksComponentUuidTest/migrate-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedProjectLinksComponentUuidTest/migrate-result.xml new file mode 100644 index 00000000000..f4c0e64e068 --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedProjectLinksComponentUuidTest/migrate-result.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedProjectLinksComponentUuidTest/migrate.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedProjectLinksComponentUuidTest/migrate.xml new file mode 100644 index 00000000000..b7143fc55cf --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedProjectLinksComponentUuidTest/migrate.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedProjectLinksComponentUuidTest/not_migrate_already_migrated_data.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedProjectLinksComponentUuidTest/not_migrate_already_migrated_data.xml new file mode 100644 index 00000000000..08a42761a3c --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedProjectLinksComponentUuidTest/not_migrate_already_migrated_data.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedProjectLinksComponentUuidTest/schema.sql b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedProjectLinksComponentUuidTest/schema.sql new file mode 100644 index 00000000000..f04590ffebd --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedProjectLinksComponentUuidTest/schema.sql @@ -0,0 +1,31 @@ +CREATE TABLE "PROJECT_LINKS" ( + "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), + "PROJECT_ID" INTEGER NOT NULL, + "COMPONENT_UUID" VARCHAR(50), + "LINK_TYPE" VARCHAR(20), + "NAME" VARCHAR(128), + "HREF" VARCHAR(2048) NOT NULL +); + +CREATE TABLE "PROJECTS" ( + "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), + "KEE" VARCHAR(400), + "ROOT_ID" INTEGER, + "UUID" VARCHAR(50), + "PROJECT_UUID" VARCHAR(50), + "MODULE_UUID" VARCHAR(50), + "MODULE_UUID_PATH" VARCHAR(4000), + "NAME" VARCHAR(256), + "DESCRIPTION" VARCHAR(2000), + "ENABLED" BOOLEAN NOT NULL DEFAULT TRUE, + "SCOPE" VARCHAR(3), + "QUALIFIER" VARCHAR(10), + "DEPRECATED_KEE" VARCHAR(400), + "PATH" VARCHAR(2000), + "LANGUAGE" VARCHAR(20), + "COPY_RESOURCE_ID" INTEGER, + "LONG_NAME" VARCHAR(256), + "PERSON_ID" INTEGER, + "CREATED_AT" TIMESTAMP, + "AUTHORIZATION_UPDATED_AT" BIGINT +); diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/models/measure_filter.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/models/measure_filter.rb index bed5b3abdf9..255f6355966 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/models/measure_filter.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/models/measure_filter.rb @@ -288,18 +288,22 @@ class MeasureFilter < ActiveRecord::Base if require_links? project_ids = [] + project_uuids = [] + project_id_by_uuid = {} rows_by_project_id = {} snapshots.each do |snapshot| project_ids << snapshot.project_id + project_uuids << snapshot.project.uuid + project_id_by_uuid[snapshot.project.uuid] = snapshot.project_id rows_by_project_id[snapshot.project_id] = rows_by_snapshot_id[snapshot.id] end links = [] - project_ids.each_slice(999) do |safe_for_oracle_ids| - links.concat(ProjectLink.all(:conditions => {:project_id => safe_for_oracle_ids}, :order => 'link_type')) + project_uuids.each_slice(999) do |safe_for_oracle_uuids| + links.concat(ProjectLink.all(:conditions => {:component_uuid => safe_for_oracle_uuids}, :order => 'link_type')) end links.each do |link| - rows_by_project_id[link.project_id].add_link(link) + rows_by_project_id[project_id_by_uuid[link.component_uuid]].add_link(link) end end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/models/project.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/models/project.rb index 9b8d332ec12..f8d83a5640b 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/models/project.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/models/project.rb @@ -24,7 +24,7 @@ class Project < ActiveRecord::Base has_many :snapshots has_many :processed_snapshots, :class_name => 'Snapshot', :conditions => "status='#{Snapshot::STATUS_PROCESSED}' AND qualifier<>'LIB'", :order => 'created_at asc' has_many :events, :foreign_key => 'resource_id', :order => 'event_date DESC' - has_many :project_links, :dependent => :delete_all, :order => 'link_type' + has_many :project_links, :foreign_key => 'component_uuid', :primary_key => 'uuid', :dependent => :delete_all, :order => 'link_type' has_many :user_roles, :foreign_key => 'resource_id' has_many :group_roles, :foreign_key => 'resource_id' has_many :manual_measures, :foreign_key => 'resource_id' diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/models/project_link.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/models/project_link.rb index 794722faa18..66bd78f004c 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/models/project_link.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/models/project_link.rb @@ -18,7 +18,7 @@ # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # class ProjectLink < ActiveRecord::Base - belongs_to :project + belongs_to :project, :foreign_key => 'uuid', :primary_key => 'component_uuid' LINK_HOMEPAGE = "homepage" LINK_CONTINUOUS_INTEGRATION = "ci" diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/900_add_project_links_component_uuid.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/900_add_project_links_component_uuid.rb new file mode 100644 index 00000000000..97da0c9b437 --- /dev/null +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/900_add_project_links_component_uuid.rb @@ -0,0 +1,31 @@ +# +# 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. +# + +# +# SonarQube 5.2 +# SONAR-6262 +# +class AddProjectLinksComponentUuid < ActiveRecord::Migration + + def self.up + add_column 'project_links', 'component_uuid', :string, :limit => 50 + end + +end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/901_feed_project_links_component_uuid.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/901_feed_project_links_component_uuid.rb new file mode 100644 index 00000000000..e35cedf1125 --- /dev/null +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/901_feed_project_links_component_uuid.rb @@ -0,0 +1,31 @@ +# +# 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. +# + +# +# SonarQube 5.2 +# SONAR-6262 +# +class FeedProjectLinksComponentUuid < ActiveRecord::Migration + + def self.up + execute_java_migration('org.sonar.server.db.migrations.v52.FeedProjectLinksComponentUuid') + end + +end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/902_remove_project_links_project_id.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/902_remove_project_links_project_id.rb new file mode 100644 index 00000000000..6130008512e --- /dev/null +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/902_remove_project_links_project_id.rb @@ -0,0 +1,31 @@ +# +# 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. +# + +# +# SonarQube 5.2 +# SONAR-6262 +# +class RemoveProjectLinksProjectId < ActiveRecord::Migration + + def self.up + remove_column 'project_links', 'project_id' + end + +end 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 48459ea8fc6..1ebd681a27c 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 @@ -33,7 +33,7 @@ import java.util.List; */ public class DatabaseVersion implements BatchComponent, ServerComponent { - public static final int LAST_VERSION = 796; + public static final int LAST_VERSION = 902; /** * List of all the tables.n diff --git a/sonar-core/src/main/java/org/sonar/core/purge/PurgeCommands.java b/sonar-core/src/main/java/org/sonar/core/purge/PurgeCommands.java index 687788e415d..6abf150e396 100644 --- a/sonar-core/src/main/java/org/sonar/core/purge/PurgeCommands.java +++ b/sonar-core/src/main/java/org/sonar/core/purge/PurgeCommands.java @@ -63,8 +63,8 @@ class PurgeCommands { // possible missing optimization: filter requests according to resource scope profiler.start("deleteResourceLinks (project_links)"); - for (List partResourceIds : componentIdPartitions) { - purgeMapper.deleteResourceLinks(partResourceIds); + for (List componentUuidPartition : componentUuidsPartitions) { + purgeMapper.deleteResourceLinks(componentUuidPartition); } session.commit(); profiler.stop(); diff --git a/sonar-core/src/main/java/org/sonar/core/purge/PurgeMapper.java b/sonar-core/src/main/java/org/sonar/core/purge/PurgeMapper.java index 643cb15c4a9..730b6845f43 100644 --- a/sonar-core/src/main/java/org/sonar/core/purge/PurgeMapper.java +++ b/sonar-core/src/main/java/org/sonar/core/purge/PurgeMapper.java @@ -22,6 +22,7 @@ package org.sonar.core.purge; import org.apache.ibatis.annotations.Param; import javax.annotation.Nullable; + import java.util.List; public interface PurgeMapper { @@ -66,7 +67,7 @@ public interface PurgeMapper { void setSnapshotIsLastToFalse(long resourceId); - void deleteResourceLinks(@Param("resourceIds") List resourceIds); + void deleteResourceLinks(@Param("componentUuids") List componentUuids); void deleteResourceProperties(@Param("resourceIds") List resourceIds); 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 a410243e678..f09dceaddea 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 @@ -323,6 +323,9 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('793'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('794'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('795'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('796'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('900'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('901'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('902'); 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', '1418215735482', '1418215735482', 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 a722b4673ae..91af4c31769 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 @@ -202,7 +202,7 @@ CREATE TABLE "PROPERTIES" ( CREATE TABLE "PROJECT_LINKS" ( "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), - "PROJECT_ID" INTEGER NOT NULL, + "COMPONENT_UUID" VARCHAR(50), "LINK_TYPE" VARCHAR(20), "NAME" VARCHAR(128), "HREF" VARCHAR(2048) NOT NULL diff --git a/sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml b/sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml index 38d83162163..04c718a1eca 100644 --- a/sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml @@ -197,9 +197,9 @@ - delete from project_links where project_id in - - #{resourceId} + delete from project_links where component_uuid in + + #{componentUuid} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/ResourceModel.java b/sonar-plugin-api/src/main/java/org/sonar/api/database/model/ResourceModel.java index 25b564605e0..3f0f2469cbb 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/ResourceModel.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/database/model/ResourceModel.java @@ -30,14 +30,7 @@ import org.sonar.api.resources.ProjectLink; import org.sonar.api.resources.Resource; import javax.annotation.Nullable; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; +import javax.persistence.*; import java.util.ArrayList; import java.util.Date; @@ -102,6 +95,7 @@ public class ResourceModel extends BaseIdentifiable implements Cloneable { private Date createdAt; @OneToMany(mappedBy = "resource", fetch = FetchType.LAZY, cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REMOVE}) + @JoinColumn(name = "component_uuid") @BatchSize(size = 8) private List projectLinks = new ArrayList(); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/ProjectLink.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/ProjectLink.java index 079d5160417..3e4f276571d 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/ProjectLink.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/ProjectLink.java @@ -38,7 +38,7 @@ public class ProjectLink extends BaseIdentifiable { public static final int HREF_COLUMN_SIZE = 2048; @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "project_id", updatable = false, nullable = false) + @JoinColumn(name = "component_uuid", referencedColumnName = "uuid", updatable = false, nullable = false) private ResourceModel resource; @Column(name = "link_type", updatable = true, nullable = true, length = 20) -- 2.39.5