]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6471 Remove BaseDao from GroupDao
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Tue, 19 May 2015 08:32:28 +0000 (10:32 +0200)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Fri, 22 May 2015 13:25:20 +0000 (15:25 +0200)
server/sonar-server/src/main/java/org/sonar/server/user/UserUpdater.java
server/sonar-server/src/main/java/org/sonar/server/user/db/GroupDao.java
server/sonar-server/src/test/java/org/sonar/server/user/db/GroupDaoTest.java

index a5de8393e3b904cd07cca99b7db51816aa5ecd04..9683ecc1485db20a19b7592278853233b21c7add 100644 (file)
@@ -312,7 +312,7 @@ public class UserUpdater {
         return input != null && input.getKey().equals(defaultGroup);
       }
     })) {
-      GroupDto groupDto = dbClient.groupDao().getByKey(dbSession, defaultGroup);
+      GroupDto groupDto = dbClient.groupDao().selectByKey(dbSession, defaultGroup);
       dbClient.userGroupDao().insert(dbSession, new UserGroupDto().setUserId(userDto.getId()).setGroupId(groupDto.getId()));
     }
   }
index 56210ce94340f1f8ea482bf43c4430f22dc2b90d..e8ae651cc2f7dd145d5577bd9fb6039e762d4cd4 100644 (file)
 package org.sonar.server.user.db;
 
 import org.sonar.api.utils.System2;
+import org.sonar.core.persistence.DaoComponent;
 import org.sonar.core.persistence.DbSession;
 import org.sonar.core.user.GroupDto;
 import org.sonar.core.user.GroupMapper;
-import org.sonar.server.db.BaseDao;
 
+import java.util.Date;
 import java.util.List;
 
 /**
  * @since 3.2
  */
-public class GroupDao extends BaseDao<GroupMapper, GroupDto, String> {
+public class GroupDao implements DaoComponent {
+
+  private System2 system;
 
   public GroupDao(System2 system) {
-    super(GroupMapper.class, system);
+    this.system = system;
   }
 
-  @Override
-  protected GroupDto doGetNullableByKey(DbSession session, String key) {
+  public GroupDto selectByKey(DbSession session, String key) {
     return mapper(session).selectByKey(key);
   }
 
-  @Override
-  protected GroupDto doInsert(DbSession session, GroupDto item) {
+  public GroupDto insert(DbSession session, GroupDto item) {
+    Date createdAt = new Date(system.now());
+    item.setCreatedAt(createdAt)
+      .setUpdatedAt(createdAt);
     mapper(session).insert(item);
     return item;
   }
@@ -52,4 +56,7 @@ public class GroupDao extends BaseDao<GroupMapper, GroupDto, String> {
     return mapper(session).selectByUserLogin(login);
   }
 
+  private GroupMapper mapper(DbSession session) {
+    return session.getMapper(GroupMapper.class);
+  }
 }
index fc2baa3dd1c370ccbdc7c40137b5986d947fbd38..ca20818864c75c7a05cf451b49b642f262b1eed2 100644 (file)
@@ -55,7 +55,7 @@ public class GroupDaoTest extends AbstractDaoTestCase {
   public void select_by_key() {
     setupData("select_by_key");
 
-    GroupDto group = new GroupDao(system2).getByKey(session, "sonar-users");
+    GroupDto group = new GroupDao(system2).selectByKey(session, "sonar-users");
     assertThat(group).isNotNull();
     assertThat(group.getId()).isEqualTo(1L);
     assertThat(group.getName()).isEqualTo("sonar-users");