-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SONAR-23978 Add DAO for user_ai_tool_usages table
- Loading branch information
1 parent
e118109
commit eb6c821
Showing
9 changed files
with
287 additions
and
0 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
server/sonar-db-dao/src/it/java/org/sonar/db/user/ai/UserAiToolUsageDaoIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* SonarQube | ||
* Copyright (C) 2009-2024 SonarSource SA | ||
* mailto:info 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.user.ai; | ||
|
||
import java.util.stream.IntStream; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
import org.sonar.db.DbSession; | ||
import org.sonar.db.DbTester; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.tuple; | ||
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; | ||
|
||
class UserAiToolUsageDaoIT { | ||
@RegisterExtension | ||
private final DbTester db = DbTester.create(); | ||
|
||
private final DbSession dbSession = db.getSession(); | ||
|
||
private final UserAiToolUsageDao underTest = db.getDbClient().userAiToolUsageDao(); | ||
|
||
@Test | ||
void insert_shouldSaveSingleEntry() { | ||
UserAiToolUsageDto dto = new UserAiToolUsageDto() | ||
.setUuid("uuid") | ||
.setUserUuid("userUuid") | ||
.setActivatedAt(1L) | ||
.setLastActivityAt(2L); | ||
|
||
underTest.insert(dbSession, dto); | ||
|
||
assertThat(underTest.selectAll(dbSession)) | ||
.extracting(UserAiToolUsageDto::getUuid, UserAiToolUsageDto::getUserUuid, UserAiToolUsageDto::getActivatedAt, UserAiToolUsageDto::getLastActivityAt) | ||
.containsExactly(tuple("uuid", "userUuid", 1L, 2L)); | ||
} | ||
|
||
@Test | ||
void insert_shouldSaveMultipleEntry() { | ||
IntStream.range(0, 10).forEach(i -> { | ||
UserAiToolUsageDto dto = new UserAiToolUsageDto() | ||
.setUuid("uuid" + i) | ||
.setUserUuid("userUuid" + i) | ||
.setActivatedAt(1L + i) | ||
.setLastActivityAt(2L + i); | ||
underTest.insert(dbSession, dto); | ||
}); | ||
|
||
assertThat(underTest.selectAll(dbSession)) | ||
.hasSize(10); | ||
} | ||
|
||
@Test | ||
void select_whenLastActivityIsMissing_shouldReturnLastActivityEmpty() { | ||
UserAiToolUsageDto dto = new UserAiToolUsageDto() | ||
.setUuid("uuid") | ||
.setUserUuid("userUuid") | ||
.setActivatedAt(1L); | ||
|
||
underTest.insert(dbSession, dto); | ||
|
||
assertThat(underTest.selectAll(dbSession)) | ||
.extracting(UserAiToolUsageDto::getUuid, UserAiToolUsageDto::getUserUuid, UserAiToolUsageDto::getActivatedAt, UserAiToolUsageDto::getLastActivityAt) | ||
.containsExactly(tuple("uuid", "userUuid", 1L, null)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
server/sonar-db-dao/src/main/java/org/sonar/db/user/ai/UserAiToolUsageDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* SonarQube | ||
* Copyright (C) 2009-2024 SonarSource SA | ||
* mailto:info 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.user.ai; | ||
|
||
import java.util.List; | ||
import org.sonar.db.Dao; | ||
import org.sonar.db.DbSession; | ||
|
||
public class UserAiToolUsageDao implements Dao { | ||
|
||
public void insert(DbSession dbSession, UserAiToolUsageDto userAiToolUsageDto) { | ||
mapper(dbSession).insert(userAiToolUsageDto); | ||
} | ||
|
||
public List<UserAiToolUsageDto> selectAll(DbSession dbSession) { | ||
return mapper(dbSession).selectAll(); | ||
} | ||
|
||
private static UserAiToolUsageMapper mapper(DbSession session) { | ||
return session.getMapper(UserAiToolUsageMapper.class); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
server/sonar-db-dao/src/main/java/org/sonar/db/user/ai/UserAiToolUsageDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* SonarQube | ||
* Copyright (C) 2009-2024 SonarSource SA | ||
* mailto:info 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.user.ai; | ||
|
||
import javax.annotation.CheckForNull; | ||
import javax.annotation.Nullable; | ||
|
||
public class UserAiToolUsageDto { | ||
|
||
private String uuid = null; | ||
private String userUuid = null; | ||
private Long activatedAt = null; | ||
private Long lastActivityAt = null; | ||
|
||
public String getUuid() { | ||
return uuid; | ||
} | ||
|
||
public UserAiToolUsageDto setUuid(String uuid) { | ||
this.uuid = uuid; | ||
return this; | ||
} | ||
|
||
public String getUserUuid() { | ||
return userUuid; | ||
} | ||
|
||
public UserAiToolUsageDto setUserUuid(String userUuid) { | ||
this.userUuid = userUuid; | ||
return this; | ||
} | ||
|
||
public Long getActivatedAt() { | ||
return activatedAt; | ||
} | ||
|
||
public UserAiToolUsageDto setActivatedAt(Long activatedAt) { | ||
this.activatedAt = activatedAt; | ||
return this; | ||
} | ||
|
||
@CheckForNull | ||
public Long getLastActivityAt() { | ||
return lastActivityAt; | ||
} | ||
|
||
public UserAiToolUsageDto setLastActivityAt(@Nullable Long lastActivityAt) { | ||
this.lastActivityAt = lastActivityAt; | ||
return this; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
server/sonar-db-dao/src/main/java/org/sonar/db/user/ai/UserAiToolUsageMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* SonarQube | ||
* Copyright (C) 2009-2024 SonarSource SA | ||
* mailto:info 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.user.ai; | ||
|
||
import java.util.List; | ||
|
||
public interface UserAiToolUsageMapper { | ||
|
||
void insert(UserAiToolUsageDto userAiToolUsageDto); | ||
|
||
List<UserAiToolUsageDto> selectAll(); | ||
} |
23 changes: 23 additions & 0 deletions
23
server/sonar-db-dao/src/main/java/org/sonar/db/user/ai/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* SonarQube | ||
* Copyright (C) 2009-2024 SonarSource SA | ||
* mailto:info 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. | ||
*/ | ||
@ParametersAreNonnullByDefault | ||
package org.sonar.db.user.ai; | ||
|
||
import javax.annotation.ParametersAreNonnullByDefault; |
35 changes: 35 additions & 0 deletions
35
server/sonar-db-dao/src/main/resources/org/sonar/db/user/ai/UserAiToolUsageMapper.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd"> | ||
|
||
<mapper namespace="org.sonar.db.user.ai.UserAiToolUsageMapper"> | ||
|
||
<sql id="columns"> | ||
uatu.uuid as uuid, | ||
uatu.user_uuid as "userUuid", | ||
uatu.activated_at as "activatedAt", | ||
uatu.last_activity_at as "lastActivityAt" | ||
</sql> | ||
|
||
<select id="selectAll" parameterType="String" resultType="org.sonar.db.user.ai.UserAiToolUsageDto"> | ||
select | ||
<include refid="columns"/> | ||
from user_ai_tool_usages uatu | ||
</select> | ||
|
||
<insert id="insert" parameterType="org.sonar.db.user.ai.UserAiToolUsageDto" useGeneratedKeys="false"> | ||
insert into user_ai_tool_usages | ||
( | ||
uuid, | ||
user_uuid, | ||
activated_at, | ||
last_activity_at | ||
) | ||
values ( | ||
#{uuid, jdbcType=VARCHAR}, | ||
#{userUuid, jdbcType=VARCHAR}, | ||
#{activatedAt, jdbcType=BIGINT}, | ||
#{lastActivityAt, jdbcType=BIGINT} | ||
) | ||
</insert> | ||
|
||
</mapper> |