From 099d46d39848b39df264fc75592868d4c9ca5e56 Mon Sep 17 00:00:00 2001 From: Teryk Bellahsene Date: Thu, 4 Aug 2016 17:45:59 +0200 Subject: [PATCH] Rename ResourceKeyUpdaterDao to ComponentKeyUpdaterDao --- .../server/component/ComponentService.java | 6 +++--- .../component/ws/BulkUpdateKeyAction.java | 2 +- .../src/main/java/org/sonar/db/DaoModule.java | 4 ++-- .../src/main/java/org/sonar/db/DbClient.java | 10 +++++----- .../src/main/java/org/sonar/db/MyBatis.java | 4 ++-- ...erDao.java => ComponentKeyUpdaterDao.java} | 20 +++++++++---------- ...er.java => ComponentKeyUpdaterMapper.java} | 2 +- ...pper.xml => ComponentKeyUpdaterMapper.xml} | 2 +- ...t.java => ComponentKeyUpdaterDaoTest.java} | 4 ++-- .../shared.xml | 0 .../shouldBulkUpdateKey-result.xml | 0 ...BulkUpdateKeyOnOnlyOneSubmodule-result.xml | 0 .../shouldNotUpdateAllSubmodules-result.xml | 0 .../shouldNotUpdateAllSubmodules.xml | 0 .../shouldUpdateKey-result.xml | 0 15 files changed, 27 insertions(+), 27 deletions(-) rename sonar-db/src/main/java/org/sonar/db/component/{ResourceKeyUpdaterDao.java => ComponentKeyUpdaterDao.java} (90%) rename sonar-db/src/main/java/org/sonar/db/component/{ResourceKeyUpdaterMapper.java => ComponentKeyUpdaterMapper.java} (96%) rename sonar-db/src/main/resources/org/sonar/db/component/{ResourceKeyUpdaterMapper.xml => ComponentKeyUpdaterMapper.xml} (95%) rename sonar-db/src/test/java/org/sonar/db/component/{ResourceKeyUpdaterDaoTest.java => ComponentKeyUpdaterDaoTest.java} (97%) rename sonar-db/src/test/resources/org/sonar/db/component/{ResourceKeyUpdaterDaoTest => ComponentKeyUpdaterDaoTest}/shared.xml (100%) rename sonar-db/src/test/resources/org/sonar/db/component/{ResourceKeyUpdaterDaoTest => ComponentKeyUpdaterDaoTest}/shouldBulkUpdateKey-result.xml (100%) rename sonar-db/src/test/resources/org/sonar/db/component/{ResourceKeyUpdaterDaoTest => ComponentKeyUpdaterDaoTest}/shouldBulkUpdateKeyOnOnlyOneSubmodule-result.xml (100%) rename sonar-db/src/test/resources/org/sonar/db/component/{ResourceKeyUpdaterDaoTest => ComponentKeyUpdaterDaoTest}/shouldNotUpdateAllSubmodules-result.xml (100%) rename sonar-db/src/test/resources/org/sonar/db/component/{ResourceKeyUpdaterDaoTest => ComponentKeyUpdaterDaoTest}/shouldNotUpdateAllSubmodules.xml (100%) rename sonar-db/src/test/resources/org/sonar/db/component/{ResourceKeyUpdaterDaoTest => ComponentKeyUpdaterDaoTest}/shouldUpdateKey-result.xml (100%) diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ComponentService.java b/server/sonar-server/src/main/java/org/sonar/server/component/ComponentService.java index d2c3bd8b730..59aa3d0b31f 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/ComponentService.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/ComponentService.java @@ -123,7 +123,7 @@ public class ComponentService { checkIsProjectOrModule(component); checkProjectOrModuleKeyFormat(newKey); - dbClient.resourceKeyUpdaterDao().updateKey(component.uuid(), newKey); + dbClient.componentKeyUpdaterDao().updateKey(component.uuid(), newKey); } public Map checkModuleKeysBeforeRenaming(String projectKey, String stringToReplace, String replacementString) { @@ -131,7 +131,7 @@ public class ComponentService { try { ComponentDto project = getByKey(projectKey); userSession.checkComponentUuidPermission(UserRole.ADMIN, project.projectUuid()); - return dbClient.resourceKeyUpdaterDao().checkModuleKeysBeforeRenaming(project.uuid(), stringToReplace, replacementString); + return dbClient.componentKeyUpdaterDao().checkModuleKeysBeforeRenaming(project.uuid(), stringToReplace, replacementString); } finally { session.close(); } @@ -141,7 +141,7 @@ public class ComponentService { ComponentDto project = getByKey(dbSession, projectKey); userSession.checkComponentUuidPermission(UserRole.ADMIN, project.projectUuid()); checkIsProjectOrModule(project); - dbClient.resourceKeyUpdaterDao().bulkUpdateKey(dbSession, project.uuid(), stringToReplace, replacementString); + dbClient.componentKeyUpdaterDao().bulkUpdateKey(dbSession, project.uuid(), stringToReplace, replacementString); } public void bulkUpdateKey(String projectKey, String stringToReplace, String replacementString) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ws/BulkUpdateKeyAction.java b/server/sonar-server/src/main/java/org/sonar/server/component/ws/BulkUpdateKeyAction.java index fe403a77f2a..f3ee2b81a1d 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/ws/BulkUpdateKeyAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/ws/BulkUpdateKeyAction.java @@ -55,7 +55,7 @@ public class BulkUpdateKeyAction implements ComponentsWsAction { public BulkUpdateKeyAction(DbClient dbClient, ComponentFinder componentFinder, UserSession userSession) { this.dbClient = dbClient; - this.componentKeyUpdater = dbClient.resourceKeyUpdaterDao(); + this.componentKeyUpdater = dbClient.componentKeyUpdaterDao(); this.componentFinder = componentFinder; this.userSession = userSession; } diff --git a/sonar-db/src/main/java/org/sonar/db/DaoModule.java b/sonar-db/src/main/java/org/sonar/db/DaoModule.java index 9eb8fcad164..4649f70ecc2 100644 --- a/sonar-db/src/main/java/org/sonar/db/DaoModule.java +++ b/sonar-db/src/main/java/org/sonar/db/DaoModule.java @@ -29,7 +29,7 @@ import org.sonar.db.component.ComponentDao; import org.sonar.db.component.ComponentLinkDao; import org.sonar.db.component.ResourceDao; import org.sonar.db.component.ResourceIndexDao; -import org.sonar.db.component.ResourceKeyUpdaterDao; +import org.sonar.db.component.ComponentKeyUpdaterDao; import org.sonar.db.component.SnapshotDao; import org.sonar.db.dashboard.ActiveDashboardDao; import org.sonar.db.dashboard.DashboardDao; @@ -109,7 +109,7 @@ public class DaoModule extends Module { ActiveRuleDao.class, ResourceIndexDao.class, ResourceDao.class, - ResourceKeyUpdaterDao.class, + ComponentKeyUpdaterDao.class, RoleDao.class, SnapshotDao.class, UserDao.class, diff --git a/sonar-db/src/main/java/org/sonar/db/DbClient.java b/sonar-db/src/main/java/org/sonar/db/DbClient.java index e909f36c3d0..e883d1cb62b 100644 --- a/sonar-db/src/main/java/org/sonar/db/DbClient.java +++ b/sonar-db/src/main/java/org/sonar/db/DbClient.java @@ -29,7 +29,7 @@ import org.sonar.db.component.ComponentDao; import org.sonar.db.component.ComponentLinkDao; import org.sonar.db.component.ResourceDao; import org.sonar.db.component.ResourceIndexDao; -import org.sonar.db.component.ResourceKeyUpdaterDao; +import org.sonar.db.component.ComponentKeyUpdaterDao; import org.sonar.db.component.SnapshotDao; import org.sonar.db.dashboard.ActiveDashboardDao; import org.sonar.db.dashboard.DashboardDao; @@ -79,7 +79,7 @@ public class DbClient { private final SnapshotDao snapshotDao; private final ComponentDao componentDao; private final ResourceDao resourceDao; - private final ResourceKeyUpdaterDao resourceKeyUpdaterDao; + private final ComponentKeyUpdaterDao componentKeyUpdaterDao; private final MeasureDao measureDao; private final MeasureFilterDao measureFilterDao; private final MeasureFilterFavouriteDao measureFilterFavouriteDao; @@ -134,7 +134,7 @@ public class DbClient { snapshotDao = getDao(map, SnapshotDao.class); componentDao = getDao(map, ComponentDao.class); resourceDao = getDao(map, ResourceDao.class); - resourceKeyUpdaterDao = getDao(map, ResourceKeyUpdaterDao.class); + componentKeyUpdaterDao = getDao(map, ComponentKeyUpdaterDao.class); measureDao = getDao(map, MeasureDao.class); measureFilterDao = getDao(map, MeasureFilterDao.class); measureFilterFavouriteDao = getDao(map, MeasureFilterFavouriteDao.class); @@ -234,8 +234,8 @@ public class DbClient { return resourceDao; } - public ResourceKeyUpdaterDao resourceKeyUpdaterDao() { - return resourceKeyUpdaterDao; + public ComponentKeyUpdaterDao componentKeyUpdaterDao() { + return componentKeyUpdaterDao; } public MeasureDao measureDao() { diff --git a/sonar-db/src/main/java/org/sonar/db/MyBatis.java b/sonar-db/src/main/java/org/sonar/db/MyBatis.java index 4bd7fe55fd1..45a675457b3 100644 --- a/sonar-db/src/main/java/org/sonar/db/MyBatis.java +++ b/sonar-db/src/main/java/org/sonar/db/MyBatis.java @@ -42,7 +42,7 @@ import org.sonar.db.component.FilePathWithHashDto; import org.sonar.db.component.ResourceDto; import org.sonar.db.component.ResourceIndexDto; import org.sonar.db.component.ResourceIndexMapper; -import org.sonar.db.component.ResourceKeyUpdaterMapper; +import org.sonar.db.component.ComponentKeyUpdaterMapper; import org.sonar.db.component.ResourceMapper; import org.sonar.db.component.SnapshotDto; import org.sonar.db.component.SnapshotMapper; @@ -225,7 +225,7 @@ public class MyBatis { IsAliveMapper.class, LoadedTemplateMapper.class, MeasureFilterMapper.class, MeasureFilterFavouriteMapper.class, PermissionTemplateMapper.class, PermissionTemplateCharacteristicMapper.class, - PropertiesMapper.class, PurgeMapper.class, ResourceKeyUpdaterMapper.class, ResourceIndexMapper.class, RoleMapper.class, RuleMapper.class, + PropertiesMapper.class, PurgeMapper.class, ComponentKeyUpdaterMapper.class, ResourceIndexMapper.class, RoleMapper.class, RuleMapper.class, SchemaMigrationMapper.class, WidgetMapper.class, WidgetPropertyMapper.class, UserMapper.class, GroupMapper.class, UserGroupMapper.class, UserTokenMapper.class, FileSourceMapper.class, diff --git a/sonar-db/src/main/java/org/sonar/db/component/ResourceKeyUpdaterDao.java b/sonar-db/src/main/java/org/sonar/db/component/ComponentKeyUpdaterDao.java similarity index 90% rename from sonar-db/src/main/java/org/sonar/db/component/ResourceKeyUpdaterDao.java rename to sonar-db/src/main/java/org/sonar/db/component/ComponentKeyUpdaterDao.java index 24fd831d68a..a57b6734c76 100644 --- a/sonar-db/src/main/java/org/sonar/db/component/ResourceKeyUpdaterDao.java +++ b/sonar-db/src/main/java/org/sonar/db/component/ComponentKeyUpdaterDao.java @@ -44,18 +44,18 @@ import static org.sonar.core.component.ComponentKeys.isValidModuleKey; * * @since 3.2 */ -public class ResourceKeyUpdaterDao implements Dao { +public class ComponentKeyUpdaterDao implements Dao { private static final Set PROJECT_OR_MODULE_QUALIFIERS = ImmutableSet.of(Qualifiers.PROJECT, Qualifiers.MODULE); private MyBatis mybatis; - public ResourceKeyUpdaterDao(MyBatis mybatis) { + public ComponentKeyUpdaterDao(MyBatis mybatis) { this.mybatis = mybatis; } public void updateKey(String projectUuid, String newKey) { DbSession session = mybatis.openSession(true); - ResourceKeyUpdaterMapper mapper = session.getMapper(ResourceKeyUpdaterMapper.class); + ComponentKeyUpdaterMapper mapper = session.getMapper(ComponentKeyUpdaterMapper.class); try { if (mapper.countResourceByKey(newKey) > 0) { throw new IllegalArgumentException("Impossible to update key: a component with key \"" + newKey + "\" already exists."); @@ -78,7 +78,7 @@ public class ResourceKeyUpdaterDao implements Dao { public Map checkModuleKeysBeforeRenaming(String projectUuid, String stringToReplace, String replacementString) { SqlSession session = mybatis.openSession(false); - ResourceKeyUpdaterMapper mapper = session.getMapper(ResourceKeyUpdaterMapper.class); + ComponentKeyUpdaterMapper mapper = session.getMapper(ComponentKeyUpdaterMapper.class); Map result = Maps.newHashMap(); try { Set modules = collectAllModules(projectUuid, stringToReplace, mapper); @@ -120,7 +120,7 @@ public class ResourceKeyUpdaterDao implements Dao { } public void bulkUpdateKey(DbSession session, String projectUuid, String stringToReplace, String replacementString) { - ResourceKeyUpdaterMapper mapper = session.getMapper(ResourceKeyUpdaterMapper.class); + ComponentKeyUpdaterMapper mapper = session.getMapper(ComponentKeyUpdaterMapper.class); // must SELECT first everything Set modules = collectAllModules(projectUuid, stringToReplace, mapper); checkNewNameOfAllModules(modules, stringToReplace, replacementString, mapper); @@ -143,7 +143,7 @@ public class ResourceKeyUpdaterDao implements Dao { return resource.getKey().replaceAll(stringToReplace, replacementString); } - private static void runBatchUpdateForAllResources(Collection resources, String oldKey, String newKey, ResourceKeyUpdaterMapper mapper) { + private static void runBatchUpdateForAllResources(Collection resources, String oldKey, String newKey, ComponentKeyUpdaterMapper mapper) { for (ResourceDto resource : resources) { String oldResourceKey = resource.getKey(); String newResourceKey = newKey + oldResourceKey.substring(oldKey.length(), oldResourceKey.length()); @@ -157,7 +157,7 @@ public class ResourceKeyUpdaterDao implements Dao { } } - private static Set collectAllModules(String projectUuid, String stringToReplace, ResourceKeyUpdaterMapper mapper) { + private static Set collectAllModules(String projectUuid, String stringToReplace, ComponentKeyUpdaterMapper mapper) { ResourceDto project = mapper.selectProject(projectUuid); Set modules = Sets.newHashSet(); if (project.getKey().contains(stringToReplace)) { @@ -169,7 +169,7 @@ public class ResourceKeyUpdaterDao implements Dao { return modules; } - private static void checkNewNameOfAllModules(Set modules, String stringToReplace, String replacementString, ResourceKeyUpdaterMapper mapper) { + private static void checkNewNameOfAllModules(Set modules, String stringToReplace, String replacementString, ComponentKeyUpdaterMapper mapper) { for (ResourceDto module : modules) { String newKey = computeNewKey(module, stringToReplace, replacementString); checkArgument(isValidModuleKey(newKey), "Malformed key for '%s'. Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit.", newKey); @@ -179,7 +179,7 @@ public class ResourceKeyUpdaterDao implements Dao { } } - private ResourceKeyUpdaterMapper mapper(DbSession dbSession) { - return dbSession.getMapper(ResourceKeyUpdaterMapper.class); + private static ComponentKeyUpdaterMapper mapper(DbSession dbSession) { + return dbSession.getMapper(ComponentKeyUpdaterMapper.class); } } diff --git a/sonar-db/src/main/java/org/sonar/db/component/ResourceKeyUpdaterMapper.java b/sonar-db/src/main/java/org/sonar/db/component/ComponentKeyUpdaterMapper.java similarity index 96% rename from sonar-db/src/main/java/org/sonar/db/component/ResourceKeyUpdaterMapper.java rename to sonar-db/src/main/java/org/sonar/db/component/ComponentKeyUpdaterMapper.java index c38ee177cf1..87f44b1ba83 100644 --- a/sonar-db/src/main/java/org/sonar/db/component/ResourceKeyUpdaterMapper.java +++ b/sonar-db/src/main/java/org/sonar/db/component/ComponentKeyUpdaterMapper.java @@ -25,7 +25,7 @@ import org.apache.ibatis.annotations.Param; /** * @since 3.2 */ -public interface ResourceKeyUpdaterMapper { +public interface ComponentKeyUpdaterMapper { int countResourceByKey(String key); diff --git a/sonar-db/src/main/resources/org/sonar/db/component/ResourceKeyUpdaterMapper.xml b/sonar-db/src/main/resources/org/sonar/db/component/ComponentKeyUpdaterMapper.xml similarity index 95% rename from sonar-db/src/main/resources/org/sonar/db/component/ResourceKeyUpdaterMapper.xml rename to sonar-db/src/main/resources/org/sonar/db/component/ComponentKeyUpdaterMapper.xml index 0d6bd0f1b6c..c1adecc5f45 100644 --- a/sonar-db/src/main/resources/org/sonar/db/component/ResourceKeyUpdaterMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/component/ComponentKeyUpdaterMapper.xml @@ -1,7 +1,7 @@ - + diff --git a/sonar-db/src/test/java/org/sonar/db/component/ResourceKeyUpdaterDaoTest.java b/sonar-db/src/test/java/org/sonar/db/component/ComponentKeyUpdaterDaoTest.java similarity index 97% rename from sonar-db/src/test/java/org/sonar/db/component/ResourceKeyUpdaterDaoTest.java rename to sonar-db/src/test/java/org/sonar/db/component/ComponentKeyUpdaterDaoTest.java index fc6fe33e731..518871a4d35 100644 --- a/sonar-db/src/test/java/org/sonar/db/component/ResourceKeyUpdaterDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/component/ComponentKeyUpdaterDaoTest.java @@ -34,7 +34,7 @@ import static org.assertj.core.api.Assertions.entry; import static org.sonar.db.component.ComponentTesting.newFileDto; import static org.sonar.db.component.ComponentTesting.newProjectDto; -public class ResourceKeyUpdaterDaoTest { +public class ComponentKeyUpdaterDaoTest { @Rule public ExpectedException thrown = ExpectedException.none(); @@ -44,7 +44,7 @@ public class ResourceKeyUpdaterDaoTest { private DbSession dbSession = db.getSession(); ComponentDbTester componentDb = new ComponentDbTester(db); - ResourceKeyUpdaterDao underTest = db.getDbClient().resourceKeyUpdaterDao(); + ComponentKeyUpdaterDao underTest = db.getDbClient().componentKeyUpdaterDao(); @Test public void shouldUpdateKey() { diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceKeyUpdaterDaoTest/shared.xml b/sonar-db/src/test/resources/org/sonar/db/component/ComponentKeyUpdaterDaoTest/shared.xml similarity index 100% rename from sonar-db/src/test/resources/org/sonar/db/component/ResourceKeyUpdaterDaoTest/shared.xml rename to sonar-db/src/test/resources/org/sonar/db/component/ComponentKeyUpdaterDaoTest/shared.xml diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceKeyUpdaterDaoTest/shouldBulkUpdateKey-result.xml b/sonar-db/src/test/resources/org/sonar/db/component/ComponentKeyUpdaterDaoTest/shouldBulkUpdateKey-result.xml similarity index 100% rename from sonar-db/src/test/resources/org/sonar/db/component/ResourceKeyUpdaterDaoTest/shouldBulkUpdateKey-result.xml rename to sonar-db/src/test/resources/org/sonar/db/component/ComponentKeyUpdaterDaoTest/shouldBulkUpdateKey-result.xml diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceKeyUpdaterDaoTest/shouldBulkUpdateKeyOnOnlyOneSubmodule-result.xml b/sonar-db/src/test/resources/org/sonar/db/component/ComponentKeyUpdaterDaoTest/shouldBulkUpdateKeyOnOnlyOneSubmodule-result.xml similarity index 100% rename from sonar-db/src/test/resources/org/sonar/db/component/ResourceKeyUpdaterDaoTest/shouldBulkUpdateKeyOnOnlyOneSubmodule-result.xml rename to sonar-db/src/test/resources/org/sonar/db/component/ComponentKeyUpdaterDaoTest/shouldBulkUpdateKeyOnOnlyOneSubmodule-result.xml diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceKeyUpdaterDaoTest/shouldNotUpdateAllSubmodules-result.xml b/sonar-db/src/test/resources/org/sonar/db/component/ComponentKeyUpdaterDaoTest/shouldNotUpdateAllSubmodules-result.xml similarity index 100% rename from sonar-db/src/test/resources/org/sonar/db/component/ResourceKeyUpdaterDaoTest/shouldNotUpdateAllSubmodules-result.xml rename to sonar-db/src/test/resources/org/sonar/db/component/ComponentKeyUpdaterDaoTest/shouldNotUpdateAllSubmodules-result.xml diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceKeyUpdaterDaoTest/shouldNotUpdateAllSubmodules.xml b/sonar-db/src/test/resources/org/sonar/db/component/ComponentKeyUpdaterDaoTest/shouldNotUpdateAllSubmodules.xml similarity index 100% rename from sonar-db/src/test/resources/org/sonar/db/component/ResourceKeyUpdaterDaoTest/shouldNotUpdateAllSubmodules.xml rename to sonar-db/src/test/resources/org/sonar/db/component/ComponentKeyUpdaterDaoTest/shouldNotUpdateAllSubmodules.xml diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceKeyUpdaterDaoTest/shouldUpdateKey-result.xml b/sonar-db/src/test/resources/org/sonar/db/component/ComponentKeyUpdaterDaoTest/shouldUpdateKey-result.xml similarity index 100% rename from sonar-db/src/test/resources/org/sonar/db/component/ResourceKeyUpdaterDaoTest/shouldUpdateKey-result.xml rename to sonar-db/src/test/resources/org/sonar/db/component/ComponentKeyUpdaterDaoTest/shouldUpdateKey-result.xml -- 2.39.5