aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2015-01-14 16:38:05 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2015-01-14 16:38:13 +0100
commited9951f36292c30b82f49423c184ba3259b05aac (patch)
treeb63c7e58b9534950c764c67c07be371737078823 /sonar-core
parent47e1279bacee4f9ca5bbd46a51bde25efac35a67 (diff)
downloadsonarqube-ed9951f36292c30b82f49423c184ba3259b05aac.tar.gz
sonarqube-ed9951f36292c30b82f49423c184ba3259b05aac.zip
Fix issue on project bulk update key
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/preview/PreviewCache.java15
-rw-r--r--sonar-core/src/main/java/org/sonar/core/resource/ResourceKeyUpdaterDao.java39
-rw-r--r--sonar-core/src/test/java/org/sonar/core/preview/PreviewCacheTest.java9
3 files changed, 37 insertions, 26 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/preview/PreviewCache.java b/sonar-core/src/main/java/org/sonar/core/preview/PreviewCache.java
index 57c2adeae9d..9cfeceec661 100644
--- a/sonar-core/src/main/java/org/sonar/core/preview/PreviewCache.java
+++ b/sonar-core/src/main/java/org/sonar/core/preview/PreviewCache.java
@@ -27,6 +27,7 @@ import org.slf4j.LoggerFactory;
import org.sonar.api.ServerExtension;
import org.sonar.api.platform.ServerFileSystem;
import org.sonar.api.utils.SonarException;
+import org.sonar.core.persistence.DbSession;
import org.sonar.core.persistence.MyBatis;
import org.sonar.core.persistence.PreviewDatabaseFactory;
import org.sonar.core.properties.PropertiesDao;
@@ -207,11 +208,21 @@ public class PreviewCache implements ServerExtension {
}
public void reportResourceModification(String resourceKey) {
- ResourceDto rootProject = resourceDao.getRootProjectByComponentKey(resourceKey);
+ DbSession session = mybatis.openSession(false);
+ try {
+ reportResourceModification(session, resourceKey);
+ session.commit();
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+
+ public void reportResourceModification(DbSession session, String resourceKey) {
+ ResourceDto rootProject = resourceDao.getRootProjectByComponentKey(session, resourceKey);
if (rootProject == null) {
throw new SonarException("Unable to find root project for component with [key=" + resourceKey + "]");
}
propertiesDao.setProperty(new PropertyDto().setKey(SONAR_PREVIEW_CACHE_LAST_UPDATE_KEY).setResourceId(rootProject.getId())
- .setValue(String.valueOf(System.currentTimeMillis())));
+ .setValue(String.valueOf(System.currentTimeMillis())), session);
}
}
diff --git a/sonar-core/src/main/java/org/sonar/core/resource/ResourceKeyUpdaterDao.java b/sonar-core/src/main/java/org/sonar/core/resource/ResourceKeyUpdaterDao.java
index 06a202424dd..37d41bac024 100644
--- a/sonar-core/src/main/java/org/sonar/core/resource/ResourceKeyUpdaterDao.java
+++ b/sonar-core/src/main/java/org/sonar/core/resource/ResourceKeyUpdaterDao.java
@@ -87,27 +87,30 @@ public class ResourceKeyUpdaterDao {
return result;
}
- public void bulkUpdateKey(long projectId, String stringToReplace, String replacementString) {
- DbSession session = mybatis.openSession(true);
+ public void bulkUpdateKey(DbSession session, long projectId, String stringToReplace, String replacementString) {
ResourceKeyUpdaterMapper mapper = session.getMapper(ResourceKeyUpdaterMapper.class);
- try {
- // must SELECT first everything
- Set<ResourceDto> modules = collectAllModules(projectId, stringToReplace, mapper);
- checkNewNameOfAllModules(modules, stringToReplace, replacementString, mapper);
- Map<ResourceDto, List<ResourceDto>> allResourcesByModuleMap = Maps.newHashMap();
- for (ResourceDto module : modules) {
- allResourcesByModuleMap.put(module, mapper.selectProjectResources(module.getId()));
- }
+ // must SELECT first everything
+ Set<ResourceDto> modules = collectAllModules(projectId, stringToReplace, mapper);
+ checkNewNameOfAllModules(modules, stringToReplace, replacementString, mapper);
+ Map<ResourceDto, List<ResourceDto>> allResourcesByModuleMap = Maps.newHashMap();
+ for (ResourceDto module : modules) {
+ allResourcesByModuleMap.put(module, mapper.selectProjectResources(module.getId()));
+ }
- // and then proceed with the batch UPDATE at once
- for (ResourceDto module : modules) {
- String oldModuleKey = module.getKey();
- String newModuleKey = computeNewKey(module, stringToReplace, replacementString);
- Collection<ResourceDto> resources = Lists.newArrayList(module);
- resources.addAll(allResourcesByModuleMap.get(module));
- runBatchUpdateForAllResources(resources, oldModuleKey, newModuleKey, mapper);
- }
+ // and then proceed with the batch UPDATE at once
+ for (ResourceDto module : modules) {
+ String oldModuleKey = module.getKey();
+ String newModuleKey = computeNewKey(module, stringToReplace, replacementString);
+ Collection<ResourceDto> resources = Lists.newArrayList(module);
+ resources.addAll(allResourcesByModuleMap.get(module));
+ runBatchUpdateForAllResources(resources, oldModuleKey, newModuleKey, mapper);
+ }
+ }
+ public void bulkUpdateKey(long projectId, String stringToReplace, String replacementString) {
+ DbSession session = mybatis.openSession(true);
+ try {
+ bulkUpdateKey(session, projectId, stringToReplace, replacementString);
session.commit();
} finally {
MyBatis.closeQuietly(session);
diff --git a/sonar-core/src/test/java/org/sonar/core/preview/PreviewCacheTest.java b/sonar-core/src/test/java/org/sonar/core/preview/PreviewCacheTest.java
index c635741e6d4..6ef5ae0974e 100644
--- a/sonar-core/src/test/java/org/sonar/core/preview/PreviewCacheTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/preview/PreviewCacheTest.java
@@ -45,10 +45,7 @@ import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.isNull;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.*;
public class PreviewCacheTest {
@@ -226,7 +223,7 @@ public class PreviewCacheTest {
@Test
public void test_report_resource_modification() {
- when(resourceDao.getRootProjectByComponentKey("foo")).thenReturn(new ResourceDto().setId(456L));
+ when(resourceDao.getRootProjectByComponentKey(session, "foo")).thenReturn(new ResourceDto().setId(456L));
dryRunCache.reportResourceModification("foo");
@@ -234,6 +231,6 @@ public class PreviewCacheTest {
new PropertyDto()
.setKey(PreviewCache.SONAR_PREVIEW_CACHE_LAST_UPDATE_KEY)
.setValue(anyString())
- .setResourceId(456L));
+ .setResourceId(456L), eq(session));
}
}