From ddb80f56a69ee22e361766ecaffcf0baed979316 Mon Sep 17 00:00:00 2001 From: Aindriu Lavelle Date: Mon, 8 Apr 2024 14:25:56 +0100 Subject: [PATCH] Improve cross DB compatibility by using jpql Signed-off-by: Aindriu Lavelle --- .../java/io/aiven/klaw/helpers/db/rdbms/SelectDataJdbc.java | 2 +- core/src/main/java/io/aiven/klaw/repository/AclRepo.java | 6 +----- .../io/aiven/klaw/helpers/db/rdbms/SelectDataJdbcTest.java | 5 +++-- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/io/aiven/klaw/helpers/db/rdbms/SelectDataJdbc.java b/core/src/main/java/io/aiven/klaw/helpers/db/rdbms/SelectDataJdbc.java index 3eb5bfa2dd..6901953732 100644 --- a/core/src/main/java/io/aiven/klaw/helpers/db/rdbms/SelectDataJdbc.java +++ b/core/src/main/java/io/aiven/klaw/helpers/db/rdbms/SelectDataJdbc.java @@ -109,7 +109,7 @@ public boolean existsAclRequest( } public boolean existsAclSslInTeam(int teamId, int tenantId, String aclSsl) { - return aclRepo.existsAclSslInTeamInTenant(teamId, tenantId, aclSsl); + return aclRepo.existsByTeamIdAndTenantIdAndAclssl(teamId, tenantId, aclSsl); } public boolean existsSpecificAclRequest( diff --git a/core/src/main/java/io/aiven/klaw/repository/AclRepo.java b/core/src/main/java/io/aiven/klaw/repository/AclRepo.java index efa547b425..d1bd3038f1 100644 --- a/core/src/main/java/io/aiven/klaw/repository/AclRepo.java +++ b/core/src/main/java/io/aiven/klaw/repository/AclRepo.java @@ -44,11 +44,7 @@ boolean existsByTeamIdNotAndTenantIdAndConsumergroup( boolean existsByEnvironmentAndTenantId( @Param("envId") String envId, @Param("tenantId") Integer tenantId); - @Query( - value = - "select count(*) > 0 from kwacls where teamid = :teamId and tenantid = :tenantId and aclssl = :aclSsl", - nativeQuery = true) - boolean existsAclSslInTeamInTenant(Integer teamId, Integer tenantId, String aclSsl); + boolean existsByTeamIdAndTenantIdAndAclssl(Integer teamId, Integer tenantId, String aclSsl); @Query( value = "select count(*) from kwacls where env = :envId and tenantid = :tenantId", diff --git a/core/src/test/java/io/aiven/klaw/helpers/db/rdbms/SelectDataJdbcTest.java b/core/src/test/java/io/aiven/klaw/helpers/db/rdbms/SelectDataJdbcTest.java index 3750336ad4..2fb1aaec73 100644 --- a/core/src/test/java/io/aiven/klaw/helpers/db/rdbms/SelectDataJdbcTest.java +++ b/core/src/test/java/io/aiven/klaw/helpers/db/rdbms/SelectDataJdbcTest.java @@ -359,11 +359,12 @@ public static Stream doesAclExist() { public void doesAclSslExistInTeam( int teamId, int tenantId, String aclSsl, boolean expectedResult) { - when(aclRepo.existsAclSslInTeamInTenant(teamId, tenantId, aclSsl)).thenReturn(expectedResult); + when(aclRepo.existsByTeamIdAndTenantIdAndAclssl(teamId, tenantId, aclSsl)) + .thenReturn(expectedResult); assertThat(selectData.existsAclSslInTeam(teamId, tenantId, aclSsl)).isEqualTo(expectedResult); - verify(aclRepo, times(1)).existsAclSslInTeamInTenant(teamId, tenantId, aclSsl); + verify(aclRepo, times(1)).existsByTeamIdAndTenantIdAndAclssl(teamId, tenantId, aclSsl); } public static Stream doesAclSslExistInTeam() {