aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-db/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-db/src/main/java')
-rw-r--r--sonar-db/src/main/java/org/sonar/db/component/ComponentDao.java12
-rw-r--r--sonar-db/src/main/java/org/sonar/db/component/ComponentMapper.java7
-rw-r--r--sonar-db/src/main/java/org/sonar/db/component/ComponentUpdateDto.java179
-rw-r--r--sonar-db/src/main/java/org/sonar/db/purge/PurgeConfiguration.java19
-rw-r--r--sonar-db/src/main/java/org/sonar/db/purge/PurgeDao.java39
-rw-r--r--sonar-db/src/main/java/org/sonar/db/purge/PurgeMapper.java7
-rw-r--r--sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java2
-rw-r--r--sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java5
-rw-r--r--sonar-db/src/main/java/org/sonar/db/version/v60/AddBColumnsToProjects.java55
9 files changed, 277 insertions, 48 deletions
diff --git a/sonar-db/src/main/java/org/sonar/db/component/ComponentDao.java b/sonar-db/src/main/java/org/sonar/db/component/ComponentDao.java
index 6742bec2cc0..af24457c602 100644
--- a/sonar-db/src/main/java/org/sonar/db/component/ComponentDao.java
+++ b/sonar-db/src/main/java/org/sonar/db/component/ComponentDao.java
@@ -345,8 +345,16 @@ public class ComponentDao implements Dao {
insert(session, Lists.asList(item, others));
}
- public void update(DbSession session, ComponentDto item) {
- mapper(session).update(item);
+ public void update(DbSession session, ComponentUpdateDto component) {
+ mapper(session).update(component);
+ }
+
+ public void applyBChangesForRootComponentUuid(DbSession session, String projectUuid) {
+ mapper(session).applyBChangesForRootComponentUuid(projectUuid);
+ }
+
+ public void resetBChangedForRootComponentUuid(DbSession session, String projectUuid) {
+ mapper(session).resetBChangedForRootComponentUuid(projectUuid);
}
public void delete(DbSession session, long componentId) {
diff --git a/sonar-db/src/main/java/org/sonar/db/component/ComponentMapper.java b/sonar-db/src/main/java/org/sonar/db/component/ComponentMapper.java
index 9f69872a2fa..74d4b1c92b0 100644
--- a/sonar-db/src/main/java/org/sonar/db/component/ComponentMapper.java
+++ b/sonar-db/src/main/java/org/sonar/db/component/ComponentMapper.java
@@ -141,7 +141,12 @@ public interface ComponentMapper {
void insertBatch(ComponentDto componentDto);
- void update(ComponentDto componentDto);
+ void update(ComponentUpdateDto component);
+
+ void applyBChangesForRootComponentUuid(@Param("projectUuid") String projectUuid);
+
+ void resetBChangedForRootComponentUuid(@Param("projectUuid") String projectUuid);
void delete(long componentId);
+
}
diff --git a/sonar-db/src/main/java/org/sonar/db/component/ComponentUpdateDto.java b/sonar-db/src/main/java/org/sonar/db/component/ComponentUpdateDto.java
new file mode 100644
index 00000000000..7f9af5ab723
--- /dev/null
+++ b/sonar-db/src/main/java/org/sonar/db/component/ComponentUpdateDto.java
@@ -0,0 +1,179 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.db.component;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
+public class ComponentUpdateDto {
+ private String uuid;
+
+ /**
+ * if true, the component is being updated
+ * See https://jira.sonarsource.com/browse/SONAR-7700
+ */
+ private boolean bChanged;
+ private String bCopyComponentUuid;
+ private String bDescription;
+ private boolean bEnabled;
+ private String bLanguage;
+ private String bLongName;
+ private String bModuleUuid;
+ private String bModuleUuidPath;
+ private String bName;
+ private String bPath;
+ private String bQualifier;
+
+ public ComponentUpdateDto setUuid(String uuid) {
+ this.uuid = uuid;
+ return this;
+ }
+
+ public String getUuid() {
+ return uuid;
+ }
+
+ public boolean isBChanged() {
+ return bChanged;
+ }
+
+ @CheckForNull
+ public String getBCopyComponentUuid() {
+ return bCopyComponentUuid;
+ }
+
+ @CheckForNull
+ public String getBDescription() {
+ return bDescription;
+ }
+
+ public boolean isBEnabled() {
+ return bEnabled;
+ }
+
+ @CheckForNull
+ public String getBLanguage() {
+ return bLanguage;
+ }
+
+ @CheckForNull
+ public String getBLongName() {
+ return bLongName;
+ }
+
+ @CheckForNull
+ public String getBModuleUuid() {
+ return bModuleUuid;
+ }
+
+ @CheckForNull
+ public String getBModuleUuidPath() {
+ return bModuleUuidPath;
+ }
+
+ @CheckForNull
+ public String getBName() {
+ return bName;
+ }
+
+ @CheckForNull
+ public String getBPath() {
+ return bPath;
+ }
+
+ @CheckForNull
+ public String getBQualifier() {
+ return bQualifier;
+ }
+
+ public ComponentUpdateDto setBChanged(boolean b) {
+ this.bChanged = b;
+ return this;
+ }
+
+ public ComponentUpdateDto setBCopyComponentUuid(@Nullable String s) {
+ this.bCopyComponentUuid = s;
+ return this;
+ }
+
+ public ComponentUpdateDto setBEnabled(boolean b) {
+ this.bEnabled = b;
+ return this;
+ }
+
+ public ComponentUpdateDto setBName(@Nullable String s) {
+ this.bName = s;
+ return this;
+ }
+
+ public ComponentUpdateDto setBLongName(@Nullable String s) {
+ this.bLongName = s;
+ return this;
+ }
+
+ public ComponentUpdateDto setBDescription(@Nullable String s) {
+ this.bDescription = s;
+ return this;
+ }
+
+ public ComponentUpdateDto setBModuleUuid(@Nullable String s) {
+ this.bModuleUuid = s;
+ return this;
+ }
+
+ public ComponentUpdateDto setBModuleUuidPath(@Nullable String s) {
+ this.bModuleUuidPath = s;
+ return this;
+ }
+
+ public ComponentUpdateDto setBPath(@Nullable String s) {
+ this.bPath = s;
+ return this;
+ }
+
+ public ComponentUpdateDto setBLanguage(@Nullable String s) {
+ this.bLanguage = s;
+ return this;
+ }
+
+ public ComponentUpdateDto setBQualifier(@Nullable String s) {
+ this.bQualifier = s;
+ return this;
+ }
+
+ /**
+ * Copy the A-fields to B-fields. The field bChanged is kept to false.
+ */
+ public static ComponentUpdateDto copyFrom(ComponentDto from) {
+ return new ComponentUpdateDto()
+ .setUuid(from.uuid())
+ .setBChanged(false)
+ .setBCopyComponentUuid(from.getCopyResourceUuid())
+ .setBDescription(from.description())
+ .setBEnabled(from.isEnabled())
+ .setBLanguage(from.language())
+ .setBLongName(from.longName())
+ .setBModuleUuid(from.moduleUuid())
+ .setBModuleUuidPath(from.moduleUuidPath())
+ .setBName(from.name())
+ .setBPath(from.path())
+ .setBQualifier(from.qualifier());
+ }
+}
diff --git a/sonar-db/src/main/java/org/sonar/db/purge/PurgeConfiguration.java b/sonar-db/src/main/java/org/sonar/db/purge/PurgeConfiguration.java
index 4c9256e2f07..6e51564cadc 100644
--- a/sonar-db/src/main/java/org/sonar/db/purge/PurgeConfiguration.java
+++ b/sonar-db/src/main/java/org/sonar/db/purge/PurgeConfiguration.java
@@ -20,6 +20,7 @@
package org.sonar.db.purge;
import com.google.common.annotations.VisibleForTesting;
+import java.util.Collection;
import java.util.Date;
import javax.annotation.CheckForNull;
import org.apache.commons.lang.time.DateUtils;
@@ -34,25 +35,23 @@ public class PurgeConfiguration {
private final String[] scopesWithoutHistoricalData;
private final int maxAgeInDaysOfClosedIssues;
private final System2 system2;
+ private final Collection<String> disabledComponentUuids;
- public PurgeConfiguration(IdUuidPair rootProjectId, String[] scopesWithoutHistoricalData, int maxAgeInDaysOfClosedIssues) {
- this(rootProjectId, scopesWithoutHistoricalData, maxAgeInDaysOfClosedIssues, System2.INSTANCE);
- }
-
- @VisibleForTesting
- PurgeConfiguration(IdUuidPair rootProjectId, String[] scopesWithoutHistoricalData, int maxAgeInDaysOfClosedIssues, System2 system2) {
+ public PurgeConfiguration(IdUuidPair rootProjectId, String[] scopesWithoutHistoricalData, int maxAgeInDaysOfClosedIssues,
+ System2 system2, Collection<String> disabledComponentUuids) {
this.rootProjectIdUuid = rootProjectId;
this.scopesWithoutHistoricalData = scopesWithoutHistoricalData;
this.maxAgeInDaysOfClosedIssues = maxAgeInDaysOfClosedIssues;
this.system2 = system2;
+ this.disabledComponentUuids = disabledComponentUuids;
}
- public static PurgeConfiguration newDefaultPurgeConfiguration(Settings settings, IdUuidPair idUuidPair) {
+ public static PurgeConfiguration newDefaultPurgeConfiguration(Settings settings, IdUuidPair idUuidPair, Collection<String> disabledComponentUuids) {
String[] scopes = new String[] {Scopes.FILE};
if (settings.getBoolean(PurgeConstants.PROPERTY_CLEAN_DIRECTORY)) {
scopes = new String[] {Scopes.DIRECTORY, Scopes.FILE};
}
- return new PurgeConfiguration(idUuidPair, scopes, settings.getInt(PurgeConstants.DAYS_BEFORE_DELETING_CLOSED_ISSUES));
+ return new PurgeConfiguration(idUuidPair, scopes, settings.getInt(PurgeConstants.DAYS_BEFORE_DELETING_CLOSED_ISSUES), System2.INSTANCE, disabledComponentUuids);
}
public IdUuidPair rootProjectIdUuid() {
@@ -63,6 +62,10 @@ public class PurgeConfiguration {
return scopesWithoutHistoricalData;
}
+ public Collection<String> getDisabledComponentUuids() {
+ return disabledComponentUuids;
+ }
+
@CheckForNull
public Date maxLiveDateOfClosedIssues() {
return maxLiveDateOfClosedIssues(new Date(system2.now()));
diff --git a/sonar-db/src/main/java/org/sonar/db/purge/PurgeDao.java b/sonar-db/src/main/java/org/sonar/db/purge/PurgeDao.java
index 93ea962bb19..bd8da668000 100644
--- a/sonar-db/src/main/java/org/sonar/db/purge/PurgeDao.java
+++ b/sonar-db/src/main/java/org/sonar/db/purge/PurgeDao.java
@@ -20,12 +20,11 @@
package org.sonar.db.purge;
import com.google.common.collect.Lists;
-import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.List;
-import org.apache.ibatis.session.SqlSession;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
@@ -63,9 +62,7 @@ public class PurgeDao implements Dao {
deleteAbortedAnalyses(rootUuid, commands);
deleteDataOfComponentsWithoutHistoricalData(session, rootUuid, conf.scopesWithoutHistoricalData(), commands);
purgeAnalyses(commands, rootUuid);
-
- // FIXME to be re-enabled with
- //disableOrphanResources(rootUuid, session, mapper, listener);
+ purgeDisabledComponents(session, conf.getDisabledComponentUuids(), listener);
deleteOldClosedIssues(conf, mapper, listener);
}
@@ -135,19 +132,17 @@ public class PurgeDao implements Dao {
.setSortFields(UUID_FIELD_SORT);
}
- private void disableOrphanResources(String rootUuid, SqlSession session, PurgeMapper mapper, PurgeListener listener) {
- List<String> componentUuids = new ArrayList<>();
- mapper.selectComponentUuidsToDisable(
- rootUuid,
- resultContext -> {
- String componentUuid = (String) resultContext.getResultObject();
- if (componentUuid != null) {
- componentUuids.add(componentUuid);
- }
+ private void purgeDisabledComponents(DbSession session, Collection<String> uuids, PurgeListener listener) {
+ PurgeMapper mapper = mapper(session);
+ executeLargeInputs(uuids,
+ input -> {
+ mapper.deleteResourceIndex(input);
+ mapper.deleteFileSourcesByUuid(input);
+ mapper.resolveComponentIssuesNotAlreadyResolved(input, system2.now());
+ return emptyList();
});
- disableComponents(componentUuids, mapper);
- for (String componentUuid : componentUuids) {
+ for (String componentUuid : uuids) {
listener.onComponentDisabling(componentUuid);
}
@@ -178,18 +173,6 @@ public class PurgeDao implements Dao {
commands.deleteCeActivity(rootUuid);
}
- private void disableComponents(List<String> uuids, PurgeMapper mapper) {
- executeLargeInputs(uuids,
- input -> {
- mapper.deleteResourceIndex(input);
- mapper.setAnalysisIsLastToFalse(input);
- mapper.deleteFileSourcesByUuid(input);
- mapper.disableComponent(input);
- mapper.resolveComponentIssuesNotAlreadyResolved(input, system2.now());
- return emptyList();
- });
- }
-
public void deleteAnalyses(DbSession session, PurgeProfiler profiler, List<IdUuidPair> analysisIdUuids) {
new PurgeCommands(session, profiler).deleteAnalyses(analysisIdUuids);
}
diff --git a/sonar-db/src/main/java/org/sonar/db/purge/PurgeMapper.java b/sonar-db/src/main/java/org/sonar/db/purge/PurgeMapper.java
index 0b6aaa5011b..91cb547e29f 100644
--- a/sonar-db/src/main/java/org/sonar/db/purge/PurgeMapper.java
+++ b/sonar-db/src/main/java/org/sonar/db/purge/PurgeMapper.java
@@ -22,7 +22,6 @@ package org.sonar.db.purge;
import java.util.List;
import javax.annotation.Nullable;
import org.apache.ibatis.annotations.Param;
-import org.apache.ibatis.session.ResultHandler;
public interface PurgeMapper {
@@ -33,8 +32,6 @@ public interface PurgeMapper {
*/
List<IdUuidPair> selectComponentsByProjectUuid(String projectUuid);
- void selectComponentUuidsToDisable(@Param("rootUuid") String rootUuid, ResultHandler resultHandler);
-
void deleteAnalyses(@Param("analysisUuids") List<String> analysisUuids);
void deleteAnalysisDuplications(@Param("analysisUuids") List<String> analysisUuids);
@@ -53,14 +50,10 @@ public interface PurgeMapper {
void updatePurgeStatusToOne(@Param("analysisUuids") List<String> analysisUuid);
- void disableComponent(@Param("componentUuids") List<String> componentUuids);
-
void resolveComponentIssuesNotAlreadyResolved(@Param("componentUuids") List<String> componentUuids, @Param("dateAsLong") Long dateAsLong);
void deleteResourceIndex(@Param("componentUuids") List<String> componentUuids);
- void setAnalysisIsLastToFalse(@Param("componentUuids") List<String> componentUuids);
-
void deleteComponentLinks(@Param("componentUuids") List<String> componentUuids);
void deleteComponentProperties(@Param("componentIds") List<Long> componentIds);
diff --git a/sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java b/sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java
index 616324a2ed8..796c16e5954 100644
--- a/sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java
+++ b/sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java
@@ -30,7 +30,7 @@ import org.sonar.db.MyBatis;
public class DatabaseVersion {
- public static final int LAST_VERSION = 1_275;
+ public static final int LAST_VERSION = 1_276;
/**
* The minimum supported version which can be upgraded. Lower
diff --git a/sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java b/sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java
index 41900151987..72d947d5e85 100644
--- a/sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java
+++ b/sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java
@@ -87,6 +87,7 @@ import org.sonar.db.version.v60.AddAnalysisUuidColumnToCeActivity;
import org.sonar.db.version.v60.AddAnalysisUuidColumnToDuplicationsIndex;
import org.sonar.db.version.v60.AddAnalysisUuidColumnToEvents;
import org.sonar.db.version.v60.AddAnalysisUuidColumnToMeasures;
+import org.sonar.db.version.v60.AddBColumnsToProjects;
import org.sonar.db.version.v60.AddComponentUuidColumnToDuplicationsIndex;
import org.sonar.db.version.v60.AddComponentUuidColumnToMeasures;
import org.sonar.db.version.v60.AddComponentUuidColumnsToSnapshots;
@@ -310,6 +311,8 @@ public class MigrationStepModule extends Module {
DropTreesOfSnapshots.class,
DropTreeColumnsFromSnapshots.class,
- DropSnapshotIdColumnFromMeasures.class);
+ DropSnapshotIdColumnFromMeasures.class,
+ AddBColumnsToProjects.class
+ );
}
}
diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/AddBColumnsToProjects.java b/sonar-db/src/main/java/org/sonar/db/version/v60/AddBColumnsToProjects.java
new file mode 100644
index 00000000000..72af465d5b2
--- /dev/null
+++ b/sonar-db/src/main/java/org/sonar/db/version/v60/AddBColumnsToProjects.java
@@ -0,0 +1,55 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.db.version.v60;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.db.version.AddColumnsBuilder;
+import org.sonar.db.version.DdlChange;
+
+import static org.sonar.db.version.BooleanColumnDef.newBooleanColumnDefBuilder;
+import static org.sonar.db.version.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class AddBColumnsToProjects extends DdlChange {
+
+ private static final String TABLE_PROJECTS = "projects";
+
+ public AddBColumnsToProjects(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AddColumnsBuilder(getDatabase().getDialect(), TABLE_PROJECTS)
+ .addColumn(newBooleanColumnDefBuilder().setColumnName("b_changed").build())
+ .addColumn(newVarcharColumnDefBuilder().setColumnName("b_copy_component_uuid").setLimit(50).setIsNullable(true).build())
+ .addColumn(newVarcharColumnDefBuilder().setColumnName("b_description").setLimit(2000).setIsNullable(true).build())
+ .addColumn(newBooleanColumnDefBuilder().setColumnName("b_enabled").build())
+ .addColumn(newVarcharColumnDefBuilder().setColumnName("b_language").setLimit(20).setIsNullable(true).build())
+ .addColumn(newVarcharColumnDefBuilder().setColumnName("b_long_name").setLimit(2000).setIsNullable(true).build())
+ .addColumn(newVarcharColumnDefBuilder().setColumnName("b_module_uuid").setLimit(50).setIsNullable(true).build())
+ .addColumn(newVarcharColumnDefBuilder().setColumnName("b_module_uuid_path").setLimit(4000).setIsNullable(true).build())
+ .addColumn(newVarcharColumnDefBuilder().setColumnName("b_name").setLimit(2000).setIsNullable(true).build())
+ .addColumn(newVarcharColumnDefBuilder().setColumnName("b_path").setLimit(2000).setIsNullable(true).build())
+ .addColumn(newVarcharColumnDefBuilder().setColumnName("b_qualifier").setLimit(3).setIsNullable(true).build())
+ .build());
+ }
+
+}